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.

220 lines
7.3 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. wsbpstbl.h
  5. Abstract:
  6. Abstract classes that provides persistence methods.
  7. Author:
  8. Chuck Bardeen [cbardeen] 29-Oct-1996
  9. Revision History:
  10. --*/
  11. #ifndef _WSBPSTBL_
  12. #define _WSBPSTBL_
  13. #include "wsbpstrg.h"
  14. // The name of the stream that is created when objects are persisted
  15. // to structured storage files.
  16. #define WSB_PERSIST_DEFAULT_STREAM_NAME OLESTR("WsbStuff")
  17. // The size of the overhead associated with persisting an object.
  18. #define WSB_PERSIST_BASE_SIZE sizeof(CLSID)
  19. // Times used for autosave functionality
  20. #define DEFAULT_AUTOSAVE_INTERVAL (5 * 60 * 1000) // 5 minutes
  21. #define MAX_AUTOSAVE_INTERVAL (24 * 60 * 60 * 1000) // 24 hours
  22. // Macros to help determine how much space is needed to persist an
  23. // object or a portion of an object.
  24. #define WsbPersistSize(a) (WSB_PERSIST_BASE_SIZE + a)
  25. #define WsbPersistSizeOf(a) (WsbPersistSize(sizeof(a)))
  26. /*++
  27. Enumeration Name:
  28. WSB_PERSIST_STATE
  29. Description:
  30. An enumeration that indicates the state of the persistance object. The
  31. states actually used depend on the type of persistance which is used.
  32. --*/
  33. typedef enum {
  34. WSB_PERSIST_STATE_UNINIT = 0, // Uninitialized
  35. WSB_PERSIST_STATE_NORMAL = 1, // Normal state
  36. WSB_PERSIST_STATE_NOSCRIBBLE = 2, // No scribble state
  37. WSB_PERSIST_STATE_RELEASED = 3 // File was released
  38. } WSB_PERSIST_STATE;
  39. /*++
  40. Class Name:
  41. CWsbPersistStream
  42. Class Description:
  43. An object persistable to/from a stream.
  44. This is really an abstract class, but is constructable so that
  45. other class can delegate to it.
  46. --*/
  47. class WSB_EXPORT CWsbPersistStream :
  48. public CComObjectRoot,
  49. public IPersistStream,
  50. public IWsbPersistStream
  51. {
  52. BEGIN_COM_MAP(CWsbPersistStream)
  53. COM_INTERFACE_ENTRY(IPersist)
  54. COM_INTERFACE_ENTRY(IPersistStream)
  55. COM_INTERFACE_ENTRY(IWsbPersistStream)
  56. END_COM_MAP()
  57. // CComObjectRoot
  58. public:
  59. STDMETHOD(FinalConstruct)(void);
  60. void FinalRelease(void);
  61. #if defined(WSB_TRACK_MEMORY)
  62. ULONG InternalAddRef( );
  63. ULONG InternalRelease( );
  64. #endif
  65. // IPersistStream
  66. public:
  67. STDMETHOD(IsDirty)(void);
  68. // IWsbPersistStream
  69. public:
  70. STDMETHOD(SetIsDirty)(BOOL bIsDirty);
  71. protected:
  72. BOOL m_isDirty;
  73. };
  74. /*++
  75. Class Name:
  76. CWsbPersistable
  77. Class Description:
  78. A object persistable to/from a stream, storage, or file.
  79. This is really an abstract class, but is constructable so that
  80. other class can delegate to it. CWsbPersistStream should be used
  81. instead of this class unless storage and/or file persistence is
  82. absolutely necessary! If the object is persisted as part of a parent
  83. object, then only the parent object (or its parent) needs to support
  84. persistence to storage and/or file.
  85. --*/
  86. class WSB_EXPORT CWsbPersistable :
  87. public CWsbPersistStream,
  88. public IPersistFile,
  89. public IWsbPersistable
  90. {
  91. BEGIN_COM_MAP(CWsbPersistable)
  92. COM_INTERFACE_ENTRY2(IPersist, CWsbPersistStream)
  93. COM_INTERFACE_ENTRY2(IPersistStream, CWsbPersistStream)
  94. COM_INTERFACE_ENTRY2(IWsbPersistStream, CWsbPersistStream)
  95. COM_INTERFACE_ENTRY(IPersistFile)
  96. COM_INTERFACE_ENTRY(IWsbPersistable)
  97. END_COM_MAP()
  98. // CComObjectRoot
  99. public:
  100. STDMETHOD(FinalConstruct)(void);
  101. void FinalRelease(void);
  102. // IPersistFile
  103. public:
  104. STDMETHOD(GetCurFile)(LPOLESTR* pszFileName);
  105. STDMETHOD(Load)(LPCOLESTR pszFileName, DWORD dwMode);
  106. STDMETHOD(Save)(LPCOLESTR pszFileName, BOOL bRemember);
  107. STDMETHOD(SaveCompleted)(LPCOLESTR pszFileName);
  108. // IWsbPersistStream
  109. STDMETHOD(IsDirty)(void)
  110. { return(CWsbPersistStream::IsDirty()); }
  111. STDMETHOD(SetIsDirty)(BOOL bIsDirty)
  112. { return(CWsbPersistStream::SetIsDirty(bIsDirty)); }
  113. // IWsbPersistable
  114. public:
  115. STDMETHOD(GetDefaultFileName)(LPOLESTR* pszFileName, ULONG ulBufferSize);
  116. STDMETHOD(ReleaseFile)(void);
  117. STDMETHOD(SetDefaultFileName)(LPOLESTR pszFileName);
  118. protected:
  119. WSB_PERSIST_STATE m_persistState;
  120. CWsbStringPtr m_persistFileName;
  121. CWsbStringPtr m_persistDefaultName;
  122. CComPtr<IStorage> m_persistStorage;
  123. CComPtr<IStream> m_persistStream;
  124. };
  125. // Persistence Helper Functions
  126. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, BOOL* pValue);
  127. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, GUID* pValue);
  128. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, LONG* pValue);
  129. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, SHORT* pValue);
  130. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, BYTE* pValue);
  131. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, UCHAR* pValue, ULONG bufferSize);
  132. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, OLECHAR** pValue, ULONG bufferSize);
  133. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, ULONG* pValue);
  134. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, USHORT* pValue);
  135. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, LONGLONG* pValue);
  136. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, ULONGLONG* pValue);
  137. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, DATE* pValue);
  138. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, FILETIME* pValue);
  139. extern WSB_EXPORT HRESULT WsbLoadFromStream(IStream* pStream, ULARGE_INTEGER* pValue);
  140. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, BOOL value);
  141. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, GUID value);
  142. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, LONG value);
  143. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, SHORT value);
  144. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, BYTE value);
  145. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, UCHAR* value, ULONG bufferSize);
  146. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, OLECHAR* value);
  147. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, ULONG value);
  148. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, USHORT value);
  149. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, LONGLONG value);
  150. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, ULONGLONG value);
  151. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, DATE value);
  152. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, FILETIME value);
  153. extern WSB_EXPORT HRESULT WsbSaveToStream(IStream* pStream, ULARGE_INTEGER value);
  154. extern WSB_EXPORT HRESULT WsbBstrFromStream(IStream* pStream, BSTR* pValue);
  155. extern WSB_EXPORT HRESULT WsbBstrToStream(IStream* pStream, BSTR value);
  156. extern WSB_EXPORT HRESULT WsbPrintfToStream(IStream* pStream, OLECHAR* fmtString, ...);
  157. extern WSB_EXPORT HRESULT WsbStreamToFile(HANDLE hFile, IStream* pStream, BOOL AddCR);
  158. extern WSB_EXPORT HRESULT WsbSafeCreate(OLECHAR *, IPersistFile* pIPFile);
  159. extern WSB_EXPORT HRESULT WsbSafeLoad(OLECHAR *, IPersistFile* pIPFile, BOOL UseBackup);
  160. extern WSB_EXPORT HRESULT WsbSafeSave(IPersistFile* pIPFile);
  161. extern WSB_EXPORT HRESULT WsbMakeBackupName(OLECHAR* pSaveName, OLECHAR* pExtension,
  162. OLECHAR** ppBackupName);
  163. #endif // _WSBPSTBL_