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.

384 lines
15 KiB

  1. //*****************************************************************************
  2. //
  3. // Copyright (c) 1996-1999, Microsoft Corporation, All rights reserved
  4. //
  5. // EVENTREP.H
  6. //
  7. // This file contains basic definitions and classes for event representation.
  8. //
  9. // Classes defined:
  10. //
  11. // CEventRepresentation
  12. //
  13. // History:
  14. //
  15. // 11/27/96 a-levn Compiles.
  16. //
  17. //*****************************************************************************
  18. #ifndef __EVENT_REP__H_
  19. #define __EVENT_REP__H_
  20. #include <wbemidl.h>
  21. #include <wbemint.h>
  22. #include "parmdefs.h"
  23. #include <wbemcomn.h>
  24. // Class and property names of the schema objects related to event subsystem
  25. // =========================================================================
  26. #define SECURITY_DESCRIPTOR_PROPNAME L"SECURITY_DESCRIPTOR"
  27. #define EVENT_PROVIDER_REGISTRATION_CLASS L"__EventProviderRegistration"
  28. #define PROVIDER_CLASS L"__Provider"
  29. #define EVENT_FILTER_CLASS L"__EventFilter"
  30. #define BASE_STANDARD_FILTER_CLASS L"__BaseStandardEventFilter"
  31. #define CONSUMER_CLASS L"__EventConsumer"
  32. #define BINDING_CLASS L"__FilterToConsumerBinding"
  33. #define GENERATOR_CLASS L"__EventGenerator"
  34. #define GENERATOR_BINDING_CLASS L"__GeneratorToConsumerBinding"
  35. #define TIMER_BASE_CLASS L"__TimerInstruction"
  36. #define TIMER_ABSOLUTE_CLASS L"__AbsoluteTimerInstruction"
  37. #define TIMER_INTERVAL_CLASS L"__IntervalTimerInstruction"
  38. #define WIN32_PROVIDER_CLASS L"__Win32Provider"
  39. #define CONSUMER_PROVIDER_REGISTRATION_CLASS \
  40. L"__EventConsumerProviderRegistration"
  41. #define EVENT_DROP_CLASS L"__EventDroppedEvent"
  42. #define QUEUE_OVERFLOW_CLASS L"__EventQueueOverflowEvent"
  43. #define CONSUMER_FAILURE_CLASS L"__ConsumerFailureEvent"
  44. #define QOS_FAILURE_CLASS L"__QoSFailureEvent"
  45. #define OWNER_SID_PROPNAME L"CreatorSID"
  46. #define FILTER_ROLE_NAME L"Filter"
  47. #define CONSUMER_ROLE_NAME L"Consumer"
  48. #define BINDING_QOS_PROPNAME L"DeliveryQoS"
  49. #define BINDING_SYNCHRONICITY_PROPNAME L"DeliverSynchronously"
  50. #define BINDING_SECURE_PROPNAME L"MaintainSecurityContext"
  51. #define BINDING_SLOWDOWN_PROPNAME L"SlowDownProviders"
  52. #define TIMER_ID_PROPNAME L"TimerID"
  53. #define FILTER_KEY_PROPNAME L"Name"
  54. #define FILTER_QUERY_PROPNAME L"Query"
  55. #define FILTER_LANGUAGE_PROPNAME L"QueryLanguage"
  56. #define FILTER_EVENTNAMESPACE_PROPNAME L"EventNamespace"
  57. #define FILTER_EVENTACCESS_PROPNAME L"EventAccess"
  58. #define FILTER_GUARDNAMESPACE_PROPNAME L"ConditionNamespace"
  59. #define FILTER_GUARD_PROPNAME L"Condition"
  60. #define FILTER_GUARDLANG_PROPNAME L"ConditionLanguage"
  61. #define CONSUMER_MACHINE_NAME_PROPNAME L"MachineName"
  62. #define CONSUMER_MAXQUEUESIZE_PROPNAME L"MaximumQueueSize"
  63. #define PROVIDER_CLSID_PROPNAME L"Clsid"
  64. #define PROVIDER_NAME_PROPNAME L"Name"
  65. #define EVPROVREG_PROVIDER_REF_PROPNAME L"Provider"
  66. #define EVPROVREG_QUERY_LIST_PROPNAME L"EventQueryList"
  67. #define CONSPROV_PROVIDER_REF_PROPNAME L"Provider"
  68. #define CONSPROV_CLSID_PROPNAME L"CLSID"
  69. #define TARGET_NAMESPACE_PROPNAME L"TargetNamespace"
  70. #define PREVIOUS_NAMESPACE_PROPNAME L"PreviousNamespace"
  71. #define TARGET_CLASS_PROPNAME L"TargetClass"
  72. #define PREVIOUS_CLASS_PROPNAME L"PreviousCLass"
  73. #define TARGET_INSTANCE_PROPNAME L"TargetInstance"
  74. #define PREVIOUS_INSTANCE_PROPNAME L"PreviousInstance"
  75. #define EVENT_DROP_EVENT_PROPNAME L"Event"
  76. #define EVENT_DROP_CONSUMER_PROPNAME L"IntendedConsumer"
  77. #define CONSUMER_FAILURE_ERROR_PROPNAME L"ErrorCode"
  78. #define CONSUMER_FAILURE_ERROROBJ_PROPNAME L"ErrorObject"
  79. #define QOS_FAILURE_ERROR_PROPNAME L"ErrorCode"
  80. #define QUEUE_OVERFLOW_SIZE_PROPNAME L"CurrentQueueSize"
  81. #define MONITOR_BASE_EVENT_CLASS L"__MonitorEvent"
  82. #define MONITOR_DATA_EVENT_CLASS L"__MonitorDataEvent"
  83. #define ASSERT_EVENT_CLASS L"__MonitorAssertEvent"
  84. #define RETRACT_EVENT_CLASS L"__MonitorRetractEvent"
  85. #define GOINGUP_EVENT_CLASS L"__MonitorUpEvent"
  86. #define GOINGDOWN_EVENT_CLASS L"__MonitorDownEvent"
  87. #define MONITORERROR_EVENT_CLASS L"__MonitorErrorEvent"
  88. #define MONITOR_CLASS L"__MonitorInstruction"
  89. #define MONITORNAME_EVENT_PROPNAME L"MonitorName"
  90. #define MONITOROBJECT_EVENT_PROPNAME L"RowObject"
  91. #define MONITORCOUNT_EVENT_PROPNAME L"TotalObjects"
  92. #define MONITORNEW_EVENT_PROPNAME L"GuaranteedNew"
  93. #define MONITOR_NAME_PROPNAME L"Name"
  94. #define MONITOR_QUERY_PROPNAME L"Query"
  95. #define MONITOR_QUERYLANG_PROPNAME L"QueryLanguage"
  96. #define MONITOR_NAMESPACE_PROPNAME L"TargetNamespace"
  97. #define E_NOTFOUND WBEM_E_NOT_FOUND
  98. typedef IWbemClassObject IWbemEvent;
  99. // Helper functions
  100. // ================
  101. inline DELETE_ME LPWSTR CloneWstr(READ_ONLY LPCWSTR wsz)
  102. {
  103. LPWSTR wszNew = new WCHAR[wcslen(wsz)+1];
  104. if(wszNew == NULL)
  105. return NULL;
  106. wcscpy(wszNew, wsz);
  107. return wszNew;
  108. }
  109. // Event types. These are used in IndicateEx calls, as well as internally.
  110. // =======================================================================
  111. typedef enum{
  112. e_EventTypeInvalid = WBEM_EVENTTYPE_Invalid,
  113. e_EventTypeExtrinsic = WBEM_EVENTTYPE_Extrinsic,
  114. e_EventTypeTimer = WBEM_EVENTTYPE_Timer,
  115. e_EventTypeNamespaceCreation = WBEM_EVENTTYPE_NamespaceCreation,
  116. e_EventTypeNamespaceDeletion = WBEM_EVENTTYPE_NamespaceDeletion,
  117. e_EventTypeNamespaceModification = WBEM_EVENTTYPE_NamespaceModification,
  118. e_EventTypeClassCreation = WBEM_EVENTTYPE_ClassCreation,
  119. e_EventTypeClassDeletion = WBEM_EVENTTYPE_ClassDeletion,
  120. e_EventTypeClassModification = WBEM_EVENTTYPE_ClassModification,
  121. e_EventTypeInstanceCreation = WBEM_EVENTTYPE_InstanceCreation,
  122. e_EventTypeInstanceDeletion = WBEM_EVENTTYPE_InstanceDeletion,
  123. e_EventTypeInstanceModification = WBEM_EVENTTYPE_InstanceModification,
  124. e_EventTypeSystem = WBEM_EVENTTYPE_System
  125. } EEventType;
  126. #define INTRINSIC_EVENTS_MASK (~(1<<e_EventTypeExtrinsic))
  127. #define INSTANCE_EVENTS_MASK ( \
  128. (1<<e_EventTypeInstanceCreation) | \
  129. (1<<e_EventTypeInstanceDeletion) | \
  130. (1<<e_EventTypeInstanceModification))
  131. #define CLASS_EVENTS_MASK ( \
  132. (1<<e_EventTypeClassCreation) | \
  133. (1<<e_EventTypeClassDeletion) | \
  134. (1<<e_EventTypeClassModification))
  135. #define NAMESPACE_EVENTS_MASK ( \
  136. (1<<e_EventTypeNamespaceCreation) | \
  137. (1<<e_EventTypeNamespaceDeletion) | \
  138. (1<<e_EventTypeNamespaceModification))
  139. #define DATA_EVENTS_MASK \
  140. (INSTANCE_EVENTS_MASK | CLASS_EVENTS_MASK | NAMESPACE_EVENTS_MASK)
  141. //*****************************************************************************
  142. //
  143. // class CEventRepresentation
  144. //
  145. // This class represents an event that ESS receives. It has public datafields
  146. // corresponding to the parameters of the IndicateEx call and that is
  147. // precisely what is stored in it.
  148. //
  149. // This class has two types of existence: allocated and not allocated. Non
  150. // allocated state is the default. In it, CEventRepresentation string fields
  151. // contain pointers to data that does not 'belong' to this class, and is not
  152. // deleted in the destructor.
  153. //
  154. // The other, allocated, state is entered when a new copy of this object is
  155. // created using MakePermanentCopy(). In this state, all string fields contain
  156. // allocated data which is deleted on destruct.
  157. //
  158. // CEventRepresentation also contains a table mapping event types into event
  159. // class names and event filter class names.
  160. //
  161. // Finally, CEventRepresentation is derived from CPropertySource and provides
  162. // property values (taken from the first included IWbemClassObject) to the
  163. // SQL1 query evaluator.
  164. //
  165. //*****************************************************************************
  166. //
  167. // MakePermanentCopy
  168. //
  169. // This function produces a new copy of the event, which can survive complete
  170. // destruction of the original object. All strings are reallocated and all
  171. // IWbemClassObjects are Clone'ed. The reason for that is that WinMgmt core may
  172. // call ESS with temporary (non-OLE) objects, and if ESS needs to keep them
  173. // after it returns from the call, it needs to make a complete copy.
  174. //
  175. // Returns:
  176. //
  177. // CEventRepresentation* pointing to the new object, Must be deleted
  178. // by the called.
  179. //
  180. //*****************************************************************************
  181. //
  182. // MakeWbemObject
  183. //
  184. // This function creates an IWbemClassObject representation of the event for
  185. // clients that do not accept NotifyEx calls. The object will be of the class
  186. // determined by the type of the event and will contain all the properties
  187. // appropriate for that class (with values taken from CEventRepresentation
  188. // properties).
  189. //
  190. // Parameters:
  191. //
  192. // IWbemClassObject** ppEventObject Destination for the newely created
  193. // object. Caller must Release it when
  194. // done.
  195. // Returns:
  196. //
  197. // S_OK on success
  198. // S_FALSE if event is extrinsic. When extrinsic events are specified
  199. // in IndicateEx, the first object IS the class object for
  200. // the event, and so no additional object creation is
  201. // necessary for Indicate.
  202. //
  203. // Any CoCreateInstance error.
  204. // Any IWbemClassObject::Put error.
  205. //
  206. //*****************************************************************************
  207. //
  208. // static GetEventName
  209. //
  210. // Retreives the name of the event class corresponding to a given
  211. // event type.
  212. //
  213. // Parameters:
  214. //
  215. // EEventType type
  216. //
  217. // Returns:
  218. //
  219. // LPCWSTR containing the event class name. This pointer is internal and
  220. // may NOT be modified or deleted.
  221. //
  222. //*****************************************************************************
  223. //
  224. // static GetTypeFromName
  225. //
  226. // Retreives the type of the event given the name of the event class.
  227. //
  228. // Parameters:
  229. //
  230. // LPCWSTR wszEventName The name of the event class.
  231. //
  232. // Returns:
  233. //
  234. // EEventType
  235. //
  236. //*****************************************************************************
  237. //
  238. // Get
  239. //
  240. // Retrives the value of a property, as required by CPropertySource class.
  241. // This implementation uses the first included object (apObjects[0]) to
  242. // get the values. Access to other objects is not available.
  243. //
  244. // Parameters:
  245. //
  246. // LPCWSTR wszPropName The same name as in IWbemClassObject
  247. // VARIANT* pValue Destination for the value. The caller must
  248. // initialize and clear this value.
  249. // Returns:
  250. //
  251. // S_OK on success
  252. // Any IWbemClassObject::Get error code
  253. //
  254. //*****************************************************************************
  255. class CEssNamespace;
  256. class CEss;
  257. class CEventRepresentation
  258. {
  259. protected:
  260. BOOL m_bAllocated;
  261. IWbemClassObject* m_pCachedObject;
  262. public:
  263. long type;
  264. DWORD dw1;
  265. DWORD dw2;
  266. LPWSTR wsz1;
  267. LPWSTR wsz2;
  268. LPWSTR wsz3;
  269. int nObjects;
  270. IWbemClassObject** apObjects;
  271. public:
  272. CEventRepresentation()
  273. : m_bAllocated(FALSE),
  274. m_pCachedObject(NULL),
  275. wsz1( NULL ),
  276. wsz2( NULL ),
  277. wsz3( NULL ),
  278. apObjects( NULL )
  279. {
  280. // uninitialized for speed
  281. }
  282. ~CEventRepresentation();
  283. STDMETHOD_(ULONG, AddRef)() {return 1;}
  284. STDMETHOD_(ULONG, Release)() {return 1;}
  285. STDMETHOD(QueryInterface)(REFIID riid, void** ppv)
  286. {*ppv = this; return S_OK;}
  287. STDMETHOD(GetPropertyValue)(WBEM_PROPERTY_NAME* pName, long lFlags,
  288. WBEM_WSTR* pwszCimType, WBEM_VARIANT* pvValue);
  289. STDMETHOD(InheritsFrom)(WBEM_WSTR wszName);
  290. inline EEventType GetEventType() {return (EEventType)type;}
  291. DELETE_ME CEventRepresentation* MakePermanentCopy();
  292. HRESULT MakeWbemObject(CEssNamespace* pNamespace,
  293. RELEASE_ME IWbemClassObject** ppEventObj);
  294. HRESULT CreateFromObject(IWbemClassObject* pEvent, LPWSTR wszNamespace);
  295. HRESULT Get(READ_ONLY LPCWSTR wszPropName,
  296. INIT_AND_CLEAR_ME VARIANT* pValue);
  297. inline BOOL IsInstanceEvent();
  298. inline BOOL IsClassEvent();
  299. static HRESULT Initialize(IWbemServices* pNamespace,
  300. IWbemDecorator* pDecorator);
  301. static HRESULT Shutdown();
  302. static INTERNAL LPCWSTR GetEventName(EEventType type);
  303. static DWORD GetTypeMaskFromName(READ_ONLY LPCWSTR wszEventName);
  304. static EEventType GetTypeFromName(READ_ONLY LPCWSTR wszEventName);
  305. static INTERNAL IWbemClassObject* GetEventClass(CEssNamespace* pNamespace,
  306. EEventType type);
  307. static INTERNAL IWbemClassObject* GetEventClass(CEss* pNamespace,
  308. EEventType type);
  309. protected:
  310. static HRESULT GetObjectPropertyValue(IWbemClassObject* pObj,
  311. WBEM_PROPERTY_NAME* pName,
  312. long lFlags, WBEM_WSTR* pwszCimType,
  313. VARIANT* pvValue);
  314. struct CEventTypeData
  315. {
  316. EEventType type;
  317. LPWSTR wszEventName;
  318. IWbemClassObject* pEventClass;
  319. };
  320. static CEventTypeData staticTypes[];
  321. static int NumEventTypes();
  322. static IWbemDecorator* mstatic_pDecorator;
  323. friend class CEss;
  324. };
  325. #define CLASS_OF(EVENT) (EVENT.wsz2)
  326. #define NAMESPACE_OF(EVENT) (EVENT.wsz1)
  327. #define OBJECT_OF(EVENT) (EVENT.apObjects[0])
  328. #define OTHER_OBJECT_OF(EVENT) (EVENT.apObjects[1])
  329. inline BOOL CEventRepresentation::IsInstanceEvent()
  330. {
  331. return (type == e_EventTypeInstanceCreation ||
  332. type == e_EventTypeInstanceModification ||
  333. type == e_EventTypeInstanceDeletion);
  334. }
  335. inline BOOL CEventRepresentation::IsClassEvent()
  336. {
  337. return (type == e_EventTypeClassCreation ||
  338. type == e_EventTypeClassModification ||
  339. type == e_EventTypeClassDeletion);
  340. }
  341. #endif