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.

229 lines
7.9 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. lmsvc.hxx
  7. This file contains the class defintion for the LM_SERVICE class
  8. FILE HISTORY:
  9. ChuckC 19-Aug-1991 Created
  10. ChuckC 23-Sep-1991 Code review changes.
  11. Attended by JimH, KeithMo, EricCh, O-SimoP
  12. terryk 07-Oct-1991 types changes for NT
  13. terryk 17-Oct-1991 Add a destructor and change variable
  14. to pointer
  15. terryk 21-Oct-1991 change _pBuffer to BYTE * type
  16. */
  17. #ifndef _LMSVC_HXX_
  18. #define _LMSVC_HXX_
  19. #include "base.hxx"
  20. #include "string.hxx"
  21. #include "uibuffer.hxx"
  22. /*
  23. * status of the service
  24. */
  25. enum LM_SERVICE_STATUS
  26. {
  27. LM_SVC_STATUS_UNKNOWN,
  28. LM_SVC_STARTED,
  29. LM_SVC_STOPPED,
  30. LM_SVC_PAUSED,
  31. LM_SVC_STARTING,
  32. LM_SVC_STOPPING,
  33. LM_SVC_PAUSING,
  34. LM_SVC_CONTINUING
  35. } ;
  36. /*
  37. * other (secondary) status
  38. */
  39. typedef struct {
  40. BOOL fUnInstallable;
  41. BOOL fPauseable;
  42. BOOL fRdrDiskPaused;
  43. BOOL fRdrPrintPaused;
  44. BOOL fRdrCommPaused;
  45. BOOL fHint;
  46. ULONG ulSecCode;
  47. ULONG ulCheckPointNum;
  48. ULONG ulWaitTime; // in milliseconds
  49. APIERR errExit;
  50. APIERR errSpecific;
  51. } LM_SERVICE_OTHER_STATUS ;
  52. #define DEFAULT_MAX_TRIES 10
  53. #define DEFAULT_SLEEP_TIME 3000
  54. /*************************************************************************
  55. NAME: LM_SERVICE
  56. SYNOPSIS: class for controlling/querying Lan Manager services.
  57. All Query methods return current status by querying the
  58. service. No information is cached. All control operations
  59. are asynchronous, ie. they return immediately, possibly
  60. before the service achieves the desired state.
  61. INTERFACE:
  62. Start() - Start the service. Returns NERR_Success if
  63. successful, API error otherwise.
  64. Pause() - Pause the service. Returns NERR_Success if
  65. successful, API error otherwise.
  66. Continue() - Continue the service. Returns NERR_Success if
  67. successful, API error otherwise.
  68. Stop() - Stop the service. Returns NERR_Success if
  69. successful, API error otherwise.
  70. Poll() - Polls the service to see if one of the
  71. above operations has completed.
  72. IsStarted() - Returns TRUE if service is started, FALSE
  73. otherwise.
  74. IsPaused() - Returns TRUE if service is paused, FALSE
  75. otherwise.
  76. IsStopped() - Returns TRUE if service is stopped (ie. not
  77. installed), FALSE otherwise.
  78. IsStarting() - Returns TRUE if service is starting, FALSE
  79. otherwise.
  80. IsPausing() - Returns TRUE if service is pausing, FALSE
  81. otherwise.
  82. IsStopping() - Returns TRUE if service is stopping, FALSE
  83. otherwise.
  84. IsContinuing() - Returns TRUE if service is continuing, FALSE
  85. otherwise.
  86. IsInstalled() - Returns TRUE if service is not stopped, FALSE
  87. otherwise. Identical to !IsStopped().
  88. QueryStatus() - Returns LM_SERVICE_STATUS enumeration.
  89. QueryFullStatus() - Returns LM_SERVICE_STATUS enumeration and
  90. additional info like hints, checkpoint, etc.
  91. QueryName() - Returns TCHAR * to service name.
  92. QueryServerName() - Returns TCHAR * to server of focus.
  93. PARENT: BASE
  94. USES:
  95. CAVEATS:
  96. NOTES:
  97. NetServiceGetInfo() is not used, we only do NetServiceControl(),
  98. even to query status. By doing so, we are less efficient but
  99. more accurate, since GetInfo() just looks at last recorded status
  100. whereas Control() goes out to ask the service. If we need fast
  101. Querys, we may revisit this.
  102. HISTORY:
  103. ChuckC 19-Aug-1991 Created
  104. KeithMo 30-Sep-1991 Moved polling logic from UI_SERVICE
  105. to LM_SERVICE.
  106. **************************************************************************/
  107. DLL_CLASS LM_SERVICE : public BASE
  108. {
  109. public:
  110. APIERR Start( const TCHAR * pszArgs = NULL,
  111. UINT uiSleepTime = DEFAULT_SLEEP_TIME,
  112. UINT uiMaxTries = DEFAULT_MAX_TRIES );
  113. APIERR Pause(UINT uiSleepTime = DEFAULT_SLEEP_TIME,
  114. UINT uiMaxTries = DEFAULT_MAX_TRIES ) ;
  115. APIERR Continue(UINT uiSleepTime = DEFAULT_SLEEP_TIME,
  116. UINT uiMaxTries = DEFAULT_MAX_TRIES ) ;
  117. APIERR Stop(UINT uiSleepTime = DEFAULT_SLEEP_TIME,
  118. UINT uiMaxTries = DEFAULT_MAX_TRIES ) ;
  119. APIERR Poll(BOOL * pfDone);
  120. BOOL IsStarted(APIERR *pErr = NULL) ;
  121. BOOL IsPaused(APIERR *pErr = NULL) ;
  122. BOOL IsStopped(APIERR *pErr = NULL) ;
  123. BOOL IsInstalled(APIERR *pErr = NULL) { return(!IsStopped(pErr)) ; }
  124. BOOL IsStarting(APIERR *pErr = NULL) ;
  125. BOOL IsPausing(APIERR *pErr = NULL) ;
  126. BOOL IsStopping(APIERR *pErr = NULL) ;
  127. BOOL IsContinuing(APIERR *pErr = NULL) ;
  128. LM_SERVICE_STATUS QueryStatus(APIERR *pErr = NULL) ;
  129. const TCHAR *QueryName(VOID) const {return _nlsService.QueryPch() ;}
  130. const TCHAR *QueryServerName(VOID) const {return _nlsServer.QueryPch() ;}
  131. APIERR QueryFullStatus(LM_SERVICE_STATUS *pSvcStat,
  132. LM_SERVICE_OTHER_STATUS *pSvcOtherStat);
  133. LM_SERVICE(const TCHAR *pszServer, const TCHAR *pszServiceName) ;
  134. ~LM_SERVICE();
  135. APIERR QueryExitCode( VOID ) const;
  136. APIERR QuerySpecificCode( VOID ) const
  137. { return _errSpecific; }
  138. BOOL IsWellKnownService( VOID ) const
  139. { return _fIsWellKnownService; }
  140. protected:
  141. APIERR SetName(const TCHAR *pszServiceName) ;
  142. APIERR SetServerName(const TCHAR *pszServerName) ;
  143. private:
  144. BYTE * _pBuffer ;
  145. ULONG _ulServiceStatus ;
  146. ULONG _ulServiceCode ;
  147. LM_SERVICE_STATUS _svcStat ;
  148. DECL_CLASS_NLS_STR(_nlsService,SNLEN) ;
  149. DECL_CLASS_NLS_STR(_nlsServer,MAX_PATH) ;
  150. UINT _uiMaxTries;
  151. UINT _uiCurrentTry;
  152. UINT _uiSleepTime;
  153. ULONG _ulOldCheckPoint;
  154. LM_SERVICE_STATUS _lmsvcDesiredStat;
  155. LM_SERVICE_STATUS _lmsvcPollStat;
  156. APIERR _errExit;
  157. APIERR _errSpecific;
  158. BOOL _fIsWellKnownService;
  159. APIERR W_QueryStatus(LM_SERVICE_STATUS *pSvcStat,
  160. LM_SERVICE_OTHER_STATUS *pSvcOtherStat = NULL);
  161. APIERR W_ServiceStart( const TCHAR * pszArgs ) ;
  162. APIERR W_ServiceControl(UINT opcode, UINT fbArg = 0) ;
  163. VOID W_InterpretStatus( const service_info_2 * psvi2,
  164. LM_SERVICE_STATUS * pSvcStat,
  165. LM_SERVICE_OTHER_STATUS * pSvcOtherStat );
  166. VOID W_ComputeOtherStatus(LM_SERVICE_OTHER_STATUS *pSvcOtherStat);
  167. BOOL W_IsWellKnownService( VOID ) const;
  168. };
  169. #endif // _LMSVC_HXX_