[go: up one dir, main page]

File: WinService.h

package info (click to toggle)
dibbler 0.7.3-1.3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,148 kB
  • ctags: 8,720
  • sloc: cpp: 54,863; sh: 9,389; ansic: 8,659; yacc: 2,570; makefile: 1,061; lex: 842; perl: 49; xml: 6
file content (95 lines) | stat: -rw-r--r-- 2,406 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*                                                                           
 * Dibbler - a portable DHCPv6 
 *                                                                           
 * authors: Tomasz Mrugalski <thomson@klub.com.pl>                           
 *          Marek Senderski <msend@o2.pl>                                    
 *
 * $Id: WinService.h,v 1.9 2005-07-26 00:03:03 thomson Exp $
 *                                                                           
 * Released under GNU GPL v2 licence                                
 *
 */

#ifndef _WINSERVICE_
#define _WINSERVICE_

#include <windows.h>
#include <string>

#define SERVICE_CONTROL_USER 128

typedef enum {
	STATUS,
	START,
	STOP,
	INSTALL,
	UNINSTALL,
    SERVICE,
	RUN,
	HELP,
	INVALID
} EServiceState;

class TWinService
{
 public:
  std::string ServiceDir;
  TWinService(const char* serviceName, const char* dispName,
	      DWORD deviceType=SERVICE_DEMAND_START,
	      char* dependencies=NULL, char* descr=NULL);
  static void WINAPI ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
  static void WINAPI Handler(DWORD dwOpcode);
  void LogEvent(WORD wType, DWORD dwID, const char* pszS1 = NULL,
		const char* pszS2 = NULL, const char* pszS3 = NULL);
  bool IsInstalled();
  bool IsInstalled(const char *name);
  bool Install();
  bool Uninstall();
  bool StartService(); /* invoked to trigger start */
  bool RunService();   /* actual service start and run */
  bool StopService();
  void SetStatus(DWORD dwState);
  bool Initialize();
  void showStatus();
  bool verifyPort();
  int getStatus();
  bool isRunning(const char * name);
  bool isRunning();
  
  virtual void Run();
  virtual bool OnInit();
  virtual void OnStop();
  virtual void OnInterrogate();
  virtual void OnPause();
  virtual void OnContinue();
  virtual void OnShutdown();
  virtual bool OnUserControl(DWORD dwOpcode);
  
  ~TWinService(void);

 protected:
  SERVICE_STATUS Status;
  SERVICE_STATUS_HANDLE	hServiceStatus;
  BOOL IsRunning;
  
  char ServiceName[64];
  int MajorVersion;
  int MinorVersion;
  DWORD ServiceType;
  char* Dependencies;
  char* DisplayName;
  char* descr;
  static TWinService* ServicePtr;
  HANDLE EventSource;
};
#endif

/*
 * $Log: WinService.h,v $
 * Revision 1.9  2005-07-26 00:03:03  thomson
 * Preparation for relase 0.4.1
 *
 * Revision 1.1  2005/07/23 14:33:22  thomson
 * Port for win2k/NT added.
 *
 */