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.

290 lines
7.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: psetstg.hxx
  7. //
  8. // Contents: Header for classes which provides common implementation of
  9. // IPropertySetStorage. CPropertySetStorage is a generic
  10. // implementation.
  11. //
  12. // Classes: CPropertySetStorage
  13. //
  14. // History: 17-Mar-93 BillMo Created.
  15. // 18-Aug-96 MikeHill Updated for StgCreatePropSet APIs.
  16. // 07-Feb-97 Danl Removed CDocFilePropertySetStorage.
  17. // 5/18/98 MikeHill
  18. // - Cleaned up CPropertySetStorage constructor by moving
  19. // some parameters to a new Init method.
  20. // - Added bool to cleanly determine if IStorage is ref-ed.
  21. //
  22. // Notes:
  23. //
  24. //--------------------------------------------------------------------------
  25. #ifndef _PSETSTG_HXX_
  26. #define _PSETSTG_HXX_
  27. #include <stgprops.hxx>
  28. #include "utils.hxx"
  29. //
  30. // Mapped Stream Option Flags used by propapi and docfile.
  31. // This tells CPropertySetStorage constructor to either Create or
  32. // QueryInterface for the mapped stream.
  33. //
  34. enum MAPPED_STREAM_OPTS
  35. {
  36. MAPPED_STREAM_CREATE,
  37. MAPPED_STREAM_QI
  38. };
  39. #define PROPERTYSETSTORAGE_SIG LONGSIG('P','S','S','T')
  40. #define PROPERTYSETSTORAGE_SIGDEL LONGSIG('P','S','S','t')
  41. #define ENUMSTATPROPSETSTG_SIG LONGSIG('S','P','S','S')
  42. #define ENUMSTATPROPSETSTG_SIGDEL LONGSIG('S','P','S','s')
  43. //+-------------------------------------------------------------------------
  44. //
  45. // Class: CPropertySetStorage
  46. //
  47. // Purpose: Implementation of IPropertySetStorage for generic
  48. // IStorage objects.
  49. //
  50. //--------------------------------------------------------------------------
  51. class CPropertySetStorage : public IPropertySetStorage
  52. {
  53. public:
  54. // ------------
  55. // Construction
  56. // ------------
  57. CPropertySetStorage( MAPPED_STREAM_OPTS MSOpts );
  58. ~CPropertySetStorage();
  59. void Init( IStorage *pstg, IBlockingLock *pBlockingLock,
  60. BOOL fControlLifetimes );
  61. // -------------------
  62. // IPropertySetStorage
  63. // -------------------
  64. STDMETHOD(QueryInterface)( REFIID riid, void **ppvObject);
  65. STDMETHOD_(ULONG,AddRef)(void);
  66. STDMETHOD_(ULONG,Release)(void);
  67. STDMETHOD(Create)( REFFMTID rfmtid,
  68. const CLSID * pclsid,
  69. DWORD grfFlags,
  70. DWORD grfMode,
  71. IPropertyStorage ** ppprstg);
  72. STDMETHOD(Open)( REFFMTID rfmtid,
  73. DWORD grfMode,
  74. IPropertyStorage ** ppprstg);
  75. STDMETHOD(Delete)( REFFMTID rfmtid);
  76. STDMETHOD(Enum)( IEnumSTATPROPSETSTG ** ppenum);
  77. // ----------------
  78. // Internal Methods
  79. // ----------------
  80. protected:
  81. VOID Lock();
  82. VOID Unlock();
  83. HRESULT CreateUserDefinedStream (
  84. IStorage * pstg,
  85. CPropSetName & psn,
  86. DWORD grfMode,
  87. BOOL * pfCreated,
  88. IStream ** ppStream );
  89. inline HRESULT Validate();
  90. // ------------
  91. // Data Members
  92. // ------------
  93. protected:
  94. ULONG _ulSig;
  95. BOOL _fContainingStgIsRefed:1;
  96. IStorage *_pstg;
  97. MAPPED_STREAM_OPTS _MSOpts;
  98. IBlockingLock * _pBlockingLock;
  99. #ifndef _MAC
  100. CRITICAL_SECTION _CriticalSection;
  101. BOOL _fInitCriticalSection;
  102. #endif
  103. LONG _cReferences;
  104. };
  105. //+-------------------------------------------------------------------
  106. //
  107. // Member: CPropertySetStorage::~CPropertySetStorage
  108. //
  109. // Synopsis: Set the deletion signature.
  110. //
  111. //--------------------------------------------------------------------
  112. inline CPropertySetStorage::~CPropertySetStorage()
  113. {
  114. _ulSig = PROPERTYSETSTORAGE_SIGDEL;
  115. #ifndef _MAC
  116. if (_fInitCriticalSection)
  117. DeleteCriticalSection( &_CriticalSection );
  118. #endif
  119. if( _fContainingStgIsRefed )
  120. {
  121. _pstg->Release();
  122. if( NULL != _pBlockingLock )
  123. _pBlockingLock->Release();
  124. }
  125. }
  126. //+-------------------------------------------------------------------
  127. //
  128. // Member: CPropertySetStorage::CPropertySetStorage
  129. //
  130. // Synopsis: Initialize the generic property storage object.
  131. //
  132. // Arguments: [MAPPED_STREAM_OPTS] fMSOpts
  133. // Flag that indicates whether to Create or QI for the
  134. // mapped stream.
  135. //
  136. // Note: This routine doesn't AddRef pstg or pBlockingLock because of the way this class
  137. // is used in the docfile class hierarchy. The life of pstg is
  138. // coupled to the life of CExposedDocfile.
  139. //
  140. //--------------------------------------------------------------------
  141. inline CPropertySetStorage::CPropertySetStorage(
  142. MAPPED_STREAM_OPTS MSOpts )
  143. {
  144. _ulSig = PROPERTYSETSTORAGE_SIG;
  145. _fContainingStgIsRefed = FALSE;
  146. _cReferences = 1;
  147. _pBlockingLock = NULL;
  148. _pstg = NULL;
  149. _MSOpts = MSOpts;
  150. #ifndef _MAC
  151. _fInitCriticalSection = FALSE;
  152. __try
  153. {
  154. InitializeCriticalSection( &_CriticalSection );
  155. _fInitCriticalSection = TRUE;
  156. }
  157. __except( EXCEPTION_EXECUTE_HANDLER )
  158. {
  159. }
  160. #endif
  161. }
  162. //+-------------------------------------------------------------------
  163. //
  164. // Member: CPropertySetStorage::Validate
  165. //
  166. // Synopsis: Validate signature.
  167. //
  168. //--------------------------------------------------------------------
  169. inline HRESULT CPropertySetStorage::Validate()
  170. {
  171. if( !_fInitCriticalSection )
  172. return E_OUTOFMEMORY;
  173. else
  174. return _ulSig == PROPERTYSETSTORAGE_SIG ? S_OK : STG_E_INVALIDHANDLE;
  175. }
  176. //+-------------------------------------------------------------------------
  177. //
  178. // Class: CEnumSTATPROPSETSTG
  179. //
  180. // Purpose: Implementation of IEnumSTATPROPSETSTG for native and docfile
  181. // IStorage objects.
  182. //
  183. // Notes:
  184. //
  185. //--------------------------------------------------------------------------
  186. class CEnumSTATPROPSETSTG : public IEnumSTATPROPSETSTG
  187. {
  188. public:
  189. // for IPropertySetStorage::Enum
  190. CEnumSTATPROPSETSTG(IStorage *pstg, HRESULT *phr);
  191. // for IEnumSTATPROPSETSTG::Clone
  192. CEnumSTATPROPSETSTG(CEnumSTATPROPSETSTG &Other, HRESULT *phr);
  193. ~CEnumSTATPROPSETSTG();
  194. STDMETHOD(QueryInterface)( REFIID riid, void **ppvObject);
  195. STDMETHOD_(ULONG, AddRef)(void);
  196. STDMETHOD_(ULONG, Release)(void);
  197. STDMETHOD(Next)(ULONG celt,
  198. STATPROPSETSTG * rgelt,
  199. ULONG * pceltFetched);
  200. // We don't need RemoteNext.
  201. STDMETHOD(Skip)(ULONG celt);
  202. STDMETHOD(Reset)();
  203. STDMETHOD(Clone)(IEnumSTATPROPSETSTG ** ppenum);
  204. private:
  205. inline HRESULT Validate();
  206. VOID CleanupStatArray();
  207. private:
  208. ULONG _ulSig;
  209. LONG _cRefs;
  210. IEnumSTATSTG * _penumSTATSTG;
  211. STATSTG _statarray[1];
  212. ULONG _cstatTotalInArray;
  213. ULONG _istatNextToRead;
  214. };
  215. //+-------------------------------------------------------------------
  216. //
  217. // Member: CEnumSTATPROPSETSTG::Validate
  218. //
  219. // Synopsis: Validate signature.
  220. //
  221. //--------------------------------------------------------------------
  222. inline HRESULT CEnumSTATPROPSETSTG::Validate()
  223. {
  224. return _ulSig == ENUMSTATPROPSETSTG_SIG ? S_OK : STG_E_INVALIDHANDLE;
  225. }
  226. #endif