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.

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