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.

147 lines
3.6 KiB

  1. // Connection.cpp: implementation of the CConnection class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "ConnMgr.h"
  6. #include "Connection.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // CEventRegistrationEntry
  14. IMPLEMENT_DYNCREATE(CEventRegistrationEntry,CObject)
  15. //////////////////////////////////////////////////////////////////////
  16. // Construction/Destruction
  17. //////////////////////////////////////////////////////////////////////
  18. CEventRegistrationEntry::CEventRegistrationEntry()
  19. {
  20. OutputDebugString(_T("CEventRegistrationEntry::CEventRegistrationEntry()\n"));
  21. m_pSink = NULL;
  22. m_bRegistered = FALSE;
  23. m_sQuery = _T("");
  24. }
  25. CEventRegistrationEntry::CEventRegistrationEntry(CString sQuery, IWbemObjectSink* pSink)
  26. {
  27. OutputDebugString(_T("CEventRegistrationEntry::CEventRegistrationEntry(CString, IWbemObjectSink*)\n"));
  28. m_pSink = pSink;
  29. m_pSink->AddRef();
  30. m_sQuery = sQuery;
  31. m_bRegistered = FALSE;
  32. if (m_sQuery == IDS_STRING_HMEVENT_QUERY)
  33. {
  34. m_bsClassName = SysAllocString(L"HMEvent");
  35. m_eType = HMEvent;
  36. }
  37. else if (m_sQuery == IDS_STRING_HMMACHSTATUS_QUERY)
  38. {
  39. m_bsClassName = SysAllocString(L"HMMachStatus");
  40. m_eType = HMMachStatus;
  41. }
  42. else if( m_sQuery == IDS_STRING_HMCATSTATUS_QUERY)
  43. {
  44. m_bsClassName = SysAllocString(L"HMCatStatus");
  45. m_eType = HMCatStatus;
  46. }
  47. else if( m_sQuery == IDS_STRING_HMSYSTEMSTATUS_QUERY)
  48. {
  49. m_bsClassName = SysAllocString(L"Microsoft_HMSystemStatus");
  50. m_eType = HMSystemStatus;
  51. }
  52. else if( m_sQuery == IDS_STRING_HMCONFIGCREATE_QUERY)
  53. {
  54. m_bsClassName = NULL;
  55. m_eType = HMConfig;
  56. }
  57. else if( m_sQuery == IDS_STRING_HMCONFIGDELETE_QUERY)
  58. {
  59. m_bsClassName = NULL;
  60. m_eType = HMConfig;
  61. }
  62. else
  63. {
  64. m_eType = AsyncQuery;
  65. m_bsClassName = NULL;
  66. }
  67. }
  68. CEventRegistrationEntry::~CEventRegistrationEntry()
  69. {
  70. OutputDebugString(_T("CEventRegistrationEntry::~CEventRegistrationEntry()\n"));
  71. if (m_pSink)
  72. m_pSink->Release();
  73. m_pSink = NULL;
  74. SysFreeString(m_bsClassName);
  75. }
  76. HRESULT CEventRegistrationEntry::NotifyConsole(long lFlag, HRESULT hr)
  77. {
  78. OutputDebugString(_T("CEventRegistrationEntry::NotifyConsole()\n"));
  79. ASSERT(m_pSink);
  80. // other temporary data
  81. HRESULT hResult = hr;
  82. BSTR strParam = NULL;
  83. IWbemClassObject* pObjParam = NULL;
  84. HRESULT hRes = m_pSink->SetStatus(lFlag, hResult, strParam, pObjParam);
  85. return hRes;
  86. }
  87. HRESULT CEventRegistrationEntry::SendInstances(IWbemServices*& pServices, long lFlag)
  88. {
  89. OutputDebugString(_T("CEventRegistrationEntry::SendInstances()\n"));
  90. ASSERT(pServices);
  91. HRESULT hRes = S_OK;
  92. if(m_eType == HMEvent || m_eType == HMSystemStatus)
  93. {
  94. OutputDebugString(_T("\tSending HMSystemStatus instances...\n"));
  95. OutputDebugString(_T("\t"));
  96. OutputDebugString(m_bsClassName);
  97. OutputDebugString(_T("\n"));
  98. if (lFlag == 2)
  99. hRes = pServices->CreateInstanceEnumAsync(m_bsClassName, WBEM_FLAG_SHALLOW, NULL, m_pSink);
  100. return hRes;
  101. }
  102. else if( m_eType == AsyncQuery )
  103. {
  104. if (lFlag == 2)
  105. {
  106. OutputDebugString(_T("\tExecuting async query for instances...\n"));
  107. OutputDebugString(_T("\t"));
  108. OutputDebugString(m_sQuery);
  109. OutputDebugString(_T("\n"));
  110. BSTR bsQuery = m_sQuery.AllocSysString();
  111. BSTR bsLanguage = SysAllocString(_T("WQL"));
  112. hRes = pServices->ExecQueryAsync(bsLanguage, bsQuery, WBEM_FLAG_BIDIRECTIONAL, NULL, m_pSink);
  113. SysFreeString(bsQuery);
  114. SysFreeString(bsLanguage);
  115. }
  116. return hRes;
  117. }
  118. hRes = pServices->CreateInstanceEnumAsync(m_bsClassName, WBEM_FLAG_SHALLOW, NULL, m_pSink);
  119. return hRes;
  120. }