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.

403 lines
11 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1997-1998 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: sdocomponentmgr.cpp
  6. //
  7. // Project: Everest
  8. //
  9. // Description: IAS - Server Core Manager Implementation
  10. //
  11. // Author: TLP
  12. //
  13. // Log:
  14. //
  15. // When Who What
  16. // ---- --- ----
  17. // 6/08/98 TLP Initial Version
  18. //
  19. ///////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "sdocomponentmgr.h"
  22. #include "sdocomponentfactory.h"
  23. #include "sdohelperfuncs.h"
  24. #include "sdocomponent.h"
  25. #include <iascomp.h>
  26. #include <iastlb.h>
  27. /////////////////////////////////////////
  28. // Component Master Pointer Intance Count
  29. /////////////////////////////////////////
  30. DWORD ComponentMasterPtr::m_dwInstances = 0;
  31. //////////////////////////////////////////////////////////////////////////////
  32. // The Component (Envelope) Constructor
  33. //
  34. // Only a ComponentMasterPtr object can construct a component object
  35. //
  36. //////////////////////////////////////////////////////////////////////////////
  37. CComponent::CComponent(LONG eComponentType, LONG lComponentId)
  38. : m_lId(lComponentId),
  39. m_eState(COMPONENT_STATE_SHUTDOWN),
  40. m_eType((COMPONENTTYPE)eComponentType),
  41. m_pComponent(NULL)
  42. {
  43. TRACE_ENVELOPE_CREATE(CComponent);
  44. _ASSERT( COMPONENT_TYPE_MAX > eComponentType );
  45. // create letter object
  46. //
  47. switch( eComponentType )
  48. {
  49. case COMPONENT_TYPE_AUDITOR:
  50. m_pComponent = new CComponentAuditor(lComponentId);
  51. break;
  52. case COMPONENT_TYPE_PROTOCOL:
  53. m_pComponent = new CComponentProtocol(lComponentId);
  54. break;
  55. case COMPONENT_TYPE_REQUEST_HANDLER:
  56. m_pComponent = new CComponentRequestHandler(lComponentId);
  57. break;
  58. default:
  59. _ASSERT( FALSE );
  60. };
  61. }
  62. //////////////////////////////////////////////////////////////////////////////
  63. // IAS COMPONENT MANAGER CLASSES
  64. //
  65. // These classes are responsible for configuring, kick-starting and finally
  66. // shutting down IAS core components. A component class basically is a wrapper
  67. // around the IIasComponent interface. Its value add is that it knows how
  68. // to configure / initialize / shutdown the component using mechanisms
  69. // unknown to the underlying component.
  70. //
  71. //////////////////////////////////////////////////////////////////////////////
  72. //////////////////////////////////////////////////////////////////////////////
  73. // Auditor
  74. //////////////////////////////////////////////////////////////////////////////
  75. //////////////////////////////////////////////////////////////////////////////
  76. HRESULT CComponentAuditor::Initialize(ISdo* pSdoAuditor)
  77. {
  78. HRESULT hr;
  79. IASComponentPtr pAuditor;
  80. do
  81. {
  82. hr = SDOCreateComponentFromObject(
  83. pSdoAuditor,
  84. &pAuditor
  85. );
  86. if ( FAILED(hr) )
  87. break;
  88. hr = pAuditor->InitNew();
  89. if ( FAILED(hr) )
  90. break;
  91. hr = SDOConfigureComponentFromObject(
  92. pSdoAuditor,
  93. pAuditor.p
  94. );
  95. if ( FAILED(hr) )
  96. {
  97. pAuditor->Shutdown();
  98. break;
  99. }
  100. hr = pAuditor->Initialize();
  101. if ( FAILED(hr) )
  102. {
  103. IASTracePrintf("Error in Auditor Component - Initialize() for Auditor %d failed...",GetId());
  104. pAuditor->Shutdown();
  105. break;
  106. }
  107. m_pAuditor = pAuditor;
  108. } while (FALSE);
  109. return hr;
  110. }
  111. //////////////////////////////////////////////////////////////////////////////
  112. HRESULT CComponentAuditor::Configure(ISdo* pSdoAuditor)
  113. {
  114. return SDOConfigureComponentFromObject(
  115. pSdoAuditor,
  116. m_pAuditor
  117. );
  118. };
  119. ///////////////////////////////////////////////////////////////////
  120. HRESULT CComponentAuditor::GetObject(IUnknown** ppObj, REFIID riid)
  121. {
  122. _ASSERT( FALSE );
  123. return E_FAIL;
  124. }
  125. ///////////////////////////////////////////////////////////////////
  126. HRESULT CComponentAuditor::PutObject(IUnknown* pObj, REFIID riid)
  127. {
  128. _ASSERT( FALSE );
  129. return E_FAIL;
  130. }
  131. //////////////////////////////////////////////////////////////////////////////
  132. HRESULT CComponentAuditor::Suspend()
  133. {
  134. return m_pAuditor->Suspend();
  135. }
  136. //////////////////////////////////////////////////////////////////////////////
  137. HRESULT CComponentAuditor::Resume()
  138. {
  139. return m_pAuditor->Resume();
  140. }
  141. //////////////////////////////////////////////////////////////////////////////
  142. void CComponentAuditor::Shutdown()
  143. {
  144. m_pAuditor->Shutdown();
  145. m_pAuditor.Release();
  146. }
  147. //////////////////////////////////////////////////////////////////////////////
  148. // Protocol
  149. //////////////////////////////////////////////////////////////////////////////
  150. //////////////////////////////////////////////////////////////////////////////
  151. HRESULT CComponentProtocol::Initialize(ISdo* pSdoProtocol)
  152. {
  153. HRESULT hr;
  154. IASComponentPtr pProtocol;
  155. do
  156. {
  157. hr = SDOCreateComponentFromObject(pSdoProtocol, &pProtocol);
  158. if ( FAILED(hr) )
  159. break;
  160. // We don't really initialize the protocol (entirely anyway). What
  161. // we really want to do at this point is configure the protocol since
  162. // the protocol SDO is available. We can't finish initialization until
  163. // the protocol receives an IRequestHandler interface (for the
  164. // component that will process protocol generated requests).
  165. //
  166. hr = pProtocol->InitNew();
  167. if ( FAILED(hr) )
  168. {
  169. IASTracePrintf("Error in Protocol Component - Initialize() - Could not InitNew() protocol %d failed...",GetId());
  170. break;
  171. }
  172. hr = SDOConfigureComponentFromObject(
  173. pSdoProtocol,
  174. pProtocol
  175. );
  176. if ( FAILED(hr) )
  177. {
  178. IASTracePrintf("Error in Protocol Component - Initialize() - Could not configure protocol %d failed...",GetId());
  179. pProtocol->Shutdown();
  180. break;
  181. }
  182. hr = pProtocol->Initialize();
  183. if ( FAILED(hr) )
  184. {
  185. IASTracePrintf("Error in Protocol Component - Initialize() - Could not initialize protocol %d failed...",GetId());
  186. pProtocol->Shutdown();
  187. break;
  188. }
  189. m_pProtocol = pProtocol;
  190. } while (FALSE);
  191. return hr;
  192. }
  193. //////////////////////////////////////////////////////////////////////////////
  194. HRESULT CComponentProtocol::Configure(ISdo* pSdoProtocol)
  195. {
  196. return SDOConfigureComponentFromObject(
  197. pSdoProtocol,
  198. m_pProtocol
  199. );
  200. }
  201. ///////////////////////////////////////////////////////////////////
  202. HRESULT CComponentProtocol::GetObject(IUnknown** ppObj, REFIID riid)
  203. {
  204. _ASSERT( FALSE );
  205. return E_FAIL;
  206. }
  207. //////////////////////////////////////////////////////////////////////////////
  208. HRESULT CComponentProtocol::PutObject(IUnknown* pObject, REFIID riid)
  209. {
  210. HRESULT hr;
  211. _variant_t vtRequestHandler;
  212. _ASSERT( riid == IID_IRequestHandler);
  213. _ASSERT( NULL != pObject );
  214. vtRequestHandler = (IDispatch*)pObject;
  215. hr = m_pProtocol->PutProperty(PROPERTY_PROTOCOL_REQUEST_HANDLER, &vtRequestHandler);
  216. return hr;
  217. }
  218. //////////////////////////////////////////////////////////////////////////////
  219. HRESULT CComponentProtocol::Suspend()
  220. {
  221. return m_pProtocol->Suspend();
  222. }
  223. //////////////////////////////////////////////////////////////////////////////
  224. HRESULT CComponentProtocol::Resume()
  225. {
  226. return m_pProtocol->Resume();
  227. }
  228. //////////////////////////////////////////////////////////////////////////////
  229. void CComponentProtocol::Shutdown()
  230. {
  231. // a Protocol can get shutdown while suspended or initialized!
  232. //
  233. m_pProtocol->Shutdown();
  234. m_pProtocol.Release();
  235. }
  236. //////////////////////////////////////////////////////////////////////////////
  237. // Request Handler
  238. //////////////////////////////////////////////////////////////////////////////
  239. //////////////////////////////////////////////////////////////////////////////
  240. HRESULT CComponentRequestHandler::Initialize(ISdo* pSdoService)
  241. {
  242. HRESULT hr;
  243. CComPtr<ISdo> pSdoRequestHandler;
  244. _ASSERT( NULL != m_pRequestHandler.p );
  245. // request handler may or may not have an SDO associated
  246. // with it. Those request handlers that do not expose
  247. // configuration data will not have an associated SDO.
  248. hr = SDOGetComponentFromCollection(
  249. pSdoService,
  250. PROPERTY_IAS_REQUESTHANDLERS_COLLECTION,
  251. GetId(),
  252. &pSdoRequestHandler
  253. );
  254. if ( SUCCEEDED(hr) )
  255. {
  256. hr = SDOConfigureComponentFromObject(
  257. pSdoRequestHandler,
  258. m_pRequestHandler.p
  259. );
  260. }
  261. else
  262. {
  263. hr = S_OK;
  264. }
  265. if ( SUCCEEDED(hr) )
  266. {
  267. hr = m_pRequestHandler->Initialize();
  268. if ( FAILED(hr) )
  269. IASTracePrintf("Error in Request Handler Component - Initialize() - failed for request handler %d...", GetId());
  270. }
  271. return hr;
  272. }
  273. ///////////////////////////////////////////////////////////////////
  274. HRESULT CComponentRequestHandler::GetObject(IUnknown** ppObj, REFIID riid)
  275. {
  276. _ASSERT( FALSE );
  277. return E_FAIL;
  278. }
  279. //////////////////////////////////////////////////////////////////////////////
  280. HRESULT CComponentRequestHandler::PutObject(IUnknown* pObject, REFIID riid)
  281. {
  282. HRESULT hr;
  283. _ASSERT( riid == IID_IIasComponent );
  284. _ASSERT( NULL != pObject );
  285. _ASSERT( NULL == m_pRequestHandler.p );
  286. hr = pObject->QueryInterface(riid, (void**)&m_pRequestHandler.p);
  287. if ( SUCCEEDED(hr) )
  288. hr = m_pRequestHandler->InitNew();
  289. return hr;
  290. }
  291. //////////////////////////////////////////////////////////////////////////////
  292. HRESULT CComponentRequestHandler::Configure(ISdo* pSdoService)
  293. {
  294. HRESULT hr;
  295. CComPtr<ISdo> pSdoRequestHandler;
  296. _ASSERT( NULL != m_pRequestHandler.p );
  297. // request handler may or may not have an SDO associated
  298. // with it. Those request handlers that do not expose
  299. // configuration data will not have an associated SDO.
  300. hr = SDOGetComponentFromCollection(
  301. pSdoService,
  302. PROPERTY_IAS_REQUESTHANDLERS_COLLECTION,
  303. GetId(),
  304. &pSdoRequestHandler
  305. );
  306. if ( SUCCEEDED(hr) )
  307. {
  308. hr = SDOConfigureComponentFromObject(
  309. pSdoRequestHandler,
  310. m_pRequestHandler.p
  311. );
  312. }
  313. else
  314. {
  315. hr = S_OK;
  316. }
  317. return hr;
  318. }
  319. //////////////////////////////////////////////////////////////////////////////
  320. HRESULT CComponentRequestHandler::Suspend()
  321. {
  322. return m_pRequestHandler->Suspend();
  323. }
  324. //////////////////////////////////////////////////////////////////////////////
  325. HRESULT CComponentRequestHandler::Resume()
  326. {
  327. return m_pRequestHandler->Resume();
  328. }
  329. //////////////////////////////////////////////////////////////////////////////
  330. void CComponentRequestHandler::Shutdown()
  331. {
  332. m_pRequestHandler->Shutdown();
  333. m_pRequestHandler.Release();
  334. }