Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* 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. |
| 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 | #include <windows.h> |
| 31 | |
| 32 | namespace rfb { |
| 33 | |
| 34 | namespace win32 { |
| 35 | |
| 36 | // |
| 37 | // -=- Service |
| 38 | // |
| 39 | |
| 40 | // Application base-class for services. |
| 41 | |
| 42 | class Service { |
| 43 | public: |
| 44 | |
| 45 | Service(const TCHAR* name_); |
| 46 | virtual ~Service(); |
| 47 | |
| 48 | const TCHAR* getName() {return name;} |
| 49 | SERVICE_STATUS& getStatus() {return status;} |
| 50 | |
| 51 | void setStatus(DWORD status); |
| 52 | void setStatus(); |
| 53 | |
| 54 | // - Start the service, having initialised it |
| 55 | void start(); |
| 56 | |
| 57 | // - Service main procedure - override to implement a service |
| 58 | virtual DWORD serviceMain(int argc, TCHAR* argv[]) = 0; |
| 59 | |
| 60 | // - Service control notifications |
| 61 | |
| 62 | // To get notified when the OS is shutting down |
| 63 | virtual void osShuttingDown() {}; |
| 64 | |
| 65 | // To get notified when the service parameters change |
| 66 | virtual void readParams() {}; |
| 67 | |
| 68 | // To cause the serviceMain() routine to return |
| 69 | virtual void stop() {}; |
| 70 | |
| 71 | public: |
| 72 | SERVICE_STATUS_HANDLE status_handle; |
| 73 | SERVICE_STATUS status; |
| 74 | protected: |
| 75 | const TCHAR* name; |
| 76 | }; |
| 77 | |
| 78 | class ServiceHandle { |
| 79 | public: |
| 80 | ServiceHandle(SC_HANDLE h) : handle(h) {} |
| 81 | ~ServiceHandle() {CloseServiceHandle(handle);} |
| 82 | operator SC_HANDLE() const {return handle;} |
| 83 | protected: |
| 84 | SC_HANDLE handle; |
| 85 | }; |
| 86 | |
| 87 | // -=- Routines used by desktop back-end code to manage desktops/window stations |
| 88 | |
| 89 | // Returns false under Win9x |
| 90 | bool desktopChangeRequired(); |
| 91 | |
| 92 | // Returns true under Win9x |
| 93 | bool changeDesktop(); |
| 94 | |
| 95 | // -=- Routines used by the SInput Keyboard class to emulate Ctrl-Alt-Del |
| 96 | // Returns false under Win9x |
| 97 | bool emulateCtrlAltDel(); |
| 98 | |
| 99 | // -=- Routines to initialise the Event Log target Logger |
| 100 | // Returns false under Win9x |
| 101 | bool initEventLogLogger(const TCHAR* srcname); |
| 102 | |
| 103 | // -=- Routines to register/unregister the service |
| 104 | // These routines also take care of registering the required |
| 105 | // event source information, etc. |
| 106 | // *** should really accept TCHAR argv |
| 107 | |
Adam Tkac | 8fb6ac0 | 2010-06-25 11:24:27 +0000 | [diff] [blame] | 108 | bool registerService(const TCHAR* name, const TCHAR* desc, int argc, char** argv); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 109 | bool unregisterService(const TCHAR* name); |
| 110 | |
| 111 | bool startService(const TCHAR* name); |
| 112 | bool stopService(const TCHAR* name); |
| 113 | |
| 114 | // -=- Get the state of the named service (one of the NT service state values) |
| 115 | DWORD getServiceState(const TCHAR* name); |
| 116 | |
| 117 | // -=- Convert a supplied service state value to a printable string e.g. Running, Stopped... |
| 118 | // The caller must delete the returned string buffer |
| 119 | char* serviceStateName(DWORD state); |
| 120 | |
| 121 | // -=- Routine to determine whether the host process is running a service |
| 122 | bool isServiceProcess(); |
| 123 | |
| 124 | }; |
| 125 | |
| 126 | }; |
| 127 | |
| 128 | #endif // __RFB_WIN32_SERVICE_NT_H__ |