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.

772 lines
22 KiB

  1. //*****************************************************************************
  2. //
  3. // Copyright (c) 1996-1999, Microsoft Corporation, All rights reserved
  4. //
  5. // EVENTREP.CPP
  6. //
  7. // This file implements basic classes for event representation.
  8. //
  9. // See eventrep.h for documentation.
  10. //
  11. // History:
  12. //
  13. // 11/27/96 a-levn Compiles.
  14. //
  15. //*****************************************************************************
  16. #include "precomp.h"
  17. #include <stdio.h>
  18. #include <ess.h>
  19. CEventRepresentation::CEventTypeData CEventRepresentation::staticTypes[] =
  20. {
  21. {e_EventTypeExtrinsic, L"__ExtrinsicEvent", NULL},
  22. {e_EventTypeNamespaceCreation, L"__NamespaceCreationEvent", NULL},
  23. {e_EventTypeNamespaceDeletion, L"__NamespaceDeletionEvent", NULL},
  24. {e_EventTypeNamespaceModification, L"__NamespaceModificationEvent", NULL},
  25. {e_EventTypeClassCreation, L"__ClassCreationEvent", NULL},
  26. {e_EventTypeClassDeletion, L"__ClassDeletionEvent", NULL},
  27. {e_EventTypeClassModification, L"__ClassModificationEvent", NULL},
  28. {e_EventTypeInstanceCreation, L"__InstanceCreationEvent", NULL},
  29. {e_EventTypeInstanceDeletion, L"__InstanceDeletionEvent", NULL},
  30. {e_EventTypeInstanceModification, L"__InstanceModificationEvent", NULL},
  31. {e_EventTypeTimer, L"__TimerEvent", NULL}
  32. };
  33. IWbemDecorator* CEventRepresentation::mstatic_pDecorator = NULL;
  34. //******************************************************************************
  35. // public
  36. //
  37. // See eventrep.h for documentation
  38. //
  39. //******************************************************************************
  40. int CEventRepresentation::NumEventTypes()
  41. {
  42. return sizeof(staticTypes) / sizeof CEventTypeData;
  43. }
  44. //******************************************************************************
  45. // public
  46. //
  47. // See eventrep.h for documentation
  48. //
  49. //******************************************************************************
  50. HRESULT CEventRepresentation::Initialize(IWbemServices* pNamespace,
  51. IWbemDecorator* pDecorator)
  52. {
  53. mstatic_pDecorator = pDecorator;
  54. pDecorator->AddRef();
  55. return WBEM_S_NO_ERROR;
  56. }
  57. HRESULT CEventRepresentation::Shutdown()
  58. {
  59. if(mstatic_pDecorator)
  60. {
  61. mstatic_pDecorator->Release();
  62. mstatic_pDecorator = NULL;
  63. }
  64. for(int i = 0; i < NumEventTypes(); i++)
  65. {
  66. if(staticTypes[i].pEventClass != NULL)
  67. {
  68. staticTypes[i].pEventClass->Release();
  69. staticTypes[i].pEventClass = NULL;
  70. }
  71. }
  72. return WBEM_S_NO_ERROR;
  73. }
  74. //******************************************************************************
  75. // public
  76. //
  77. // See eventrep.h for documentation
  78. //
  79. //******************************************************************************
  80. CEventRepresentation::~CEventRepresentation()
  81. {
  82. if(m_bAllocated)
  83. {
  84. // All fields have been allocated, and need to be deleted
  85. // ======================================================
  86. delete wsz1;
  87. delete wsz2;
  88. delete wsz3;
  89. for(int i = 0; i < nObjects; i++)
  90. {
  91. (apObjects[i])->Release();
  92. }
  93. delete [] apObjects;
  94. }
  95. if(m_pCachedObject)
  96. m_pCachedObject->Release();
  97. }
  98. //******************************************************************************
  99. // public
  100. //
  101. // See eventrep.h for documentation
  102. //
  103. //******************************************************************************
  104. DELETE_ME CEventRepresentation* CEventRepresentation::MakePermanentCopy()
  105. {
  106. // Allocate a new event structure and set flags to "allocated"
  107. // ===========================================================
  108. CEventRepresentation* pCopy = _new CEventRepresentation;
  109. if(pCopy == NULL)
  110. return NULL;
  111. pCopy->m_bAllocated = TRUE;
  112. pCopy->type = type;
  113. pCopy->dw1 = dw1;
  114. pCopy->dw2 = dw2;
  115. if(wsz1)
  116. {
  117. pCopy->wsz1 = _new WCHAR[wcslen(wsz1)+1];
  118. if(pCopy->wsz1 == NULL)
  119. {
  120. delete pCopy;
  121. return NULL;
  122. }
  123. wcscpy(pCopy->wsz1, wsz1);
  124. }
  125. else pCopy->wsz1 = NULL;
  126. if(wsz2)
  127. {
  128. pCopy->wsz2 = _new WCHAR[wcslen(wsz2)+1];
  129. if(pCopy->wsz2 == NULL)
  130. {
  131. delete pCopy;
  132. return NULL;
  133. }
  134. wcscpy(pCopy->wsz2, wsz2);
  135. }
  136. else pCopy->wsz2 = NULL;
  137. if(wsz3)
  138. {
  139. pCopy->wsz3 = _new WCHAR[wcslen(wsz3)+1];
  140. if(pCopy->wsz3 == NULL)
  141. {
  142. delete pCopy;
  143. return NULL;
  144. }
  145. wcscpy(pCopy->wsz3, wsz3);
  146. }
  147. else pCopy->wsz3 = NULL;
  148. pCopy->nObjects = nObjects;
  149. pCopy->apObjects = _new IWbemClassObject*[nObjects];
  150. if(pCopy->apObjects == NULL)
  151. {
  152. delete pCopy;
  153. return NULL;
  154. }
  155. // Make fresh copies of all objects
  156. // ================================
  157. // TBD: more effecient solutions may be possible here!
  158. for(int i = 0; i < nObjects; i++)
  159. {
  160. HRESULT hres = apObjects[i]->Clone(pCopy->apObjects + i);
  161. if(FAILED(hres))
  162. {
  163. // Abort
  164. pCopy->nObjects = i; // successfully copied
  165. delete pCopy;
  166. return NULL;
  167. }
  168. }
  169. return pCopy;
  170. }
  171. //******************************************************************************
  172. // public
  173. //
  174. // See esssink.h for documentation
  175. //
  176. //******************************************************************************
  177. INTERNAL LPCWSTR CEventRepresentation::GetEventName(EEventType type)
  178. {
  179. for(int i = 0; i < NumEventTypes(); i++)
  180. {
  181. if(staticTypes[i].type == type) return staticTypes[i].wszEventName;
  182. }
  183. return NULL;
  184. }
  185. //******************************************************************************
  186. // public
  187. //
  188. // See esssink.h for documentation
  189. //
  190. //******************************************************************************
  191. INTERNAL IWbemClassObject* CEventRepresentation::GetEventClass(
  192. CEssNamespace* pNamespace, EEventType type)
  193. {
  194. for(int i = 0; i < NumEventTypes(); i++)
  195. {
  196. if(staticTypes[i].type == type)
  197. {
  198. if(staticTypes[i].pEventClass == NULL)
  199. {
  200. _IWmiObject* pClass = NULL;
  201. HRESULT hres = pNamespace->GetClass(staticTypes[i].wszEventName,
  202. &pClass);
  203. if(FAILED(hres))
  204. return NULL;
  205. staticTypes[i].pEventClass = pClass;
  206. }
  207. return staticTypes[i].pEventClass;
  208. }
  209. }
  210. return NULL;
  211. }
  212. INTERNAL IWbemClassObject* CEventRepresentation::GetEventClass(CEss* pEss,
  213. EEventType type)
  214. {
  215. CEssNamespace* pNamespace = NULL;
  216. HRESULT hres = pEss->GetNamespaceObject( L"root", FALSE, &pNamespace);
  217. if(FAILED(hres))
  218. return NULL;
  219. IWbemClassObject* pClass = GetEventClass(pNamespace, type);
  220. pNamespace->Release();
  221. return pClass;
  222. }
  223. //******************************************************************************
  224. // public
  225. //
  226. // See esssink.h for documentation
  227. //
  228. //******************************************************************************
  229. DWORD CEventRepresentation::GetTypeMaskFromName(READ_ONLY LPCWSTR wszEventName)
  230. {
  231. if(wszEventName[0] != '_')
  232. return 1 << e_EventTypeExtrinsic;
  233. for(int i = 0; i < NumEventTypes(); i++)
  234. {
  235. if(!wbem_wcsicmp(staticTypes[i].wszEventName, wszEventName))
  236. return (1 << staticTypes[i].type);
  237. }
  238. if(!wbem_wcsicmp(wszEventName, L"__Event"))
  239. {
  240. return 0xFFFFFFFF;
  241. }
  242. if(!wbem_wcsicmp(wszEventName, L"__NamespaceOperationEvent"))
  243. {
  244. return (1 << e_EventTypeNamespaceCreation) |
  245. (1 << e_EventTypeNamespaceDeletion) |
  246. (1 << e_EventTypeNamespaceModification);
  247. }
  248. if(!wbem_wcsicmp(wszEventName, L"__ClassOperationEvent"))
  249. {
  250. return (1 << e_EventTypeClassCreation) |
  251. (1 << e_EventTypeClassDeletion) |
  252. (1 << e_EventTypeClassModification);
  253. }
  254. if(!wbem_wcsicmp(wszEventName, L"__InstanceOperationEvent"))
  255. {
  256. return (1 << e_EventTypeInstanceCreation) |
  257. (1 << e_EventTypeInstanceDeletion) |
  258. (1 << e_EventTypeInstanceModification);
  259. }
  260. if(!wbem_wcsicmp(wszEventName, EVENT_DROP_CLASS) ||
  261. !wbem_wcsicmp(wszEventName, QUEUE_OVERFLOW_CLASS) ||
  262. !wbem_wcsicmp(wszEventName, CONSUMER_FAILURE_CLASS))
  263. {
  264. return (1 << e_EventTypeSystem);
  265. }
  266. return 1 << e_EventTypeExtrinsic;
  267. }
  268. //******************************************************************************
  269. // public
  270. //
  271. // See esssink.h for documentation
  272. //
  273. //******************************************************************************
  274. EEventType CEventRepresentation::GetTypeFromName(READ_ONLY LPCWSTR wszEventName)
  275. {
  276. for(int i = 0; i < NumEventTypes(); i++)
  277. {
  278. if(!_wcsicmp(staticTypes[i].wszEventName, wszEventName))
  279. return staticTypes[i].type;
  280. }
  281. return e_EventTypeExtrinsic;
  282. }
  283. //******************************************************************************
  284. // public
  285. //
  286. // See esssink.h for documentation
  287. //
  288. //******************************************************************************
  289. HRESULT CEventRepresentation::MakeWbemObject(
  290. CEssNamespace* pNamespace,
  291. RELEASE_ME IWbemClassObject** ppEventObj)
  292. {
  293. HRESULT hres;
  294. // Check if we have a cached copy
  295. // ==============================
  296. if(m_pCachedObject != NULL)
  297. {
  298. *ppEventObj = m_pCachedObject;
  299. m_pCachedObject->AddRef();
  300. return S_OK;
  301. }
  302. if(type == e_EventTypeExtrinsic || type == e_EventTypeTimer ||
  303. type == e_EventTypeSystem)
  304. {
  305. *ppEventObj = apObjects[0];
  306. (*ppEventObj)->AddRef();
  307. return S_OK;
  308. }
  309. // Create an instance
  310. // ==================
  311. IWbemClassObject* pClass = GetEventClass(pNamespace, (EEventType)type);
  312. if(pClass == NULL)
  313. {
  314. return WBEM_E_NOT_FOUND;
  315. }
  316. IWbemClassObject* pEventObj = NULL;
  317. if(FAILED(pClass->SpawnInstance(0, &pEventObj)))
  318. {
  319. return WBEM_E_FAILED;
  320. }
  321. CReleaseMe rm1(pEventObj);
  322. // Set event-dependent properties
  323. // ==============================
  324. VARIANT vFirst, vSecond;
  325. VariantInit(&vFirst);
  326. VariantInit(&vSecond);
  327. CClearMe cm1(&vFirst);
  328. CClearMe cm2(&vSecond);
  329. if(nObjects > 0)
  330. {
  331. V_VT(&vFirst) = VT_EMBEDDED_OBJECT;
  332. V_EMBEDDED_OBJECT(&vFirst) = apObjects[0];
  333. apObjects[0]->AddRef();
  334. }
  335. if(nObjects > 1)
  336. {
  337. V_VT(&vSecond) = VT_EMBEDDED_OBJECT;
  338. V_EMBEDDED_OBJECT(&vSecond) = apObjects[1];
  339. if(apObjects[1])
  340. apObjects[1]->AddRef();
  341. else
  342. V_VT(&vSecond) = VT_NULL; // no previous!
  343. }
  344. LPCWSTR wszFirstProp = NULL, wszSecondProp = NULL;
  345. hres = WBEM_E_CRITICAL_ERROR;
  346. switch(type)
  347. {
  348. case e_EventTypeInstanceCreation:
  349. hres = pEventObj->Put(TARGET_INSTANCE_PROPNAME, 0, &vFirst, 0);
  350. break;
  351. case e_EventTypeInstanceDeletion:
  352. hres = pEventObj->Put(TARGET_INSTANCE_PROPNAME, 0, &vFirst, 0);
  353. break;
  354. case e_EventTypeInstanceModification:
  355. hres = pEventObj->Put(TARGET_INSTANCE_PROPNAME, 0, &vFirst, 0);
  356. if(SUCCEEDED(hres))
  357. hres = pEventObj->Put(PREVIOUS_INSTANCE_PROPNAME, 0,
  358. &vSecond, 0);
  359. break;
  360. case e_EventTypeClassCreation:
  361. hres = pEventObj->Put(TARGET_CLASS_PROPNAME, 0, &vFirst, 0);
  362. break;
  363. case e_EventTypeClassDeletion:
  364. hres = pEventObj->Put(TARGET_CLASS_PROPNAME, 0, &vFirst, 0);
  365. break;
  366. case e_EventTypeClassModification:
  367. hres = pEventObj->Put(TARGET_CLASS_PROPNAME, 0, &vFirst, 0);
  368. if(SUCCEEDED(hres))
  369. hres = pEventObj->Put(PREVIOUS_CLASS_PROPNAME, 0, &vSecond,
  370. 0);
  371. break;
  372. case e_EventTypeNamespaceCreation:
  373. hres = pEventObj->Put(TARGET_NAMESPACE_PROPNAME, 0, &vFirst, 0);
  374. break;
  375. case e_EventTypeNamespaceDeletion:
  376. hres = pEventObj->Put(TARGET_NAMESPACE_PROPNAME, 0, &vFirst, 0);
  377. break;
  378. case e_EventTypeNamespaceModification:
  379. hres = pEventObj->Put(TARGET_NAMESPACE_PROPNAME, 0, &vFirst, 0);
  380. if(SUCCEEDED(hres))
  381. hres = pEventObj->Put(PREVIOUS_NAMESPACE_PROPNAME, 0,
  382. &vSecond, 0);
  383. break;
  384. }
  385. if(FAILED(hres))
  386. return hres;
  387. // Decorate it
  388. // ===========
  389. if(mstatic_pDecorator)
  390. {
  391. hres = mstatic_pDecorator->DecorateObject(pEventObj, wsz1);
  392. if(FAILED(hres))
  393. return hres;
  394. }
  395. // Store it in our cache
  396. // =====================
  397. m_pCachedObject = pEventObj;
  398. m_pCachedObject->AddRef();
  399. *ppEventObj = pEventObj;
  400. (*ppEventObj)->AddRef();
  401. return S_OK;
  402. }
  403. HRESULT CEventRepresentation::CreateFromObject(IWbemClassObject* pEvent,
  404. LPWSTR wszNamespace)
  405. {
  406. HRESULT hres;
  407. // Get the class of the event
  408. // ==========================
  409. VARIANT vClass;
  410. VariantInit(&vClass);
  411. pEvent->Get(L"__CLASS", 0, &vClass, NULL, NULL);
  412. type = GetTypeFromName(V_BSTR(&vClass));
  413. dw1 = 0;
  414. dw2 = 0;
  415. wsz1 = _new WCHAR[wcslen(wszNamespace)+1];
  416. wcscpy(wsz1, wszNamespace);
  417. wsz2 = NULL;
  418. wsz3 = NULL;
  419. nObjects = 1;
  420. m_bAllocated = TRUE;
  421. IWbemClassObject** aEmbedded = new IWbemClassObject*[2];
  422. apObjects = (IWbemClassObject**)aEmbedded;
  423. aEmbedded[0] = pEvent;
  424. pEvent->AddRef();
  425. VariantClear(&vClass);
  426. // If the event is an intrinsic one, get the class of the target object
  427. // ====================================================================
  428. VARIANT vEmbed;
  429. VariantInit(&vEmbed);
  430. #define SET_FIRST_OBJECT \
  431. { \
  432. pEvent->Release(); \
  433. aEmbedded[0] = (IWbemClassObject*)V_EMBEDDED_OBJECT(&vEmbed); \
  434. aEmbedded[0]->AddRef(); \
  435. aEmbedded[0]->Get(L"__CLASS", 0, &vClass, NULL, NULL); \
  436. wsz2 = _new WCHAR[wcslen(V_BSTR(&vClass))+1]; \
  437. wcscpy(wsz2, V_BSTR(&vClass)); \
  438. VariantClear(&vEmbed); \
  439. }
  440. #define SET_SECOND_OBJECT \
  441. { \
  442. nObjects = 2; \
  443. aEmbedded[1] = (IWbemClassObject*)V_EMBEDDED_OBJECT(&vEmbed); \
  444. aEmbedded[1]->AddRef(); \
  445. VariantClear(&vEmbed); \
  446. }
  447. switch(type)
  448. {
  449. case e_EventTypeClassModification:
  450. hres = pEvent->Get(PREVIOUS_CLASS_PROPNAME, 0, &vEmbed, NULL, NULL);
  451. if(SUCCEEDED(hres))
  452. SET_SECOND_OBJECT;
  453. case e_EventTypeClassCreation:
  454. case e_EventTypeClassDeletion:
  455. hres = pEvent->Get(TARGET_CLASS_PROPNAME, 0, &vEmbed, NULL, NULL);
  456. if(SUCCEEDED(hres))
  457. SET_FIRST_OBJECT
  458. break;
  459. case e_EventTypeInstanceModification:
  460. hres = pEvent->Get(PREVIOUS_INSTANCE_PROPNAME, 0, &vEmbed,
  461. NULL, NULL);
  462. if(SUCCEEDED(hres))
  463. SET_SECOND_OBJECT;
  464. case e_EventTypeInstanceCreation:
  465. case e_EventTypeInstanceDeletion:
  466. hres = pEvent->Get(TARGET_INSTANCE_PROPNAME, 0, &vEmbed,
  467. NULL, NULL);
  468. if(SUCCEEDED(hres))
  469. SET_FIRST_OBJECT;
  470. break;
  471. case e_EventTypeNamespaceModification:
  472. hres = pEvent->Get(PREVIOUS_NAMESPACE_PROPNAME, 0, &vEmbed,
  473. NULL, NULL);
  474. if(SUCCEEDED(hres))
  475. SET_SECOND_OBJECT;
  476. case e_EventTypeNamespaceCreation:
  477. case e_EventTypeNamespaceDeletion:
  478. hres = pEvent->Get(TARGET_NAMESPACE_PROPNAME, 0, &vEmbed,
  479. NULL, NULL);
  480. if(SUCCEEDED(hres))
  481. SET_FIRST_OBJECT;
  482. break;
  483. }
  484. return WBEM_S_NO_ERROR;
  485. }
  486. //******************************************************************************
  487. // public
  488. //
  489. // See esssink.h for documentation
  490. //
  491. //******************************************************************************
  492. HRESULT CEventRepresentation::Get(READ_ONLY LPCWSTR wszPropName,
  493. INIT_AND_CLEAR_ME VARIANT* pValue)
  494. {
  495. // Get the property from the first object
  496. // ======================================
  497. return apObjects[0]->Get((LPWSTR)wszPropName, 0, pValue, NULL, NULL);
  498. }
  499. STDMETHODIMP CEventRepresentation::GetPropertyValue(WBEM_PROPERTY_NAME* pName,
  500. long lFlags, WBEM_WSTR* pwszCimType, WBEM_VARIANT* pvValue)
  501. {
  502. if(type == e_EventTypeExtrinsic || type == e_EventTypeTimer)
  503. {
  504. return GetObjectPropertyValue(apObjects[0], pName, lFlags,
  505. pwszCimType, pvValue);
  506. }
  507. if(pName->m_lNumElements == 0 ||
  508. pName->m_aElements[0].m_nType != WBEM_NAME_ELEMENT_TYPE_PROPERTY)
  509. {
  510. return WBEM_E_NOT_FOUND;
  511. }
  512. // Check if it is a system property
  513. // ================================
  514. WBEM_WSTR wszFirst = pName->m_aElements[0].Element.m_wszPropertyName;
  515. if(wszFirst[0] == L'_')
  516. {
  517. if(pwszCimType)
  518. *pwszCimType = NULL;
  519. if(!_wcsicmp(wszFirst, L"__CLASS"))
  520. {
  521. V_VT(pvValue) = VT_BSTR;
  522. V_BSTR(pvValue) = SysAllocString(GetEventName((EEventType)type));
  523. if(V_BSTR(pvValue) == NULL)
  524. return WBEM_E_OUT_OF_MEMORY;
  525. }
  526. else if(!_wcsicmp(wszFirst, L"__SUPERCLASS"))
  527. {
  528. LPCWSTR wszClass = GetEventName((EEventType)type);
  529. if(wszClass == NULL)
  530. return WBEM_E_OUT_OF_MEMORY;
  531. V_VT(pvValue) = VT_BSTR;
  532. if(wszClass[2] == 'N')
  533. {
  534. V_BSTR(pvValue) = SysAllocString(L"__NamespaceOperationEvent");
  535. if(V_BSTR(pvValue) == NULL)
  536. return WBEM_E_OUT_OF_MEMORY;
  537. }
  538. if(wszClass[2] == 'C')
  539. {
  540. V_BSTR(pvValue) = SysAllocString(L"__ClassOperationEvent");
  541. if(V_BSTR(pvValue) == NULL)
  542. return WBEM_E_OUT_OF_MEMORY;
  543. }
  544. if(wszClass[2] == 'I')
  545. {
  546. V_BSTR(pvValue) = SysAllocString(L"__InstanceOperationEvent");
  547. if(V_BSTR(pvValue) == NULL)
  548. return WBEM_E_OUT_OF_MEMORY;
  549. }
  550. else
  551. {
  552. V_BSTR(pvValue) = SysAllocString(L"__Event");
  553. if(V_BSTR(pvValue) == NULL)
  554. return WBEM_E_OUT_OF_MEMORY;
  555. }
  556. }
  557. else if(!_wcsicmp(wszFirst, L"__DYNASTY"))
  558. {
  559. V_VT(pvValue) = VT_BSTR;
  560. V_BSTR(pvValue) = SysAllocString(L"__SystemClass");
  561. if(V_BSTR(pvValue) == NULL)
  562. return WBEM_E_OUT_OF_MEMORY;
  563. }
  564. else
  565. {
  566. return WBEM_E_NOT_FOUND;
  567. }
  568. return WBEM_S_NO_ERROR;
  569. }
  570. // Remove the first segment
  571. // ========================
  572. WBEM_PROPERTY_NAME Rest;
  573. Rest.m_lNumElements = pName->m_lNumElements - 1;
  574. Rest.m_aElements = pName->m_aElements + 1;
  575. IWbemClassObject* pObj = NULL;
  576. switch(type)
  577. {
  578. case e_EventTypeInstanceCreation:
  579. case e_EventTypeInstanceDeletion:
  580. if(!_wcsicmp(wszFirst, TARGET_INSTANCE_PROPNAME))
  581. pObj = apObjects[0];
  582. break;
  583. case e_EventTypeInstanceModification:
  584. if(!_wcsicmp(wszFirst, TARGET_INSTANCE_PROPNAME))
  585. pObj = apObjects[0];
  586. else if(!_wcsicmp(wszFirst, PREVIOUS_INSTANCE_PROPNAME))
  587. pObj = apObjects[1];
  588. break;
  589. case e_EventTypeClassCreation:
  590. case e_EventTypeClassDeletion:
  591. if(!_wcsicmp(wszFirst, TARGET_CLASS_PROPNAME))
  592. pObj = apObjects[0];
  593. break;
  594. case e_EventTypeClassModification:
  595. if(!_wcsicmp(wszFirst, TARGET_CLASS_PROPNAME))
  596. pObj = apObjects[0];
  597. else if(!_wcsicmp(wszFirst, PREVIOUS_CLASS_PROPNAME))
  598. pObj = apObjects[1];
  599. break;
  600. case e_EventTypeNamespaceCreation:
  601. case e_EventTypeNamespaceDeletion:
  602. if(!_wcsicmp(wszFirst, TARGET_NAMESPACE_PROPNAME))
  603. pObj = apObjects[0];
  604. break;
  605. case e_EventTypeNamespaceModification:
  606. if(!_wcsicmp(wszFirst, TARGET_NAMESPACE_PROPNAME))
  607. pObj = apObjects[0];
  608. else if(!_wcsicmp(wszFirst, PREVIOUS_NAMESPACE_PROPNAME))
  609. pObj = apObjects[1];
  610. break;
  611. }
  612. if(pObj == NULL)
  613. return WBEM_E_NOT_FOUND;
  614. return GetObjectPropertyValue(pObj, &Rest, lFlags, pwszCimType, pvValue);
  615. }
  616. STDMETHODIMP CEventRepresentation::InheritsFrom(WBEM_WSTR wszName)
  617. {
  618. if(type == e_EventTypeExtrinsic)
  619. return apObjects[0]->InheritsFrom(wszName);
  620. LPCWSTR wszEventName = GetEventName((EEventType)type);
  621. if(wszEventName == NULL)
  622. return WBEM_E_OUT_OF_MEMORY;
  623. if(!_wcsicmp(wszName, wszEventName))
  624. return S_OK;
  625. if(!_wcsicmp(wszName, L"__IndicationRelated"))
  626. return S_OK;
  627. if(!_wcsicmp(wszName, L"__Event"))
  628. return S_OK;
  629. if(!_wcsicmp(wszName, L"__NamespaceOperationEvent") &&
  630. wcsstr(wszEventName, L"Namespace"))
  631. return S_OK;
  632. if(!_wcsicmp(wszName, L"__ClassOperationEvent") &&
  633. wcsstr(wszEventName, L"Class"))
  634. return S_OK;
  635. if(!_wcsicmp(wszName, L"__InstanceOperationEvent") &&
  636. wcsstr(wszEventName, L"Instance"))
  637. return S_OK;
  638. return S_FALSE;
  639. }
  640. HRESULT CEventRepresentation::GetObjectPropertyValue(
  641. IWbemClassObject* pObj, WBEM_PROPERTY_NAME* pName,
  642. long lFlags, WBEM_WSTR* pwszCimType,
  643. VARIANT* pvValue)
  644. {
  645. // Check if there is no name
  646. // =========================
  647. if(pName->m_lNumElements == 0)
  648. {
  649. // Return ourselves in a variant
  650. // =============================
  651. if(pwszCimType)
  652. *pwszCimType = WbemStringCopy(L"object");
  653. V_VT(pvValue) = VT_EMBEDDED_OBJECT;
  654. V_EMBEDDED_OBJECT(pvValue) = (I_EMBEDDED_OBJECT*)pObj;
  655. return S_OK;
  656. }
  657. IWbemPropertySource* pSource;
  658. if(FAILED(pObj->QueryInterface(IID_IWbemPropertySource, (void**)&pSource)))
  659. {
  660. return WBEM_E_CRITICAL_ERROR;
  661. }
  662. HRESULT hres = pSource->GetPropertyValue(pName, lFlags, pwszCimType,
  663. pvValue);
  664. pSource->Release();
  665. return hres;
  666. }