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.

374 lines
8.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: stgconn.cxx
  7. //
  8. // Contents: Connection points for Async Storage/Stream Wrappers
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 19-Dec-95 SusiA Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "astghead.cxx"
  18. #pragma hdrstop
  19. #include "stgwrap.hxx"
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Member: CConnectionPoint::CConnectionPoint, public
  23. //
  24. // Synopsis: Constructor
  25. //
  26. // Arguments:
  27. //
  28. // History: 28-Dec-95 SusiA Created
  29. //
  30. //----------------------------------------------------------------------------
  31. CConnectionPoint::CConnectionPoint()
  32. {
  33. astgDebugOut((DEB_ITRACE, "In CConnectionPoint::CConnectionPoint:%p()\n", this));
  34. _cReferences = 1;
  35. _dwCookie = 0;
  36. _pSinkHead = NULL;
  37. astgDebugOut((DEB_ITRACE, "Out CConnectionPoint::CConnectionPoint\n"));
  38. }
  39. void CConnectionPoint::Init(IConnectionPointContainer *pCPC)
  40. {
  41. _pCPC = pCPC;
  42. }
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Member: CConnectionPoint::QueryInterface, public
  46. //
  47. // Synopsis:
  48. //
  49. // Arguments:
  50. //
  51. // Returns: Appropriate status code
  52. //
  53. // Modifies:
  54. //
  55. // History: 01-Jan-96 SusiA Created
  56. //
  57. // Notes:
  58. //
  59. //----------------------------------------------------------------------------
  60. STDMETHODIMP CConnectionPoint::QueryInterface(REFIID iid, void **ppvObj)
  61. {
  62. SCODE sc = S_OK;
  63. astgDebugOut((DEB_TRACE,
  64. "In CConnectionPoint::QueryInterface:%p()\n",
  65. this));
  66. *ppvObj = NULL;
  67. if ((IsEqualIID(iid, IID_IUnknown)) ||
  68. (IsEqualIID(iid, IID_IConnectionPoint)))
  69. {
  70. *ppvObj = (IConnectionPoint *)this;
  71. CConnectionPoint::AddRef();
  72. }
  73. else
  74. {
  75. return E_NOINTERFACE;
  76. }
  77. astgDebugOut((DEB_TRACE, "Out CConnectionPoint::QueryInterface\n"));
  78. return ResultFromScode(sc);
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Member: CConnectionPoint::AddRef, public
  83. //
  84. // Synopsis:
  85. //
  86. // Arguments:
  87. //
  88. // Returns: Appropriate status code
  89. //
  90. // Modifies:
  91. //
  92. // History: 29-Dec-95 SusiA Created
  93. //
  94. // Notes:
  95. //
  96. //----------------------------------------------------------------------------
  97. STDMETHODIMP_(ULONG) CConnectionPoint::AddRef(void)
  98. {
  99. ULONG ulRet;
  100. astgDebugOut((DEB_TRACE,
  101. "In CConnectionPoint::AddRef:%p()\n",
  102. this));
  103. InterlockedIncrement(&_cReferences);
  104. ulRet = _cReferences;
  105. astgDebugOut((DEB_TRACE, "Out CConnectionPoint::AddRef\n"));
  106. return ulRet;
  107. }
  108. //+---------------------------------------------------------------------------
  109. //
  110. // Member: CConnectionPoint::Release, public
  111. //
  112. // Synopsis:
  113. //
  114. // Arguments:
  115. //
  116. // Returns: Appropriate status code
  117. //
  118. // Modifies:
  119. //
  120. // History: 30-Dec-95 SusiA Created
  121. //
  122. // Notes:
  123. //
  124. //----------------------------------------------------------------------------
  125. STDMETHODIMP_(ULONG) CConnectionPoint::Release(void)
  126. {
  127. LONG lRet;
  128. astgDebugOut((DEB_TRACE,
  129. "In CConnectionPoint::Release:%p()\n",
  130. this));
  131. astgAssert(_cReferences > 0);
  132. lRet = InterlockedDecrement(&_cReferences);
  133. if (lRet == 0)
  134. {
  135. astgAssert((lRet > 0) && "Connection point released too many times.");
  136. }
  137. else if (lRet < 0)
  138. lRet = 0;
  139. astgDebugOut((DEB_TRACE, "Out CConnectionPoint::Release\n"));
  140. return (ULONG)lRet;
  141. }
  142. //+---------------------------------------------------------------------------
  143. //
  144. // Member: CConnectionPoint::GetConnectionInterface, public
  145. //
  146. // Synopsis:
  147. //
  148. // Arguments:
  149. //
  150. // Returns: Appropriate status code
  151. //
  152. // Modifies:
  153. //
  154. // History: 30-Dec-95 SusiA Created
  155. //
  156. // Notes:
  157. //
  158. //----------------------------------------------------------------------------
  159. STDMETHODIMP CConnectionPoint::GetConnectionInterface(IID *pIID)
  160. {
  161. astgDebugOut((DEB_ITRACE,
  162. "In CConnectionPoint::GetConnectionInterface:%p()\n",
  163. this));
  164. *pIID = IID_IProgressNotify;
  165. astgDebugOut((DEB_ITRACE, "Out CConnectionPoint::GetConnectionInterface\n"));
  166. return S_OK;
  167. }
  168. //+---------------------------------------------------------------------------
  169. //
  170. // Member: CConnectionPoint::GetConnectionPointContainer, public
  171. //
  172. // Synopsis:
  173. //
  174. // Arguments:
  175. //
  176. // Returns: Appropriate status code
  177. //
  178. // Modifies:
  179. //
  180. // History: 30-Dec-95 SusiA Created
  181. //
  182. // Notes:
  183. //
  184. //----------------------------------------------------------------------------
  185. STDMETHODIMP CConnectionPoint::GetConnectionPointContainer(
  186. IConnectionPointContainer ** ppCPC)
  187. {
  188. astgDebugOut((DEB_ITRACE,
  189. "In CConnectionPoint::GetConnectionPointContainer:%p()\n",
  190. this));
  191. *ppCPC = _pCPC;
  192. _pCPC->AddRef();
  193. astgDebugOut((DEB_ITRACE,
  194. "Out CConnectionPoint::GetConnectionPointContainer\n"));
  195. return S_OK;
  196. }
  197. //+---------------------------------------------------------------------------
  198. //
  199. // Member: CConnectionPoint::Advise, public
  200. //
  201. // Synopsis:
  202. //
  203. // Arguments:
  204. //
  205. // Returns: Appropriate status code
  206. //
  207. // Modifies:
  208. //
  209. // History: 29-Dec-95 SusiA Created
  210. //
  211. // Notes:
  212. //
  213. //----------------------------------------------------------------------------
  214. STDMETHODIMP CConnectionPoint::Advise(IUnknown *pUnkSink,
  215. DWORD *pdwCookie)
  216. {
  217. SCODE sc;
  218. CSinkList *pslTemp = NULL;
  219. CSinkList **ppslHead = NULL;
  220. void *pv = NULL;
  221. astgDebugOut((DEB_ITRACE, "In CConnectionPoint::Advise:%p()\n", this));
  222. IProgressNotify *ppn;
  223. // for the sweeper release, only one Advise sink per storage/Stream will be allowed
  224. if (_pSinkHead != NULL)
  225. return E_UNEXPECTED;
  226. //BUGBUG: Multithread access
  227. astgMem(pslTemp = new CSinkList);
  228. //Note: The QueryInterface will give us a reference to hold on to.
  229. astgChk(pUnkSink->QueryInterface(IID_IProgressNotify, &pv));
  230. pslTemp->SetProgressNotify((IProgressNotify *)pv);
  231. pslTemp->SetNext(_pSinkHead);
  232. *pdwCookie = ++_dwCookie;
  233. pslTemp->SetCookie(*pdwCookie);
  234. _pSinkHead = pslTemp;
  235. astgDebugOut((DEB_ITRACE, "Out CConnectionPoint::Advise\n"));
  236. return sc;
  237. Err:
  238. delete pslTemp;
  239. return sc;
  240. }
  241. //+---------------------------------------------------------------------------
  242. //
  243. // Member: CConnectionPoint::Unadvise, public
  244. //
  245. // Synopsis:
  246. //
  247. // Arguments:
  248. //
  249. // Returns: Appropriate status code
  250. //
  251. // Modifies:
  252. //
  253. // History: 30-Dec-95 SusiA Created
  254. //
  255. // Notes:
  256. //
  257. //----------------------------------------------------------------------------
  258. STDMETHODIMP CConnectionPoint::Unadvise(DWORD dwCookie)
  259. {
  260. CSinkList *pslTemp;
  261. CSinkList *pslPrev;
  262. astgDebugOut((DEB_ITRACE, "In CConnectionPoint::Unadvise:%p()\n", this));
  263. pslTemp = _pSinkHead;
  264. pslPrev = NULL;
  265. while ((pslTemp != NULL) && (pslTemp->GetCookie() != dwCookie))
  266. {
  267. pslPrev = pslTemp;
  268. pslTemp = pslTemp->GetNext();
  269. }
  270. if (pslTemp != NULL)
  271. {
  272. //Found the sink. Delete it from the list.
  273. if (pslPrev != NULL)
  274. {
  275. pslPrev->SetNext(pslTemp->GetNext());
  276. }
  277. else
  278. {
  279. _pSinkHead = pslTemp->GetNext();
  280. }
  281. pslTemp->GetProgressNotify()->Release();
  282. delete pslTemp;
  283. }
  284. else
  285. //Client passed in unknown cookie.
  286. return E_UNEXPECTED;
  287. astgDebugOut((DEB_ITRACE, "Out CConnectionPoint::Unadvise\n"));
  288. return S_OK;
  289. }
  290. //+---------------------------------------------------------------------------
  291. //
  292. // Member: CConnectionPoint::EnumConnections, public
  293. //
  294. // Synopsis:
  295. //
  296. // Arguments:
  297. //
  298. // Returns: Appropriate status code
  299. //
  300. // Modifies:
  301. //
  302. // History: 30-Dec-95 SusiA Created
  303. //
  304. // Notes:
  305. //
  306. //----------------------------------------------------------------------------
  307. STDMETHODIMP CConnectionPoint::EnumConnections(
  308. IEnumConnections **ppEnum)
  309. {
  310. astgDebugOut((DEB_ITRACE, "In CConnectionPoint::EnumConnections:%p()\n", this));
  311. astgDebugOut((DEB_ITRACE, "Out CConnectionPoint::EnumConnections\n"));
  312. return E_NOTIMPL;
  313. }