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.

152 lines
6.4 KiB

  1. //--------------------------------------------------------------------------
  2. // Stream.h
  3. //--------------------------------------------------------------------------
  4. #pragma once
  5. //--------------------------------------------------------------------------
  6. // Forward Decls
  7. //--------------------------------------------------------------------------
  8. #include "database.h"
  9. //--------------------------------------------------------------------------
  10. // CDatabaseStream
  11. //--------------------------------------------------------------------------
  12. class CDatabaseStream : public IDatabaseStream
  13. {
  14. public:
  15. //----------------------------------------------------------------------
  16. // Construction
  17. //----------------------------------------------------------------------
  18. CDatabaseStream(CDatabase *pDB, STREAMINDEX iStream, ACCESSTYPE tyAccess, FILEADDRESS faStart)
  19. : m_iStream(iStream),
  20. m_faStart(faStart),
  21. m_tyAccess(tyAccess)
  22. {
  23. TraceCall("CDatabaseStream::CDatabaseStream");
  24. m_cRef = 1;
  25. m_cbOffset = 0;
  26. m_iCurrent = 0;
  27. m_cbCurrent = 0;
  28. m_faCurrent = m_faStart;
  29. m_pDB = pDB;
  30. m_pDB->AddRef();
  31. }
  32. //----------------------------------------------------------------------
  33. // De-construction
  34. //----------------------------------------------------------------------
  35. ~CDatabaseStream(void) {
  36. TraceCall("CDatabaseStream::~CDatabaseStream");
  37. m_pDB->StreamRelease(this); m_pDB->Release();
  38. }
  39. //----------------------------------------------------------------------
  40. // IUnknown Members
  41. //----------------------------------------------------------------------
  42. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv) {
  43. TraceCall("CDatabaseStream::QueryInterface");
  44. *ppv = NULL;
  45. if (IID_IUnknown == riid)
  46. *ppv = (IUnknown *)(IDatabaseStream *)this;
  47. else if (IID_IStream == riid)
  48. *ppv = (IStream *)this;
  49. else if (IID_IDatabaseStream == riid)
  50. *ppv = (IDatabaseStream *)this;
  51. else if (IID_CDatabaseStream == riid)
  52. *ppv = (CDatabaseStream *)this;
  53. else
  54. return TraceResult(E_NOINTERFACE);
  55. ((IUnknown *)*ppv)->AddRef();
  56. return S_OK;
  57. }
  58. //----------------------------------------------------------------------
  59. // IStream::AddRef
  60. //----------------------------------------------------------------------
  61. STDMETHODIMP_(ULONG) AddRef(void) {
  62. TraceCall("CDatabaseStream::AddRef");
  63. return InterlockedIncrement(&m_cRef);
  64. }
  65. //----------------------------------------------------------------------
  66. // IStream::Release
  67. //----------------------------------------------------------------------
  68. STDMETHODIMP_(ULONG) Release(void) {
  69. TraceCall("CDatabaseStream::Release");
  70. LONG cRef = InterlockedDecrement(&m_cRef);
  71. if (0 == cRef)
  72. delete this;
  73. return (ULONG)cRef;
  74. }
  75. //----------------------------------------------------------------------
  76. // IStream::Read
  77. //----------------------------------------------------------------------
  78. STDMETHODIMP Read(LPVOID pvData, ULONG cbWanted, ULONG *pcbRead) {
  79. TraceCall("CDatabaseStream::Read");
  80. return m_pDB->StreamRead(this, pvData, cbWanted, pcbRead);
  81. }
  82. //----------------------------------------------------------------------
  83. // IStream::Write
  84. //----------------------------------------------------------------------
  85. STDMETHODIMP Write(const void *pvData, ULONG cb, ULONG *pcbWritten) {
  86. TraceCall("CDatabaseStream::Write");
  87. return m_pDB->StreamWrite(this, pvData, cb, pcbWritten);
  88. }
  89. //----------------------------------------------------------------------
  90. // IStream::Seek
  91. //----------------------------------------------------------------------
  92. STDMETHODIMP Seek(LARGE_INTEGER liMove, DWORD dwOrigin, ULARGE_INTEGER *pulNew) {
  93. TraceCall("CDatabaseStream::Seek");
  94. return m_pDB->StreamSeek(this, liMove, dwOrigin, pulNew);
  95. }
  96. //----------------------------------------------------------------------
  97. // CDatabaseStream::GetFileAddress
  98. //----------------------------------------------------------------------
  99. STDMETHODIMP GetFileAddress(LPFILEADDRESS pfaStream) {
  100. TraceCall("CDatabaseStream::GetFileAddress");
  101. return m_pDB->GetStreamAddress(this, pfaStream);
  102. }
  103. //----------------------------------------------------------------------
  104. // CDatabaseStream::CompareDatabase
  105. //----------------------------------------------------------------------
  106. STDMETHODIMP CompareDatabase(IDatabase *pDatabase) {
  107. TraceCall("CDatabaseStream::CompareDatabase");
  108. return m_pDB->StreamCompareDatabase(this, pDatabase);
  109. }
  110. //----------------------------------------------------------------------
  111. // Not Implemented IStream Methods
  112. //----------------------------------------------------------------------
  113. STDMETHODIMP SetSize(ULARGE_INTEGER uliSize) { return E_NOTIMPL; }
  114. STDMETHODIMP Commit(DWORD) { return S_OK; }
  115. STDMETHODIMP CopyTo(LPSTREAM, ULARGE_INTEGER, ULARGE_INTEGER*, ULARGE_INTEGER*) { return E_NOTIMPL; }
  116. STDMETHODIMP Revert(void) { return E_NOTIMPL; }
  117. STDMETHODIMP LockRegion(ULARGE_INTEGER, ULARGE_INTEGER,DWORD) { return E_NOTIMPL; }
  118. STDMETHODIMP UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { return E_NOTIMPL; }
  119. STDMETHODIMP Stat(STATSTG *, DWORD) { return E_NOTIMPL; }
  120. STDMETHODIMP Clone(LPSTREAM*) { return E_NOTIMPL; }
  121. private:
  122. //----------------------------------------------------------------------
  123. // Private Data
  124. //----------------------------------------------------------------------
  125. LONG m_cRef;
  126. STREAMINDEX m_iStream;
  127. FILEADDRESS m_faStart;
  128. ACCESSTYPE m_tyAccess;
  129. DWORD m_iCurrent;
  130. DWORD m_faCurrent;
  131. DWORD m_cbCurrent;
  132. DWORD m_cbOffset;
  133. CDatabase *m_pDB;
  134. //----------------------------------------------------------------------
  135. // Private Friend
  136. //----------------------------------------------------------------------
  137. friend CDatabase;
  138. };