blob: 691ad95da405d1a0366df21f9754bc210dc43cf9 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 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.
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000024
25#ifndef __RFB_WIN32_SERVICE_H__
26#define __RFB_WIN32_SERVICE_H__
27
28#include <windows.h>
29
30namespace rfb {
31
32 namespace win32 {
33
34 //
35 // -=- Service
36 //
37
38 // Application base-class for services.
39
40 class Service {
41 public:
42
43 Service(const TCHAR* name_);
44 virtual ~Service();
45
46 const TCHAR* getName() {return name;}
47 SERVICE_STATUS& getStatus() {return status;}
48
49 void setStatus(DWORD status);
50 void setStatus();
51
52 // - Start the service, having initialised it
53 void start();
54
55 // - Service main procedure - override to implement a service
56 virtual DWORD serviceMain(int argc, TCHAR* argv[]) = 0;
57
58 // - Service control notifications
59
60 // To get notified when the OS is shutting down
61 virtual void osShuttingDown() {};
62
63 // To get notified when the service parameters change
64 virtual void readParams() {};
65
66 // To cause the serviceMain() routine to return
67 virtual void stop() {};
68
69 public:
70 SERVICE_STATUS_HANDLE status_handle;
71 SERVICE_STATUS status;
72 protected:
73 const TCHAR* name;
74 };
75
76 class ServiceHandle {
77 public:
78 ServiceHandle(SC_HANDLE h) : handle(h) {}
79 ~ServiceHandle() {CloseServiceHandle(handle);}
80 operator SC_HANDLE() const {return handle;}
81 protected:
82 SC_HANDLE handle;
83 };
84
85 // -=- Routines used by desktop back-end code to manage desktops/window stations
86
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000087 bool desktopChangeRequired();
88
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000089 bool changeDesktop();
90
91 // -=- Routines used by the SInput Keyboard class to emulate Ctrl-Alt-Del
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000092 bool emulateCtrlAltDel();
93
94 // -=- Routines to initialise the Event Log target Logger
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000095 bool initEventLogLogger(const TCHAR* srcname);
96
97 // -=- Routines to register/unregister the service
98 // These routines also take care of registering the required
99 // event source information, etc.
100 // *** should really accept TCHAR argv
101
Pierre Ossman018c67e2016-01-12 10:13:17 +0100102 bool registerService(const TCHAR* name, const TCHAR* display,
103 const TCHAR* desc, int argc, char** argv);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000104 bool unregisterService(const TCHAR* name);
105
106 bool startService(const TCHAR* name);
107 bool stopService(const TCHAR* name);
108
109 // -=- Get the state of the named service (one of the NT service state values)
110 DWORD getServiceState(const TCHAR* name);
111
112 // -=- Convert a supplied service state value to a printable string e.g. Running, Stopped...
113 // The caller must delete the returned string buffer
114 char* serviceStateName(DWORD state);
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__