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.

286 lines
7.5 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. _pstg->Release();
  121. }
  122. //+-------------------------------------------------------------------
  123. //
  124. // Member: CPropertySetStorage::CPropertySetStorage
  125. //
  126. // Synopsis: Initialize the generic property storage object.
  127. //
  128. // Arguments: [MAPPED_STREAM_OPTS] fMSOpts
  129. // Flag that indicates whether to Create or QI for the
  130. // mapped stream.
  131. //
  132. // Note: This routine doesn't AddRef pstg or pBlockingLock because of the way this class
  133. // is used in the docfile class hierarchy. The life of pstg is
  134. // coupled to the life of CExposedDocfile.
  135. //
  136. //--------------------------------------------------------------------
  137. inline CPropertySetStorage::CPropertySetStorage(
  138. MAPPED_STREAM_OPTS MSOpts )
  139. {
  140. _ulSig = PROPERTYSETSTORAGE_SIG;
  141. _fContainingStgIsRefed = FALSE;
  142. _cReferences = 1;
  143. _pBlockingLock = NULL;
  144. _pstg = NULL;
  145. _MSOpts = MSOpts;
  146. #ifndef _MAC
  147. _fInitCriticalSection = FALSE;
  148. __try
  149. {
  150. InitializeCriticalSection( &_CriticalSection );
  151. _fInitCriticalSection = TRUE;
  152. }
  153. __except( EXCEPTION_EXECUTE_HANDLER )
  154. {
  155. }
  156. #endif
  157. }
  158. //+-------------------------------------------------------------------
  159. //
  160. // Member: CPropertySetStorage::Validate
  161. //
  162. // Synopsis: Validate signature.
  163. //
  164. //--------------------------------------------------------------------
  165. inline HRESULT CPropertySetStorage::Validate()
  166. {
  167. if( !_fInitCriticalSection )
  168. return E_OUTOFMEMORY;
  169. else
  170. return _ulSig == PROPERTYSETSTORAGE_SIG ? S_OK : STG_E_INVALIDHANDLE;
  171. }
  172. //+-------------------------------------------------------------------------
  173. //
  174. // Class: CEnumSTATPROPSETSTG
  175. //
  176. // Purpose: Implementation of IEnumSTATPROPSETSTG for native and docfile
  177. // IStorage objects.
  178. //
  179. // Notes:
  180. //
  181. //--------------------------------------------------------------------------
  182. class CEnumSTATPROPSETSTG : public IEnumSTATPROPSETSTG
  183. {
  184. public:
  185. // for IPropertySetStorage::Enum
  186. CEnumSTATPROPSETSTG(IStorage *pstg, HRESULT *phr);
  187. // for IEnumSTATPROPSETSTG::Clone
  188. CEnumSTATPROPSETSTG(CEnumSTATPROPSETSTG &Other, HRESULT *phr);
  189. ~CEnumSTATPROPSETSTG();
  190. STDMETHOD(QueryInterface)( REFIID riid, void **ppvObject);
  191. STDMETHOD_(ULONG, AddRef)(void);
  192. STDMETHOD_(ULONG, Release)(void);
  193. STDMETHOD(Next)(ULONG celt,
  194. STATPROPSETSTG * rgelt,
  195. ULONG * pceltFetched);
  196. // We don't need RemoteNext.
  197. STDMETHOD(Skip)(ULONG celt);
  198. STDMETHOD(Reset)();
  199. STDMETHOD(Clone)(IEnumSTATPROPSETSTG ** ppenum);
  200. private:
  201. inline HRESULT Validate();
  202. VOID CleanupStatArray();
  203. private:
  204. ULONG _ulSig;
  205. LONG _cRefs;
  206. IEnumSTATSTG * _penumSTATSTG;
  207. STATSTG _statarray[1];
  208. ULONG _cstatTotalInArray;
  209. ULONG _istatNextToRead;
  210. };
  211. //+-------------------------------------------------------------------
  212. //
  213. // Member: CEnumSTATPROPSETSTG::Validate
  214. //
  215. // Synopsis: Validate signature.
  216. //
  217. //--------------------------------------------------------------------
  218. inline HRESULT CEnumSTATPROPSETSTG::Validate()
  219. {
  220. return _ulSig == ENUMSTATPROPSETSTG_SIG ? S_OK : STG_E_INVALIDHANDLE;
  221. }
  222. #endif