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.

166 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. dispatch.h
  5. Abstract:
  6. This module contains the class definition for the Server
  7. Extension Object Dispatcher service.
  8. Author:
  9. Andy Jacobs (andyj@microsoft.com)
  10. Revision History:
  11. andyj 12/04/96 created
  12. andyj 02/12/97 Converted PropertyBag's to Dictonary's
  13. dondu 03/14/97 Major rewrite
  14. dondu 03/31/97 Updated for ISEODispatcher::SetContext
  15. --*/
  16. /*
  17. Typical usage...
  18. class CMyDispatcher :
  19. public CSEOBaseDispatcher,
  20. public IMyDispatcher,
  21. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  22. public CCoClass<CMyDispatcher,CLSID_CCMyDispatcher> {
  23. DECLARE_PROTECT_FINAL_CONSTRUCT();
  24. DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  25. L"MyDispatcher Class",
  26. L"My.MyDispatcher.1",
  27. L"My.MyDispatcher");
  28. DECLARE_GET_CONTROLLING_UNKNOWN();
  29. BEGIN_COM_MAP(CSEORouter)
  30. COM_INTERFACE_ENTRY(ISEODispatcher)
  31. COM_INTERFACE_ENTRY(IMyDispatcher)
  32. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p) // if free-threaded
  33. END_COM_MAP()
  34. // You implement this if you need to do something during init...
  35. HRESULT FinalConstruct() {
  36. // If you are free-threaded, you must at least do this.
  37. return (CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p));
  38. }
  39. // You implement this if you need to do something during term...
  40. void FinalRelease();
  41. // Private stuff
  42. class CMyEventParams : CEventParams {
  43. virtual HRESULT CheckRule(CBinding& bBinding); // you have to implement this ...
  44. virtual HRESULT CallObject(CBinding& bBinding); // ... and this too
  45. DWORD m_dwWhatever; // these are your parameters which ...
  46. IUnknown *pUnkWhatever; // ... you are going to pass to the sink
  47. };
  48. // You have to implement this.
  49. HRESULT CMyEventParams::CheckRule(CBinding& bBinding) {
  50. if (bBinding.m_piRuleEngine) {
  51. // call the external rule engine
  52. } else {
  53. // do internal rule evaluation
  54. }
  55. // return values are either S_OK to call the object, or anything else (usually
  56. // S_FALSE for no error) if not to call the object
  57. return (S_OK);
  58. }
  59. // And you have to implement this.
  60. HRESULT CMyEventParams::CallObject(CBinding& bBinding) {
  61. // use bBinding.clsidObject to create the object
  62. // QI for the interface you want
  63. // call the object
  64. return (S_OK);
  65. }
  66. // IMyDispatcher - this is your server-specific dispatcher interface
  67. // Do something like this...
  68. HRESULT STDMETHODCALLTYPE OnEvent(DWORD dwWhatever, IUnknown *pUnkWhatever) {
  69. CMyEventParams epParams;
  70. epParams.m_dwWhatever = dwWhatever;
  71. epParams.m_dwUnkWhatever = pUnkWhatever;
  72. return (Dispatch(&epParams));
  73. }
  74. // If you want to add stuff to the CBinding object, you can override
  75. // CSEOBaseDispatcher::AllocBinding, and use that function to allocate,
  76. // initialize, and return an object which is derived from CBinding.
  77. class CMyBinding : public CBinding {
  78. DWORD m_dwSomeNewProperty;
  79. HRESULT Init(ISEODictionary *piBinding) {
  80. // some custom init code
  81. return (S_OK);
  82. }
  83. };
  84. HRESULT AllocBinding(ISEODictionary *piBinding, CBinding **ppbBinding) {
  85. *ppbBinding = new CMyBinding;
  86. if (!*ppbBinding) {
  87. return (E_OUTOFMEMORY);
  88. }
  89. hrRes = ((CMyBinding *) (*ppbBinding))->Init(piBinding);
  90. if (!SUCCEEDED(hrRes)) {
  91. delete *ppbBinding;
  92. *ppbBinding = NULL;
  93. }
  94. return (hrRes);
  95. }
  96. };
  97. */
  98. class CSEOBaseDispatcher : public ISEODispatcher {
  99. public:
  100. CSEOBaseDispatcher();
  101. virtual ~CSEOBaseDispatcher();
  102. class CBinding {
  103. public:
  104. CBinding() { m_bValid = FALSE; };
  105. virtual ~CBinding() {};
  106. HRESULT Init(ISEODictionary *piBinding);
  107. virtual int Compare(const CBinding& b) const;
  108. public:
  109. DWORD m_dwPriority;
  110. CComPtr<ISEODictionary> m_piBinding;
  111. CComPtr<ISEOBindingRuleEngine> m_piRuleEngine;
  112. BOOL m_bExclusive;
  113. CLSID m_clsidObject;
  114. BOOL m_bValid;
  115. };
  116. class CEventParams {
  117. public:
  118. virtual HRESULT CheckRule(CBinding& bBinding) = 0;
  119. virtual HRESULT CallObject(CBinding& bBinding) = 0;
  120. };
  121. virtual HRESULT Dispatch(CEventParams *pEventParams);
  122. public:
  123. // ISEODispatcher
  124. HRESULT STDMETHODCALLTYPE SetContext(ISEORouter *piRouter, ISEODictionary *pdictBP);
  125. protected:
  126. virtual HRESULT AllocBinding(ISEODictionary *pdictBinding, CBinding **ppbBinding);
  127. CComPtr<ISEORouter> m_piRouter;
  128. CComPtr<ISEODictionary> m_pdictBP;
  129. private:
  130. friend static int _cdecl comp_binding(const void *pv1, const void *pv2);
  131. CBinding **m_apbBindings;
  132. DWORD m_dwBindingsCount;
  133. };