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.

222 lines
4.2 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. WBEMNTFY.CPP
  5. Abstract:
  6. History:
  7. --*/
  8. #include "precomp.h"
  9. #include <wbemint.h>
  10. #include <wbemdlg.h>
  11. #include <resource.h>
  12. #include <resrc1.h>
  13. #include <wbemntfy.h>
  14. CStatusMonitor gStatus;
  15. SCODE CTestNotify::QueryInterface(
  16. REFIID riid,
  17. LPVOID * ppvObj
  18. )
  19. {
  20. if (riid == IID_IUnknown)
  21. {
  22. *ppvObj = (IUnknown *)this;
  23. }
  24. else if (riid == IID_IWbemObjectSink)
  25. {
  26. *ppvObj = (IWbemObjectSink *)this;
  27. }
  28. else if (riid == IID_IWbemObjectSinkEx)
  29. {
  30. *ppvObj = (IWbemObjectSinkEx *)this;
  31. }
  32. else
  33. {
  34. *ppvObj = NULL;
  35. return E_NOINTERFACE;
  36. }
  37. AddRef();
  38. return NOERROR;
  39. }
  40. ULONG CTestNotify::AddRef()
  41. {
  42. return (ULONG)InterlockedIncrement(&m_lRefCount);
  43. }
  44. ULONG CTestNotify::Release()
  45. {
  46. Lock();
  47. if(m_lRefCount <= 0) {
  48. char szDebug[1000];
  49. wsprintf(szDebug, "CTestNotify::Release(), ref count is %d", m_lRefCount);
  50. MessageBox(NULL, szDebug, "DEBUG", MB_OK);
  51. delete this;
  52. return 0;
  53. }
  54. if (InterlockedDecrement(&m_lRefCount))
  55. {
  56. Unlock();
  57. return 1;
  58. }
  59. Unlock();
  60. delete this;
  61. return 0;
  62. }
  63. SCODE CTestNotify::Indicate(
  64. long lObjectCount,
  65. IWbemClassObject ** pObjArray
  66. )
  67. {
  68. if(lObjectCount == 0) return WBEM_NO_ERROR;
  69. Lock();
  70. for (int i = 0; i < lObjectCount; i++)
  71. {
  72. IWbemClassObject *pObj = pObjArray[i];
  73. pObj->AddRef();
  74. m_aObjects.Add(pObj);
  75. }
  76. Unlock();
  77. return WBEM_NO_ERROR;
  78. }
  79. HRESULT CTestNotify::Set(
  80. long lFlags,
  81. REFIID riid,
  82. void *pComObject)
  83. {
  84. Lock();
  85. m_pInterfaceID=riid;
  86. if(pComObject)
  87. {
  88. m_pInterface=(IUnknown *)pComObject;
  89. m_pInterface->AddRef();
  90. }
  91. Unlock();
  92. return WBEM_NO_ERROR;
  93. }
  94. STDMETHODIMP CTestNotify::SetStatus(long lFlags, HRESULT hResult, BSTR strParam,
  95. IWbemClassObject* pObjParam)
  96. {
  97. m_hres = hResult;
  98. if(lFlags & WBEM_STATUS_PROGRESS)
  99. {
  100. gStatus.Add(lFlags, hResult, strParam);
  101. return WBEM_NO_ERROR;
  102. }
  103. m_pErrorObj = pObjParam;
  104. if(pObjParam)
  105. pObjParam->AddRef();
  106. SetEvent(m_hEvent);
  107. return WBEM_NO_ERROR;
  108. }
  109. CTestNotify::CTestNotify(LONG lStartingRefCount)
  110. {
  111. InitializeCriticalSection(&m_cs);
  112. m_lRefCount = lStartingRefCount;
  113. m_hEvent = CreateEvent(0, FALSE, FALSE, 0);
  114. m_pErrorObj = NULL;
  115. m_pInterface = NULL;
  116. }
  117. CTestNotify::~CTestNotify()
  118. {
  119. DeleteCriticalSection(&m_cs);
  120. CloseHandle(m_hEvent);
  121. for (int i = 0; i < m_aObjects.Size(); i++)
  122. ((IWbemClassObject *) m_aObjects[i])->Release();
  123. if(m_pErrorObj) m_pErrorObj->Release();
  124. }
  125. CStatusMonitor::CStatusMonitor()
  126. {
  127. m_bVisible = FALSE;
  128. m_hDlg = CreateDialog(GetModuleHandle(NULL),
  129. MAKEINTRESOURCE(IDD_STATUS_MONITOR), NULL,
  130. (DLGPROC)CStatusMonitor::DlgProc);
  131. ShowWindow(m_hDlg, SW_HIDE);
  132. m_hList = GetDlgItem(m_hDlg, IDC_REPORTS);
  133. }
  134. CStatusMonitor::~CStatusMonitor()
  135. {
  136. if(m_bOpen)
  137. EndDialog(m_hDlg, 0);
  138. }
  139. char buff[2048];
  140. void CStatusMonitor::Add(long lFlags, HRESULT lParam, BSTR strParam)
  141. {
  142. if(m_bVisible == FALSE)
  143. {
  144. ShowWindow(m_hDlg, SW_SHOW);
  145. SendMessage(m_hList, LB_RESETCONTENT, 0, 0);
  146. }
  147. m_bVisible = TRUE;
  148. if(strParam)
  149. wsprintf(buff,"Go progress, value is 0x%0x, and string is %S", lParam, strParam);
  150. else
  151. wsprintf(buff,"Go progress, value is 0x%0x, and no string", lParam);
  152. SendMessage(m_hList, LB_ADDSTRING, 0, (LPARAM)(LPSTR)buff);
  153. }
  154. void CStatusMonitor::Hide()
  155. {
  156. ShowWindow(m_hDlg, SW_HIDE);
  157. m_bVisible = FALSE;
  158. }
  159. BOOL CALLBACK CStatusMonitor::DlgProc(
  160. HWND hDlg,
  161. UINT uMsg,
  162. WPARAM wParam,
  163. LPARAM lParam
  164. )
  165. {
  166. HWND hList;
  167. switch (uMsg)
  168. {
  169. case WM_INITDIALOG:
  170. hList = GetDlgItem(hDlg, IDC_REPORTS);
  171. SendMessage(hList, LB_RESETCONTENT, 0, 0);
  172. return TRUE;
  173. case WM_COMMAND:
  174. switch (LOWORD(wParam))
  175. {
  176. case 2: // was IDANI_CLOSE:
  177. gStatus.Hide();
  178. return TRUE;
  179. }
  180. break;
  181. }
  182. return FALSE;
  183. }