Source code of Windows XP (NT5)
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.

111 lines
3.6 KiB

  1. #include "service.h"
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //
  4. struct CTRLEVENT;
  5. struct SERVICEENTRY
  6. {
  7. HANDLE _hEventRelinquishControl;
  8. IService* _pservice;
  9. SERVICE_STATUS _servicestatus;
  10. SERVICE_STATUS_HANDLE _ssh;
  11. BOOL _fWantsDeviceEvents;
  12. CTRLEVENT* _peventQueueHead;
  13. CTRLEVENT* _peventQueueTail;
  14. BOOL _fSkipTerminatingEvents;
  15. HANDLE _hEventSynchProcessing;
  16. #ifdef DEBUG
  17. DWORD _cEvents;
  18. WCHAR _szServiceName[256];
  19. #endif
  20. };
  21. ///////////////////////////////////////////////////////////////////////////////
  22. //
  23. class CGenericServiceManager
  24. {
  25. public:
  26. static HRESULT Install();
  27. static HRESULT UnInstall();
  28. public:
  29. // call in WinMain only
  30. static HRESULT Init();
  31. static HRESULT Cleanup();
  32. static HRESULT StartServiceCtrlDispatcher();
  33. public:
  34. // call publicly in process.cpp only
  35. static void WINAPI _ServiceMain(DWORD cArg, LPWSTR* ppszArgs);
  36. static DWORD WINAPI _ServiceHandler(DWORD dwControl, DWORD dwEventType,
  37. LPVOID pEventData, LPVOID lpContext);
  38. static HRESULT _HandleWantsDeviceEvents(LPCWSTR pszServiceName,
  39. BOOL fWantsDeviceEvents);
  40. private:
  41. static HRESULT _ProcessServiceControlCodes(SERVICEENTRY* pse);
  42. static HRESULT _GetServiceIndex(LPCWSTR pszServiceName, DWORD* pdw);
  43. static HRESULT _GetServiceCLSID(LPCWSTR pszServiceName, CLSID* pclsid);
  44. static HRESULT _CreateIService(LPCWSTR pszServiceName,
  45. IService** ppservice);
  46. static HRESULT _InitServiceEntry(LPCWSTR pszServiceName,
  47. SERVICEENTRY** ppse);
  48. static HRESULT _CleanupServiceEntry(SERVICEENTRY* pse);
  49. static HRESULT _RegisterServiceCtrlHandler(LPCWSTR pszServiceName,
  50. SERVICEENTRY* pse);
  51. static BOOL _SetServiceStatus(SERVICEENTRY* pse);
  52. static HRESULT _HandleServiceControls(SERVICEENTRY* pse, DWORD dwControl,
  53. DWORD dwEventType, PVOID pvEventData);
  54. static HRESULT _HandlePreState(SERVICEENTRY* pse, DWORD dwControl);
  55. static HRESULT _HandlePostState(SERVICEENTRY* pse, DWORD dwControl,
  56. BOOL fPending);
  57. static HRESULT _QueueEvent(SERVICEENTRY* pse, DWORD dwControl,
  58. DWORD dwEventType, PVOID pEventData);
  59. static HRESULT _DeQueueEvent(SERVICEENTRY* pse, CTRLEVENT** ppevent);
  60. static HRESULT _MakeEvent(DWORD dwControl, DWORD dwEventType,
  61. PVOID pvEventData, CTRLEVENT** ppevent);
  62. static HRESULT _EventNeedsToBeProcessedSynchronously(DWORD dwControl,
  63. DWORD dwEventType, LPVOID pvEventData, SERVICEENTRY* pse,
  64. BOOL* pfBool);
  65. static HRESULT _Init();
  66. static HRESULT _Cleanup();
  67. public:
  68. static SERVICE_TABLE_ENTRY _rgste[];
  69. struct SUBSERVICE
  70. {
  71. LPWSTR pszProgID;
  72. UINT uFriendlyName;
  73. LPWSTR pszDependencies; // double null-terminated array of
  74. // null-separated names
  75. LPWSTR pszLoadOrderGroup;
  76. UINT uDescription;
  77. SERVICEENTRY se;
  78. };
  79. static SUBSERVICE _rgsubservice[];
  80. static BOOL _fSVCHosted;
  81. private:
  82. static DWORD _cste;
  83. static CRITICAL_SECTION _cs;
  84. static BOOL _fInitializationDone;
  85. static ULONG _cRefCS;
  86. static HANDLE _hEventInitCS;
  87. #ifdef DEBUG
  88. public:
  89. static BOOL _fRunAsService;
  90. #endif
  91. };