Utils/Daemon: Add instance() and logReopen() member and bind SIGHUP to logReopen()
[senf.git] / Utils / Daemon / Daemon.hh
index 25b8e60..76e10e7 100644 (file)
@@ -28,6 +28,7 @@
 
 // Custom includes
 #include <boost/utility.hpp>
+#include "../Logger/SenfLog.hh"
 
 //#include "Daemon.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
@@ -103,6 +104,8 @@ namespace senf {
     class Daemon : boost::noncopyable
     {
     public:
+        SENF_LOG_CLASS_AREA();
+
         ///////////////////////////////////////////////////////////////////////////
         // Types
         
@@ -154,9 +157,13 @@ namespace senf {
                                              successful startup. */
 
         int argc();                     ///< Access command line parameter count
-        char ** argv();           ///< Access command line parameters
+        char ** argv();                 ///< Access command line parameters
+
+        static void exit(unsigned code=0); ///< Terminate daemon with failure
 
-        static void exit(unsigned code=0);     ///< Terminate daemon with failure
+        void logReopen();               ///< Reopen the log files
+                                        /**< This is used when rotating the logs. By default,
+                                             SIGHUP calls logReopen. */
 
         ///\}
         
@@ -164,6 +171,8 @@ namespace senf {
                                         /**< Normally not called directly but from the
                                              \ref SENF_DAEMON_MAIN macro. */
 
+        static Daemon & instance();     ///< Return the Daemon instance
+
     protected:
         Daemon();
 
@@ -195,10 +204,10 @@ namespace senf {
                                              This member is only called, if the default main()
                                              implementation is not overridden. */
     private:
-
         void openLog();
         void fork();
         bool pidfileCreate();
+        void installSighandlers();
 
         int argc_;
         char ** argv_;
@@ -212,6 +221,8 @@ namespace senf {
         bool pidfileCreated_;
 
         bool detached_;
+
+        static Daemon * instance_;
     };
 
     /** \brief Provide \c main() function