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.

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