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.

229 lines
5.5 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. MCAObjectSink.cpp
  5. Abstract:
  6. This class is used to register as a temporary consumer to WMI for CMC and CPE
  7. event notifications. It functions as a IWbemObjectSink to retrieve the
  8. instances in the result of the query (WMI event notification). When a registered
  9. event occurs, WMI calls the Indicate function to notify about the event.
  10. For more information look at MSDN for: IWbemObjectSink.
  11. Author:
  12. Abdullah Ustuner (AUstuner) 28-August-2002
  13. --*/
  14. #include "MCAObjectSink.h"
  15. extern HANDLE gErrorProcessedEvent;
  16. MCAObjectSink::MCAObjectSink()
  17. /*++
  18. Routine Description:
  19. This function is the constructor of the class. It is responsible for initializing
  20. the member variables.
  21. Arguments:
  22. none
  23. Return Value:
  24. none
  25. --*/
  26. {
  27. referenceCount = 0;
  28. }
  29. ULONG
  30. MCAObjectSink::AddRef()
  31. /*++
  32. Routine Description:
  33. This function increases the object's reference count by one. The function prevents
  34. more than one thread to increase the value simultaneously.
  35. Arguments:
  36. none
  37. Return Value:
  38. Reference count to this object (after increment operation).
  39. --*/
  40. {
  41. return InterlockedIncrement(&referenceCount);
  42. }
  43. ULONG
  44. MCAObjectSink::Release()
  45. /*++
  46. Routine Description:
  47. This function decreases the object's reference count by one. The function prevents
  48. more than one thread to decrease the value simultaneously. If no other reference
  49. is left, the object is deallocated.
  50. Arguments:
  51. none
  52. Return Value:
  53. lRef - Reference count to this object (after decrement operation).
  54. --*/
  55. {
  56. LONG lRef = InterlockedDecrement(&referenceCount);
  57. if (lRef == 0) {
  58. delete this;
  59. }
  60. return lRef;
  61. }
  62. HRESULT
  63. MCAObjectSink::QueryInterface(IN REFIID riid,
  64. OUT VOID** ppv
  65. )
  66. /*++
  67. Routine Description:
  68. This function determines if the object supports a particular COM interface.
  69. If it does, the system increases the object's reference count, and the
  70. application can use that interface immediately.
  71. Arguments:
  72. riid - The COM interface identifier of the requested interface.
  73. ppv - Address of a pointer that will be filled with the interface pointer if
  74. the query succeeds.
  75. Return Value:
  76. S_OK - Successful
  77. E_NOINTERFACE - Unsuccessful. Requested interface is not supported.
  78. --*/
  79. {
  80. if (riid == IID_IUnknown || riid == IID_IWbemObjectSink) {
  81. *ppv = (IWbemObjectSink *) this;
  82. AddRef();
  83. return S_OK;
  84. }
  85. else return E_NOINTERFACE;
  86. }
  87. HRESULT
  88. MCAObjectSink::Indicate(IN LONG lObjCount,
  89. IN IWbemClassObject **pArray
  90. )
  91. /*++
  92. Routine Description:
  93. This function receives the notifications from the WMI provider.
  94. Arguments:
  95. lObjCount - The number of objects in the following array of pointers.
  96. pArray - An array of pointers to IWbemClassObject interfaces, that is the event objects.
  97. The array memory itself is read-only, and is owned by the caller of the method.
  98. Since this is an in-parameter, the interface called has the option of calling
  99. IWbemServices::AddRef on any object pointer in the array and holding it before
  100. returning. The interface called is only required to copy and then call
  101. IWbemServices::AddRef on the pointers if the pointers will be used after the
  102. call returns, according to COM rules. The interface called should not call
  103. Release on the objects without corresponding calls to AddRef. For more
  104. information on the IUnknown Interface methods, see the Microsoft Platform SDK.
  105. Return Value:
  106. WBEM_S_NO_ERROR - Indicating successful processing of the notification.
  107. --*/
  108. {
  109. LONG objectIndex = 0;
  110. //
  111. // Extract all of the event objects from the array and inform the test engine.
  112. //
  113. for (objectIndex = 0; objectIndex < lObjCount; objectIndex++) {
  114. //
  115. // Inform the corrected engine about the event retrieval.
  116. //
  117. MCAErrorReceived(pArray[objectIndex]);
  118. SetEvent(gErrorProcessedEvent);
  119. }
  120. return WBEM_S_NO_ERROR;
  121. }
  122. HRESULT
  123. MCAObjectSink::SetStatus(IN LONG lFlags,
  124. IN HRESULT hResult,
  125. IN BSTR strParam,
  126. IN IWbemClassObject __RPC_FAR *pObjParam
  127. )
  128. /*++
  129. Routine Description:
  130. This function is called by sources to indicate the end of a notification sequence
  131. or the end of a result code of an asynchronous method of IWbemServices.
  132. Arguments:
  133. lFlags - Reserved. It must be zero.
  134. hResult - Set to the HRESULT of the asynchronous operation or notification.
  135. strParam - Receives a pointer to a read-only BSTR, if the original asynchronous operation
  136. returns a string.
  137. pObjParam - In cases where a complex error or status object is returned, this contains
  138. a pointer to the object. If the object is required after the call returns,
  139. the called object must AddRef the pointer before returning.
  140. Return Value:
  141. WBEM_S_NO_ERROR
  142. --*/
  143. {
  144. return WBEM_S_NO_ERROR;
  145. }