OmniEvents
|
00001 // Package : omniEvents 00002 // daemon_windows.h Created : 2004/07/30 00003 // Author : Alex Tingle 00004 // 00005 // Copyright (C) 2004 Alex Tingle. 00006 // 00007 // This file is part of the omniEvents application. 00008 // 00009 // omniEvents is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Lesser General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2.1 of the License, or (at your option) any later version. 00013 // 00014 // omniEvents is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 00024 #ifndef OMNIEVENTS__DAEMON_WINDOWS_H 00025 #define OMNIEVENTS__DAEMON_WINDOWS_H 00026 00027 #ifndef __WIN32__ 00028 # error("This file is only intended for Windows.") 00029 #endif 00030 00031 #include <windows.h> 00032 #include <winsvc.h> 00033 #include <iostream> 00034 00035 namespace OmniEvents { 00036 00040 class Service 00041 { 00042 public: 00043 Service(); 00044 ~Service(); 00045 00046 void start(int& argc,char**& argv); 00047 00048 void tracefile(const char* val); 00049 void pidfile(const char* val); 00050 void foreground(bool val); 00051 00053 void daemonize(); 00054 00056 void runningOk(); 00057 00059 void shutdown(); 00060 00061 // Callbacks. 00062 00064 static void log(const char* message); 00065 00067 static void ctrlHandler(DWORD controlCode); 00068 00069 private: 00070 char* _tracefile; 00071 const char* _regSubKey; 00072 bool _serviceRunning; 00073 int _callCount; 00074 char* _parameters; 00075 char** _argv; 00076 std::ostream* _logstream; 00077 SERVICE_STATUS_HANDLE _serviceStatusHandle; 00078 00079 void Service::setArgcArgv(int& argc,char**& argv); 00080 void install(int argc,char** argv) const; 00081 void uninstall() const; 00082 00084 void readParameters(); 00086 void writeParameters(int argc, char** argv) const; 00087 00088 bool Service::setServiceStatus( 00089 DWORD currentState, 00090 DWORD win32ExitCode, 00091 DWORD serviceSpecificExitCode, 00092 DWORD checkPoint, 00093 DWORD waitHint 00094 ); 00095 00096 }; // class Service 00097 00098 } // end namespace OmniEvents 00099 00100 #endif // OMNIEVENTS__DAEMON_WINDOWS_H 00101