rxprotevnt.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. //
  13. // rxprotevnt.h
  14. //
  15. // AcRxObject
  16. // AcRxProtocolReactor
  17. // AcRxProtocolReactorIterator
  18. // AcRxProtocolReactorList
  19. // AcRxProtocolReactorListIterator
  20. // AcRxProtocolReactorManager
  21. // AcRxProtocolReactorManagerFactory
  22. //
  23. // DESCRIPTION:
  24. //
  25. // The classes in this file comprise a framework for attaching reactor-like
  26. // objects to AcRx classes via the AcRx protoocol extension mechanism. Unlike
  27. // normal protocol extensions, there may be more than one object implementing
  28. // an event interface for a given event class on a single AcRx object.
  29. //
  30. // The classes in this file allow define the base reactor class which is a simple
  31. // base class for run time type identification.
  32. //
  33. // Applications derive from specific reactor classes and attach an instance of
  34. // their objects implementing the reactor to a specific AcRx class via the
  35. // AcRxprotocolReactorManager.
  36. //
  37. // The AcRxProtocolReactor framework manages the reactors as follows:
  38. //
  39. // AcRxClass
  40. // -> AcRxProtocolReactorManager (at most 1 per AcRx class)
  41. // -> AcRxProtocolReactorList (any number,
  42. // indexed by AcRxProtocolReactor class)
  43. // -> AcRxProtocolReactor (any number)
  44. //
  45. // Note that the framework does not manage the allocation/deallocation of the
  46. // reactors themselves. Applications must allocate reactors, add them a
  47. // reactor list associated with one (or more) classes. Before unloading
  48. // applications should remove the reactors from the reactor lists and free the
  49. // associated memory. Applications typically do the allocation when loaded and
  50. // deallocation when unloaded but the actual timing is left up to the
  51. // applications.
  52. #pragma once
  53. #include "rxdefs.h"
  54. #include "acadstrc.h"
  55. #pragma pack (push, 8)
  56. class AcRxProtocolReactor;
  57. class AcRxProtocolReactorIterator;
  58. class AcRxProtocolReactorList;
  59. class AcRxProtocolReactorListIterator;
  60. class AcRxProtocolReactorManager;
  61. class AcRxProtocolReactorManagerFactory;
  62. ////////////////////// AcRxProtocolReactor class //////////////////////////////
  63. //
  64. /// <summary>
  65. /// The base class for all protocol reactors. All protocol reactor classes
  66. /// must derive from this class.
  67. /// </summary>
  68. class ADESK_NO_VTABLE AcRxProtocolReactor : public AcRxObject
  69. {
  70. public:
  71. ACRX_DECLARE_MEMBERS(AcRxProtocolReactor);
  72. };
  73. ////////////////////// AcRxProtocolReactorIterator class //////////////////////
  74. //
  75. /// <summary>
  76. /// An iterator for enumerating AcRxProtocolReactors in an
  77. /// AcRxProtocolReactorList.
  78. /// </summary>
  79. ///
  80. /// <remarks>
  81. /// Instances of this class are returned by
  82. /// <c>AcRxProtocolReactorList::newIterator()</c>.
  83. /// </remarks>
  84. ///
  85. class ADESK_NO_VTABLE AcRxProtocolReactorIterator : public AcRxObject
  86. {
  87. public:
  88. ACRX_DECLARE_MEMBERS(AcRxProtocolReactorIterator);
  89. // The AcRxClass of the AcRxProtocolReactors returned by the
  90. // iterator.
  91. /// <summary>
  92. /// Returns the AcRxClass type returned by the iterator.
  93. /// </summary>
  94. ///
  95. /// <returns>
  96. /// A pointer to the AcRxClass type.
  97. /// </returns>
  98. ///
  99. virtual AcRxClass* reactorClass () const = 0;
  100. /// <summary>
  101. /// Rewinds the iterator to the beginning of the list.
  102. /// </summary>
  103. ///
  104. virtual void start() = 0;
  105. /// <summary>
  106. /// Advances the iterator to the next item in the list.
  107. /// </summary>
  108. ///
  109. /// <returns>
  110. /// True if there are more items in the list, false if the iterator has
  111. /// reached the end of the list.
  112. /// </returns>
  113. ///
  114. virtual bool next () = 0;
  115. /// <summary>
  116. /// Determines whether the iterator has reached the end of the list.
  117. /// </summary>
  118. ///
  119. /// <returns>
  120. /// True if there are more items in the list, false if the iterator has
  121. /// reached the end of the list.
  122. /// </returns>
  123. ///
  124. virtual bool done () const = 0;
  125. /// <summary>
  126. /// Returns the AcRxProtocolReactor at the current iterator position.
  127. /// </summary>
  128. ///
  129. /// <returns>
  130. /// Returns a pointer to the AcRxProtocolReactor at the current iterator
  131. /// position.
  132. /// </returns>
  133. ///
  134. virtual AcRxProtocolReactor* object () const = 0;
  135. };
  136. ////////////////////// AcRxProtocolReactorList class //////////////////////////
  137. //
  138. /// <summary>
  139. /// A simple collection of AcRxProtocolReactors.
  140. /// </summary>
  141. ///
  142. /// <remarks>
  143. /// Instances of this class contain a single kind of AcRxProtocolReactor.
  144. /// Collections of this class are associated with an AcRxClass through the
  145. /// protocol reactor framework and the AcRxProtocolReactorManager class.
  146. /// </remarks>
  147. ///
  148. class ADESK_NO_VTABLE AcRxProtocolReactorList : public AcRxObject
  149. {
  150. public:
  151. ACRX_DECLARE_MEMBERS(AcRxProtocolReactorList);
  152. /// <summary>
  153. /// Returns the AcRxClass type returned by the iterator.
  154. /// </summary>
  155. ///
  156. /// <returns>
  157. /// A pointer to the AcRxClass type.
  158. /// </returns>
  159. virtual AcRxClass* reactorClass() const = 0;
  160. /// <summary>
  161. /// Adds a reactor to the collection.
  162. /// </summary>
  163. ///
  164. /// <param name="pReactor">
  165. /// A pointer to the reactor to add to the collection.
  166. /// </param>
  167. ///
  168. /// <returns>
  169. /// Returns Acad::eOk if successful. Returns Acad::eWrongObjectType if
  170. /// <paramref name="pReactor"/> is not a kind of <c>reactorClass()</c>.
  171. /// </returns>
  172. ///
  173. virtual Acad::ErrorStatus addReactor (AcRxProtocolReactor* pReactor) = 0;
  174. /// <summary>
  175. /// Removes a reactor from the collection.
  176. /// </summary>
  177. ///
  178. /// <param name="pReactor">
  179. /// A pointer to the reactor to remove from the collection.
  180. /// </param>
  181. ///
  182. virtual void removeReactor(AcRxProtocolReactor* pReactor) = 0;
  183. /// <summary>
  184. /// Obtains an iterator on the contents of the list.
  185. /// </summary>
  186. ///
  187. /// <returns>
  188. /// A pointer to an AcRxProtocolReactorIterator that can be used to
  189. /// enumerate the contents of the list.
  190. /// </returns>
  191. ///
  192. /// <remarks>
  193. /// Callers are responsible for deleting the returned iterator.
  194. /// </remarks>
  195. ///
  196. virtual AcRxProtocolReactorIterator* newIterator () const = 0;
  197. };
  198. ////////////////////// AcRxProtocolReactorListIterator class //////////////////
  199. //
  200. /// <summary>
  201. /// An iterator for enumerating AcRxProtocolReactorLists in an
  202. /// AcRxProtocolReactorManager.
  203. /// </summary>
  204. ///
  205. /// <remarks>
  206. /// Instances of this class are returned by
  207. /// <c>AcRxProtocolReactorManager::newIterator()</c>.
  208. /// </remarks>
  209. ///
  210. class ADESK_NO_VTABLE AcRxProtocolReactorListIterator : public AcRxObject
  211. {
  212. public:
  213. ACRX_DECLARE_MEMBERS(AcRxProtocolReactorListIterator);
  214. /// <summary>
  215. /// Rewinds the iterator to the beginning of the list.
  216. /// </summary>
  217. ///
  218. virtual void start() = 0;
  219. /// <summary>
  220. /// Advances the iterator to the next item in the list.
  221. /// </summary>
  222. ///
  223. /// <returns>
  224. /// True if there are more items in the list, false if the iterator has
  225. /// reached the end of the list.
  226. /// </returns>
  227. ///
  228. virtual bool next () = 0;
  229. /// <summary>
  230. /// Determines whether the iterator has reached the end of the list.
  231. /// </summary>
  232. ///
  233. /// <returns>
  234. /// True if there are more items in the list, false if the iterator has
  235. /// reached the end of the list.
  236. /// </returns>
  237. ///
  238. virtual bool done () const = 0;
  239. /// <summary>
  240. /// Returns the AcRxProtocolReactorList at the current iterator position.
  241. /// </summary>
  242. ///
  243. /// <returns>
  244. /// Returns a pointer to the AcRxProtocolReactorList at the current
  245. /// iterator position.
  246. /// </returns>
  247. ///
  248. virtual AcRxProtocolReactorList* object () const = 0;
  249. };
  250. ////////////////////// AcRxProtocolReactorManager class ///////////////////////
  251. //
  252. /// <summary>
  253. /// Container class for a collection of AcRxProtocolReactorLists.
  254. /// </summary>
  255. ///
  256. /// <remarks>
  257. /// Instances of AcRxProtocolReactorManagers are associated to AcRxClasses at
  258. /// runtime using the protocol extension framework. Instances of this class
  259. /// allow multiple kinds of AcRxProtocolReactors to be associated with a single
  260. /// AcRxClass.
  261. /// </remarks>
  262. ///
  263. class ADESK_NO_VTABLE AcRxProtocolReactorManager: public AcRxObject
  264. {
  265. public:
  266. ACRX_DECLARE_MEMBERS(AcRxProtocolReactorManager);
  267. /// <summary>
  268. /// Returns an AcRxProtocolReactorList for a specific reactor class.
  269. /// </summary>
  270. ///
  271. /// <param name="pReactorClass">
  272. /// A pointer to the AcRxClass of the reactor managed by the returned list.
  273. /// </param>
  274. ///
  275. /// <returns>
  276. /// A pointer to the AcRxProtocolReactorList.
  277. /// </returns>
  278. ///
  279. /// <remarks>
  280. /// If a list for the reactor class does not exist a new one is created and
  281. /// returned.
  282. /// </remarks>
  283. ///
  284. virtual AcRxProtocolReactorList* createReactorList (
  285. AcRxClass* pReactorClass) = 0;
  286. /// <summary>
  287. /// Returns an iterator for all of the AcRxProtocolReactorLists instances
  288. /// contained in the manager.
  289. /// </summary>
  290. ///
  291. /// <returns>
  292. /// A pointer to a new AcRxProtocolReactorListIterator that can be used to
  293. /// enumerate the AcRxProtocolReactorList instances contained in the
  294. /// manager.
  295. /// </returns>
  296. ///
  297. /// <remarks>
  298. /// Callers are responsible for deleting the returned iterator.
  299. /// </remarks>
  300. ///
  301. virtual AcRxProtocolReactorListIterator* newIterator () const = 0;
  302. };
  303. ////////////////////// AcRxProtocolReactorManagerFactory class ////////////////
  304. //
  305. /// <summary>
  306. /// A factory class for obtaining the single AcRxProtocolReactorManager
  307. /// associated
  308. /// </summary>
  309. ///
  310. class ADESK_NO_VTABLE AcRxProtocolReactorManagerFactory : public AcRxService
  311. {
  312. public:
  313. ACRX_DECLARE_MEMBERS(AcRxProtocolReactorManagerFactory);
  314. /// <summary>
  315. /// Returns the reactor manager for the specified AcRxClass.
  316. /// </summary>
  317. ///
  318. /// <param name="pRxClass">
  319. /// A pointer to the AcRxClass with the associated
  320. /// AcRxProtocolReactorManager.
  321. /// </param>
  322. ///
  323. /// <returns>
  324. /// A pointer to the AcRxProtocolReactorManager associated with <paramref
  325. /// name="pRxClass"/>.
  326. /// </returns>
  327. ///
  328. /// <remarks>
  329. /// If an AcRxProtocolReactorManager is not associated with the specified
  330. /// class a new one is created and returned to the caller.
  331. /// </remarks>
  332. ///
  333. virtual AcRxProtocolReactorManager* createReactorManager (
  334. AcRxClass* pRxClass) const = 0;
  335. };
  336. /////////////////////// Macros ////////////////////////////////////////////////
  337. // The following macros facilitate access to framework classes.
  338. // acrxProtocolReactors macro
  339. // Returns a poitner to the global AcRxProtocolReactorManagerFactory instance.
  340. //
  341. #define acrxProtocolReactors \
  342. AcRxProtocolReactorManagerFactory::cast(acrxServiceDictionary-> \
  343. at(ACRX_PROTOCOL_REACTOR_MANAGER))
  344. // ACRX_PROTOCOL_REACTOR_MANAGER_AT(acrxClass)
  345. // Returns a pointer to the AcRxProtocolReactorManager associated with the
  346. // specified acrxClass.
  347. //
  348. #define ACRX_PROTOCOL_REACTOR_MANAGER_AT(acrxClass) \
  349. acrxProtocolReactors->createReactorManager(acrxClass)
  350. // ACRX_PROTOCOL_REACTOR_LIST(acrxClass, reactorClass)
  351. // Returns a pointer to the AcRxProtocolReactorList associated with the
  352. // specified acrxClass and containing zero or more reactorClass instances.
  353. //
  354. #define ACRX_PROTOCOL_REACTOR_LIST_AT(acrxClass, reactorClass) \
  355. ACRX_PROTOCOL_REACTOR_MANAGER_AT(acrxClass)->createReactorList(reactorClass)
  356. #pragma pack (pop)