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.

103 lines
4.8 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: Service.h
  3. //
  4. // Copyright (c) 2000, Microsoft Corporation
  5. //
  6. // This file contains a class that implements generic portions of a Win32
  7. // serivce.
  8. //
  9. // History: 2000-11-29 vtan created
  10. // --------------------------------------------------------------------------
  11. #ifndef _Service_
  12. #define _Service_
  13. #include "APIConnection.h"
  14. // --------------------------------------------------------------------------
  15. // CService
  16. //
  17. // Purpose: Base class implementation of a service for the service control
  18. // manager.
  19. //
  20. // History: 2000-11-29 vtan created
  21. // --------------------------------------------------------------------------
  22. class CService : public CCountedObject
  23. {
  24. private:
  25. friend class CServiceWorkItem;
  26. CService (void);
  27. protected:
  28. CService (CAPIConnection *pAPIConnection, CServerAPI *pServerAPI, const TCHAR *pszServiceName);
  29. virtual ~CService (void);
  30. public:
  31. void Start (void);
  32. static NTSTATUS Install (const TCHAR *pszName,
  33. const TCHAR *pszImage,
  34. const TCHAR *pszGroup,
  35. const TCHAR *pszAccount,
  36. const TCHAR *pszDllName,
  37. const TCHAR *pszDependencies,
  38. const TCHAR *pszSvchostGroup,
  39. const TCHAR *pszServiceMainName,
  40. DWORD dwStartType,
  41. HINSTANCE hInstance,
  42. UINT uiDisplayNameID,
  43. UINT uiDescriptionID,
  44. SERVICE_FAILURE_ACTIONS *psfa = NULL);
  45. static NTSTATUS Remove (const TCHAR *pszName);
  46. protected:
  47. virtual NTSTATUS Signal (void);
  48. virtual DWORD HandlerEx (DWORD dwControl);
  49. private:
  50. static DWORD WINAPI CB_HandlerEx (DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext);
  51. static NTSTATUS AddService (const TCHAR *pszName,
  52. const TCHAR *pszImage,
  53. const TCHAR *pszGroup,
  54. const TCHAR *pszAccount,
  55. const TCHAR *pszDependencies,
  56. DWORD dwStartType,
  57. HINSTANCE hInstance,
  58. UINT uiDisplayNameID,
  59. SERVICE_FAILURE_ACTIONS *psfa = NULL);
  60. static NTSTATUS AddServiceDescription (const TCHAR *pszName, HINSTANCE hInstance, UINT uiDescriptionID);
  61. static NTSTATUS AddServiceParameters (const TCHAR *pszName, const TCHAR *pszDllName, const TCHAR *pszServiceMainName);
  62. static NTSTATUS AddServiceToGroup (const TCHAR *pszName, const TCHAR *pszSvchostGroup);
  63. static bool StringInMulitpleStringList (const TCHAR *pszStringList, const TCHAR *pszString);
  64. static void StringInsertInMultipleStringList (TCHAR *pszStringList, const TCHAR *pszString, DWORD dwStringListSize);
  65. protected:
  66. SERVICE_STATUS_HANDLE _hService;
  67. SERVICE_STATUS _serviceStatus;
  68. const TCHAR* _pszServiceName;
  69. CAPIConnection* _pAPIConnection;
  70. CServerAPI* _pServerAPI;
  71. };
  72. // --------------------------------------------------------------------------
  73. // CServiceWorkItem
  74. //
  75. // Purpose: Work item class to stop the server using the CServerAPI class.
  76. //
  77. // History: 2000-11-29 vtan created
  78. // --------------------------------------------------------------------------
  79. class CServiceWorkItem : public CWorkItem
  80. {
  81. private:
  82. CServiceWorkItem (void);
  83. public:
  84. CServiceWorkItem (CServerAPI *pServerAPI);
  85. virtual ~CServiceWorkItem (void);
  86. protected:
  87. virtual void Entry (void);
  88. private:
  89. CServerAPI* _pServerAPI;
  90. };
  91. #endif /* _Service_ */