FreeRDP-WebConnect WebSockets gateway  1.0.0.167
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
NTService.hpp
1 /* vim: set et ts=4 sw=4 cindent:
2  *
3  * FreeRDP-WebConnect,
4  * A gateway for seamless access to your RDP-Sessions in any HTML5-compliant browser.
5  *
6  * Copyright 2012 Fritz Elfert <wsgate@fritz-elfert.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef _NTSERVICE_H_
21 #define _NTSERVICE_H_
22 
23 #if defined(_WIN32) || defined(DOXYGEN_RUN)
24 
25 #include <string>
26 
27 namespace wsgate {
28 
37  class NTService {
38 
39  public:
40 
41  enum {
42  SERVICE_CONTROL_USER = 128
43  };
44 
50  NTService(const std::string & displayName, const std::string & serviceName = "");
51 
52  // Destructor
53  virtual ~NTService();
54 
61  bool IsServiceInstalled() const;
62 
68  void Start() const;
69 
75  void Stop() const;
76 
82  void InstallService() const;
83 
89  void UninstallService() const;
90 
97  bool Execute() const;
98 
103  uint32_t ServiceExitCode() const;
104 
105  protected:
114  virtual bool OnServiceInit(uint32_t argc, char **argv);
121  virtual void RunService();
128  virtual bool OnServiceStop();
135  virtual bool OnServiceInterrogate();
142  virtual bool OnServicePause();
149  virtual bool OnServiceContinue();
156  virtual bool OnServiceShutdown();
163  virtual bool OnServiceParamChange();
170  virtual bool OnServiceDeviceEvent();
177  virtual bool OnServiceHardwareProfileChange();
184  virtual bool OnServicePowerEvent();
191  virtual bool OnServiceSessionChange();
199  virtual bool OnServiceUserControl(uint32_t opcode);
200 
206  std::string StatusString(uint32_t state);
212  std::string CtrlString(uint32_t ctrl);
217  void AddDependency(const std::string &s);
222  void SetServiceStatus(uint32_t state);
226  void ReportServiceStatus();
227 
228  // data members
229  protected:
235  SERVICE_STATUS m_ServiceStatus;
237  std::string m_sServiceName;
239  std::string m_sDisplayName;
241  std::string m_sDescription;
243  std::string m_sModulePath;
244 
245  private:
246  bool InitializeService(uint32_t argc, char **argv);
247  void ServiceMain(uint32_t argc, char **argv);
248  uint32_t ControlHandler(uint32_t opcode, uint32_t eventType, void *eventData);
249 
250  std::string m_sDependencies;
251  SERVICE_STATUS_HANDLE m_hServiceStatus;
252 
253 
254  // nasty hack to get object ptr
255  static NTService* m_pSelf;
256 
257  // static callback functions (called from Service-Manager)
258  static void WINAPI _ServiceMain(unsigned long argc, char **argv);
259  static unsigned long WINAPI _ControlHandler(unsigned long opcode,
260  unsigned long eventType, void *eventData, void *context);
261  };
262 
263 }
264 #endif
265 
266 #endif // _NTSERVICE_H_