Leaked source code of windows server 2003
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.

106 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. WCHAR _szServiceEventName[100];
  17. #ifdef DEBUG
  18. DWORD _cEvents;
  19. WCHAR _szServiceName[256];
  20. #endif
  21. };
  22. ///////////////////////////////////////////////////////////////////////////////
  23. //
  24. class CGenericServiceManager
  25. {
  26. public:
  27. static HRESULT Install();
  28. static HRESULT UnInstall();
  29. public:
  30. // call publicly in process.cpp only
  31. static void WINAPI _ServiceMain(DWORD cArg, LPWSTR* ppszArgs);
  32. static DWORD WINAPI _ServiceHandler(DWORD dwControl, DWORD dwEventType,
  33. LPVOID pEventData, LPVOID lpContext);
  34. static HRESULT _HandleWantsDeviceEvents(LPCWSTR pszServiceName,
  35. BOOL fWantsDeviceEvents);
  36. // called from dll.cpp
  37. static HRESULT DllAttach(HINSTANCE hinst);
  38. static HRESULT DllDetach();
  39. private:
  40. static HRESULT _ProcessServiceControlCodes(SERVICEENTRY* pse);
  41. static HRESULT _GetServiceIndex(LPCWSTR pszServiceName, DWORD* pdw);
  42. static HRESULT _GetServiceCLSID(LPCWSTR pszServiceName, CLSID* pclsid);
  43. static HRESULT _CreateIService(LPCWSTR pszServiceName,
  44. IService** ppservice);
  45. static HRESULT _InitServiceEntry(LPCWSTR pszServiceName,
  46. SERVICEENTRY** ppse);
  47. static HRESULT _CleanupServiceEntry(SERVICEENTRY* pse);
  48. static HRESULT _RegisterServiceCtrlHandler(LPCWSTR pszServiceName,
  49. SERVICEENTRY* pse);
  50. static BOOL _SetServiceStatus(SERVICEENTRY* pse);
  51. static HRESULT _HandleServiceControls(SERVICEENTRY* pse, DWORD dwControl,
  52. DWORD dwEventType, PVOID pvEventData);
  53. static HRESULT _HandlePreState(SERVICEENTRY* pse, DWORD dwControl);
  54. static HRESULT _HandlePostState(SERVICEENTRY* pse, DWORD dwControl,
  55. BOOL fPending);
  56. static HRESULT _QueueEvent(SERVICEENTRY* pse, DWORD dwControl,
  57. DWORD dwEventType, PVOID pEventData);
  58. static HRESULT _DeQueueEvent(SERVICEENTRY* pse, CTRLEVENT** ppevent);
  59. static HRESULT _MakeEvent(DWORD dwControl, DWORD dwEventType,
  60. PVOID pvEventData, CTRLEVENT** ppevent);
  61. static HRESULT _EventNeedsToBeProcessedSynchronously(DWORD dwControl,
  62. DWORD dwEventType, LPVOID pvEventData, SERVICEENTRY* pse,
  63. BOOL* pfBool);
  64. static HRESULT _Init();
  65. static HRESULT _Cleanup();
  66. public:
  67. static SERVICE_TABLE_ENTRY _rgste[];
  68. struct SUBSERVICE
  69. {
  70. LPWSTR pszProgID;
  71. UINT uFriendlyName;
  72. LPWSTR pszDependencies; // double null-terminated array of
  73. // null-separated names
  74. LPWSTR pszLoadOrderGroup;
  75. UINT uDescription;
  76. SERVICEENTRY se;
  77. };
  78. static SUBSERVICE _rgsubservice[];
  79. private:
  80. static DWORD _cste;
  81. static CRITICAL_SECTION _csQueue;
  82. static BOOL _fCritSectInit;
  83. static HANDLE _hEventInitCS;
  84. #ifdef DEBUG
  85. public:
  86. static BOOL _fRunAsService;
  87. #endif
  88. };