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.

189 lines
6.7 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2000
  5. //
  6. // File: snapinpersistence.h
  7. //
  8. // Contents:
  9. //
  10. // Classes: CComponentPersistor, CDPersistor
  11. //
  12. //____________________________________________________________________________
  13. #pragma once
  14. #ifndef SNAPINPERSISTENCE_H_INCLUDED
  15. class CMTSnapInNode;
  16. class CComponentData;
  17. /***************************************************************************\
  18. *
  19. * CLASS: CMTSnapinNodeStreamsAndStorages
  20. *
  21. * PURPOSE: Unified base class for CComponentPersistor and CDPersistor
  22. * Encapsulated data and functionality for maintaining the collection
  23. * of snapin streams and storages.
  24. *
  25. * USAGE: Used as a base for CComponentPersistor and CDPersistor
  26. * public methods available for clients of CComponentPersistor,
  27. * CDPersistor uses iterfaces internally.
  28. *
  29. \***************************************************************************/
  30. class CMTSnapinNodeStreamsAndStorages : public XMLListCollectionBase
  31. {
  32. typedef std::pair<int, CLSID> key_t;
  33. typedef std::pair<int, std::wstring> hash_t;
  34. public:
  35. // CDPersistor uses the same storage (provided by the this class)
  36. // as CComponent persistor , but it is not related to any view.
  37. // VIEW_ID_DOCUMENT is the special value for indicating ComponentData entry
  38. enum { VIEW_ID_DOCUMENT = -1 };
  39. public: // methods not throwing exceptions
  40. // Initialize the storage for a snapin by copying the contents from
  41. // provided initialization source.
  42. SC ScInitIStorage( int idView, LPCWSTR szHash, IStorage *pSource );
  43. SC ScInitIStream ( int idView, LPCWSTR szHash, IStream *pSource );
  44. // Returns the storage for snapin. Creates and caches one if does not have already
  45. SC ScGetIStorage( int idView, const CLSID& clsid, IStorage **ppStorage );
  46. SC ScGetIStream ( int idView, const CLSID& clsid, IStream **ppStream );
  47. // Checks if it has a storage for a snapins
  48. bool HasStream(int idView, const CLSID& clsid);
  49. bool HasStorage(int idView, const CLSID& clsid);
  50. void RemoveView(int nViewId);
  51. // returns the pointer to CXML_IStxxxxx object. Creates the object if does not have one
  52. SC ScGetXmlStorage(int idView, const CLSID& clsid, CXML_IStorage *& pXMLStorage);
  53. SC ScGetXmlStream (int idView, const CLSID& clsid, CXML_IStream *& pXMLStream);
  54. protected:
  55. std::map<key_t, CXML_IStorage> m_XMLStorage;
  56. std::map<key_t, CXML_IStream> m_XMLStream;
  57. public:
  58. // persistence support for derived classes
  59. void Persist(CPersistor& persistor, bool bPersistViewId);
  60. virtual void OnNewElement(CPersistor& persistor);
  61. // implemented by the derived class
  62. virtual LPCTSTR GetItemXMLType() = 0;
  63. private:
  64. SC ScFindXmlStorage(int idView, const CLSID& clsid, bool& bFound, CXML_IStorage *& pXMLStorage);
  65. SC ScFindXmlStream (int idView, const CLSID& clsid, bool& bFound, CXML_IStream *& pXMLStream);
  66. // looks for snapin's data by the hash value
  67. // if any is found - moves data to 'known' snapin collection
  68. SC ScCheckForStreamsAndStoragesByHashValue( int idView, const CLSID& clsid, bool& bFound );
  69. // maps holding the old data comming from structured storage
  70. // untill the real data owner (snapin's CLSID) is known
  71. // We need this coz there is no conversion from hash to clsid
  72. std::map<hash_t, CXML_IStorage> m_StorageByHash;
  73. std::map<hash_t, CXML_IStream> m_StreamByHash;
  74. };
  75. /*+-------------------------------------------------------------------------*
  76. * class CComponentPersistor
  77. *
  78. * PURPOSE: Persists IComponent collection accociated with the snapin
  79. * holds IStream & IStorage maps for loading / storing data
  80. *
  81. * Also holds and maintains a collection of all the streams and storages
  82. * used by components of the snapin node and all the extensions
  83. * extending this node or it's subnodes
  84. *
  85. *+-------------------------------------------------------------------------*/
  86. class CComponentPersistor : public CMTSnapinNodeStreamsAndStorages
  87. {
  88. typedef CMTSnapinNodeStreamsAndStorages BC;
  89. public:
  90. SC ScReset();
  91. protected:
  92. virtual void Persist(CPersistor& persistor);
  93. public:
  94. DEFINE_XML_TYPE(XML_TAG_ICOMPONENT_LIST);
  95. static LPCTSTR _GetItemXMLType() { return XML_TAG_ICOMPONENT; }
  96. virtual LPCTSTR GetItemXMLType() { return _GetItemXMLType(); }
  97. };
  98. /*+-------------------------------------------------------------------------*
  99. * class CDPersistor
  100. *
  101. * PURPOSE: Persists IComponentData collection accociated with the snapin
  102. * holds IStream & IStorage maps for loading / storing data
  103. *
  104. * Also holds and maintains a collection of all the streams and storages
  105. * used by component datas of the snapin node and all the extensions
  106. * extending this node or it's subnodes
  107. *
  108. *+-------------------------------------------------------------------------*/
  109. class CDPersistor : public CMTSnapinNodeStreamsAndStorages
  110. {
  111. typedef CMTSnapinNodeStreamsAndStorages BC;
  112. public: // interface to data maintained by CMTSnapinNodeStreamsAndStorages
  113. // CDPersistor uses the same storage (provided by the base class)
  114. // as CComponent persistor , but it is not related to any view.
  115. // VIEW_ID_DOCUMENT is the special value for indicating ComponentData entry
  116. // Initialize the storage for a snapin by copying the contents from
  117. // provided initialization source.
  118. SC ScInitIStorage( LPCWSTR szHash, IStorage *pSource )
  119. {
  120. return BC::ScInitIStorage( VIEW_ID_DOCUMENT, szHash, pSource );
  121. }
  122. SC ScInitIStream ( LPCWSTR szHash, IStream *pSource )
  123. {
  124. return BC::ScInitIStream ( VIEW_ID_DOCUMENT, szHash, pSource );
  125. }
  126. // Returns the storage for snapin. Creates and caches one if does not have already
  127. SC ScGetIStorage( const CLSID& clsid, IStorage **ppStorage )
  128. {
  129. return BC::ScGetIStorage( VIEW_ID_DOCUMENT, clsid, ppStorage );
  130. }
  131. SC ScGetIStream ( const CLSID& clsid, IStream **ppStream )
  132. {
  133. return BC::ScGetIStream ( VIEW_ID_DOCUMENT, clsid, ppStream );
  134. }
  135. // Checks if it has a storage for a snapins
  136. bool HasStream(const CLSID& clsid)
  137. {
  138. return BC::HasStream(VIEW_ID_DOCUMENT, clsid);
  139. }
  140. bool HasStorage(const CLSID& clsid)
  141. {
  142. return BC::HasStorage(VIEW_ID_DOCUMENT, clsid);
  143. }
  144. public:
  145. SC ScReset();
  146. protected:
  147. virtual void Persist(CPersistor& persistor);
  148. public:
  149. DEFINE_XML_TYPE(XML_TAG_ICOMPONENT_DATA_LIST);
  150. static LPCTSTR _GetItemXMLType() { return XML_TAG_ICOMPONENT_DATA; }
  151. virtual LPCTSTR GetItemXMLType() { return _GetItemXMLType(); }
  152. };
  153. #endif SNAPINPERSISTENCE_H_INCLUDED