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.

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