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.

225 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. sink.cxx
  5. Abstract:
  6. Implements the BASE_ADMIN_SINK object.
  7. Author:
  8. Keith Moore (keithmo) 05-Feb-1997
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #pragma hdrstop
  13. //
  14. // Private constants.
  15. //
  16. //
  17. // Private types.
  18. //
  19. //
  20. // Private globals.
  21. //
  22. //
  23. // Private prototypes.
  24. //
  25. //
  26. // Public functions.
  27. //
  28. BASE_ADMIN_SINK::BASE_ADMIN_SINK()
  29. {
  30. //
  31. // Put everything into a known state.
  32. //
  33. m_ReferenceCount = 0;
  34. m_SinkCookie = 0;
  35. m_ConnectionPoint = NULL;
  36. } // BASE_ADMIN_SINK::BASE_ADMIN_SINK
  37. BASE_ADMIN_SINK::~BASE_ADMIN_SINK()
  38. {
  39. //
  40. // Unadvise if necessary.
  41. //
  42. Unadvise();
  43. //
  44. // Release the connection point.
  45. //
  46. RELEASE_INTERFACE( m_ConnectionPoint );
  47. } // BASE_ADMIN_SINK::~BASE_ADMIN_SINK
  48. HRESULT
  49. BASE_ADMIN_SINK::Initialize(
  50. IN IUnknown * Object
  51. )
  52. {
  53. HRESULT result;
  54. IConnectionPointContainer * container;
  55. //
  56. // Get the connection point container from the given interface.
  57. //
  58. result = Object->QueryInterface(
  59. IID_IConnectionPointContainer,
  60. (VOID **)&container
  61. );
  62. if( SUCCEEDED(result) ) {
  63. //
  64. // Find the necessary connection point.
  65. //
  66. result = container->FindConnectionPoint(
  67. IID_IMSAdminBaseSink,
  68. &m_ConnectionPoint
  69. );
  70. if( SUCCEEDED(result) ) {
  71. //
  72. // Setup the advise association.
  73. //
  74. result = m_ConnectionPoint->Advise(
  75. (IUnknown *)this,
  76. &m_SinkCookie
  77. );
  78. }
  79. container->Release();
  80. }
  81. return result;
  82. } // BASE_ADMIN_SINK::Initialize
  83. HRESULT
  84. BASE_ADMIN_SINK::Unadvise(
  85. VOID
  86. )
  87. {
  88. HRESULT result = NO_ERROR;
  89. DWORD tmpCookie;
  90. //
  91. // Unadvise if necessary.
  92. //
  93. tmpCookie = (DWORD)InterlockedExchange(
  94. (LPLONG)&m_SinkCookie,
  95. 0
  96. );
  97. if( tmpCookie != 0 ) {
  98. result = m_ConnectionPoint->Unadvise( tmpCookie );
  99. }
  100. return result;
  101. } // BASE_ADMIN_SINK::Unadvise
  102. HRESULT
  103. STDMETHODCALLTYPE
  104. BASE_ADMIN_SINK::QueryInterface(
  105. IN REFIID InterfaceId,
  106. OUT VOID ** Object
  107. )
  108. {
  109. //
  110. // This class supports IUnknown and IADMCOMSINK. If it's one of these,
  111. // just return "this". Otherwise, fail it.
  112. //
  113. if( InterfaceId == IID_IUnknown ||
  114. InterfaceId == IID_IMSAdminBaseSink ) {
  115. *Object = (VOID *)this;
  116. AddRef();
  117. return NO_ERROR;
  118. }
  119. return E_NOINTERFACE;
  120. } // BASE_ADMIN_SINK::QueryInterface
  121. ULONG
  122. STDMETHODCALLTYPE
  123. BASE_ADMIN_SINK::AddRef()
  124. {
  125. ULONG newCount;
  126. //
  127. // Increment our ref count and return the updated value.
  128. //
  129. newCount = (ULONG)InterlockedIncrement( &m_ReferenceCount );
  130. return newCount;
  131. } // BASE_ADMIN_SINK::AddRef
  132. ULONG
  133. STDMETHODCALLTYPE
  134. BASE_ADMIN_SINK::Release()
  135. {
  136. ULONG newCount;
  137. //
  138. // Decrement our ref count. It it becomes zero, delete the current
  139. // object. In any case, return the updated value.
  140. //
  141. newCount = (ULONG)InterlockedDecrement( &m_ReferenceCount );
  142. if( newCount == 0 ) {
  143. delete this;
  144. }
  145. return newCount;
  146. } // BASE_ADMIN_SINK::Release
  147. //
  148. // Private functions.
  149. //