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.

170 lines
4.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1997-1998 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: sdoservice.cpp
  6. //
  7. // Project: Everest
  8. //
  9. // Description: IAS Service SDO Implementation
  10. //
  11. // Author: TLP 2/3/98
  12. //
  13. ///////////////////////////////////////////////////////////////////////////
  14. #include "stdafx.h"
  15. #include "sdoservice.h"
  16. #include "sdocoremgr.h"
  17. /////////////////////////////////////////////////////////////
  18. // CSdoService Class - Implements ISdoService
  19. /////////////////////////////////////////////////////////////
  20. //////////////////////////////////////////////////////////////////////////////
  21. CSdoService::CSdoService()
  22. : m_theThread(NULL)
  23. {
  24. }
  25. //////////////////////////////////////////////////////////////////////////////
  26. CSdoService::~CSdoService()
  27. {
  28. }
  29. //////////////////////
  30. // ISdoService Methods
  31. //////////////////////
  32. //////////////////////////////////////////////////////////////////////////////
  33. STDMETHODIMP CSdoService::InitializeService(SERVICE_TYPE eServiceType)
  34. {
  35. // Check preconditions...
  36. //
  37. _ASSERT ( SERVICE_TYPE_MAX > eServiceType );
  38. // Use this to debug the service...
  39. // DebugBreak();
  40. return S_OK;
  41. }
  42. //////////////////////////////////////////////////////////////////////////////
  43. STDMETHODIMP CSdoService::ShutdownService(SERVICE_TYPE eServiceType)
  44. {
  45. // Check preconditions...
  46. //
  47. _ASSERT ( SERVICE_TYPE_MAX > eServiceType );
  48. return S_OK;
  49. }
  50. //////////////////////////////////////////////////////////////////////////////
  51. STDMETHODIMP CSdoService::StartService(SERVICE_TYPE eServiceType)
  52. {
  53. // Check preconditions...
  54. //
  55. _ASSERT ( SERVICE_TYPE_MAX > eServiceType );
  56. CSdoLock theLock(*this);
  57. IASTracePrintf("Service SDO is starting service: %d...", eServiceType);
  58. return GetCoreManager().StartService(eServiceType);
  59. }
  60. //////////////////////////////////////////////////////////////////////////////
  61. STDMETHODIMP CSdoService::StopService(SERVICE_TYPE eServiceType)
  62. {
  63. // Check preconditions...
  64. //
  65. _ASSERT ( SERVICE_TYPE_MAX > eServiceType );
  66. CSdoLock theLock(*this);
  67. IASTracePrintf("Service SDO is stopping service: %d...", eServiceType);
  68. return GetCoreManager().StopService(eServiceType);
  69. }
  70. //////////////////////////////////////////////////////////////////////////////
  71. STDMETHODIMP CSdoService::ConfigureService (SERVICE_TYPE eServiceType)
  72. {
  73. // Check preconditions...
  74. //
  75. _ASSERT ( SERVICE_TYPE_MAX > eServiceType );
  76. CSdoLock theLock(*this);
  77. if ( m_theThread )
  78. {
  79. // We already have a thread, so just interrupt it to reset the timer.
  80. QueueUserAPC(InterruptThread, m_theThread, 0);
  81. }
  82. else
  83. {
  84. // Create a new thread.
  85. DWORD threadId;
  86. m_theThread = CreateThread(
  87. NULL,
  88. 0,
  89. DebounceAndConfigure,
  90. (LPVOID)this,
  91. 0,
  92. &threadId
  93. );
  94. if ( ! m_theThread )
  95. {
  96. // We couldn't create a new thread, so we'll just do it ourself.
  97. UpdateConfiguration();
  98. }
  99. }
  100. return S_OK;
  101. }
  102. //////////////////
  103. // Private Methods
  104. //////////////////
  105. //////////////////////////////////////////////////////////////////////////////
  106. void CSdoService::UpdateConfiguration()
  107. {
  108. // Clear out the thread handle.
  109. CSdoLock theLock(*this);
  110. if ( m_theThread )
  111. {
  112. CloseHandle( m_theThread );
  113. m_theThread = NULL;
  114. }
  115. IASTracePrintf("Service SDO is configuring services...");
  116. GetCoreManager().UpdateConfiguration();
  117. }
  118. //////////////////////////////////////////////////////////////////////////////
  119. // Empty APC used to interrupt the debounce thread.
  120. //////////////////////////////////////////////////////////////////////////////
  121. VOID WINAPI CSdoService::InterruptThread(
  122. /*[in]*/ ULONG_PTR dwParam
  123. )
  124. {
  125. }
  126. // Debounce interval in milliseconds.
  127. const DWORD DEBOUNCE_INTERVAL = 5000;
  128. //////////////////////////////////////////////////////////////////////////////
  129. // Entry point for the debounce thread.
  130. //////////////////////////////////////////////////////////////////////////////
  131. DWORD WINAPI CSdoService::DebounceAndConfigure(
  132. /*[in]*/ LPVOID pSdoService
  133. )
  134. {
  135. // Loop until we sleep for DEBOUNCE_INTERVAL without being interrupted.
  136. while (SleepEx(DEBOUNCE_INTERVAL, TRUE) == WAIT_IO_COMPLETION) { }
  137. // Update the configuration.
  138. ((CSdoService*)pSdoService)->UpdateConfiguration();
  139. return 0;
  140. }