Service.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 }; // namespace ccxx
00199 
00200 #endif // __ccxx_Service_hxx
00201 
00202 /* end of header file */
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3