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.

351 lines
9.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1997-1998 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: sdocomponentmgr.h
  6. //
  7. // Project: Everest
  8. //
  9. // Description: IAS Core Component Manager Definitions
  10. //
  11. // Log:
  12. //
  13. // When Who What
  14. // ---- --- ----
  15. // 6/08/98 TLP Initial Version
  16. // 8/13/98 SEB dsource.h has been merged into iastlb.h
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef __INC_SDO_COMPONENT_MGR_H_
  20. #define __INC_SDO_COMPONENT_MGR_H_
  21. #include "sdobasedefs.h"
  22. #include <iastlb.h>
  23. //////////////////////////////////////////////////////////////////////////////
  24. // IAS Component Interface Class
  25. //////////////////////////////////////////////////////////////////////////////
  26. /////////////////////////////////////////////
  27. // Component Class Lifetime Trace (Debugging)
  28. //
  29. // #define TRACE_ENVELOPE_LETTER_LIFETIME
  30. #ifdef TRACE_ENVELOPE_LETTER_LIFETIME
  31. #define TRACE_ENVELOPE_CREATE(x) ATLTRACE(L"Created %ls - envelope class - at %p \n", L#x, this);
  32. #define TRACE_ENVELOPE_DESTROY(x) ATLTRACE(L"Destroyed %ls - envelope class - at %p \n", L#x, this);
  33. #define TRACE_LETTER_CREATE(x) ATLTRACE(L"Created %ls - letter class - at %p \n", L#x, this);
  34. #define TRACE_LETTER_DESTROY(x) ATLTRACE(L"Destroyed %ls - letter class - at %p \n", L#x, this);
  35. #else
  36. #define TRACE_ENVELOPE_CREATE(x)
  37. #define TRACE_ENVELOPE_DESTROY(x)
  38. #define TRACE_LETTER_CREATE(x)
  39. #define TRACE_LETTER_DESTROY(x)
  40. #endif
  41. //////////////////////
  42. // Types of Components
  43. //
  44. typedef enum _COMPONENTTYPE
  45. {
  46. COMPONENT_TYPE_AUDITOR = 0x100,
  47. COMPONENT_TYPE_UNUSED,
  48. COMPONENT_TYPE_PROTOCOL,
  49. COMPONENT_TYPE_REQUEST_HANDLER,
  50. COMPONENT_TYPE_MAX
  51. } COMPONENTTYPE;
  52. ///////////////////
  53. // Component States
  54. //
  55. typedef enum _COMPONENTSTATE
  56. {
  57. COMPONENT_STATE_SHUTDOWN = 0x100,
  58. COMPONENT_STATE_INITIALIZED,
  59. COMPONENT_STATE_SUSPENDED
  60. } COMPONENTSTATE;
  61. /////////////////////////////////////////////////////////////////////////////
  62. // The Base Componet Class (Envelope )
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Forward references
  65. //
  66. class CComponent;
  67. class CComponentAuditor;
  68. class CComponentProtocol;
  69. class CComponentRequestHandler;
  70. // Object management class typedefs
  71. //
  72. typedef CSdoMasterPtr<CComponent> ComponentMasterPtr;
  73. typedef CSdoHandle<CComponent> ComponentPtr;
  74. // Component container class typedefs
  75. //
  76. typedef LONG IAS_COMPONENT_ID;
  77. typedef map<IAS_COMPONENT_ID, ComponentPtr> ComponentMap;
  78. typedef map<IAS_COMPONENT_ID, ComponentPtr>::iterator ComponentMapIterator;
  79. ///////////////////////////////////////////
  80. // Dummy class used for letter construction
  81. //
  82. struct LetterConstructor
  83. {
  84. LetterConstructor(int=0) { }
  85. };
  86. /////////////////////////////////////////////////////////////////////////////
  87. class CComponent
  88. {
  89. public:
  90. //////////////////////////////////////////////////////////////////////////
  91. virtual ~CComponent()
  92. {
  93. // if m_pComponent is not NULL then the envelope is being destroyed.
  94. // if m_pComponent is NULL then the letter is being destroyed.
  95. //
  96. // the enveloper will only be destroyed by the master pointer that
  97. // owns it. The envelope will then destroy the letter it created. The
  98. // letter, which is derived from the envelope, will eventually cause
  99. // this destructor to be invoked again - this time however
  100. // m_pComponent is set to NULL.
  101. //
  102. if ( NULL != m_pComponent )
  103. {
  104. TRACE_ENVELOPE_DESTROY(CComponent);
  105. delete m_pComponent;
  106. }
  107. }
  108. //////////////////////////////////////////////////////////////////////////
  109. virtual HRESULT Initialize(ISdo* pSdoService)
  110. {
  111. _ASSERT( COMPONENT_STATE_SHUTDOWN == m_eState );
  112. HRESULT hr = m_pComponent->Initialize(pSdoService);
  113. if ( SUCCEEDED(hr) )
  114. m_eState = COMPONENT_STATE_INITIALIZED;
  115. return hr;
  116. }
  117. //////////////////////////////////////////////////////////////////////////
  118. virtual HRESULT Configure(ISdo* pSdoService)
  119. {
  120. _ASSERT( COMPONENT_STATE_SHUTDOWN != m_eState );
  121. return m_pComponent->Configure(pSdoService);
  122. }
  123. //////////////////////////////////////////////////////////////////////////
  124. virtual HRESULT Suspend(void)
  125. {
  126. _ASSERT( COMPONENT_STATE_INITIALIZED == m_eState );
  127. HRESULT hr = m_pComponent->Suspend();
  128. if ( SUCCEEDED(hr) )
  129. m_eState = COMPONENT_STATE_SUSPENDED;
  130. return hr;
  131. }
  132. //////////////////////////////////////////////////////////////////////////
  133. virtual HRESULT Resume(void)
  134. {
  135. _ASSERT( COMPONENT_STATE_SUSPENDED == m_eState );
  136. HRESULT hr = m_pComponent->Resume();
  137. if ( SUCCEEDED(hr) )
  138. m_eState = COMPONENT_STATE_INITIALIZED;
  139. return hr;
  140. }
  141. //////////////////////////////////////////////////////////////////////////
  142. virtual HRESULT PutObject(IUnknown* pObj, REFIID riid)
  143. {
  144. // _ASSERT( COMPONENT_STATE_INITIALIZED == m_eState );
  145. return m_pComponent->PutObject(pObj, riid);
  146. }
  147. //////////////////////////////////////////////////////////////////////////
  148. virtual HRESULT GetObject(IUnknown** ppObj, REFIID riid)
  149. {
  150. _ASSERT( COMPONENT_STATE_INITIALIZED == m_eState );
  151. return m_pComponent->GetObject(ppObj, riid);
  152. }
  153. //////////////////////////////////////////////////////////////////////////
  154. virtual void Shutdown(void)
  155. {
  156. _ASSERT(
  157. COMPONENT_STATE_INITIALIZED == m_eState ||
  158. COMPONENT_STATE_SUSPENDED == m_eState
  159. );
  160. m_pComponent->Shutdown();
  161. m_eState = COMPONENT_STATE_SHUTDOWN;
  162. }
  163. //////////////////////////////////////////////////////////////////////////
  164. inline LONG GetId(void) const
  165. { return m_lId; }
  166. //////////////////////////////////////////////////////////////////////////
  167. inline COMPONENTSTATE GetState(void) const
  168. { return m_eState; }
  169. //////////////////////////////////////////////////////////////////////////
  170. inline COMPONENTTYPE GetType(void) const
  171. { return m_eType; }
  172. protected:
  173. typedef CComPtr<IIasComponent> IASComponentPtr;
  174. // Invoked explicitly by derived (letter) classes
  175. //
  176. CComponent(LONG eComponentType, LONG lComponentId, LetterConstructor TheDummy)
  177. : m_lId(lComponentId),
  178. m_eState(COMPONENT_STATE_SHUTDOWN), // Not used by derived class
  179. m_eType((COMPONENTTYPE)eComponentType),
  180. m_pComponent(NULL)
  181. {
  182. }
  183. private:
  184. // No default constructor since we would'nt know what
  185. // type of component to build by default
  186. //
  187. CComponent();
  188. // The constructor - Only a ComponentMasterPtr can construct this class
  189. //
  190. friend ComponentMasterPtr;
  191. CComponent(LONG eComponentType, LONG lComponentId);
  192. // No copy - No Assignment - No Shirt, No Shoes, No Service
  193. //
  194. CComponent(const CComponent& theComponent);
  195. CComponent& operator = (const CComponent& theComponent);
  196. /////////////////////////////////////////////////////////////////////////
  197. LONG m_lId;
  198. COMPONENTSTATE m_eState;
  199. COMPONENTTYPE m_eType;
  200. CComponent* m_pComponent;
  201. };
  202. ///////////////////////////////////////////////////////////////////
  203. // IAS Component (Letter) Classes
  204. ///////////////////////////////////////////////////////////////////
  205. ///////////////////////////////////////////////////////////////////
  206. class CComponentAuditor : public CComponent
  207. {
  208. public:
  209. CComponentAuditor(LONG lComponentId)
  210. : CComponent(COMPONENT_TYPE_AUDITOR, lComponentId, LetterConstructor())
  211. {
  212. TRACE_LETTER_CREATE(CComponentAuditor);
  213. }
  214. virtual ~CComponentAuditor()
  215. {
  216. TRACE_LETTER_DESTROY(CComponentAuditor);
  217. }
  218. virtual HRESULT Initialize(ISdo* pSdoService);
  219. virtual HRESULT Configure(ISdo* pSdoService);
  220. virtual HRESULT Suspend(void);
  221. virtual HRESULT Resume(void);
  222. virtual HRESULT GetObject(IUnknown** ppObj, REFIID riid);
  223. virtual HRESULT PutObject(IUnknown* pObj, REFIID riid);
  224. virtual void Shutdown(void);
  225. private:
  226. CComponentAuditor(const CComponentAuditor& x);
  227. CComponentAuditor& operator = (const CComponentAuditor& x);
  228. IASComponentPtr m_pAuditor;
  229. };
  230. ///////////////////////////////////////////////////////////////////
  231. class CComponentProtocol : public CComponent
  232. {
  233. public:
  234. CComponentProtocol(LONG lComponentId)
  235. : CComponent(COMPONENT_TYPE_PROTOCOL, lComponentId, LetterConstructor())
  236. {
  237. TRACE_LETTER_CREATE(CComponentProtocol);
  238. }
  239. virtual ~CComponentProtocol()
  240. {
  241. TRACE_LETTER_DESTROY(CComponentProtocol);
  242. }
  243. virtual HRESULT Initialize(ISdo* pSdo);
  244. virtual HRESULT Configure(ISdo* pSdo);
  245. virtual HRESULT Suspend(void);
  246. virtual HRESULT Resume(void);
  247. virtual HRESULT GetObject(IUnknown** ppObj, REFIID riid);
  248. virtual HRESULT PutObject(IUnknown* pObj, REFIID riid);
  249. virtual void Shutdown(void);
  250. private:
  251. CComponentProtocol(const CComponentProtocol& x);
  252. CComponentProtocol& operator = (const CComponentProtocol& x);
  253. IASComponentPtr m_pProtocol;
  254. };
  255. ///////////////////////////////////////////////////////////////////
  256. class CComponentRequestHandler : public CComponent
  257. {
  258. public:
  259. CComponentRequestHandler(LONG lComponentId)
  260. : CComponent(COMPONENT_TYPE_REQUEST_HANDLER, lComponentId, LetterConstructor())
  261. {
  262. TRACE_LETTER_CREATE(CComponentRequestHandler);
  263. }
  264. ~CComponentRequestHandler()
  265. {
  266. TRACE_LETTER_DESTROY(CComponentRequestHandler);
  267. }
  268. virtual HRESULT Initialize(ISdo* pSdo);
  269. virtual HRESULT Configure(ISdo* pSdo);
  270. virtual HRESULT Suspend(void);
  271. virtual HRESULT Resume(void);
  272. virtual HRESULT GetObject(IUnknown** ppObj, REFIID riid);
  273. virtual HRESULT PutObject(IUnknown* pObj, REFIID riid);
  274. virtual void Shutdown(void);
  275. private:
  276. CComponentRequestHandler(const CComponentRequestHandler& x);
  277. CComponentRequestHandler& operator = (const CComponentRequestHandler& x);
  278. IASComponentPtr m_pRequestHandler;
  279. };
  280. #endif // __INC_SDO_COMPONENT_MGR_H_