00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00026 #ifndef OW32_Service_h
00027 #define OW32_Service_h
00028
00029 #include <OW32/OW32Libs.h>
00030 #include <OW32/EventLog.h>
00031 #include <OW32/tstl.h>
00032
00033 namespace OW32
00034 {
00035
00039 class OW32_LIB_EXPORT CService
00040 {
00041 private:
00042 bool m_DebugFlag;
00043 bool m_Interactive;
00044
00045 LPCTSTR m_ServiceName;
00046 LPCTSTR m_ServiceDescription;
00047 DWORD m_dwDesiredAccess;
00048 DWORD m_dwServiceType;
00049 DWORD m_dwStartType;
00050 DWORD m_dwErrorControl;
00051 LPCTSTR m_lpBinaryPathName;
00052 LPCTSTR m_lpLoadOrderGroup;
00053 LPCTSTR m_lpDependencies;
00054 LPCTSTR m_lpServiceStartName;
00055 LPCTSTR m_lpPassword;
00056
00057 static CService* m_pThis;
00058
00059 public:
00060
00061
00062 CService(LPCTSTR pServiceName, LPCTSTR pServiceDescription,
00063 DWORD dwDesiredAccess = STANDARD_RIGHTS_REQUIRED,
00064 DWORD dwServiceType = SERVICE_WIN32_OWN_PROCESS,
00065 DWORD dwStartType = SERVICE_AUTO_START,
00066 DWORD dwErrorControl = SERVICE_ERROR_NORMAL,
00067 LPCTSTR lpBinaryPathName = NULL,
00068 LPCTSTR lpLoadOrderGroup = NULL,
00069 LPCTSTR lpDependencies = NULL,
00070 LPCTSTR lpServiceStartName = NULL,
00071 LPCTSTR lpPassword = NULL) :
00072 m_ServiceName(pServiceName),
00073 m_ServiceDescription(pServiceDescription),
00074 m_dwDesiredAccess(dwDesiredAccess),
00075 m_dwServiceType(dwServiceType),
00076 m_dwStartType(dwStartType),
00077 m_dwErrorControl(dwErrorControl),
00078 m_lpBinaryPathName(lpBinaryPathName),
00079 m_lpLoadOrderGroup(lpLoadOrderGroup),
00080 m_lpDependencies(lpDependencies),
00081 m_lpServiceStartName(lpServiceStartName),
00082 m_lpPassword(lpPassword),
00083 m_hServiceStatus(NULL),
00084 m_DebugFlag(false),
00085 m_Interactive(false)
00086 {
00087
00088 m_pThis = this;
00089 }
00090
00091
00092 virtual void Install();
00093 virtual void Uninstall();
00094
00095
00096 virtual LPCTSTR GetServiceName() const { return m_ServiceName; }
00097
00098
00099
00100
00101
00102 int _tmain(int argc, TCHAR* argv[]);
00103
00104
00105 virtual DWORD ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv) = 0;
00106
00107
00108 virtual void ServiceHandler(DWORD fdwControl);
00109
00110 bool InDebugMode() { return m_DebugFlag; }
00111 void SetDebugMode(bool bDebugFlag) { m_DebugFlag = bDebugFlag; }
00112 bool InInteractiveMode() { return m_Interactive; }
00113 void SetInteractiveMode(bool bInteractive) { m_Interactive = bInteractive; }
00114
00115
00116 virtual void Stop() {}
00117
00118 virtual void Pause() {}
00119
00120 virtual void Continue() {}
00121
00122 virtual void Shutdown() {}
00123
00124 virtual void Interrogate() {
00125 UpdateSCM(SERVICE_RUNNING);
00126 }
00127
00128
00129 void UpdateSCM(DWORD state, DWORD dwCheckPoint = 0, DWORD dwWaitHint = 1000);
00130
00131
00132
00133 SERVICE_STATUS_HANDLE m_hServiceStatus;
00134
00135
00136 CEventLog m_SysLog;
00137
00138 private:
00139
00140 static void WINAPI ServiceMainCallback(DWORD dwArgc, LPTSTR* lpszArgv);
00141 static void WINAPI ServiceHandlerCallback(DWORD fdwControl);
00142 };
00143
00144 }
00145
00146 #endif // OW32_Service_h