Version: 0.6.0
service.h
1 /******************************************************************************
2  * Project: wxGIS (GIS Server)
3  * Purpose: wxGISService class.
4  * Author: Bishop (aka Barishnikov Dmitriy), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2011 Bishop
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 /*
23 #include "wxgis/base.h"
24 #include "wxgissrv/srv_framework/server.h"
25 
26 class ISysService
27 {
28 protected:
29  virtual ~ISysService(void){};
30  virtual bool Install() = 0;
31  virtual bool Uninstall() = 0;
32  virtual void Run() = 0;
33  virtual void OnStop() = 0;
34  virtual long GetExitCode() = 0;
35 };
36 
37 #ifdef __WXMSW__ //Win
38 
39 #define EVMSG_INSTALLED 0x00000064L
40 #define EVMSG_REMOVED 0x00000065L
41 #define EVMSG_NOTREMOVED 0x00000066L
42 #define EVMSG_CTRLHANDLERNOTINSTALLED 0x00000067L
43 #define EVMSG_FAILEDINIT 0x00000068L
44 #define EVMSG_STARTED 0x00000069L
45 #define EVMSG_BADREQUEST 0x0000006AL
46 #define EVMSG_DEBUG 0x0000006BL
47 #define EVMSG_STOPPED 0x0000006CL
48 
49 #define SERVICE_CONTROL_USER 128
50 
51 #include <windows.h>
52 #include <winnt.h>
53 #include <stdio.h>
54 #include <winsvc.h>
55 //#include "TCHAR.H"
56 
57 class wxGISNTService : public ISysService
58 {
59 public:
60  wxGISNTService(wxString sServiceName);
61  virtual ~wxGISNTService();
62  //IService
63  virtual bool IsInstalled();
64  virtual bool Install();
65  virtual bool Uninstall();
66  virtual void Run();
67  virtual void OnStop();
68  //wxGISNTService
69  virtual bool StartService();
70  virtual void LogEvent(WORD wType, DWORD dwID, const TCHAR* pszS1 = NULL, const TCHAR* pszS2 = NULL, const TCHAR* pszS3 = NULL);
71  virtual void SetStatus(DWORD dwState);
72  virtual bool Initialize();
73  virtual bool OnInit();
74  virtual void OnInterrogate();
75  virtual void OnPause();
76  virtual void OnContinue();
77  virtual void OnShutdown();
78  virtual bool OnUserControl(DWORD dwOpcode);
79  virtual long GetExitCode(){return m_Status.dwWin32ExitCode;};
80 
81  // static member functions
82  static void WINAPI ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
83  static void WINAPI Handler(DWORD dwOpcode);
84 protected:
85 
86  wxString m_sServiceName;
87  int m_iMajorVersion;
88  int m_iMinorVersion;
89  SERVICE_STATUS_HANDLE m_hServiceStatus;
90  SERVICE_STATUS m_Status;
91  bool m_bIsRunning;
92  static wxGISNTService* m_pThis; // nasty hack to get object ptr
93 
94  wxGISServer m_Server;
95  HANDLE m_hEventSource;
96 };
97 
98 #define wxGISService wxGISNTService
99 
100 #else //Lin
101 
102 //#define wxGISService
103 #endif
104 
105 */