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.

104 lines
3.1 KiB

  1. #if !defined(_FUSION_SXS_FILESTREAM_H_INCLUDED_)
  2. #define _FUSION_SXS_FILESTREAM_H_INCLUDED_
  3. #pragma once
  4. #include <objidl.h>
  5. #include "fusionbytebuffer.h"
  6. #include "impersonationdata.h"
  7. #include "smartptr.h"
  8. class CFileStreamBase : public IStream
  9. {
  10. public:
  11. SMARTTYPEDEF(CFileStreamBase);
  12. CFileStreamBase();
  13. virtual ~CFileStreamBase();
  14. virtual VOID OnRefCountZero() { /* default does nothing */ }
  15. BOOL OpenForRead(
  16. PCWSTR pszPath,
  17. const CImpersonationData &ImpersonationData,
  18. DWORD dwShareMode,
  19. DWORD dwCreationDisposition,
  20. DWORD dwFlagsAndAttributes
  21. );
  22. BOOL OpenForRead(
  23. PCWSTR pszPath,
  24. const CImpersonationData &ImpersonationData,
  25. DWORD dwShareMode,
  26. DWORD dwCreationDisposition,
  27. DWORD dwFlagsAndAttributes,
  28. DWORD &rdwLastError,
  29. SIZE_T cExceptionalLastErrors,
  30. ...
  31. );
  32. BOOL OpenForWrite(
  33. PCWSTR pszPath,
  34. DWORD dwShareMode,
  35. DWORD dwCreationDisposition,
  36. DWORD dwFlagsAndAttributes
  37. );
  38. BOOL Close();
  39. // IUnknown methods:
  40. STDMETHODIMP_(ULONG) AddRef();
  41. STDMETHODIMP_(ULONG) Release();
  42. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
  43. // ISequentialStream methods:
  44. STDMETHODIMP Read(void *pv, ULONG cb, ULONG *pcbRead);
  45. STDMETHODIMP Write(void const *pv, ULONG cb, ULONG *pcbWritten);
  46. // IStream methods:
  47. STDMETHODIMP Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
  48. STDMETHODIMP SetSize(ULARGE_INTEGER libNewSize);
  49. STDMETHODIMP CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten);
  50. STDMETHODIMP Commit(DWORD grfCommitFlags);
  51. STDMETHODIMP Revert();
  52. STDMETHODIMP LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  53. STDMETHODIMP UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  54. STDMETHODIMP Stat(STATSTG *pstatstg, DWORD grfStatFlag);
  55. STDMETHODIMP Clone(IStream **ppIStream);
  56. protected:
  57. ULONG m_cRef;
  58. HANDLE m_hFile;
  59. DWORD m_grfMode;
  60. private:
  61. CFileStreamBase(const CFileStreamBase &r); // intentionally not implemented
  62. CFileStreamBase &operator =(const CFileStreamBase &r); // intentionally not implemented
  63. };
  64. SMARTTYPE(CFileStreamBase);
  65. enum FileStreamZeroRefCountBehavior
  66. {
  67. eDeleteFileStreamOnZeroRefCount,
  68. eDoNotDeleteFileStreamOnZeroRefCount,
  69. };
  70. template <FileStreamZeroRefCountBehavior ezrcb> class CFileStreamTemplate : public CFileStreamBase
  71. {
  72. typedef CFileStreamBase Base;
  73. public:
  74. CFileStreamTemplate() : Base() { }
  75. virtual VOID OnRefCountZero() {
  76. if (ezrcb == eDeleteFileStreamOnZeroRefCount)
  77. FUSION_DELETE_SINGLETON(this);
  78. }
  79. private:
  80. CFileStreamTemplate(const CFileStreamTemplate&); // intentionally not implemented
  81. void operator=(const CFileStreamTemplate&); // intentionally not implemented
  82. };
  83. typedef CFileStreamBase CFileStream;
  84. typedef CFileStreamTemplate<eDeleteFileStreamOnZeroRefCount> CReferenceCountedFileStream;
  85. #endif