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.

328 lines
7.2 KiB

  1. /*******************************************************************************
  2. Module Name:
  3. bgitem.cpp
  4. Abstract:
  5. Implements CBridgeItem and CBridgeItemList
  6. Author:
  7. Qianbo Huai (qhuai) Jan 28 2000
  8. *******************************************************************************/
  9. #include "stdafx.h"
  10. /*///////////////////////////////////////////////////////////////////////////////
  11. constructs CBridgeItem
  12. ////*/
  13. CBridgeItem::CBridgeItem ()
  14. :next (NULL)
  15. ,prev (NULL)
  16. ,bstrID (NULL)
  17. ,bstrName (NULL)
  18. ,pCallH323 (NULL)
  19. ,pCallSDP (NULL)
  20. ,pTermHSAud (NULL)
  21. ,pTermHSVid (NULL)
  22. ,pTermSHAud (NULL)
  23. ,pTermSHVid (NULL)
  24. ,pStreamHAudCap (NULL)
  25. ,pStreamHAudRen (NULL)
  26. ,pStreamHVidCap (NULL)
  27. ,pStreamHVidRen (NULL)
  28. ,pStreamSAudCap (NULL)
  29. ,pStreamSAudRen (NULL)
  30. ,pStreamSVidCap (NULL)
  31. ,pStreamSVidRen (NULL)
  32. {
  33. }
  34. /*//////////////////////////////////////////////////////////////////////////////
  35. destructs CBridgeItem
  36. ////*/
  37. CBridgeItem::~CBridgeItem ()
  38. {
  39. // free BSTR
  40. if (bstrID)
  41. {
  42. SysFreeString (bstrID);
  43. bstrID = NULL;
  44. }
  45. if (bstrName)
  46. {
  47. SysFreeString (bstrName);
  48. bstrName = NULL;
  49. }
  50. // free terminals
  51. if (pTermHSAud)
  52. {
  53. pTermHSAud->Release ();
  54. pTermHSAud = NULL;
  55. }
  56. if (pTermHSVid)
  57. {
  58. pTermHSVid->Release ();
  59. pTermHSVid = NULL;
  60. }
  61. if (pTermSHAud)
  62. {
  63. pTermSHAud->Release ();
  64. pTermSHAud = NULL;
  65. }
  66. if (pTermSHVid)
  67. {
  68. pTermSHVid->Release ();
  69. pTermSHVid = NULL;
  70. }
  71. // free streams on H323
  72. if (pStreamHAudCap)
  73. {
  74. pStreamHAudCap->Release ();
  75. pStreamHAudCap = NULL;
  76. }
  77. if (pStreamHAudRen)
  78. {
  79. pStreamHAudRen->Release ();
  80. pStreamHAudRen = NULL;
  81. }
  82. if (pStreamHVidCap)
  83. {
  84. pStreamHVidCap->Release ();
  85. pStreamHVidCap = NULL;
  86. }
  87. if (pStreamHVidRen)
  88. {
  89. pStreamHVidRen->Release ();
  90. pStreamHVidRen = NULL;
  91. }
  92. // free streams on SDP
  93. if (pStreamSAudCap)
  94. {
  95. pStreamSAudCap->Release ();
  96. pStreamSAudCap = NULL;
  97. }
  98. if (pStreamSAudRen)
  99. {
  100. pStreamSAudRen->Release ();
  101. pStreamSAudRen = NULL;
  102. }
  103. if (pStreamSVidCap)
  104. {
  105. pStreamSVidCap->Release ();
  106. pStreamSVidCap = NULL;
  107. }
  108. if (pStreamSVidRen)
  109. {
  110. pStreamSVidRen->Release ();
  111. pStreamSVidRen = NULL;
  112. }
  113. // free calls
  114. if (pCallH323)
  115. {
  116. pCallH323->Release ();
  117. pCallH323 = NULL;
  118. }
  119. if (pCallSDP)
  120. {
  121. pCallSDP->Release ();
  122. pCallSDP = NULL;
  123. }
  124. }
  125. /*//////////////////////////////////////////////////////////////////////////////
  126. constructs CBridgeItemList
  127. ////*/
  128. CBridgeItemList::CBridgeItemList ()
  129. {
  130. // create a head for the double linked list
  131. m_pHead = new CBridgeItem;
  132. if (NULL == m_pHead)
  133. {
  134. // @@ severe error, outof memory? put some debug info here?
  135. return;
  136. }
  137. m_pHead->next = m_pHead;
  138. m_pHead->prev = m_pHead;
  139. }
  140. /*//////////////////////////////////////////////////////////////////////////////
  141. destructs CBridgeItemList
  142. ////*/
  143. CBridgeItemList::~CBridgeItemList ()
  144. {
  145. // app should already disconnected all calls
  146. // i just release the com objects here
  147. CBridgeItem *pItem = NULL;
  148. while (NULL != (pItem = DeleteFirst ()))
  149. {
  150. delete pItem;
  151. pItem = NULL;
  152. }
  153. delete m_pHead;
  154. m_pHead = NULL;
  155. }
  156. /*//////////////////////////////////////////////////////////////////////////////
  157. ////*/
  158. #define FIND_BY_H323 1
  159. #define FIND_BY_SDP 2
  160. CBridgeItem *
  161. CBridgeItemList::Find (int flag, IUnknown *pIUnknown)
  162. {
  163. // transfer through the list, stop at the first matches
  164. HRESULT hr;
  165. IUnknown *pStore = NULL;
  166. CBridgeItem *pItem = m_pHead;
  167. while (m_pHead != (pItem = pItem->next))
  168. {
  169. // @@ should report error info if failed
  170. if (flag == FIND_BY_H323)
  171. hr = pItem->pCallH323->QueryInterface (IID_IUnknown, (void**)&pStore);
  172. else
  173. hr = pItem->pCallSDP->QueryInterface (IID_IUnknown, (void**)&pStore);
  174. if (FAILED (hr))
  175. return NULL;
  176. if (pIUnknown == pStore)
  177. {
  178. pStore->Release ();
  179. return pItem;
  180. }
  181. if (pStore)
  182. {
  183. pStore->Release ();
  184. pStore = NULL;
  185. }
  186. }
  187. return NULL;
  188. }
  189. /*//////////////////////////////////////////////////////////////////////////////
  190. finds a bridge item based on IUnknown of H323 call
  191. ////*/
  192. CBridgeItem *
  193. CBridgeItemList::FindByH323 (IUnknown *pIUnknown)
  194. {
  195. return Find (FIND_BY_H323, pIUnknown);
  196. }
  197. /*//////////////////////////////////////////////////////////////////////////////
  198. finds a bridge item based on IUnknown of sdp call
  199. ////*/
  200. CBridgeItem *
  201. CBridgeItemList::FindBySDP (IUnknown *pIUnknown)
  202. {
  203. return Find (FIND_BY_SDP, pIUnknown);
  204. }
  205. /*//////////////////////////////////////////////////////////////////////////////
  206. takes the item out of the list
  207. ////*/
  208. void
  209. CBridgeItemList::TakeOut (CBridgeItem *pItem)
  210. {
  211. // ignore to check if pItem is really in the list
  212. pItem->next->prev = pItem->prev;
  213. pItem->prev->next = pItem->next;
  214. pItem->next = NULL;
  215. pItem->prev = NULL;
  216. }
  217. /*//////////////////////////////////////////////////////////////////////////////
  218. deletes from the list and returns the first item if the list is not empty
  219. ////*/
  220. CBridgeItem *
  221. CBridgeItemList::DeleteFirst ()
  222. {
  223. CBridgeItem *pItem = m_pHead->next;
  224. // if list empty
  225. if (pItem == m_pHead)
  226. return NULL;
  227. // adjust list
  228. TakeOut (pItem);
  229. return pItem;
  230. }
  231. /*//////////////////////////////////////////////////////////////////////////////
  232. ////*/
  233. BOOL
  234. CBridgeItemList::GetAllItems (CBridgeItem ***pItemArray, int *pNum)
  235. {
  236. // ignore checking pointers
  237. int num = 0;
  238. CBridgeItem *pItem = m_pHead;
  239. while (m_pHead != (pItem = pItem->next))
  240. num ++;
  241. // no call found
  242. if (num == 0)
  243. {
  244. *pItemArray == NULL;
  245. *pNum = 0;
  246. return true;
  247. }
  248. *pItemArray = (CBridgeItem**)malloc (num * sizeof (CBridgeItem*));
  249. *pNum = num;
  250. if (NULL == *pItemArray)
  251. {
  252. return false;
  253. }
  254. // copy items pointers
  255. pItem = m_pHead;
  256. num = 0;
  257. while (m_pHead != (pItem = pItem->next))
  258. (*pItemArray)[num++] = pItem;
  259. return true;
  260. }
  261. /*//////////////////////////////////////////////////////////////////////////////
  262. appends an item to the end of the list
  263. ////*/
  264. void
  265. CBridgeItemList::Append (CBridgeItem *pItem)
  266. {
  267. pItem->next = m_pHead;
  268. pItem->prev = m_pHead->prev;
  269. pItem->next->prev = pItem;
  270. pItem->prev->next = pItem;
  271. }
  272. /*//////////////////////////////////////////////////////////////////////////////
  273. ////*/
  274. BOOL
  275. CBridgeItemList::IsEmpty ()
  276. {
  277. if (m_pHead->next == m_pHead)
  278. return true;
  279. else
  280. return false;
  281. }