Source code of Windows XP (NT5)
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.

353 lines
8.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // iastl.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // Contains class declarations for the Internet Authentication Service
  12. // Template Library (IASTL).
  13. //
  14. // MODIFICATION HISTORY
  15. //
  16. // 08/09/1998 Original version.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef _IASTL_H_
  20. #define _IASTL_H_
  21. #if _MSC_VER >= 1000
  22. #pragma once
  23. #endif
  24. //////////
  25. // IASTL must be used in conjuction with ATL.
  26. //////////
  27. #ifndef __ATLCOM_H__
  28. #error iastl.h requires atlcom.h to be included first
  29. #endif
  30. //////////
  31. // MIDL generated header files containing the interfaces that must be
  32. // implemented by a request handler.
  33. //////////
  34. #include <iascomp.h>
  35. #include <iaspolcy.h>
  36. //////////
  37. // Common type library describing all of the request handler interfaces. This
  38. // type library is registered during normal IAS installation; thus, individual
  39. // request handlers should not attempt to install or register this type
  40. // library.
  41. //////////
  42. struct __declspec(uuid("6BC09690-0CE6-11D1-BAAE-00C04FC2E20D")) IASTypeLibrary;
  43. //////////
  44. // The entire library is contained within the IASTL namespace.
  45. //////////
  46. namespace IASTL {
  47. ///////////////////////////////////////////////////////////////////////////////
  48. //
  49. // CLASS
  50. //
  51. // IASComponent
  52. //
  53. // DESCRIPTION
  54. //
  55. // Serves as an abstract base class for all components that need to
  56. // implement the IIasComponent interface.
  57. //
  58. ///////////////////////////////////////////////////////////////////////////////
  59. class ATL_NO_VTABLE IASComponent :
  60. public CComObjectRootEx< CComMultiThreadModel >,
  61. public IDispatchImpl< IIasComponent,
  62. &__uuidof(IIasComponent),
  63. &__uuidof(IASTypeLibrary) >
  64. {
  65. public:
  66. // Interfaces supported by all IAS components.
  67. BEGIN_COM_MAP(IASComponent)
  68. COM_INTERFACE_ENTRY_IID(__uuidof(IIasComponent), IIasComponent)
  69. COM_INTERFACE_ENTRY_IID(__uuidof(IDispatch), IDispatch)
  70. END_COM_MAP()
  71. // Possible states for a component.
  72. enum State {
  73. STATE_SHUTDOWN,
  74. STATE_UNINITIALIZED,
  75. STATE_INITIALIZED,
  76. STATE_SUSPENDED,
  77. NUM_STATES,
  78. STATE_UNEXPECTED
  79. };
  80. // Events that may trigger state transitions.
  81. enum Event {
  82. EVENT_INITNEW,
  83. EVENT_INITIALIZE,
  84. EVENT_SUSPEND,
  85. EVENT_RESUME,
  86. EVENT_SHUTDOWN,
  87. NUM_EVENTS
  88. };
  89. // Constructor/destructor.
  90. IASComponent() throw ()
  91. : state(STATE_SHUTDOWN)
  92. { }
  93. // Fire an event on the component.
  94. HRESULT fireEvent(Event event) throw ();
  95. // Returns the state of the component.
  96. State getState() const throw ()
  97. { return state; }
  98. //////////
  99. // IIasComponent.
  100. // The derived class may override these as necessary. All of these
  101. // methods are serialized by an IASTL subclass, so generally no
  102. // additional locking is necessary.
  103. //////////
  104. STDMETHOD(InitNew)()
  105. { return S_OK; }
  106. STDMETHOD(Initialize)()
  107. { return S_OK; }
  108. STDMETHOD(Suspend)()
  109. { return S_OK; }
  110. STDMETHOD(Resume)()
  111. { return S_OK; }
  112. STDMETHOD(Shutdown)()
  113. { return S_OK; }
  114. STDMETHOD(GetProperty)(LONG Id, VARIANT* pValue)
  115. { return DISP_E_MEMBERNOTFOUND; }
  116. STDMETHOD(PutProperty)(LONG Id, VARIANT* pValue)
  117. { return E_NOTIMPL; }
  118. protected:
  119. // This should not be defined by the derived class since it is defined in
  120. // the IASComponentObject<T> class.
  121. virtual HRESULT attemptTransition(Event event) throw () = 0;
  122. private:
  123. // State of the component.
  124. State state;
  125. // State transition matrix governing the component lifecycle.
  126. static const State fsm[NUM_EVENTS][NUM_STATES];
  127. };
  128. ///////////////////////////////////////////////////////////////////////////////
  129. //
  130. // CLASS
  131. //
  132. // IASRequestHandler
  133. //
  134. // DESCRIPTION
  135. //
  136. // Serves as an abstract base class for all IAS request handlers.
  137. //
  138. ///////////////////////////////////////////////////////////////////////////////
  139. class ATL_NO_VTABLE IASRequestHandler :
  140. public IASComponent,
  141. public IDispatchImpl< IRequestHandler,
  142. &__uuidof(IRequestHandler),
  143. &__uuidof(IASTypeLibrary) >
  144. {
  145. public:
  146. // Interfaces supported by all IAS request handlers.
  147. BEGIN_COM_MAP(IASRequestHandler)
  148. COM_INTERFACE_ENTRY_IID(__uuidof(IRequestHandler), IRequestHandler)
  149. COM_INTERFACE_ENTRY_IID(__uuidof(IIasComponent), IIasComponent)
  150. END_COM_MAP()
  151. //////////
  152. // IRequestHandler.
  153. // This should not be defined by the derived class. Instead handlers
  154. // will define either onAsyncRequest or onSyncRequest (q.v.).
  155. //////////
  156. STDMETHOD(OnRequest)(IRequest* pRequest);
  157. protected:
  158. // Must be defined by the derived class to perform actual request
  159. // processing.
  160. virtual void onAsyncRequest(IRequest* pRequest) throw () = 0;
  161. };
  162. //////////
  163. // Obsolete.
  164. //////////
  165. #define IAS_DECLARE_OBJECT_ID(id) \
  166. void getObjectID() const throw () { }
  167. //////////
  168. // Obsolete.
  169. //////////
  170. #define BEGIN_IAS_RESPONSE_MAP()
  171. #define IAS_RESPONSE_ENTRY(val)
  172. #define END_IAS_RESPONSE_MAP()
  173. ///////////////////////////////////////////////////////////////////////////////
  174. //
  175. // CLASS
  176. //
  177. // IASRequestHandlerSync
  178. //
  179. // DESCRIPTION
  180. //
  181. // Extends IASRequestHandler to provide an abstract base class for request
  182. // handlers that process requests synchronously.
  183. //
  184. ///////////////////////////////////////////////////////////////////////////////
  185. class ATL_NO_VTABLE IASRequestHandlerSync
  186. : public IASRequestHandler
  187. {
  188. protected:
  189. // Must not be defined by the derived class.
  190. virtual void onAsyncRequest(IRequest* pRequest) throw ();
  191. // The derived class must define onSyncRequest *instead* of onAsyncRequest.
  192. // The derived class must not call IRequest::ReturnToSource since this will
  193. // be invoked automatically after onSyncRequest completes.
  194. virtual IASREQUESTSTATUS onSyncRequest(IRequest* pRequest) throw () = 0;
  195. };
  196. ///////////////////////////////////////////////////////////////////////////////
  197. //
  198. // CLASS
  199. //
  200. // IASComponentObject<T>
  201. //
  202. // DESCRIPTION
  203. //
  204. // Inherits from the user-defined component to enforce the semantics of the
  205. // component finite state machine.
  206. //
  207. ///////////////////////////////////////////////////////////////////////////////
  208. template <class T>
  209. class ATL_NO_VTABLE IASComponentObject
  210. : public T
  211. {
  212. public:
  213. DECLARE_NOT_AGGREGATABLE( IASComponentObject<T> );
  214. //////////
  215. // IIasComponent
  216. //////////
  217. STDMETHOD(InitNew)()
  218. {
  219. return fireEvent(EVENT_INITNEW);
  220. }
  221. STDMETHOD(Initialize)()
  222. {
  223. return fireEvent(EVENT_INITIALIZE);
  224. }
  225. STDMETHOD(Suspend)()
  226. {
  227. return fireEvent(EVENT_SUSPEND);
  228. }
  229. STDMETHOD(Resume)()
  230. {
  231. return fireEvent(EVENT_RESUME);
  232. }
  233. STDMETHOD(Shutdown)()
  234. {
  235. return fireEvent(EVENT_SHUTDOWN);
  236. }
  237. STDMETHOD(GetProperty)(LONG Id, VARIANT* pValue)
  238. {
  239. // We serialize this method to make it consistent with the others.
  240. Lock();
  241. HRESULT hr = T::GetProperty(Id, pValue);
  242. Unlock();
  243. return hr;
  244. }
  245. STDMETHOD(PutProperty)(LONG Id, VARIANT* pValue)
  246. {
  247. HRESULT hr;
  248. Lock();
  249. // PutProperty is not allowed when the object is shutdown.
  250. if (getState() != STATE_SHUTDOWN)
  251. {
  252. hr = T::PutProperty(Id, pValue);
  253. }
  254. else
  255. {
  256. hr = E_UNEXPECTED;
  257. }
  258. Unlock();
  259. return hr;
  260. }
  261. protected:
  262. //////////
  263. // Attempt to transition the component to a new state.
  264. //////////
  265. virtual HRESULT attemptTransition(IASComponent::Event event) throw ()
  266. {
  267. switch (event)
  268. {
  269. case EVENT_INITNEW:
  270. return T::InitNew();
  271. case EVENT_INITIALIZE:
  272. return T::Initialize();
  273. case EVENT_SUSPEND:
  274. return T::Suspend();
  275. case EVENT_RESUME:
  276. return T::Resume();
  277. case EVENT_SHUTDOWN:
  278. return T::Shutdown();
  279. }
  280. return E_FAIL;
  281. }
  282. };
  283. ///////////////////////////////////////////////////////////////////////////////
  284. //
  285. // CLASS
  286. //
  287. // IASRequestHandlerObject<T>
  288. //
  289. // DESCRIPTION
  290. //
  291. // This is the most derived class in the inheritance hierarchy. This must
  292. // be the class instantiated by ATL. Usually, this is accomplished through
  293. // the ATL Object Map.
  294. //
  295. // EXAMPLE
  296. //
  297. // class MyHandler : public IASRequestHandlerSync
  298. // { };
  299. //
  300. // BEGIN_OBJECT_MAP(ObjectMap)
  301. // OBJECT_ENTRY(__uuidof(MyHandler), IASRequestHandlerObject<MyHandler> )
  302. // END_OBJECT_MAP()
  303. //
  304. ///////////////////////////////////////////////////////////////////////////////
  305. template <class T>
  306. class ATL_NO_VTABLE IASRequestHandlerObject
  307. : public IASComponentObject < T >
  308. { };
  309. //////////
  310. // End of the IASTL namespace.
  311. //////////
  312. }
  313. #endif // _IASTL_H_