Service.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_Service_hxx
00024 #define __ccxx_Service_hxx
00025
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/Application.h++>
00028 #include <commonc++/SystemException.h++>
00029
00030 namespace ccxx {
00031
00077 class COMMONCPP_API Service : public Application
00078 {
00079 public:
00080
00092 Service(int argc, char **argv, const String &version,
00093 const String &compileDate = "", const String &compileTime = "");
00094
00096 virtual ~Service();
00097
00098 protected:
00099
00106 inline void setDescription(const String &desc)
00107 { _desc = desc; }
00108
00115 inline void setWorkingDir(const String &dir)
00116 { _workingDir = dir; }
00117
00118
00119
00120 virtual bool processOption(char opt, const String &longOpt,
00121 const char *arg = NULL);
00122
00133 void detach() throw(SystemException);
00134
00140 virtual void run() = 0;
00141
00147 void testShutdown();
00148
00156 virtual void shutdown() = 0;
00157
00159 inline bool isDebug() const
00160 { return(_debug); }
00161
00162 private:
00163
00164 #ifdef CCXX_OS_WINDOWS
00165 static void _serviceMain(int argc, char **argv);
00166 void _serviceInit();
00167 static void _controlHandler(DWORD code);
00168 void _serviceStart() throw(SystemException);
00169 void _serviceStop() throw(SystemException);
00170 void _serviceInstall() throw(SystemException);
00171 void _serviceUninstall() throw(SystemException);
00172 bool _waitForStatus(SC_HANDLE handle, DWORD pending, DWORD final);
00173
00174 SERVICE_STATUS_HANDLE _handle;
00175 SERVICE_STATUS _status;
00176 UINT _oldErrorMode;
00177 #endif
00178
00179 #ifdef CCXX_OS_POSIX
00180 static void _sighandler(int sig);
00181 #endif
00182
00183 String _name;
00184 String _displayName;
00185 String _desc;
00186 bool _shutdown;
00187 bool _debug;
00188 String _pidFile;
00189
00190 #ifdef CCXX_OS_WINDOWS
00191 enum Action { None, Start, Stop, Install, Uninstall } _action;
00192 #endif
00193
00194 String _workingDir;
00195 static Service *_instance;
00196 };
00197
00198 };
00199
00200 #endif // __ccxx_Service_hxx
00201
00202