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.

241 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. svcinfo.h
  5. Abstract:
  6. Author:
  7. Vlad Sadovsky (vlads) 22-Sep-1997
  8. Environment:
  9. User Mode - Win32
  10. Revision History:
  11. 22-Sep-1997 VladS created
  12. --*/
  13. # ifndef _SVCINFO_H_
  14. # define _SVCINFO_H_
  15. /************************************************************
  16. * Include Headers
  17. ************************************************************/
  18. #include <base.h>
  19. /***********************************************************
  20. * Named constants definitions
  21. ************************************************************/
  22. /************************************************************
  23. * Private Constants
  24. ************************************************************/
  25. #define NULL_SERVICE_STATUS_HANDLE ( (SERVICE_STATUS_HANDLE ) NULL)
  26. #define SERVICE_START_WAIT_HINT ( 10000) // milliseconds
  27. #define SERVICE_STOP_WAIT_HINT ( 10000) // milliseconds
  28. #ifndef DLLEXP
  29. //#define DLLEXP __declspec( dllexport )
  30. #define DLLEXP
  31. #endif
  32. /************************************************************
  33. * Type Definitions
  34. ************************************************************/
  35. #define SIGNATURE_SVC (DWORD)'SVCa'
  36. #define SIGNATURE_SVC_FREE (DWORD)'SVCf'
  37. //
  38. // These functions get called back with the pointer to SvcInfo object
  39. // as the context parameter.
  40. //
  41. typedef DWORD ( *PFN_SERVICE_SPECIFIC_INITIALIZE) ( LPVOID pContext);
  42. typedef DWORD ( *PFN_SERVICE_SPECIFIC_CLEANUP) ( LPVOID pContext);
  43. typedef DWORD ( *PFN_SERVICE_SPECIFIC_PNPPWRHANDLER) ( LPVOID pContext,UINT msg,WPARAM wParam,LPARAM lParam);
  44. typedef VOID ( *PFN_SERVICE_CTRL_HANDLER) ( DWORD OpCode);
  45. class SVC_INFO : public BASE {
  46. private:
  47. DWORD m_dwSignature;
  48. SERVICE_STATUS m_svcStatus;
  49. SERVICE_STATUS_HANDLE m_hsvcStatus;
  50. HANDLE m_hShutdownEvent;
  51. STR m_sServiceName;
  52. STR m_sModuleName;
  53. //
  54. // Call back functions for service specific data/function
  55. //
  56. PFN_SERVICE_SPECIFIC_INITIALIZE m_pfnInitialize;
  57. PFN_SERVICE_SPECIFIC_CLEANUP m_pfnCleanup;
  58. PFN_SERVICE_SPECIFIC_PNPPWRHANDLER m_pfnPnpPower;
  59. DWORD ReportServiceStatus( VOID);
  60. VOID InterrogateService( VOID );
  61. VOID StopService( VOID );
  62. VOID PauseService( VOID );
  63. VOID ContinueService( VOID );
  64. VOID ShutdownService( VOID );
  65. public:
  66. // *** IUnknown methods ***
  67. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  68. STDMETHODIMP_(ULONG) AddRef( void);
  69. STDMETHODIMP_(ULONG) Release( void);
  70. //
  71. // Initialization/Termination related methods
  72. //
  73. SVC_INFO(
  74. IN LPCTSTR lpszServiceName,
  75. IN TCHAR * lpszModuleName,
  76. IN PFN_SERVICE_SPECIFIC_INITIALIZE pfnInitialize,
  77. IN PFN_SERVICE_SPECIFIC_CLEANUP pfnCleanup,
  78. IN PFN_SERVICE_SPECIFIC_PNPPWRHANDLER pfnPnpPower
  79. );
  80. ~SVC_INFO( VOID);
  81. BOOL IsValid(VOID) const
  82. {
  83. return (( QueryError() == NO_ERROR) && (m_dwSignature == SIGNATURE_SVC));
  84. }
  85. DWORD QueryCurrentServiceState( VOID) const
  86. {
  87. return ( m_svcStatus.dwCurrentState);
  88. }
  89. //
  90. // Parameter access methods.
  91. //
  92. //
  93. // Service control related methods
  94. //
  95. LPCTSTR QueryServiceName(VOID) const
  96. {
  97. return m_sServiceName.QueryStr();
  98. }
  99. DWORD
  100. QueryServiceSpecificExitCode( VOID) const
  101. {
  102. return ( m_svcStatus.dwServiceSpecificExitCode);
  103. }
  104. VOID
  105. SetServiceSpecificExitCode( DWORD err)
  106. {
  107. m_svcStatus.dwServiceSpecificExitCode = err;
  108. }
  109. DWORD
  110. DelayCurrentServiceCtrlOperation( IN DWORD dwWaitHint)
  111. {
  112. return
  113. UpdateServiceStatus(m_svcStatus.dwCurrentState,
  114. m_svcStatus.dwWin32ExitCode,
  115. m_svcStatus.dwCheckPoint,
  116. dwWaitHint);
  117. }
  118. DWORD
  119. UpdateServiceStatus(IN DWORD State,
  120. IN DWORD Win32ExitCode,
  121. IN DWORD CheckPoint,
  122. IN DWORD WaitHint );
  123. VOID
  124. ServiceCtrlHandler( IN DWORD dwOpCode);
  125. DWORD
  126. StartServiceOperation(
  127. IN PFN_SERVICE_CTRL_HANDLER pfnCtrlHandler
  128. );
  129. //
  130. // Miscellaneous methods
  131. //
  132. }; // class SVC_INFO
  133. typedef SVC_INFO * PSVC_INFO;
  134. /************************************************************
  135. * Macros
  136. ************************************************************/
  137. //
  138. //
  139. // Use the following macro once in outer scope of the file
  140. // where we construct the global SvcInfo object.
  141. //
  142. // Every client of SvcInfo should define the following macro
  143. // passing as parameter their global pointer to SvcInfo object
  144. // This is required to generate certain stub functions, since
  145. // the service controller call-back functions do not return
  146. // the context information.
  147. //
  148. // Also we define the global g_pSvcInfo variable and
  149. // a static variable gs_pfnSch,which is a pointer to the local service control handler function.
  150. //
  151. # define _INTERNAL_DEFINE_SVCINFO_INTERFACE( pSvcInfo) \
  152. \
  153. static VOID ServiceCtrlHandler( DWORD OpCode) \
  154. { \
  155. ( pSvcInfo)->ServiceCtrlHandler( OpCode); \
  156. } \
  157. \
  158. static PFN_SERVICE_CTRL_HANDLER gs_pfnSch = ServiceCtrlHandler;
  159. //
  160. // Since all the services should use the global variable called g_pSvcInfo
  161. // this is a convenience macro for defining the interface for services
  162. // structure
  163. //
  164. # define DEFINE_SVC_INFO_INTERFACE() \
  165. PSVC_INFO g_pSvcInfo; \
  166. _INTERNAL_DEFINE_SVCINFO_INTERFACE( g_pSvcInfo);
  167. //
  168. // Use the macro SERVICE_CTRL_HANDLER() to pass the parameter for
  169. // service control handler when we initialize the SvcInfo object
  170. //
  171. # define SERVICE_CTRL_HANDLER() ( gs_pfnSch)
  172. # endif // _SVCINFO_H_
  173. /************************ End of File ***********************/