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.

167 lines
4.6 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. return GetCoreManager().StartService(eServiceType);
  58. }
  59. //////////////////////////////////////////////////////////////////////////////
  60. STDMETHODIMP CSdoService::StopService(SERVICE_TYPE eServiceType)
  61. {
  62. // Check preconditions...
  63. //
  64. _ASSERT ( SERVICE_TYPE_MAX > eServiceType );
  65. CSdoLock theLock(*this);
  66. return GetCoreManager().StopService(eServiceType);
  67. }
  68. //////////////////////////////////////////////////////////////////////////////
  69. STDMETHODIMP CSdoService::ConfigureService (SERVICE_TYPE eServiceType)
  70. {
  71. // Check preconditions...
  72. //
  73. _ASSERT ( SERVICE_TYPE_MAX > eServiceType );
  74. CSdoLock theLock(*this);
  75. if ( m_theThread )
  76. {
  77. // We already have a thread, so just interrupt it to reset the timer.
  78. QueueUserAPC(InterruptThread, m_theThread, 0);
  79. }
  80. else
  81. {
  82. // Create a new thread.
  83. DWORD threadId;
  84. m_theThread = CreateThread(
  85. NULL,
  86. 0,
  87. DebounceAndConfigure,
  88. (LPVOID)this,
  89. 0,
  90. &threadId
  91. );
  92. if ( ! m_theThread )
  93. {
  94. // We couldn't create a new thread, so we'll just do it ourself.
  95. UpdateConfiguration();
  96. }
  97. }
  98. return S_OK;
  99. }
  100. //////////////////
  101. // Private Methods
  102. //////////////////
  103. //////////////////////////////////////////////////////////////////////////////
  104. void CSdoService::UpdateConfiguration()
  105. {
  106. // Clear out the thread handle.
  107. CSdoLock theLock(*this);
  108. if ( m_theThread )
  109. {
  110. CloseHandle( m_theThread );
  111. m_theThread = NULL;
  112. }
  113. GetCoreManager().UpdateConfiguration();
  114. }
  115. //////////////////////////////////////////////////////////////////////////////
  116. // Empty APC used to interrupt the debounce thread.
  117. //////////////////////////////////////////////////////////////////////////////
  118. VOID WINAPI CSdoService::InterruptThread(
  119. /*[in]*/ ULONG_PTR dwParam
  120. )
  121. {
  122. }
  123. // Debounce interval in milliseconds.
  124. const DWORD DEBOUNCE_INTERVAL = 5000;
  125. //////////////////////////////////////////////////////////////////////////////
  126. // Entry point for the debounce thread.
  127. //////////////////////////////////////////////////////////////////////////////
  128. DWORD WINAPI CSdoService::DebounceAndConfigure(
  129. /*[in]*/ LPVOID pSdoService
  130. )
  131. {
  132. // Loop until we sleep for DEBOUNCE_INTERVAL without being interrupted.
  133. while (SleepEx(DEBOUNCE_INTERVAL, TRUE) == WAIT_IO_COMPLETION) { }
  134. // Update the configuration.
  135. ((CSdoService*)pSdoService)->UpdateConfiguration();
  136. return 0;
  137. }