You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Service.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // -=- Service.h
  19. //
  20. // Win32 service-mode code.
  21. // Derive your service from this code and let it handle the annoying Win32
  22. // service API.
  23. #ifndef __RFB_WIN32_SERVICE_H__
  24. #define __RFB_WIN32_SERVICE_H__
  25. #include <windows.h>
  26. namespace rfb {
  27. namespace win32 {
  28. //
  29. // -=- Service
  30. //
  31. // Application base-class for services.
  32. class Service {
  33. public:
  34. Service(const TCHAR* name_);
  35. virtual ~Service();
  36. const TCHAR* getName() {return name;}
  37. SERVICE_STATUS& getStatus() {return status;}
  38. void setStatus(DWORD status);
  39. void setStatus();
  40. // - Start the service, having initialised it
  41. void start();
  42. // - Service main procedure - override to implement a service
  43. virtual DWORD serviceMain(int argc, TCHAR* argv[]) = 0;
  44. // - Service control notifications
  45. // To get notified when the OS is shutting down
  46. virtual void osShuttingDown() {};
  47. // To get notified when the service parameters change
  48. virtual void readParams() {};
  49. // To cause the serviceMain() routine to return
  50. virtual void stop() {};
  51. public:
  52. SERVICE_STATUS_HANDLE status_handle;
  53. SERVICE_STATUS status;
  54. protected:
  55. const TCHAR* name;
  56. };
  57. class ServiceHandle {
  58. public:
  59. ServiceHandle(SC_HANDLE h) : handle(h) {}
  60. ~ServiceHandle() {CloseServiceHandle(handle);}
  61. operator SC_HANDLE() const {return handle;}
  62. protected:
  63. SC_HANDLE handle;
  64. };
  65. // -=- Routines used by desktop back-end code to manage desktops/window stations
  66. bool desktopChangeRequired();
  67. bool changeDesktop();
  68. // -=- Routines used by the SInput Keyboard class to emulate Ctrl-Alt-Del
  69. bool emulateCtrlAltDel();
  70. // -=- Routines to initialise the Event Log target Logger
  71. bool initEventLogLogger(const TCHAR* srcname);
  72. // -=- Routines to register/unregister the service
  73. // These routines also take care of registering the required
  74. // event source information, etc.
  75. // *** should really accept TCHAR argv
  76. bool registerService(const TCHAR* name, const TCHAR* display,
  77. const TCHAR* desc, int argc, char** argv);
  78. bool unregisterService(const TCHAR* name);
  79. bool startService(const TCHAR* name);
  80. bool stopService(const TCHAR* name);
  81. // -=- Get the state of the named service (one of the NT service state values)
  82. DWORD getServiceState(const TCHAR* name);
  83. // -=- Convert a supplied service state value to a printable string e.g. Running, Stopped...
  84. // The caller must delete the returned string buffer
  85. char* serviceStateName(DWORD state);
  86. // -=- Routine to determine whether the host process is running a service
  87. bool isServiceProcess();
  88. };
  89. };
  90. #endif // __RFB_WIN32_SERVICE_NT_H__