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.

377 lines
13 KiB

  1. //******************************************************************************
  2. //
  3. // FILTPROX.H
  4. //
  5. // Copyright (C) 1996-1999 Microsoft Corporation
  6. //
  7. //******************************************************************************
  8. #ifndef __WBEM_FILTER_PROXY__H_
  9. #define __WBEM_FILTER_PROXY__H_
  10. #include <evaltree.h>
  11. #include <TimeKeeper.h>
  12. class CWrappingMetaData : public CMetaData
  13. {
  14. protected:
  15. IWbemMetaData* m_pDest;
  16. public:
  17. CWrappingMetaData(IWbemMetaData* pDest) : m_pDest(pDest)
  18. {m_pDest->AddRef();}
  19. ~CWrappingMetaData()
  20. {m_pDest->Release();}
  21. STDMETHOD(GetClass)(LPCWSTR wszName, IWbemContext* pContext,
  22. IWbemClassObject** ppClass)
  23. {return m_pDest->GetClass(wszName, pContext, ppClass);}
  24. virtual HRESULT GetClass(LPCWSTR wszName, IWbemContext* pContext,
  25. _IWmiObject** ppClass);
  26. };
  27. class CEventBatch
  28. {
  29. public:
  30. CEventBatch();
  31. ~CEventBatch();
  32. BOOL EnsureAdditionalSize(DWORD nAdditionalNeeded);
  33. BOOL AddEvent(IWbemClassObject *pObj, CSortedArray *pTrues);
  34. void RemoveAll();
  35. void SetItemCount(DWORD nItems) { m_nItems = nItems; }
  36. DWORD GetItemCount() { return m_nItems; }
  37. IWbemClassObject **GetObjs() { return m_ppObjs; }
  38. WBEM_REM_TARGETS *GetTargets() { return m_pTargets; }
  39. protected:
  40. DWORD m_nItems,
  41. m_dwSize;
  42. IWbemClassObject **m_ppObjs;
  43. WBEM_REM_TARGETS *m_pTargets;
  44. };
  45. class CFilterProxyManager;
  46. class CFilterProxy : public IWbemEventSink, public IMarshal
  47. {
  48. protected:
  49. long m_lRef;
  50. CFilterProxyManager* m_pManager;
  51. CWrappingMetaData* m_pMetaData;
  52. CEvalTree m_SourceDefinition;
  53. CEvalTree m_Filter;
  54. WORD m_wSourceVersion;
  55. WORD m_wAppliedSourceVersion;
  56. long m_lSDLength;
  57. BYTE* m_pSD;
  58. IWbemEventProvider* m_pProvider;
  59. IWbemEventProviderQuerySink* m_pQuerySink;
  60. bool m_bRunning;
  61. bool m_bUtilizeGuarantee;
  62. CCritSec m_cs;
  63. static CTimeKeeper mstatic_TimeKeeper;
  64. /////////////////////////////////////////////////////////////////////////
  65. // Batching members
  66. void BatchEvent(IWbemClassObject *pObj, CSortedArray *pTrues);
  67. HRESULT BatchMany(long nEvents, IUnknown **ppObjects);
  68. BOOL IsBatching() { return m_bBatching; }
  69. WBEM_BATCH_TYPE m_typeBatch;
  70. DWORD m_dwCurrentBufferSize,
  71. m_dwMaxBufferSize,
  72. m_dwMaxSendLatency,
  73. m_dwLastSentStamp;
  74. BOOL m_bBatching;
  75. public:
  76. static BYTE mstatic_EmptySD;
  77. HRESULT Lock();
  78. HRESULT Unlock();
  79. HRESULT AddFilter(IWbemContext* pContext, LPCWSTR wszQuery,
  80. QL_LEVEL_1_RPN_EXPRESSION* pExp,
  81. WBEM_REMOTE_TARGET_ID_TYPE Id);
  82. HRESULT RemoveFilter(IWbemContext* pContext,
  83. WBEM_REMOTE_TARGET_ID_TYPE Id);
  84. HRESULT RemoveAllFilters(IWbemContext* pContext);
  85. HRESULT AddDefinitionQuery(IWbemContext* pContext, LPCWSTR wszQuery);
  86. HRESULT RemoveAllDefinitionQueries(IWbemContext* pContext);
  87. HRESULT AllowUtilizeGuarantee();
  88. HRESULT TransferFiltersFromMain(CFilterProxy* pMain);
  89. HRESULT FilterEvent( _IWmiObject* pEvent, CSortedArray& raTrues );
  90. public:
  91. CFilterProxy(CFilterProxyManager* pManager, IUnknown* pCallback = NULL);
  92. ~CFilterProxy();
  93. HRESULT SetRunning();
  94. // IUnknown
  95. ULONG STDMETHODCALLTYPE AddRef();
  96. ULONG STDMETHODCALLTYPE Release();
  97. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
  98. // IWbemObjectSink
  99. HRESULT STDMETHODCALLTYPE Indicate(long lNumObjects,
  100. IWbemClassObject** apObjects);
  101. HRESULT STDMETHODCALLTYPE SetStatus(long lFlags, HRESULT hResult,
  102. BSTR strResult, IWbemClassObject* pErrorObj);
  103. HRESULT STDMETHODCALLTYPE IndicateWithSD(
  104. long lNumObjects,
  105. IUnknown** apObjects,
  106. long lSDLength,
  107. BYTE* pSD);
  108. HRESULT STDMETHODCALLTYPE SetSinkSecurity(
  109. long lSDLength,
  110. BYTE* pSD);
  111. HRESULT STDMETHODCALLTYPE IsActive();
  112. HRESULT STDMETHODCALLTYPE GetRestrictedSink(
  113. long lNumQueries,
  114. const LPCWSTR* awszQueries,
  115. IUnknown* pCallback,
  116. IWbemEventSink** ppSink);
  117. HRESULT STDMETHODCALLTYPE SetBatchingParameters(
  118. LONG lFlags,
  119. DWORD dwMaxBufferSize,
  120. DWORD dwMaxSendLatency);
  121. // IMarshal
  122. STDMETHOD(GetUnmarshalClass)(REFIID riid, void* pv, DWORD dwDestContext,
  123. void* pvReserved, DWORD mshlFlags, CLSID* pClsid);
  124. STDMETHOD(GetMarshalSizeMax)(REFIID riid, void* pv, DWORD dwDestContext,
  125. void* pvReserved, DWORD mshlFlags, ULONG* plSize);
  126. STDMETHOD(MarshalInterface)(IStream* pStream, REFIID riid, void* pv,
  127. DWORD dwDestContext, void* pvReserved, DWORD mshlFlags);
  128. STDMETHOD(UnmarshalInterface)(IStream* pStream, REFIID riid, void** ppv)
  129. {return E_NOTIMPL;}
  130. STDMETHOD(ReleaseMarshalData)(IStream* pStream)
  131. {return E_NOTIMPL;}
  132. STDMETHOD(DisconnectObject)(DWORD dwReserved)
  133. {return E_NOTIMPL;}
  134. protected:
  135. HRESULT ProcessOne(IUnknown* pObj, long lSDLength, BYTE* pSD);
  136. HRESULT ProcessMany(long lNumObjects, IUnknown** apObjects,
  137. long lSDLength, BYTE* pSD);
  138. static void SetGenerationTime(_IWmiObject* pObj);
  139. };
  140. class CFilterProxyManagerBase
  141. {
  142. CLifeControl* m_pControl;
  143. public:
  144. CFilterProxyManagerBase( CLifeControl* pControl ) : m_pControl(pControl)
  145. {
  146. if( m_pControl != NULL )
  147. {
  148. m_pControl->ObjectCreated( (IUnknown*)this );
  149. }
  150. }
  151. ~CFilterProxyManagerBase()
  152. {
  153. if( m_pControl != NULL )
  154. {
  155. m_pControl->ObjectDestroyed( (IUnknown*)this );
  156. }
  157. }
  158. };
  159. class CFilterProxyManager : public IMarshal, CFilterProxyManagerBase
  160. {
  161. protected:
  162. long m_lRef;
  163. long m_lExtRef;
  164. IWbemMultiTarget* m_pMultiTarget;
  165. CWrappingMetaData* m_pMetaData;
  166. IWbemFilterStub* m_pStub;
  167. IWbemContext* m_pSpecialContext;
  168. CCritSec m_cs;
  169. CWbemCriticalSection m_Lock;
  170. CUniquePointerArray<CFilterProxy> m_apProxies;
  171. typedef std::map< WBEM_REMOTE_TARGET_ID_TYPE,
  172. WString,
  173. std::less< WBEM_REMOTE_TARGET_ID_TYPE >,
  174. wbem_allocator< WString > > TMap;
  175. typedef TMap::iterator TIterator;
  176. TMap m_mapQueries;
  177. /////////////////////////////////////////////////////////////////////////
  178. // Protected batching members
  179. typedef std::map< CFilterProxy*,
  180. DWORD,
  181. std::less< CFilterProxy* >,
  182. wbem_allocator< DWORD > > CLatencyMap;
  183. typedef CLatencyMap::iterator CLatencyMapItor;
  184. CLatencyMap m_mapLatencies;
  185. HANDLE m_heventDone,
  186. m_hthreadSend,
  187. m_heventEventsPending,
  188. m_heventBufferNotFull,
  189. m_heventBufferFull;
  190. DWORD m_dwMaxSendLatency,
  191. m_dwLastSentStamp;
  192. CCritSec m_csBuffer;
  193. CEventBatch m_batch;
  194. IStream *m_pMultiTargetStream;
  195. void LockBatching() { EnterCriticalSection(&m_csBuffer); }
  196. void UnlockBatching() { LeaveCriticalSection(&m_csBuffer); }
  197. BOOL IsBatching() { return m_hthreadSend != NULL; }
  198. CEventBatch *GetBatch(LPBYTE pSD, DWORD dwLength);
  199. void CalcMaxSendLatency();
  200. static DWORD WINAPI SendThreadProc(CFilterProxyManager *pThis);
  201. BOOL StartSendThread();
  202. void StopSendThread();
  203. protected:
  204. class XProxy : public IWbemLocalFilterProxy
  205. {
  206. protected:
  207. CFilterProxyManager* m_pObject;
  208. public:
  209. XProxy(CFilterProxyManager* pObject) : m_pObject(pObject){}
  210. // IUnknown
  211. ULONG STDMETHODCALLTYPE AddRef();
  212. ULONG STDMETHODCALLTYPE Release();
  213. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
  214. // IWbemFilterProxy
  215. HRESULT STDMETHODCALLTYPE Initialize(IWbemMetaData* pMetaData,
  216. IWbemMultiTarget* pMultiTarget);
  217. HRESULT STDMETHODCALLTYPE Lock();
  218. HRESULT STDMETHODCALLTYPE Unlock();
  219. HRESULT STDMETHODCALLTYPE AddFilter(IWbemContext* pContext,
  220. LPCWSTR wszQuery,
  221. WBEM_REMOTE_TARGET_ID_TYPE Id);
  222. HRESULT STDMETHODCALLTYPE RemoveFilter(IWbemContext* pContext,
  223. WBEM_REMOTE_TARGET_ID_TYPE Id);
  224. HRESULT STDMETHODCALLTYPE RemoveAllFilters(IWbemContext* pContext);
  225. HRESULT STDMETHODCALLTYPE AddDefinitionQuery(IWbemContext* pContext,
  226. LPCWSTR wszQuery);
  227. HRESULT STDMETHODCALLTYPE RemoveAllDefinitionQueries(
  228. IWbemContext* pContext);
  229. HRESULT STDMETHODCALLTYPE AllowUtilizeGuarantee();
  230. HRESULT STDMETHODCALLTYPE Disconnect();
  231. HRESULT STDMETHODCALLTYPE SetStub(IWbemFilterStub* pStub);
  232. HRESULT STDMETHODCALLTYPE LocalAddFilter(IWbemContext* pContext,
  233. LPCWSTR wszQuery,
  234. void* pExp,
  235. WBEM_REMOTE_TARGET_ID_TYPE Id);
  236. HRESULT STDMETHODCALLTYPE GetMainSink(IWbemEventSink** ppSink);
  237. } m_XProxy;
  238. IWbemContext* GetProperContext(IWbemContext* pCurrentContext);
  239. public:
  240. CFilterProxyManager(CLifeControl* pControl = NULL);
  241. ~CFilterProxyManager();
  242. HRESULT SetStub(IWbemFilterStub* pStub);
  243. HRESULT AddFilter(IWbemContext* pContext, LPCWSTR wszQuery,
  244. QL_LEVEL_1_RPN_EXPRESSION* pExp,
  245. WBEM_REMOTE_TARGET_ID_TYPE Id);
  246. INTERNAL IWbemEventSink* GetMainProxy();
  247. HRESULT RemoveProxy(CFilterProxy* pProxy);
  248. HRESULT GetMetaData(RELEASE_ME CWrappingMetaData** ppMeta);
  249. HRESULT DeliverEvent(long lNumToSend, IWbemClassObject** apEvents,
  250. WBEM_REM_TARGETS* aTargets,
  251. long lSDLength, BYTE* pSD);
  252. HRESULT DeliverEventMT(long lNumToSend, IWbemClassObject** apEvents,
  253. WBEM_REM_TARGETS* aTargets,
  254. long lSDLength, BYTE* pSD,
  255. IWbemMultiTarget *pMultiTarget);
  256. ULONG STDMETHODCALLTYPE AddRefProxy();
  257. ULONG STDMETHODCALLTYPE ReleaseProxy();
  258. HRESULT SetStatus(long lFlags, HRESULT hResult,
  259. BSTR strResult, IWbemClassObject* pErrorObj);
  260. // Batching
  261. void AddEvent(IWbemClassObject *pObj, CSortedArray *pTrues);
  262. HRESULT SetProxyLatency(CFilterProxy *pProxy, DWORD dwLatency);
  263. void RemoveProxyLatency(CFilterProxy *pProxy);
  264. DWORD GetLastSentStamp();
  265. void WaitForEmptyBatch();
  266. // IUnknown
  267. ULONG STDMETHODCALLTYPE AddRef();
  268. ULONG STDMETHODCALLTYPE Release();
  269. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
  270. // IWbemFilterProxy
  271. HRESULT STDMETHODCALLTYPE Initialize(IWbemMetaData* pMetaData,
  272. IWbemMultiTarget* pMultiTarget);
  273. HRESULT STDMETHODCALLTYPE Lock();
  274. HRESULT STDMETHODCALLTYPE Unlock();
  275. HRESULT STDMETHODCALLTYPE AddFilter(IWbemContext* pContext,
  276. LPCWSTR wszQuery,
  277. WBEM_REMOTE_TARGET_ID_TYPE Id);
  278. HRESULT STDMETHODCALLTYPE RemoveFilter(IWbemContext* pContext,
  279. WBEM_REMOTE_TARGET_ID_TYPE Id);
  280. HRESULT STDMETHODCALLTYPE RemoveAllFilters(IWbemContext* pContext);
  281. HRESULT STDMETHODCALLTYPE AddDefinitionQuery(IWbemContext* pContext,
  282. LPCWSTR wszQuery);
  283. HRESULT STDMETHODCALLTYPE RemoveAllDefinitionQueries(
  284. IWbemContext* pContext);
  285. HRESULT STDMETHODCALLTYPE AllowUtilizeGuarantee();
  286. HRESULT STDMETHODCALLTYPE Disconnect();
  287. HRESULT STDMETHODCALLTYPE GetRestrictedSink(
  288. long lNumQueries,
  289. const LPCWSTR* awszQueries,
  290. IUnknown* pCallback,
  291. IWbemEventSink** ppSink);
  292. // IMarshal
  293. STDMETHOD(GetUnmarshalClass)(REFIID riid, void* pv, DWORD dwDestContext,
  294. void* pvReserved, DWORD mshlFlags, CLSID* pClsid);
  295. STDMETHOD(GetMarshalSizeMax)(REFIID riid, void* pv, DWORD dwDestContext,
  296. void* pvReserved, DWORD mshlFlags, ULONG* plSize);
  297. STDMETHOD(MarshalInterface)(IStream* pStream, REFIID riid, void* pv,
  298. DWORD dwDestContext, void* pvReserved, DWORD mshlFlags);
  299. STDMETHOD(UnmarshalInterface)(IStream* pStream, REFIID riid, void** ppv);
  300. STDMETHOD(ReleaseMarshalData)(IStream* pStream);
  301. STDMETHOD(DisconnectObject)(DWORD dwReserved);
  302. };
  303. #endif