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.

608 lines
20 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1992 **/
  4. /**********************************************************************/
  5. /*
  6. lmoersm.hxx
  7. This file contains the class declarations for the LM_RESUME_ENUM
  8. and LM_RESUME_ENUM_ITER classes.
  9. LM_RESUME_ENUM is a generic enumeration class for resumeable
  10. API. LM_RESUME_ENUM_ITER is an iterator for iterating objects
  11. created from the LM_RESUME_ENUM class.
  12. NOTE: All classes contained in this file were derived from
  13. RustanL's LM_ENUM/LM_ENUM_ITER classes.
  14. FILE HISTORY:
  15. KeithMo 29-May-1991 Created for the Server Manager.
  16. KeithMo 13-Aug-1991 Cleanup, added LOCATION support.
  17. KeithMo 19-Aug-1991 Code review revisions (code review
  18. attended by ChuckC, Hui-LiCh, JimH,
  19. JonN, KevinL).
  20. KeithMo 04-Sep-1991 Added a new control flag to the method
  21. LM_RESUME_ENUM_ITER::operator() which
  22. allows the client to optionally suspend
  23. an iteration after the current enumeration
  24. buffer is exhausted.
  25. KeithMo 07-Oct-1991 Win32 Conversion.
  26. KeithMo 23-Oct-1991 Added forward references.
  27. JonN 30-Jan-1992 Split LOC_LM_RESUME_ENUM from LM_RESUME_ENUM
  28. KeithMo 18-Mar-1992 Added optional constructor parameter to
  29. force enumerator to keep all buffers.
  30. KeithMo 31-Mar-1992 Code review revisions (code review
  31. attended by JimH, JohnL, JonN, and ThomasPa).
  32. */
  33. #ifndef _LMOERSM_HXX_
  34. #define _LMOERSM_HXX_
  35. //
  36. // NOTE: Since this header file uses the ASSERT() macro, we include
  37. // UIASSERT.HXX for its definition. However, you will experience
  38. // much less "DGROUP bloat" if you use the _FILENAME_DEFINED_ONCE
  39. // trick *before* including this header file.
  40. //
  41. #include "uiassert.hxx"
  42. #include "lmoloc.hxx"
  43. #include "lmoenum.hxx"
  44. #include "slist.hxx"
  45. //
  46. // Forward references.
  47. //
  48. DLL_CLASS LM_RESUME_BUFFER;
  49. DLL_CLASS LM_RESUME_ENUM;
  50. DLL_CLASS LM_RESUME_ENUM_ITER;
  51. /*************************************************************************
  52. NAME: LM_RESUME_BUFFER
  53. SYNOPSIS: LM_RESUME_BUFFER is used to keep track of the buffers
  54. allocated by the resumeable enumerator. An SLIST of these
  55. nodes is maintained by LM_RESUME_ENUM2.
  56. INTERFACE: LM_RESUME_BUFFER - Class constructor.
  57. ~LM_RESUME_BUFFER - Class destructor.
  58. QueryItemCount - Returns the number of enumeration
  59. items stored in the buffer
  60. associated with this node.
  61. QueryBufferPtr - Returns the buffer pointer
  62. associated with this node.
  63. PARENT: BASE
  64. HISTORY:
  65. KeithMo 15-Mar-1992 Created for the Server Manager.
  66. **************************************************************************/
  67. DLL_CLASS LM_RESUME_BUFFER : public BASE
  68. {
  69. private:
  70. LM_RESUME_ENUM * _penum;
  71. UINT _cItems;
  72. BYTE * _pbBuffer;
  73. public:
  74. LM_RESUME_BUFFER( LM_RESUME_ENUM * penum,
  75. UINT cItems,
  76. BYTE * pbBuffer );
  77. ~LM_RESUME_BUFFER( VOID );
  78. UINT QueryItemCount( VOID ) const
  79. { return _cItems; }
  80. const BYTE * QueryBufferPtr( VOID ) const
  81. { return _pbBuffer; }
  82. }; // class LM_RESUME_BUFFER
  83. DECL_SLIST_OF( LM_RESUME_BUFFER, DLL_BASED );
  84. /*************************************************************************
  85. NAME: LM_RESUME_ENUM
  86. SYNOPSIS: LM_RESUME_ENUM is a generic enumeration class
  87. for resumeable LanMan enumeration API.
  88. INTERFACE: LM_RESUME_ENUM() - Class constructor.
  89. ~LM_RESUME_ENUM() - Class destructor.
  90. QueryInfoLevel() - Query the information level.
  91. GetInfo() - Retrieves enumeration info.
  92. PARENT: BASE
  93. HISTORY:
  94. KeithMo 29-May-1991 Created for the Server Manager.
  95. KeithMo 13-Aug-1991 Cleanup.
  96. JonN 30-Jan-1992 Split off LOC_LM_RESUME_ENUM
  97. **************************************************************************/
  98. DLL_CLASS LM_RESUME_ENUM : public BASE
  99. {
  100. //
  101. // Declare LM_RESUME_ENUM_ITER as a friend class so that it
  102. // can access our private data members & methods.
  103. //
  104. friend class LM_RESUME_ENUM_ITER;
  105. friend class LM_RESUME_BUFFER;
  106. private:
  107. //
  108. // The current info level.
  109. //
  110. UINT _uLevel;
  111. //
  112. // This flag is set to TRUE if GetInfo() is to
  113. // repeatedly invoke CallAPI() until the enumeration
  114. // is exhausted, keeping all of the returned buffers
  115. // in a private SLIST.
  116. //
  117. // Otherwise, each GetInfo() call will invoke CallAPI()
  118. // only once, and "old" API buffers are not kept around.
  119. //
  120. BOOL _fKeepBuffers;
  121. //
  122. // The following data items are only useful if
  123. // _fKeepBuffers is FALSE.
  124. //
  125. // _pbBuffer is a pointer to the buffer returned by CallAPI().
  126. //
  127. // _cEntriesRead is the number of data items returned by
  128. // CallAPI().
  129. //
  130. // _fMoreData is set to TRUE if there is more enumeration data
  131. // to be gleaned by subsequent CallAPI() invocations.
  132. //
  133. BYTE * _pbBuffer;
  134. UINT _cEntriesRead;
  135. BOOL _fMoreData;
  136. //
  137. // The following data items are only useful if
  138. // _fKeepBuffers is TRUE.
  139. //
  140. // _BufferList is an SLIST of LM_RESUME_BUFFERs. This
  141. // is used to keep track of the enumeration buffers
  142. // returned by CallAPI().
  143. //
  144. UINT _cAllItems;
  145. SLIST_OF( LM_RESUME_BUFFER ) _BufferList;
  146. //
  147. // This is the number of iterators which have "bound" to this
  148. // enumerator.
  149. //
  150. // NOTE: if _fKeepBuffers is FALSE, then only iterator may
  151. // be bound to the enumerator at any one time, since any call
  152. // to the iterator's Next method may potentially invalidate
  153. // all previous data returned by the iterator.
  154. //
  155. UINT _cIterRef;
  156. //
  157. // This method calls the enumeration API. The info level can be
  158. // retrieved through the QueryInfoLevel() method.
  159. //
  160. // It is assumed that any necessary resume key(s) are private data
  161. // members of the derived class.
  162. //
  163. virtual APIERR CallAPI( BOOL fRestartEnum,
  164. BYTE ** ppbBuffer,
  165. UINT * pcEntriesRead ) = 0;
  166. //
  167. // Register an iterator "binding" to this enumerator.
  168. //
  169. VOID _RegisterIter( VOID );
  170. VOID RegisterIter( VOID )
  171. #ifdef DEBUG
  172. { _RegisterIter() ; }
  173. #else
  174. {}
  175. #endif
  176. //
  177. // Deregister an iterator "unbinding" from this enumerator.
  178. //
  179. VOID _DeregisterIter( VOID );
  180. VOID DeregisterIter( VOID )
  181. #ifdef DEBUG
  182. { _DeregisterIter() ; }
  183. #else
  184. {}
  185. #endif
  186. APIERR GetInfoSingle( BOOL fRestartEnum );
  187. APIERR GetInfoMulti( VOID );
  188. protected:
  189. //
  190. // The class constructor is protected so that this
  191. // class can only be instantiated by derived subclasses.
  192. //
  193. LM_RESUME_ENUM( UINT uLevel, BOOL fKeepBuffers = FALSE );
  194. //
  195. // This method is invoked to free an enumeration buffer.
  196. //
  197. virtual VOID FreeBuffer( BYTE ** ppbBuffer ) = 0;
  198. //
  199. // This method deletes the buffer(s) maintained by this
  200. // enumerator.
  201. //
  202. // THIS METHOD **MUST** BE CALLED FROM THE DESTRUCTOR
  203. // OF ANY DERIVED SUBCLASS THAT OVERRIDES THE FreeBuffer()
  204. // VIRTUAL!!!
  205. //
  206. VOID NukeBuffers( VOID );
  207. public:
  208. //
  209. // Class destructor.
  210. //
  211. ~LM_RESUME_ENUM();
  212. //
  213. // This method returns the LanMan API info level.
  214. //
  215. UINT QueryInfoLevel( VOID ) const
  216. { return _uLevel; }
  217. //
  218. // This method performs the initial CallAPI invocation(s).
  219. //
  220. APIERR GetInfo( BOOL fRestartEnum = TRUE );
  221. //
  222. // Query the current value of the _fKeepBuffers flag.
  223. //
  224. BOOL DoesKeepBuffers( VOID ) const
  225. { return _fKeepBuffers; }
  226. //
  227. // This method is only useful if _fKeepBuffers is TRUE.
  228. //
  229. UINT QueryTotalItemCount( VOID ) const
  230. { ASSERT( DoesKeepBuffers() ); return _cAllItems; }
  231. }; // class LM_RESUME_ENUM
  232. /*************************************************************************
  233. NAME: LOC_LM_RESUME_ENUM
  234. SYNOPSIS: LOC_LM_RESUME_ENUM adds a LOCATION object to the
  235. generic resumable enumeration class.
  236. INTERFACE: LOC_LM_RESUME_ENUM() - Class constructor.
  237. ~LOC_LM_RESUME_ENUM() - Class destructor.
  238. QueryServer() - Query the target server name.
  239. PARENT: LM_RESUME_ENUM
  240. USES: LOCATION
  241. HISTORY:
  242. JonN 30-Jan-1992 Split from LM_RESUME_ENUM
  243. **************************************************************************/
  244. DLL_CLASS LOC_LM_RESUME_ENUM : public LM_RESUME_ENUM
  245. {
  246. //
  247. // Declare LM_RESUME_ENUM_ITER as a friend class so that it
  248. // can access our private data members & methods.
  249. //
  250. friend class LM_RESUME_ENUM_ITER;
  251. private:
  252. //
  253. // This represents the target server.
  254. //
  255. LOCATION _loc;
  256. //
  257. // This method calls the enumeration API. The server name and
  258. // info level can be retrieved through the
  259. // LOC_LM_RESUME_ENUM::QueryServer() and QueryInfoLevel() methods.
  260. //
  261. // It is assumed that any necessary resume key(s) are private data
  262. // members of the derived class.
  263. //
  264. virtual APIERR CallAPI( BOOL fRestartEnum,
  265. BYTE ** ppbBuffer,
  266. UINT * pcEntriesRead ) = 0;
  267. protected:
  268. //
  269. // The class constructors are protected so that this
  270. // class can only be instantiated by derived subclasses.
  271. //
  272. LOC_LM_RESUME_ENUM( const TCHAR * pszServerName,
  273. UINT uLevel,
  274. BOOL fKeepBuffers = FALSE );
  275. LOC_LM_RESUME_ENUM( LOCATION_TYPE locType,
  276. UINT uLevel,
  277. BOOL fKeepBuffers = FALSE );
  278. LOC_LM_RESUME_ENUM( const LOCATION & loc,
  279. UINT uLevel,
  280. BOOL fKeepBuffers = FALSE );
  281. //
  282. // This method is invoked to free an enumeration buffer.
  283. //
  284. virtual VOID FreeBuffer( BYTE ** ppbBuffer );
  285. public:
  286. //
  287. // Class destructor.
  288. //
  289. ~LOC_LM_RESUME_ENUM();
  290. //
  291. // This method returns the target server name.
  292. //
  293. const TCHAR * QueryServer( VOID ) const
  294. { return _loc.QueryServer(); }
  295. }; // class LOC_LM_RESUME_ENUM
  296. /*************************************************************************
  297. NAME: LM_RESUME_ENUM_ITER
  298. SYNOPSIS: LM_RESUME_ENUM_ITER is a generic iterator for
  299. LM_RESUME_ENUM objects.
  300. INTERFACE: LM_RESUME_ENUM_ITER() - Class constructor.
  301. ~LM_RESUME_ENUM_ITER() - Class destructor.
  302. QueryBasePtr() - Returns a pointer to the
  303. enumeration buffer.
  304. QueryCount() - Queries the number of objects in
  305. the current enumeration buffer.
  306. HasMoreData() - Returns TRUE if further calls
  307. to the enumerator API must be
  308. made.
  309. NextGetInfo() - Invoke the enumerator API
  310. to refill the buffer.
  311. PARENT: BASE
  312. USES: LM_RESUME_ENUM
  313. HISTORY:
  314. KeithMo 29-May-1991 Created for the Server Manager.
  315. KeithMo 13-Aug-1991 Cleanup.
  316. **************************************************************************/
  317. DLL_CLASS LM_RESUME_ENUM_ITER : public BASE
  318. {
  319. private:
  320. //
  321. // This points to the enumerator the current iterator is "bound" to.
  322. //
  323. LM_RESUME_ENUM * _plmenum;
  324. //
  325. // This field is only used if the bound enumerator has the
  326. // _fKeepBuffers field set to TRUE. This iterator is used
  327. // to iterate through the API buffer list.
  328. //
  329. ITER_SL_OF( LM_RESUME_BUFFER ) _iterBuffer;
  330. LM_RESUME_BUFFER * _plmbuffer;
  331. protected:
  332. //
  333. // Usual constructor/destructor goodies.
  334. //
  335. LM_RESUME_ENUM_ITER( LM_RESUME_ENUM & lmenum );
  336. ~LM_RESUME_ENUM_ITER();
  337. //
  338. // This method returns a pointer to the enumerators data buffer.
  339. //
  340. const BYTE * QueryBasePtr() const ;
  341. //
  342. // This method returns a count of the number of objects in the
  343. // current enumerator buffer.
  344. //
  345. UINT QueryCount( VOID ) const ;
  346. //
  347. // This method returns TRUE if there is more data available
  348. // from the enumeration API.
  349. //
  350. BOOL HasMoreData( VOID ) const ;
  351. //
  352. // This method is called to refill the enumerator buffer
  353. // after the current buffer has been exhausted.
  354. //
  355. APIERR NextGetInfo( VOID );
  356. }; // class LM_RESUME_ENUM_ITER
  357. //
  358. // Define a convenient macro for creating iterators.
  359. //
  360. // To use:
  361. //
  362. // DECLARE_LM_RESUME_ENUM_ITER_OF( FILE3, struct file_info_3 );
  363. //
  364. // The first argument is an LMOBJ class. The second argument
  365. // is a structure which the iterator returns pointers to.
  366. //
  367. #define DECLARE_LM_RESUME_ENUM_ITER_OF( enum_name, type ) \
  368. \
  369. class enum_name##_ENUM_ITER : public LM_RESUME_ENUM_ITER \
  370. { \
  371. private: \
  372. UINT _i; \
  373. enum_name##_ENUM_OBJ _enumobj; \
  374. const type * _p; \
  375. BOOL _fStopped; \
  376. \
  377. public: \
  378. enum_name##_ENUM_ITER( enum_name##_ENUM & e ); \
  379. \
  380. const enum_name##_ENUM_OBJ * Next( APIERR * perr, \
  381. BOOL fStop = FALSE ); \
  382. \
  383. const enum_name##_ENUM_OBJ * operator()( APIERR * perr, \
  384. BOOL fStop = FALSE ) \
  385. { return Next( perr, fStop ); } \
  386. \
  387. }; /* class enum_name##_ENUM_ITER */
  388. #define DEFINE_LM_RESUME_ENUM_ITER_OF( enum_name, type ) \
  389. \
  390. enum_name##_ENUM_ITER::enum_name##_ENUM_ITER( enum_name##_ENUM & e ) \
  391. : LM_RESUME_ENUM_ITER( e ), \
  392. _enumobj(), \
  393. _p( (type *)QueryBasePtr() ), \
  394. _i( 0 ), \
  395. _fStopped( FALSE ) \
  396. { \
  397. ; \
  398. \
  399. } /* enum_name##_ENUM_ITER :: enum_name##_ENUM_ITER */ \
  400. \
  401. const enum_name##_ENUM_OBJ * enum_name##_ENUM_ITER::Next( APIERR * perr, \
  402. BOOL fStop ) \
  403. { \
  404. *perr = NERR_Success; \
  405. \
  406. if( _p == NULL ) \
  407. { \
  408. return NULL; \
  409. } \
  410. \
  411. if( _i >= QueryCount() ) \
  412. { \
  413. if( HasMoreData() ) \
  414. { \
  415. if( !_fStopped && fStop ) \
  416. { \
  417. _fStopped = TRUE; \
  418. *perr = ERROR_MORE_DATA; \
  419. return NULL; \
  420. } \
  421. \
  422. _fStopped = FALSE; \
  423. \
  424. APIERR err = NextGetInfo(); \
  425. \
  426. if( err != NERR_Success ) \
  427. { \
  428. *perr = err; \
  429. _p = NULL; \
  430. return NULL; \
  431. } \
  432. \
  433. _p = (type *)QueryBasePtr(); \
  434. _i = 0; \
  435. } \
  436. } \
  437. \
  438. if( _i < QueryCount() ) \
  439. { \
  440. _i++; \
  441. _enumobj.SetBufferPtr( _p++ ); \
  442. return &_enumobj; \
  443. } \
  444. \
  445. _p = NULL; \
  446. return NULL; \
  447. \
  448. } /* enum_name##_ENUM_ITER :: operator() */
  449. #endif // _LMOERSM_HXX_