Source code of Windows XP (NT5)
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.

405 lines
9.2 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. delete p;
  86. *ppChannel = NULL;
  87. }
  88. }
  89. else
  90. {
  91. hr = E_POINTER;
  92. }
  93. }
  94. else
  95. {
  96. hr = E_OUTOFMEMORY;
  97. }
  98. DBGEXIT_HR(CNmChannelDataObj::CreateInstance,hr);
  99. return hr;
  100. }
  101. ///////////////////////////////////////////////////////////////////////////////////
  102. // INmChannelData methods
  103. ///////////////////////////////////////////////////////////////////////////////////
  104. STDMETHODIMP CNmChannelDataObj::GetGuid(GUID *pguid)
  105. {
  106. DBGENTRY(CNmChannelDataObj::GetGuid);
  107. HRESULT hr = E_UNEXPECTED;
  108. if(m_spInternalINmChannelData)
  109. {
  110. hr = m_spInternalINmChannelData->GetGuid(pguid);
  111. }
  112. DBGEXIT_HR(CNmChannelDataObj::GetGuid,hr);
  113. return hr;
  114. }
  115. STDMETHODIMP CNmChannelDataObj::SendData(INmMember *pMember, ULONG uSize, byte *pvBuffer, ULONG uOptions)
  116. {
  117. DBGENTRY(CNmChannelDataObj::SendData);
  118. HRESULT hr = S_OK;
  119. if(m_spInternalINmChannelData)
  120. {
  121. CComPtr<INmMember> spInternalMember;
  122. if(pMember)
  123. {
  124. CComPtr<IInternalMemberObj> spMemberObj = com_cast<IInternalMemberObj>(pMember);
  125. if(spMemberObj)
  126. {
  127. hr = spMemberObj->GetInternalINmMember(&spInternalMember);
  128. }
  129. }
  130. if(SUCCEEDED(hr))
  131. {
  132. hr = m_spInternalINmChannelData->SendData(spInternalMember, uSize, pvBuffer, uOptions);
  133. }
  134. }
  135. else
  136. {
  137. hr = E_UNEXPECTED;
  138. }
  139. DBGEXIT_HR(CNmChannelDataObj::SendData,hr);
  140. return hr;
  141. }
  142. ///////////////////////////////////////////////////////////////////////////////////
  143. // INmChannelData2 methods
  144. ///////////////////////////////////////////////////////////////////////////////////
  145. STDMETHODIMP CNmChannelDataObj::RegistryAllocateHandle(ULONG numberOfHandlesRequested)
  146. {
  147. DBGENTRY(CNmChannelDataObj::RegistryAllocateHandle);
  148. HRESULT hr = E_UNEXPECTED;
  149. if(m_spInternalINmChannelData)
  150. {
  151. CComPtr<INmChannelData2> spChannel = com_cast<INmChannelData2>(m_spInternalINmChannelData);
  152. if(spChannel)
  153. {
  154. hr = spChannel->RegistryAllocateHandle(numberOfHandlesRequested);
  155. }
  156. }
  157. DBGEXIT_HR(CNmChannelDataObj::RegistryAllocateHandle,hr);
  158. return hr;
  159. }
  160. ///////////////////////////////////////////////////////////////////////////////////
  161. //INmChannelDataNotify2
  162. ///////////////////////////////////////////////////////////////////////////////////
  163. STDMETHODIMP CNmChannelDataObj::DataSent(INmMember *pMember, ULONG uSize,byte *pvBuffer)
  164. {
  165. DBGENTRY(CNmChannelDataObj::DataSent);
  166. HRESULT hr = S_OK;
  167. ASSERT(GetConfObj());
  168. INmMember* pSDKMember = GetConfObj()->GetSDKMemberFromInternalMember(pMember);
  169. hr = Fire_DataSent(pSDKMember, uSize, pvBuffer);
  170. DBGEXIT_HR(CNmChannelDataObj::DataSent,hr);
  171. return hr;
  172. }
  173. STDMETHODIMP CNmChannelDataObj::DataReceived(INmMember *pInternalMember, ULONG uSize,byte *pvBuffer, ULONG dwFlags)
  174. {
  175. DBGENTRY(CNmChannelDataObj::DataReceived);
  176. HRESULT hr = S_OK;
  177. ASSERT(GetConfObj());
  178. CComPtr<INmMember> spSDKMember = GetConfObj()->GetSDKMemberFromInternalMember(pInternalMember);
  179. hr = Fire_DataReceived(spSDKMember, uSize, pvBuffer, dwFlags);
  180. DBGEXIT_HR(CNmChannelDataObj::DataReceived,hr);
  181. return hr;
  182. }
  183. STDMETHODIMP CNmChannelDataObj::AllocateHandleConfirm(ULONG handle_value, ULONG chandles)
  184. {
  185. DBGENTRY(CNmChannelDataObj::AllocateHandleConfirm);
  186. HRESULT hr = S_OK;
  187. DBGEXIT_HR(CNmChannelDataObj::AllocateHandleConfirm,hr);
  188. return hr;
  189. }
  190. ///////////////////////////////////////////////////////////////////////////////
  191. // IInternalChannelObj methods
  192. ///////////////////////////////////////////////////////////////////////////////
  193. STDMETHODIMP CNmChannelDataObj::GetInternalINmChannel(INmChannel** ppChannel)
  194. {
  195. DBGENTRY(CNmChannelDataObj::GetInternalINmChannel);
  196. HRESULT hr = S_OK;
  197. if(ppChannel)
  198. {
  199. hr = m_spInternalINmChannelData->QueryInterface(IID_INmChannel, reinterpret_cast<void**>(ppChannel));
  200. }
  201. else
  202. {
  203. hr = E_POINTER;
  204. }
  205. DBGEXIT_HR(CNmChannelDataObj::GetInternalINmChannel,hr);
  206. return hr;
  207. }
  208. HRESULT CNmChannelDataObj::ChannelRemoved()
  209. {
  210. HRESULT hr = S_OK;
  211. RemoveMembers();
  212. CNmConferenceObj* pConfObj = GetConfObj();
  213. if(pConfObj)
  214. {
  215. hr = pConfObj->Fire_ChannelChanged(NM_CHANNEL_REMOVED, com_cast<INmChannel>(GetUnknown()));
  216. }
  217. else
  218. {
  219. ERROR_OUT(("ChannelRemoved, but no ConfObject"));
  220. hr = E_UNEXPECTED;
  221. }
  222. if(m_dwInternalAdviseCookie)
  223. {
  224. ASSERT(m_spInternalINmChannelData);
  225. AtlUnadvise(m_spInternalINmChannelData, IID_INmChannelDataNotify, m_dwInternalAdviseCookie);
  226. m_dwInternalAdviseCookie = 0;
  227. }
  228. m_spInternalINmChannelData = NULL;
  229. return hr;
  230. }
  231. ///////////////////////////////////////////////////////////////////////////////
  232. // Helpers
  233. ///////////////////////////////////////////////////////////////////////////////
  234. HRESULT CNmChannelDataObj::Fire_MemberChanged(NM_MEMBER_NOTIFY uNotify, INmMember *pMember)
  235. {
  236. DBGENTRY(CNmChannelDataObj::Fire_MemberChanged);
  237. HRESULT hr = S_OK;
  238. /////////////////////////////////////////////////////
  239. // INmChannelNotify
  240. /////////////////////////////////////////////////////
  241. IConnectionPointImpl<CNmChannelDataObj, &IID_INmChannelNotify, CComDynamicUnkArray>* pCP = this;
  242. for(int i = 0; i < pCP->m_vec.GetSize(); ++i )
  243. {
  244. INmChannelNotify* pNotify = reinterpret_cast<INmChannelNotify*>(pCP->m_vec.GetAt(i));
  245. if(pNotify)
  246. {
  247. pNotify->MemberChanged(uNotify, pMember);
  248. }
  249. }
  250. /////////////////////////////////////////////////////
  251. // INmChannelDataNotify
  252. /////////////////////////////////////////////////////
  253. IConnectionPointImpl<CNmChannelDataObj, &IID_INmChannelDataNotify, CComDynamicUnkArray>* pCP2 = this;
  254. for(i = 0; i < pCP2->m_vec.GetSize(); ++i )
  255. {
  256. INmChannelDataNotify* pNotify2 = reinterpret_cast<INmChannelDataNotify*>(pCP2->m_vec.GetAt(i));
  257. if(pNotify2)
  258. {
  259. pNotify2->MemberChanged(uNotify, pMember);
  260. }
  261. }
  262. DBGEXIT_HR(CNmChannelDataObj::Fire_MemberChanged,hr)
  263. return hr;
  264. }
  265. HRESULT CNmChannelDataObj::Fire_DataSent(INmMember *pSDKMember, ULONG uSize,byte *pvBuffer)
  266. {
  267. HRESULT hr = S_OK;
  268. /////////////////////////////////////////////////////
  269. // INmChannelDataNotify
  270. /////////////////////////////////////////////////////
  271. IConnectionPointImpl<CNmChannelDataObj, &IID_INmChannelDataNotify, CComDynamicUnkArray>* pCP2 = this;
  272. for(int i = 0; i < pCP2->m_vec.GetSize(); ++i )
  273. {
  274. INmChannelDataNotify* pNotify2 = reinterpret_cast<INmChannelDataNotify*>(pCP2->m_vec.GetAt(i));
  275. if(pNotify2)
  276. {
  277. pNotify2->DataSent(pSDKMember, uSize, pvBuffer);
  278. }
  279. }
  280. return hr;
  281. }
  282. HRESULT CNmChannelDataObj::Fire_DataReceived(INmMember *pSDKMember, ULONG uSize, byte *pvBuffer, ULONG dwFlags)
  283. {
  284. HRESULT hr = S_OK;
  285. /////////////////////////////////////////////////////
  286. // INmChannelDataNotify
  287. /////////////////////////////////////////////////////
  288. IConnectionPointImpl<CNmChannelDataObj, &IID_INmChannelDataNotify, CComDynamicUnkArray>* pCP2 = this;
  289. for(int i = 0; i < pCP2->m_vec.GetSize(); ++i )
  290. {
  291. INmChannelDataNotify* pNotify2 = reinterpret_cast<INmChannelDataNotify*>(pCP2->m_vec.GetAt(i));
  292. if(pNotify2)
  293. {
  294. pNotify2->DataReceived(pSDKMember, uSize, pvBuffer, dwFlags);
  295. }
  296. }
  297. return hr;
  298. }
  299. HRESULT CNmChannelDataObj::_IsActive()
  300. {
  301. HRESULT hr = E_FAIL;
  302. if(m_spInternalINmChannelData)
  303. {
  304. hr = m_spInternalINmChannelData->IsActive();
  305. }
  306. return hr;
  307. }
  308. HRESULT CNmChannelDataObj::_SetActive(BOOL bActive)
  309. {
  310. if (GetbActive() == bActive)
  311. return S_FALSE;
  312. return E_FAIL;
  313. }