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.

188 lines
4.8 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2000
  5. //
  6. // File: comobjects.cpp
  7. //
  8. // Contents: Base code for com objects exported by Object Model.
  9. //
  10. // Classes: CMMCStrongReferences
  11. //
  12. // History: 16-May-2000 AudriusZ Created
  13. //
  14. //--------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #include <atlcom.h>
  17. #include "comerror.h"
  18. #include "events.h"
  19. #include "comobjects.h"
  20. /***************************************************************************\
  21. *
  22. * METHOD: CMMCStrongReferences::AddRef
  23. *
  24. * PURPOSE: (static) puts a strong reference on mmc
  25. *
  26. * PARAMETERS:
  27. *
  28. * RETURNS:
  29. * DWORD -
  30. *
  31. \***************************************************************************/
  32. DWORD CMMCStrongReferences::AddRef()
  33. {
  34. return GetSingletonObject().InternalAddRef();
  35. }
  36. /***************************************************************************\
  37. *
  38. * METHOD: CMMCStrongReferences::Release
  39. *
  40. * PURPOSE: (static) releases strong reference from MMC
  41. *
  42. * PARAMETERS:
  43. *
  44. * RETURNS:
  45. * DWORD
  46. *
  47. \***************************************************************************/
  48. DWORD CMMCStrongReferences::Release()
  49. {
  50. return GetSingletonObject().InternalRelease();
  51. }
  52. /***************************************************************************\
  53. *
  54. * METHOD: CMMCStrongReferences::LastRefReleased
  55. *
  56. * PURPOSE: returns whether the last strong reference was released
  57. *
  58. * PARAMETERS:
  59. *
  60. * RETURNS:
  61. * bool - true == last ref was released
  62. *
  63. \***************************************************************************/
  64. bool CMMCStrongReferences::LastRefReleased()
  65. {
  66. return GetSingletonObject().InternalLastRefReleased();
  67. }
  68. /***************************************************************************\
  69. *
  70. * METHOD: CMMCStrongReferences::CMMCStrongReferences
  71. *
  72. * PURPOSE: constructor
  73. *
  74. * PARAMETERS:
  75. *
  76. * RETURNS:
  77. *
  78. \***************************************************************************/
  79. CMMCStrongReferences::CMMCStrongReferences() :
  80. m_dwStrongRefs(0),
  81. m_bLastRefReleased(false)
  82. {
  83. }
  84. /***************************************************************************\
  85. *
  86. * METHOD: CMMCStrongReferences::GetSingletonObject
  87. *
  88. * PURPOSE: (helper) returns reference to the singleton object
  89. *
  90. * PARAMETERS:
  91. *
  92. * RETURNS:
  93. * CMMCStrongReferences& - singleto object
  94. *
  95. \***************************************************************************/
  96. CMMCStrongReferences& CMMCStrongReferences::GetSingletonObject()
  97. {
  98. static CMMCStrongReferences singleton;
  99. return singleton;
  100. }
  101. /***************************************************************************\
  102. *
  103. * METHOD: CMMCStrongReferences::InternalAddRef
  104. *
  105. * PURPOSE: (helper) implements strong addreff
  106. *
  107. * PARAMETERS:
  108. *
  109. * RETURNS:
  110. * DWORD -
  111. *
  112. \***************************************************************************/
  113. DWORD CMMCStrongReferences::InternalAddRef()
  114. {
  115. return ++m_dwStrongRefs;
  116. }
  117. /***************************************************************************\
  118. *
  119. * METHOD: CMMCStrongReferences::InternalRelease
  120. *
  121. * PURPOSE: (helper) implements strong release
  122. *
  123. * PARAMETERS:
  124. *
  125. * RETURNS:
  126. * DWORD -
  127. *
  128. \***************************************************************************/
  129. DWORD CMMCStrongReferences::InternalRelease()
  130. {
  131. if (--m_dwStrongRefs == 0)
  132. m_bLastRefReleased = true;
  133. return m_dwStrongRefs;
  134. }
  135. /***************************************************************************\
  136. *
  137. * METHOD: CMMCStrongReferences::InternalLastRefReleased
  138. *
  139. * PURPOSE: (helper) returns whether the last strong ref was released
  140. *
  141. * PARAMETERS:
  142. *
  143. * RETURNS:
  144. * bool - true == last ref was released
  145. *
  146. \***************************************************************************/
  147. bool CMMCStrongReferences::InternalLastRefReleased()
  148. {
  149. return m_bLastRefReleased;
  150. }
  151. /***************************************************************************\
  152. *
  153. * FUNCTION: GetComObjectEventSource
  154. *
  155. * PURPOSE: returns singleton for emmiting Com Object Events
  156. [ScOnDisconnectObjects() currently is the only event]
  157. *
  158. * PARAMETERS:
  159. *
  160. * RETURNS:
  161. * CEventSource<CComObjectObserver>&
  162. *
  163. \***************************************************************************/
  164. MMCBASE_API
  165. CEventSource<CComObjectObserver>&
  166. GetComObjectEventSource()
  167. {
  168. static CEventSource<CComObjectObserver> evSource;
  169. return evSource;
  170. }
  171. /***************************************************************************/
  172. // static members of class CConsoleEventDispatcherProvider
  173. MMCBASE_API
  174. CConsoleEventDispatcher *CConsoleEventDispatcherProvider::s_pDispatcher = NULL;