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.

412 lines
9.7 KiB

  1. #include "precomp.h"
  2. // NetMeeting SDK stuff
  3. #include "NmEnum.h"
  4. #include "SDKInternal.h"
  5. #include "NmConference.h"
  6. #include "NmChannel.h"
  7. #include "NmChannelData.h"
  8. CNmChannelDataObj::CNmChannelDataObj()
  9. {
  10. DBGENTRY(CNmChannelDataObj::CNmChannelDataObj);
  11. DBGEXIT(CNmChannelDataObj::CNmChannelDataObj);
  12. }
  13. CNmChannelDataObj::~CNmChannelDataObj()
  14. {
  15. DBGENTRY(CNmChannelDataObj::~CNmChannelDataObj);
  16. m_spInternalINmChannelData = NULL;
  17. DBGEXIT(CNmChannelDataObj::~CNmChannelDataObj);
  18. }
  19. HRESULT CNmChannelDataObj::FinalConstruct()
  20. {
  21. DBGENTRY(CNmChannelDataObj::FinalConstruct);
  22. HRESULT hr = S_OK;
  23. if(m_spInternalINmChannelData)
  24. {
  25. if(SUCCEEDED(hr))
  26. {
  27. hr = AtlAdvise(m_spInternalINmChannelData, GetUnknown(), IID_INmChannelDataNotify2, &m_dwInternalAdviseCookie);
  28. }
  29. }
  30. else
  31. {
  32. hr = E_UNEXPECTED;
  33. }
  34. DBGEXIT_HR(CNmChannelDataObj::FinalConstruct,hr);
  35. return hr;
  36. }
  37. ULONG CNmChannelDataObj::InternalRelease()
  38. {
  39. ATLASSERT(m_dwRef > 0);
  40. --m_dwRef;
  41. if((1 == m_dwRef) && m_dwInternalAdviseCookie)
  42. {
  43. ++m_dwRef;
  44. DWORD dwAdvise = m_dwInternalAdviseCookie;
  45. m_dwInternalAdviseCookie = 0;
  46. AtlUnadvise(m_spInternalINmChannelData, IID_INmChannelDataNotify2, dwAdvise);
  47. --m_dwRef;
  48. }
  49. return m_dwRef;
  50. }
  51. //
  52. HRESULT CNmChannelDataObj::CreateInstance(CNmConferenceObj* pConfObj, INmChannel* pInternalINmChannel, INmChannel** ppChannel)
  53. {
  54. DBGENTRY(CNmChannelDataObj::CreateInstance);
  55. HRESULT hr = S_OK;
  56. typedef CNmChannel<CNmChannelDataObj, &IID_INmChannelData, NMCH_DATA> channel_type;
  57. channel_type* p = NULL;
  58. p = new CComObject<channel_type>(NULL);
  59. if (p != NULL)
  60. {
  61. if(ppChannel)
  62. {
  63. p->SetVoid(NULL);
  64. hr = p->QueryInterface(IID_INmChannel, reinterpret_cast<void**>(ppChannel));
  65. if(SUCCEEDED(hr))
  66. {
  67. p->m_spInternalINmChannelData = com_cast<INmChannelData>(pInternalINmChannel);
  68. if(p->m_spInternalINmChannelData)
  69. {
  70. // We don't have to RefCount this because our lifetime is
  71. // contained in the CConf's lifetime
  72. p->m_pConfObj = pConfObj;
  73. // We do this so that we don't accidentally Release out of memory
  74. ++p->m_dwRef;
  75. hr = p->FinalConstruct();
  76. --p->m_dwRef;
  77. }
  78. else
  79. {
  80. hr = E_FAIL;
  81. }
  82. }
  83. if(FAILED(hr))
  84. {
  85. *ppChannel = NULL;
  86. }
  87. }
  88. else
  89. {
  90. hr = E_POINTER;
  91. }
  92. }
  93. else
  94. {
  95. hr = E_OUTOFMEMORY;
  96. }
  97. if(FAILED(hr))
  98. {
  99. delete p;
  100. }
  101. DBGEXIT_HR(CNmChannelDataObj::CreateInstance,hr);
  102. return hr;
  103. }
  104. ///////////////////////////////////////////////////////////////////////////////////
  105. // INmChannelData methods
  106. ///////////////////////////////////////////////////////////////////////////////////
  107. STDMETHODIMP CNmChannelDataObj::GetGuid(GUID *pguid)
  108. {
  109. DBGENTRY(CNmChannelDataObj::GetGuid);
  110. HRESULT hr = E_UNEXPECTED;
  111. if(m_spInternalINmChannelData)
  112. {
  113. hr = m_spInternalINmChannelData->GetGuid(pguid);
  114. }
  115. DBGEXIT_HR(CNmChannelDataObj::GetGuid,hr);
  116. return hr;
  117. }
  118. STDMETHODIMP CNmChannelDataObj::SendData(INmMember *pMember, ULONG uSize, byte *pvBuffer, ULONG uOptions)
  119. {
  120. DBGENTRY(CNmChannelDataObj::SendData);
  121. HRESULT hr = S_OK;
  122. if(m_spInternalINmChannelData)
  123. {
  124. CComPtr<INmMember> spInternalMember;
  125. if(pMember)
  126. {
  127. CComPtr<IInternalMemberObj> spMemberObj = com_cast<IInternalMemberObj>(pMember);
  128. if(spMemberObj)
  129. {
  130. hr = spMemberObj->GetInternalINmMember(&spInternalMember);
  131. }
  132. }
  133. if(SUCCEEDED(hr))
  134. {
  135. hr = m_spInternalINmChannelData->SendData(spInternalMember, uSize, pvBuffer, uOptions);
  136. }
  137. }
  138. else
  139. {
  140. hr = E_UNEXPECTED;
  141. }
  142. DBGEXIT_HR(CNmChannelDataObj::SendData,hr);
  143. return hr;
  144. }
  145. ///////////////////////////////////////////////////////////////////////////////////
  146. // INmChannelData2 methods
  147. ///////////////////////////////////////////////////////////////////////////////////
  148. STDMETHODIMP CNmChannelDataObj::RegistryAllocateHandle(ULONG numberOfHandlesRequested)
  149. {
  150. DBGENTRY(CNmChannelDataObj::RegistryAllocateHandle);
  151. HRESULT hr = E_UNEXPECTED;
  152. if(m_spInternalINmChannelData)
  153. {
  154. CComPtr<INmChannelData2> spChannel = com_cast<INmChannelData2>(m_spInternalINmChannelData);
  155. if(spChannel)
  156. {
  157. hr = spChannel->RegistryAllocateHandle(numberOfHandlesRequested);
  158. }
  159. }
  160. DBGEXIT_HR(CNmChannelDataObj::RegistryAllocateHandle,hr);
  161. return hr;
  162. }
  163. ///////////////////////////////////////////////////////////////////////////////////
  164. //INmChannelDataNotify2
  165. ///////////////////////////////////////////////////////////////////////////////////
  166. STDMETHODIMP CNmChannelDataObj::DataSent(INmMember *pMember, ULONG uSize,byte *pvBuffer)
  167. {
  168. DBGENTRY(CNmChannelDataObj::DataSent);
  169. HRESULT hr = S_OK;
  170. ASSERT(GetConfObj());
  171. INmMember* pSDKMember = GetConfObj()->GetSDKMemberFromInternalMember(pMember);
  172. hr = Fire_DataSent(pSDKMember, uSize, pvBuffer);
  173. DBGEXIT_HR(CNmChannelDataObj::DataSent,hr);
  174. return hr;
  175. }
  176. STDMETHODIMP CNmChannelDataObj::DataReceived(INmMember *pInternalMember, ULONG uSize,byte *pvBuffer, ULONG dwFlags)
  177. {
  178. DBGENTRY(CNmChannelDataObj::DataReceived);
  179. HRESULT hr = S_OK;
  180. ASSERT(GetConfObj());
  181. CComPtr<INmMember> spSDKMember = GetConfObj()->GetSDKMemberFromInternalMember(pInternalMember);
  182. hr = Fire_DataReceived(spSDKMember, uSize, pvBuffer, dwFlags);
  183. DBGEXIT_HR(CNmChannelDataObj::DataReceived,hr);
  184. return hr;
  185. }
  186. STDMETHODIMP CNmChannelDataObj::AllocateHandleConfirm(ULONG handle_value, ULONG chandles)
  187. {
  188. DBGENTRY(CNmChannelDataObj::AllocateHandleConfirm);
  189. HRESULT hr = S_OK;
  190. DBGEXIT_HR(CNmChannelDataObj::AllocateHandleConfirm,hr);
  191. return hr;
  192. }
  193. ///////////////////////////////////////////////////////////////////////////////
  194. // IInternalChannelObj methods
  195. ///////////////////////////////////////////////////////////////////////////////
  196. STDMETHODIMP CNmChannelDataObj::GetInternalINmChannel(INmChannel** ppChannel)
  197. {
  198. DBGENTRY(CNmChannelDataObj::GetInternalINmChannel);
  199. HRESULT hr = S_OK;
  200. if(ppChannel)
  201. {
  202. hr = m_spInternalINmChannelData->QueryInterface(IID_INmChannel, reinterpret_cast<void**>(ppChannel));
  203. }
  204. else
  205. {
  206. hr = E_POINTER;
  207. }
  208. DBGEXIT_HR(CNmChannelDataObj::GetInternalINmChannel,hr);
  209. return hr;
  210. }
  211. HRESULT CNmChannelDataObj::ChannelRemoved()
  212. {
  213. HRESULT hr = S_OK;
  214. RemoveMembers();
  215. CNmConferenceObj* pConfObj = GetConfObj();
  216. if(pConfObj)
  217. {
  218. hr = pConfObj->Fire_ChannelChanged(NM_CHANNEL_REMOVED, com_cast<INmChannel>(GetUnknown()));
  219. }
  220. else
  221. {
  222. ERROR_OUT(("ChannelRemoved, but no ConfObject"));
  223. hr = E_UNEXPECTED;
  224. }
  225. if(m_dwInternalAdviseCookie)
  226. {
  227. ASSERT(m_spInternalINmChannelData);
  228. AtlUnadvise(m_spInternalINmChannelData, IID_INmChannelDataNotify, m_dwInternalAdviseCookie);
  229. m_dwInternalAdviseCookie = 0;
  230. }
  231. m_spInternalINmChannelData = NULL;
  232. return hr;
  233. }
  234. ///////////////////////////////////////////////////////////////////////////////
  235. // Helpers
  236. ///////////////////////////////////////////////////////////////////////////////
  237. HRESULT CNmChannelDataObj::Fire_MemberChanged(NM_MEMBER_NOTIFY uNotify, INmMember *pMember)
  238. {
  239. DBGENTRY(CNmChannelDataObj::Fire_MemberChanged);
  240. HRESULT hr = S_OK;
  241. /////////////////////////////////////////////////////
  242. // INmChannelNotify
  243. /////////////////////////////////////////////////////
  244. IConnectionPointImpl<CNmChannelDataObj, &IID_INmChannelNotify, CComDynamicUnkArray>* pCP = this;
  245. for(int i = 0; i < pCP->m_vec.GetSize(); ++i )
  246. {
  247. INmChannelNotify* pNotify = reinterpret_cast<INmChannelNotify*>(pCP->m_vec.GetAt(i));
  248. if(pNotify)
  249. {
  250. pNotify->MemberChanged(uNotify, pMember);
  251. }
  252. }
  253. /////////////////////////////////////////////////////
  254. // INmChannelDataNotify
  255. /////////////////////////////////////////////////////
  256. IConnectionPointImpl<CNmChannelDataObj, &IID_INmChannelDataNotify, CComDynamicUnkArray>* pCP2 = this;
  257. for(i = 0; i < pCP2->m_vec.GetSize(); ++i )
  258. {
  259. INmChannelDataNotify* pNotify2 = reinterpret_cast<INmChannelDataNotify*>(pCP2->m_vec.GetAt(i));
  260. if(pNotify2)
  261. {
  262. pNotify2->MemberChanged(uNotify, pMember);
  263. }
  264. }
  265. DBGEXIT_HR(CNmChannelDataObj::Fire_MemberChanged,hr)
  266. return hr;
  267. }
  268. HRESULT CNmChannelDataObj::Fire_DataSent(INmMember *pSDKMember, ULONG uSize,byte *pvBuffer)
  269. {
  270. HRESULT hr = S_OK;
  271. /////////////////////////////////////////////////////
  272. // INmChannelDataNotify
  273. /////////////////////////////////////////////////////
  274. IConnectionPointImpl<CNmChannelDataObj, &IID_INmChannelDataNotify, CComDynamicUnkArray>* pCP2 = this;
  275. for(int i = 0; i < pCP2->m_vec.GetSize(); ++i )
  276. {
  277. INmChannelDataNotify* pNotify2 = reinterpret_cast<INmChannelDataNotify*>(pCP2->m_vec.GetAt(i));
  278. if(pNotify2)
  279. {
  280. pNotify2->DataSent(pSDKMember, uSize, pvBuffer);
  281. }
  282. }
  283. return hr;
  284. }
  285. HRESULT CNmChannelDataObj::Fire_DataReceived(INmMember *pSDKMember, ULONG uSize, byte *pvBuffer, ULONG dwFlags)
  286. {
  287. HRESULT hr = S_OK;
  288. /////////////////////////////////////////////////////
  289. // INmChannelDataNotify
  290. /////////////////////////////////////////////////////
  291. IConnectionPointImpl<CNmChannelDataObj, &IID_INmChannelDataNotify, CComDynamicUnkArray>* pCP2 = this;
  292. for(int i = 0; i < pCP2->m_vec.GetSize(); ++i )
  293. {
  294. INmChannelDataNotify* pNotify2 = reinterpret_cast<INmChannelDataNotify*>(pCP2->m_vec.GetAt(i));
  295. if(pNotify2)
  296. {
  297. pNotify2->DataReceived(pSDKMember, uSize, pvBuffer, dwFlags);
  298. }
  299. }
  300. return hr;
  301. }
  302. HRESULT CNmChannelDataObj::_IsActive()
  303. {
  304. HRESULT hr = E_FAIL;
  305. if(m_spInternalINmChannelData)
  306. {
  307. hr = m_spInternalINmChannelData->IsActive();
  308. }
  309. return hr;
  310. }
  311. HRESULT CNmChannelDataObj::_SetActive(BOOL bActive)
  312. {
  313. if (GetbActive() == bActive)
  314. return S_FALSE;
  315. return E_FAIL;
  316. }