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.

218 lines
5.0 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. TRIGGERFACTORY.CPP
  5. Abstract:
  6. Contains the class factory. This creates objects when connections are requested.
  7. Author:
  8. Vasundhara .G
  9. Revision History :
  10. Vasundhara .G 9-oct-2k : Created It.
  11. --*/
  12. #include "pch.h"
  13. #include "EventConsumerProvider.h"
  14. #include "TriggerProvider.h"
  15. #include "TriggerFactory.h"
  16. CTriggerFactory::CTriggerFactory(
  17. )
  18. /*++
  19. Routine Description:
  20. Constructor for CTriggerFactory class for initialization.
  21. Arguments:
  22. None.
  23. Return Value:
  24. None.
  25. --*/
  26. {
  27. // initialize the reference count variable
  28. m_dwCount = 0;
  29. }
  30. CTriggerFactory::~CTriggerFactory(
  31. )
  32. /*++
  33. Routine Description:
  34. Destructor for CTriggerFactory class for releasing resources.
  35. Arguments:
  36. None.
  37. Return Value:
  38. None.
  39. --*/
  40. {
  41. // there is nothing much to do at this place ... can be inlined, but
  42. }
  43. STDMETHODIMP
  44. CTriggerFactory::QueryInterface(
  45. IN REFIID riid,
  46. OUT LPVOID* ppv
  47. )
  48. /*++
  49. Routine Description:
  50. QueryInterface required to be overridden for a class derived from IUnknown
  51. interface.
  52. Arguments:
  53. [IN] riid : which has the ID value of the interface being called.
  54. [OUT] ppv : pointer to the interface requested.
  55. Return Value:
  56. NOERROR if successful.
  57. E_NOINTERFACE if unsuccessful
  58. --*/
  59. {
  60. // initialy set to NULL
  61. *ppv = NULL;
  62. // check whether interface requested is one we have
  63. if ( riid == IID_IUnknown || riid == IID_IClassFactory )
  64. {
  65. //
  66. // yes ... we have the requested interface
  67. *ppv=this; // set the out parameter for the returning the requested interface
  68. this->AddRef(); // update the reference count
  69. return NOERROR; // inform success
  70. }
  71. // interface is not available
  72. return E_NOINTERFACE;
  73. }
  74. STDMETHODIMP_(ULONG)
  75. CTriggerFactory::AddRef(
  76. void
  77. )
  78. /*++
  79. Routine Description:
  80. Addref required to be overridden for a class derived from IUnknown interface.
  81. Arguments:
  82. none.
  83. Return Value:
  84. returns value of reference member.
  85. --*/
  86. {
  87. // increment the reference count ... thread safe
  88. return InterlockedIncrement( ( LPLONG ) &m_dwCount );
  89. }
  90. STDMETHODIMP_(ULONG)
  91. CTriggerFactory::Release(
  92. void
  93. )
  94. /*++
  95. Routine Description:
  96. Release required to be overridden for a class derived from IUnknown interface.
  97. Arguments:
  98. none.
  99. Return Value:
  100. returns value of reference member, g_lCObj.
  101. --*/
  102. {
  103. DWORD dwCount;
  104. // decrement the reference count ( thread safe ) and check whether
  105. // there are some more references or not ... based on the result value
  106. dwCount = InterlockedDecrement( ( LPLONG ) &m_dwCount );
  107. if ( 0 == dwCount )
  108. {
  109. // free the current factory instance
  110. delete this;
  111. }
  112. // return the no. of instances references left
  113. return dwCount;
  114. }
  115. STDMETHODIMP
  116. CTriggerFactory::CreateInstance(
  117. IN LPUNKNOWN pUnknownOutter,
  118. IN REFIID riid,
  119. OUT LPVOID* ppvObject
  120. )
  121. /*++
  122. Routine Description:
  123. Creates an object of the specified CLSID and retrieves
  124. an interface pointer to this object.
  125. Arguments:
  126. [IN] pUnknownOutter : If the object is being created as part of an
  127. aggregate, then pIUnkOuter must be the outer
  128. unknown. Otherwise, pIUnkOuter must be NULL.
  129. [IN] riid : The IID of the requested interface.
  130. [OUT] ppvObject : A pointer to the interface pointer identified by riid.
  131. Return Value:
  132. NOERROR if successful.
  133. Otherwise error value.
  134. --*/
  135. {
  136. // local variables
  137. HRESULT hr;
  138. CTriggerProvider* pProvider = NULL;
  139. // kick off
  140. *ppvObject = NULL;
  141. hr = E_OUTOFMEMORY;
  142. if ( NULL != pUnknownOutter )
  143. {
  144. return CLASS_E_NOAGGREGATION; // object doesn't support aggregation.
  145. }
  146. // create the Initialize object.
  147. pProvider = new CTriggerProvider();
  148. if ( NULL == pProvider )
  149. {
  150. return E_OUTOFMEMORY; // ran out of memory
  151. }
  152. // get the pointer to the requested interface
  153. hr = pProvider->QueryInterface( riid, ppvObject );
  154. if ( FAILED( hr ) )
  155. {
  156. delete pProvider; // interface not available ... de-allocate memory
  157. }
  158. // return the appropriate result
  159. return hr;
  160. }
  161. STDMETHODIMP
  162. CTriggerFactory::LockServer(
  163. IN BOOL bLock
  164. )
  165. /*++
  166. Routine Description:
  167. Increments or decrements the lock count of the DLL.
  168. If the lock count goes to zero and there are no objects,
  169. the DLL is allowed to unload.
  170. arguments:
  171. [IN] bLock : specifying whether to increment or decrement the lock count.
  172. Returns Value:
  173. NOERROR always.
  174. --*/
  175. {
  176. // based on the request update the locks count
  177. if ( bLock )
  178. {
  179. InterlockedIncrement( ( LPLONG ) &g_dwLocks );
  180. }
  181. else
  182. {
  183. InterlockedDecrement( ( LPLONG ) &g_dwLocks );
  184. }
  185. // inform success
  186. return NOERROR;
  187. }