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.

181 lines
4.9 KiB

  1. //---------------------------------------------------------------------------
  2. // EntryIDData.cpp : EntryIDData implementation
  3. //
  4. // Copyright (c) 1996 Microsoft Corporation, All Rights Reserved
  5. // Developed by Sheridan Software Systems, Inc.
  6. //---------------------------------------------------------------------------
  7. #include "stdafx.h"
  8. #ifndef VD_DONT_IMPLEMENT_ISTREAM
  9. #include "Notifier.h"
  10. #include "RSColumn.h"
  11. #include "RSSource.h"
  12. #include "CursMain.h"
  13. #include "ColUpdat.h"
  14. #include "CursPos.h"
  15. #include "EntryID.h"
  16. #include "resource.h"
  17. SZTHISFILE
  18. //=--------------------------------------------------------------------------=
  19. // CVDEntryIDData - Constructor
  20. //
  21. CVDEntryIDData::CVDEntryIDData()
  22. {
  23. m_dwRefCount = 1;
  24. m_pCursorPosition = NULL;
  25. m_pColumn = NULL;
  26. m_hRow = 0;
  27. m_pStream = NULL;
  28. m_pResourceDLL = NULL;
  29. m_fDirty = FALSE;
  30. #ifdef _DEBUG
  31. g_cVDEntryIDDataCreated++;
  32. #endif
  33. }
  34. //=--------------------------------------------------------------------------=
  35. // ~CVDEntryIDData - Destructor
  36. //
  37. CVDEntryIDData::~CVDEntryIDData()
  38. {
  39. if (m_fDirty)
  40. Commit();
  41. if (m_pCursorPosition)
  42. {
  43. if (m_hRow)
  44. {
  45. IRowset * pRowset = m_pCursorPosition->GetCursorMain()->GetRowset();
  46. if (pRowset && m_pCursorPosition->GetCursorMain()->IsRowsetValid())
  47. pRowset->ReleaseRows(1, &m_hRow, NULL, NULL, NULL);
  48. }
  49. ((CVDNotifier*)m_pCursorPosition)->Release();
  50. }
  51. if (m_pStream)
  52. m_pStream->Release();
  53. #ifdef _DEBUG
  54. g_cVDEntryIDDataDestroyed++;
  55. #endif
  56. }
  57. //=--------------------------------------------------------------------------=
  58. // Create - Create entryID data object
  59. //=--------------------------------------------------------------------------=
  60. // This function creates and initializes a new entryID data object
  61. //
  62. // Parameters:
  63. // pCursorPosition - [in] backwards pointer to CVDCursorPosition object
  64. // pColumn - [in] rowset column pointer
  65. // hRow - [in] row handle
  66. // pStream - [in] data stream pointer
  67. // ppEntryIDData - [out] a pointer in which to return pointer to
  68. // entryID data object
  69. // pResourceDLL - [in] a pointer which keeps track of resource DLL
  70. //
  71. // Output:
  72. // HRESULT - S_OK if successful
  73. // E_OUTOFMEMORY not enough memory to create object
  74. //
  75. // Notes:
  76. //
  77. HRESULT CVDEntryIDData::Create(CVDCursorPosition * pCursorPosition, CVDRowsetColumn * pColumn, HROW hRow,
  78. IStream * pStream, CVDEntryIDData ** ppEntryIDData, CVDResourceDLL * pResourceDLL)
  79. {
  80. ASSERT_POINTER(pCursorPosition, CVDCursorPosition)
  81. ASSERT_POINTER(pStream, IStream)
  82. ASSERT_POINTER(ppEntryIDData, CVDEntryIDData*)
  83. ASSERT_POINTER(pResourceDLL, CVDResourceDLL)
  84. // make sure we have all necessary pointers
  85. if (!pCursorPosition || !pStream || !ppEntryIDData)
  86. {
  87. VDSetErrorInfo(IDS_ERR_INVALIDARG, IID_IEntryID, pResourceDLL);
  88. return E_INVALIDARG;
  89. }
  90. IRowset * pRowset = pCursorPosition->GetCursorMain()->GetRowset();
  91. // make sure we have a valid rowset pointer
  92. if (!pRowset || !pCursorPosition->GetCursorMain()->IsRowsetValid())
  93. {
  94. VDSetErrorInfo(IDS_ERR_ROWSETRELEASED, IID_IEntryID, pResourceDLL);
  95. return E_FAIL;
  96. }
  97. *ppEntryIDData = NULL;
  98. CVDEntryIDData * pEntryIDData = new CVDEntryIDData();
  99. if (!pEntryIDData)
  100. {
  101. VDSetErrorInfo(IDS_ERR_OUTOFMEMORY, IID_IEntryID, pResourceDLL);
  102. return E_OUTOFMEMORY;
  103. }
  104. ((CVDNotifier*)pCursorPosition)->AddRef();
  105. pRowset->AddRefRows(1, &hRow, NULL, NULL);
  106. pStream->AddRef();
  107. pEntryIDData->m_pCursorPosition = pCursorPosition;
  108. pEntryIDData->m_pColumn = pColumn;
  109. pEntryIDData->m_hRow = hRow;
  110. pEntryIDData->m_pStream = pStream;
  111. pEntryIDData->m_pResourceDLL = pResourceDLL;
  112. *ppEntryIDData = pEntryIDData;
  113. return S_OK;
  114. }
  115. //=--------------------------------------------------------------------------=
  116. // AddRef
  117. //
  118. ULONG CVDEntryIDData::AddRef(void)
  119. {
  120. return ++m_dwRefCount;
  121. }
  122. //=--------------------------------------------------------------------------=
  123. // Release
  124. //
  125. ULONG CVDEntryIDData::Release(void)
  126. {
  127. if (1 > --m_dwRefCount)
  128. {
  129. delete this;
  130. return 0;
  131. }
  132. return m_dwRefCount;
  133. }
  134. //=--------------------------------------------------------------------------=
  135. // Commit
  136. //
  137. HRESULT CVDEntryIDData::Commit()
  138. {
  139. HRESULT hr = S_OK;
  140. if (m_fDirty)
  141. {
  142. hr = m_pCursorPosition->UpdateEntryIDStream(m_pColumn, m_hRow, m_pStream);
  143. if (SUCCEEDED(hr))
  144. m_fDirty = FALSE;
  145. }
  146. return hr;
  147. }
  148. #endif //VD_DONT_IMPLEMENT_ISTREAM