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.

200 lines
6.0 KiB

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