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