blob: 164381a167644c6a9fe4e263f128e4c10a71d9ca [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- Service.h
20//
21// Win32 service-mode code.
22// Derive your service from this code and let it handle the annoying Win32
23// service API.
24// The underlying implementation takes care of the differences between
25// Windows NT and Windows 95 based systems
26
27#ifndef __RFB_WIN32_SERVICE_H__
28#define __RFB_WIN32_SERVICE_H__
29
30#define WIN32_LEAN_AND_MEAN
31#include <windows.h>
32
33namespace rfb {
34
35 namespace win32 {
36
37 //
38 // -=- Service
39 //
40
41 // Application base-class for services.
42
43 class Service {
44 public:
45
46 Service(const TCHAR* name_);
47 virtual ~Service();
48
49 const TCHAR* getName() {return name;}
50 SERVICE_STATUS& getStatus() {return status;}
51
52 void setStatus(DWORD status);
53 void setStatus();
54
55 // - Start the service, having initialised it
56 void start();
57
58 // - Service main procedure - override to implement a service
59 virtual DWORD serviceMain(int argc, TCHAR* argv[]) = 0;
60
61 // - Service control notifications
62
63 // To get notified when the OS is shutting down
64 virtual void osShuttingDown() = 0;
65
66 // To get notified when the service parameters change
67 virtual void readParams() = 0;
68
69 // To cause the serviceMain() routine to return
70 virtual void stop() = 0;
71
72 public:
73 SERVICE_STATUS_HANDLE status_handle;
74 SERVICE_STATUS status;
75 protected:
76 const TCHAR* name;
77 };
78
79 class ServiceHandle {
80 public:
81 ServiceHandle(SC_HANDLE h) : handle(h) {}
82 ~ServiceHandle() {CloseServiceHandle(handle);}
83 operator SC_HANDLE() const {return handle;}
84 protected:
85 SC_HANDLE handle;
86 };
87
88 // -=- Routines used by desktop back-end code to manage desktops/window stations
89
90 // Returns false under Win9x
91 bool desktopChangeRequired();
92
93 // Returns true under Win9x
94 bool changeDesktop();
95
96 // -=- Routines used by the SInput Keyboard class to emulate Ctrl-Alt-Del
97 // Returns false under Win9x
98 bool emulateCtrlAltDel();
99
100 // -=- Routines to initialise the Event Log target Logger
101 // Returns false under Win9x
102 bool initEventLogLogger(const TCHAR* srcname);
103
104 // -=- Routines to register/unregister the service
105 // These routines also take care of registering the required
106 // event source information, etc.
107 // *** should really accept TCHAR argv
108
109 bool registerService(const TCHAR* name, const TCHAR* desc, int argc, const char* argv[]);
110 bool unregisterService(const TCHAR* name);
111
112 bool startService(const TCHAR* name);
113 bool stopService(const TCHAR* name);
114 void printServiceStatus(const TCHAR* name);
115
116 // -=- Routine to determine whether the host process is running a service
117 bool isServiceProcess();
118
119 };
120
121};
122
123#endif // __RFB_WIN32_SERVICE_NT_H__