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.

331 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. seolib.h
  5. Abstract:
  6. This module contains definitions for useful utility
  7. classes and functions for the Server Extentions Object
  8. system.
  9. Author:
  10. Don Dumitru (dondu@microsoft.com)
  11. Revision History:
  12. dondu 05/20/97 Created.
  13. dondu 07/03/97 Rewrite.
  14. --*/
  15. #include "rwnew.h"
  16. #include "seoexports.h"
  17. /*
  18. See the ddrop2 test program for an example of how to
  19. use the CEventBaseDispatcher class.
  20. */
  21. template<class T, DWORD dwGrowBy=4>
  22. class CSEOGrowableList {
  23. public:
  24. CSEOGrowableList() {
  25. m_dwCount = 0;
  26. m_dwAlloc = 0;
  27. m_apData = NULL;
  28. };
  29. ~CSEOGrowableList() {
  30. RemoveAll();
  31. };
  32. DWORD Count() {
  33. return (m_dwCount);
  34. };
  35. T* Index(DWORD dwIdx) {
  36. T *pRet = NULL;
  37. m_slData.ShareLock();
  38. if (dwIdx<m_dwCount) {
  39. pRet = m_apData[dwIdx];
  40. }
  41. m_slData.ShareUnlock();
  42. return pRet;
  43. };
  44. T& operator[](DWORD dwIdx) {
  45. T *pRet = Index(dwIdx);
  46. _ASSERTE(pRet);
  47. return *pRet;
  48. };
  49. virtual int Compare(T* p1, T* p2) {
  50. // don't sort by default
  51. return (1);
  52. };
  53. HRESULT Add(T* pNewData) {
  54. if (!pNewData) {
  55. return (E_POINTER);
  56. }
  57. m_slData.ExclusiveLock();
  58. // Check if we have space for the new item and allocate more memory if necessary
  59. if (m_dwCount == m_dwAlloc) {
  60. // Allocate
  61. T** pNewData = (T**)realloc(m_apData,sizeof(T*)*(m_dwAlloc+dwGrowBy));
  62. if (!pNewData) {
  63. m_slData.ExclusiveUnlock();
  64. return(E_OUTOFMEMORY);
  65. }
  66. m_apData = pNewData;
  67. m_dwAlloc += dwGrowBy;
  68. // Clear new memory
  69. memset(m_apData+m_dwCount,0,sizeof(T*)*dwGrowBy);
  70. }
  71. // Now find the position for the new item - we loop from the
  72. // end to the start so that we can minimize the cost inserting
  73. // unsorted items
  74. for (DWORD dwIdx=m_dwCount;dwIdx>0;dwIdx--) {
  75. int iCmpRes = Compare(pNewData,m_apData[dwIdx-1]);
  76. if (iCmpRes < 0) {
  77. continue;
  78. }
  79. break;
  80. }
  81. // Now move the items past the new item and insert it
  82. memmove(m_apData+dwIdx+1,m_apData+dwIdx,sizeof(T*)*(m_dwCount-dwIdx));
  83. m_apData[dwIdx] = pNewData;
  84. m_dwCount++;
  85. m_slData.ExclusiveUnlock();
  86. return (S_OK);
  87. };
  88. void Remove(DWORD dwIdx, T **ppT) {
  89. if (!ppT) {
  90. _ASSERTE(FALSE);
  91. return;
  92. }
  93. m_slData.ExclusiveLock();
  94. if (dwIdx >= m_dwCount) {
  95. _ASSERTE(FALSE);
  96. *ppT = NULL;
  97. return;
  98. }
  99. *ppT = m_apData[dwIdx];
  100. memmove(&m_apData[dwIdx],&m_apData[dwIdx+1],sizeof(m_apData[0])*(m_dwCount-dwIdx-1));
  101. m_dwCount--;
  102. m_slData.ExclusiveUnlock();
  103. };
  104. void Remove(DWORD dwIdx) {
  105. T *pT;
  106. Remove(dwIdx,&pT);
  107. delete pT;
  108. };
  109. void RemoveAll() {
  110. m_slData.ExclusiveLock();
  111. if (m_apData) {
  112. for (DWORD dwIdx=0;dwIdx<m_dwCount;dwIdx++) {
  113. delete m_apData[dwIdx];
  114. }
  115. free(m_apData);
  116. }
  117. m_dwCount = 0;
  118. m_dwAlloc = 0;
  119. m_apData = NULL;
  120. m_slData.ExclusiveUnlock();
  121. }
  122. protected:
  123. DWORD m_dwCount;
  124. DWORD m_dwAlloc;
  125. T** m_apData;
  126. CShareLockNH m_slData;
  127. };
  128. class CEventBaseDispatcher : public IEventDispatcher {
  129. public:
  130. CEventBaseDispatcher();
  131. virtual ~CEventBaseDispatcher();
  132. class CBinding {
  133. public:
  134. CBinding();
  135. virtual ~CBinding();
  136. virtual HRESULT Init(IEventBinding *piBinding);
  137. virtual int Compare(const CBinding& b) const;
  138. static HRESULT InitRuleEngine(IEventBinding *piBinding, REFIID iidDesired, IUnknown **ppUnkRuleEngine);
  139. virtual HRESULT InitRuleEngine();
  140. public:
  141. BOOL m_bIsValid;
  142. CComPtr<IEventBinding> m_piBinding;
  143. BOOL m_bExclusive;
  144. DWORD m_dwPriority;
  145. };
  146. class CBindingList : public CSEOGrowableList<CBinding> {
  147. public:
  148. virtual int Compare(CBinding* p1, CBinding* p2);
  149. };
  150. class CParams {
  151. public:
  152. virtual HRESULT CheckRule(CBinding& bBinding);
  153. // returns S_OK if the object should be called
  154. // returns S_FALSE if the object should not be called
  155. // any other return value causes the object to not be called
  156. virtual HRESULT CallObject(IEventManager *piManager, CBinding& bBinding);
  157. // returns S_OK if the object was called
  158. // returns S_FALSE if the object was called and if no other objects should be called
  159. // returns FAILED() if the object was not called
  160. virtual HRESULT CallObject(CBinding& bBinding, IUnknown *pUnkSink);
  161. // returns S_OK if the object was called
  162. // returns S_FALSE if the object was called and if no other objects should be called
  163. // returns FAILED() if the object was not called
  164. virtual HRESULT Abort();
  165. // returns S_OK if processing should end
  166. // returns S_FALSE if processing should continue
  167. // any other return value causes processing to continue
  168. };
  169. virtual HRESULT Dispatcher(REFGUID rguidEventType, CParams *pParams);
  170. // returns S_OK if at least one sink was called
  171. // returns S_FALSE if no sinks were called
  172. // returns FAILED() if some super-catastrophic error happened
  173. // IEventDispatcher
  174. public:
  175. HRESULT STDMETHODCALLTYPE SetContext(REFGUID rguidEventType,
  176. IEventRouter *piRouter,
  177. IEventBindings *piBindings);
  178. public:
  179. class CETData : public CBindingList {
  180. public:
  181. CETData();
  182. virtual ~CETData();
  183. public:
  184. GUID m_guidEventType;
  185. };
  186. class CETDataList : public CSEOGrowableList<CETData> {
  187. public:
  188. CETData* Find(REFGUID guidEventType);
  189. };
  190. virtual HRESULT AllocBinding(REFGUID rguidEventType,
  191. IEventBinding *pBinding,
  192. CBinding **ppNewBinding);
  193. virtual HRESULT AllocETData(REFGUID rguidEventType,
  194. IEventBindings *piBindings,
  195. CETData **ppNewETData);
  196. CComPtr<IEventRouter> m_piRouter;
  197. CETDataList m_Data;
  198. CComPtr<IEventManager> m_piEventManager;
  199. };
  200. class CEventCreateOptionsBase : public IEventCreateOptions {
  201. HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riidDesired, LPVOID *ppvResult) {
  202. if (ppvResult) {
  203. *ppvResult = NULL;
  204. }
  205. if (!ppvResult) {
  206. return (E_NOTIMPL);
  207. }
  208. if (riidDesired == IID_IUnknown) {
  209. *ppvResult = (IUnknown *) this;
  210. } else if (riidDesired == IID_IDispatch) {
  211. *ppvResult = (IDispatch *) this;
  212. } else if (riidDesired == IID_IEventCreateOptions) {
  213. *ppvResult = (IEventCreateOptions *) this;
  214. }
  215. return ((*ppvResult)?S_OK:E_NOINTERFACE);
  216. };
  217. ULONG STDMETHODCALLTYPE AddRef() {
  218. return (2);
  219. };
  220. ULONG STDMETHODCALLTYPE Release() {
  221. return (1);
  222. };
  223. HRESULT STDMETHODCALLTYPE GetTypeInfoCount(unsigned int *) {
  224. return (E_NOTIMPL);
  225. };
  226. HRESULT STDMETHODCALLTYPE GetTypeInfo(unsigned int, LCID, ITypeInfo **) {
  227. return (E_NOTIMPL);
  228. };
  229. HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID, LPOLESTR *, unsigned int, LCID, DISPID *) {
  230. return (E_NOTIMPL);
  231. };
  232. HRESULT STDMETHODCALLTYPE Invoke(DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, unsigned int *) {
  233. return (E_NOTIMPL);
  234. };
  235. HRESULT STDMETHODCALLTYPE CreateBindCtx(DWORD, IBindCtx **) {
  236. return (E_NOTIMPL);
  237. };
  238. HRESULT STDMETHODCALLTYPE MkParseDisplayName(IBindCtx *, LPCOLESTR, ULONG *, IMoniker **) {
  239. return (E_NOTIMPL);
  240. };
  241. HRESULT STDMETHODCALLTYPE BindToObject(IMoniker *, IBindCtx *, IMoniker *, REFIID, LPVOID *) {
  242. return (E_NOTIMPL);
  243. };
  244. HRESULT STDMETHODCALLTYPE CoCreateInstance(REFCLSID, IUnknown *, DWORD, REFIID, LPVOID *) {
  245. return (E_NOTIMPL);
  246. };
  247. HRESULT STDMETHODCALLTYPE Init(REFIID riidDesired, IUnknown **ppObject, IEventBinding *pBinding, IUnknown *pInitProps) {
  248. return (E_NOTIMPL);
  249. };
  250. };
  251. // All these functions return S_OK if they succeed, and S_FALSE if the source type or source is
  252. // not present. They return FAILED() on various catastrophic errors.
  253. STDMETHODIMP SEOGetSource(REFGUID rguidSourceType, REFGUID rguidSource, IEventSource **ppSource);
  254. STDMETHODIMP SEOGetSource(REFGUID rguidSourceType, REFGUID rguidSourceBase, DWORD dwSourceIndex, IEventSource **ppSource);
  255. STDMETHODIMP SEOGetSource(REFGUID rguidSourceType, LPCSTR pszDisplayName, IEventSource **ppSource);
  256. STDMETHODIMP SEOGetSource(REFGUID rguidSourceType, LPCSTR pszProperty, DWORD dwValue, IEventSource **ppSource);
  257. STDMETHODIMP SEOGetSource(REFGUID rguidSourceType, LPCSTR pszProperty, LPCSTR pszValue, IEventSource **ppSource);
  258. STDMETHODIMP SEOGetRouter(REFGUID rguidSourceType, REFGUID rguidSource, IEventRouter **ppRouter);
  259. STDMETHODIMP SEOGetRouter(REFGUID rguidSourceType, REFGUID rguidSourceBase, DWORD dwSourceIndex, IEventRouter **ppRouter);
  260. STDMETHODIMP SEOGetRouter(REFGUID rguidSourceType, LPCSTR pszDisplayName, IEventRouter **ppRouter);
  261. STDMETHODIMP SEOGetRouter(REFGUID rguidSourceType, LPCSTR pszProperty, DWORD dwValue, IEventRouter **ppRouter);
  262. STDMETHODIMP SEOGetRouter(REFGUID rguidSourceType, LPCSTR pszProperty, LPCSTR pszValue, IEventRouter **ppRouter);
  263. STDMETHODIMP SEOGetServiceHandle(IUnknown **ppUnkHandle);
  264. STDMETHODIMP SEOCreateObject(VARIANT *pvarClass, IEventBinding *pBinding, IUnknown *pInitProperties, REFIID iidDesired, IUnknown **ppUnkObject);
  265. STDMETHODIMP SEOCreateObjectEx(VARIANT *pvarClass, IEventBinding *pBinding, IUnknown *pInitProperties, REFIID iidDesired, IUnknown *pUnkCreateOptions, IUnknown **ppUnkObject);