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.

226 lines
6.6 KiB

  1. //---------------------------------------------------------------------------
  2. // NotifyConnPt.cpp : CVDNotifyDBEventsConnPt implementation file
  3. //
  4. // Copyright (c) 1996 Microsoft Corporation, All Rights Reserved
  5. // Developed by Sheridan Software Systems, Inc.
  6. //---------------------------------------------------------------------------
  7. #include "stdafx.h"
  8. #include "NConnPt.h"
  9. #include <memory.h>
  10. // needed for ASSERTs and FAIL
  11. //
  12. SZTHISFILE
  13. //=--------------------------------------------------------------------------=
  14. // CVDNotifyDBEventsConnPt constructor
  15. //
  16. CVDNotifyDBEventsConnPt::CVDNotifyDBEventsConnPt()
  17. {
  18. m_dwRefCount = 1;
  19. m_uiConnectionsAllocated = 0;
  20. m_uiConnectionsActive = 0;
  21. m_pConnPtContainer = NULL;
  22. m_ppNotifyDBEvents = NULL;
  23. #ifdef _DEBUG
  24. g_cVDNotifyDBEventsConnPtCreated++;
  25. #endif
  26. }
  27. //=--------------------------------------------------------------------------=
  28. // CVDNotifyDBEventsConnPt destructor
  29. //
  30. CVDNotifyDBEventsConnPt::~CVDNotifyDBEventsConnPt()
  31. {
  32. for (UINT i = 0; i < m_uiConnectionsActive; i++)
  33. RELEASE_OBJECT(m_ppNotifyDBEvents[i])
  34. delete [] m_ppNotifyDBEvents; // free up table
  35. #ifdef _DEBUG
  36. g_cVDNotifyDBEventsConnPtDestroyed++;
  37. #endif
  38. }
  39. //=--------------------------------------------------------------------------=
  40. // Create - Create rowset notify connection point object
  41. //=--------------------------------------------------------------------------=
  42. // This function creates a new rowset notify connection point object
  43. //
  44. // Parameters:
  45. // pConnPtContainer - [in] a pointer to connection point container
  46. // object
  47. // ppNotifyDBEventsConnPt - [out] a pointer in which to return pointer to
  48. // connection point object
  49. //
  50. // Output:
  51. // HRESULT - S_OK if successful
  52. // E_OUTOFMEMORY not enough memory to create object
  53. //
  54. // Notes:
  55. //
  56. HRESULT CVDNotifyDBEventsConnPt::Create(IConnectionPointContainer * pConnPtContainer, CVDNotifyDBEventsConnPt ** ppNotifyDBEventsConnPt)
  57. {
  58. *ppNotifyDBEventsConnPt = NULL;
  59. CVDNotifyDBEventsConnPt * pNotifyDBEventsConnPt = new CVDNotifyDBEventsConnPt();
  60. if (!pNotifyDBEventsConnPt)
  61. return E_OUTOFMEMORY;
  62. pNotifyDBEventsConnPt->m_pConnPtContainer = pConnPtContainer;
  63. *ppNotifyDBEventsConnPt = pNotifyDBEventsConnPt;
  64. return S_OK;
  65. }
  66. //=--------------------------------------------------------------------------=
  67. // IUnknown QueryInterface
  68. //
  69. HRESULT CVDNotifyDBEventsConnPt::QueryInterface(REFIID riid, void **ppvObjOut)
  70. {
  71. ASSERT_POINTER(ppvObjOut, IUnknown*)
  72. *ppvObjOut = NULL;
  73. if (DO_GUIDS_MATCH(riid, IID_IUnknown) ||
  74. DO_GUIDS_MATCH(riid, IID_IConnectionPoint) )
  75. {
  76. *ppvObjOut = this;
  77. AddRef();
  78. return S_OK;
  79. }
  80. return E_NOINTERFACE;
  81. }
  82. //=--------------------------------------------------------------------------=
  83. // IUnknown AddRef
  84. //
  85. ULONG CVDNotifyDBEventsConnPt::AddRef(void)
  86. {
  87. return ++m_dwRefCount;
  88. }
  89. //=--------------------------------------------------------------------------=
  90. // IUnknown Release
  91. //
  92. ULONG CVDNotifyDBEventsConnPt::Release(void)
  93. {
  94. if (1 > --m_dwRefCount)
  95. {
  96. delete this;
  97. return 0;
  98. }
  99. return m_dwRefCount;
  100. }
  101. //=--------------------------------------------------------------------------=
  102. // IConnectionPoint Methods
  103. //=--------------------------------------------------------------------------=
  104. //=--------------------------------------------------------------------------=
  105. // IConnectionPoint GetConnectionInterface
  106. //
  107. HRESULT CVDNotifyDBEventsConnPt::GetConnectionInterface(IID FAR* pIID)
  108. {
  109. ASSERT_POINTER(pIID, IID)
  110. *pIID = IID_INotifyDBEvents;
  111. return S_OK;
  112. }
  113. //=--------------------------------------------------------------------------=
  114. // IConnectionPoint GetConnectionPointContainer
  115. //
  116. HRESULT CVDNotifyDBEventsConnPt::GetConnectionPointContainer(IConnectionPointContainer FAR* FAR* ppCPC)
  117. {
  118. ASSERT_POINTER(ppCPC, IConnectionPointContainer*)
  119. if ((*ppCPC = m_pConnPtContainer) != NULL)
  120. return S_OK;
  121. return E_FAIL;
  122. }
  123. //=--------------------------------------------------------------------------=
  124. // IConnectionPoint Advise
  125. //
  126. #define VD_ADVISE_TABLE_GROWBY 10
  127. HRESULT CVDNotifyDBEventsConnPt::Advise(LPUNKNOWN pUnkSink, DWORD FAR* pdwCookie)
  128. {
  129. ASSERT_NULL_OR_POINTER(pdwCookie, DWORD)
  130. ASSERT_POINTER(pUnkSink, IUnknown)
  131. if (pUnkSink == NULL)
  132. return E_POINTER;
  133. LPUNKNOWN lpInterface;
  134. if (SUCCEEDED(pUnkSink->QueryInterface(IID_INotifyDBEvents, (LPVOID*)&lpInterface)))
  135. {
  136. // 1st check to see if we need to allocate more entries
  137. if (m_uiConnectionsAllocated <= m_uiConnectionsActive)
  138. {
  139. ULONG ulNewLen = (m_uiConnectionsAllocated + VD_ADVISE_TABLE_GROWBY) * sizeof(INotifyDBEvents**);
  140. INotifyDBEvents ** pNewMem = new INotifyDBEvents *[m_uiConnectionsAllocated + VD_ADVISE_TABLE_GROWBY];
  141. if (!pNewMem)
  142. return E_OUTOFMEMORY;
  143. memset(pNewMem, 0, (int)ulNewLen);
  144. // check to see if a table already exists
  145. if (m_ppNotifyDBEvents)
  146. {
  147. // if there are active connections copy them over to the new table
  148. if (m_uiConnectionsActive > 0)
  149. memcpy(pNewMem, m_ppNotifyDBEvents, m_uiConnectionsActive * sizeof(INotifyDBEvents**));
  150. delete [] m_ppNotifyDBEvents; // free up old table
  151. }
  152. m_ppNotifyDBEvents = pNewMem;
  153. m_uiConnectionsAllocated += VD_ADVISE_TABLE_GROWBY; // grow table by 10 entries each allocation
  154. }
  155. // append to end of table
  156. m_ppNotifyDBEvents[m_uiConnectionsActive] = (INotifyDBEvents*)lpInterface;
  157. m_uiConnectionsActive++;
  158. if (pdwCookie != NULL)
  159. *pdwCookie = (DWORD)lpInterface;
  160. return S_OK;
  161. }
  162. return E_NOINTERFACE;
  163. }
  164. //=--------------------------------------------------------------------------=
  165. // IConnectionPoint Unadvise
  166. //
  167. HRESULT CVDNotifyDBEventsConnPt::Unadvise(DWORD dwCookie)
  168. {
  169. ASSERT_POINTER((INotifyDBEvents*)dwCookie, INotifyDBEvents)
  170. for (UINT i = 0; i < m_uiConnectionsActive; i++)
  171. {
  172. if (m_ppNotifyDBEvents[i] == (INotifyDBEvents*)dwCookie)
  173. {
  174. RELEASE_OBJECT(m_ppNotifyDBEvents[i])
  175. // compress remaining entries in table
  176. for (UINT j = i; j < m_uiConnectionsActive - 1; j++)
  177. m_ppNotifyDBEvents[j] = m_ppNotifyDBEvents[j + 1];
  178. m_uiConnectionsActive--;
  179. return S_OK;
  180. }
  181. }
  182. return CONNECT_E_NOCONNECTION;
  183. }
  184. //=--------------------------------------------------------------------------=
  185. // IConnectionPoint EnumConnections
  186. //
  187. HRESULT CVDNotifyDBEventsConnPt::EnumConnections(LPENUMCONNECTIONS FAR* ppEnum)
  188. {
  189. return E_NOTIMPL;
  190. }