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.

592 lines
12 KiB

  1. // autoans.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "t3test.h"
  5. #include "t3testd.h"
  6. #include "autoans.h"
  7. #ifdef _DEBUG
  8. #ifndef _WIN64 // mfc 4.2's heap debugging features generate warnings on win64
  9. #define new DEBUG_NEW
  10. #endif
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. extern DataPtrList gDataPtrList;
  15. /////////////////////////////////////////////////////////////////////////////
  16. // autoans dialog
  17. autoans::autoans(CWnd* pParent /*=NULL*/)
  18. : CDialog(autoans::IDD, pParent)
  19. {
  20. CT3testDlg::GetAddress( &m_pAddress );
  21. }
  22. void autoans::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(autoans)
  26. // NOTE: the ClassWizard will add DDX and DDV calls here
  27. //}}AFX_DATA_MAP
  28. }
  29. BOOL autoans::OnInitDialog()
  30. {
  31. CDialog::OnInitDialog();
  32. PopulateListBox();
  33. return TRUE;
  34. }
  35. BEGIN_MESSAGE_MAP(autoans, CDialog)
  36. //{{AFX_MSG_MAP(autoans)
  37. ON_BN_CLICKED(IDC_TERMINALADD, OnTerminalAdd)
  38. ON_BN_CLICKED(IDC_TERMINALREMOVE, OnTerminalRemove)
  39. ON_WM_CLOSE()
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // autoans message handlers
  44. void autoans::OnTerminalAdd()
  45. {
  46. LONG i;
  47. ITTerminal * pTerminal;
  48. i = SendDlgItemMessage(
  49. IDC_NOTSELECTED,
  50. LB_GETCURSEL,
  51. 0,
  52. 0
  53. );
  54. if ( i == LB_ERR )
  55. {
  56. return;
  57. }
  58. pTerminal = (ITTerminal *) SendDlgItemMessage(
  59. IDC_NOTSELECTED,
  60. LB_GETITEMDATA,
  61. i,
  62. 0
  63. );
  64. if ( NULL != pTerminal )
  65. {
  66. SendDlgItemMessage(
  67. IDC_NOTSELECTED,
  68. LB_DELETESTRING,
  69. i,
  70. 0
  71. );
  72. AddTerminalToListBox( pTerminal, TRUE );
  73. }
  74. else
  75. {
  76. AddDynamicTerminalToListBox( TRUE );
  77. }
  78. }
  79. void autoans::OnTerminalRemove()
  80. {
  81. LONG i;
  82. ITTerminal * pTerminal;
  83. i = SendDlgItemMessage(
  84. IDC_SELECTED,
  85. LB_GETCURSEL,
  86. 0,
  87. 0
  88. );
  89. if ( i == LB_ERR )
  90. {
  91. return;
  92. }
  93. pTerminal = (ITTerminal *) SendDlgItemMessage(
  94. IDC_SELECTED,
  95. LB_GETITEMDATA,
  96. i,
  97. 0
  98. );
  99. SendDlgItemMessage(
  100. IDC_SELECTED,
  101. LB_DELETESTRING,
  102. i,
  103. 0
  104. );
  105. if ( NULL != pTerminal )
  106. {
  107. AddTerminalToListBox( pTerminal, FALSE );
  108. }
  109. }
  110. void autoans::OnOK()
  111. {
  112. LONG i, count;
  113. i = 0;
  114. count = SendDlgItemMessage(
  115. IDC_SELECTED,
  116. LB_GETCOUNT,
  117. 0,
  118. 0
  119. );
  120. for( i = 0; i < count; i++ )
  121. {
  122. ITTerminal * pTerminal;
  123. pTerminal = (ITTerminal *)SendDlgItemMessage(
  124. IDC_SELECTED,
  125. LB_GETITEMDATA,
  126. i,
  127. 0
  128. );
  129. AddTerminalToAAList( pTerminal );
  130. if ( NULL != pTerminal )
  131. {
  132. pTerminal->Release();
  133. }
  134. }
  135. count = SendDlgItemMessage(
  136. IDC_NOTSELECTED,
  137. LB_GETCOUNT,
  138. 0,
  139. 0
  140. );
  141. for ( i = 0; i < count; i++ )
  142. {
  143. ITTerminal * pTerminal;
  144. pTerminal = (ITTerminal *)SendDlgItemMessage(
  145. IDC_NOTSELECTED,
  146. LB_GETITEMDATA,
  147. i,
  148. 0
  149. );
  150. if ( NULL != pTerminal )
  151. {
  152. pTerminal->Release();
  153. }
  154. }
  155. CDialog::OnOK();
  156. }
  157. void autoans::OnCancel()
  158. {
  159. LONG i, count;
  160. i = 0;
  161. count = SendDlgItemMessage(
  162. IDC_SELECTED,
  163. LB_GETCOUNT,
  164. 0,
  165. 0
  166. );
  167. for( i = 0; i < count; i++ )
  168. {
  169. ITTerminal * pTerminal;
  170. pTerminal = (ITTerminal *)SendDlgItemMessage(
  171. IDC_SELECTED,
  172. LB_GETITEMDATA,
  173. i,
  174. 0
  175. );
  176. if ( NULL != pTerminal )
  177. {
  178. pTerminal->Release();
  179. }
  180. }
  181. count = SendDlgItemMessage(
  182. IDC_NOTSELECTED,
  183. LB_GETCOUNT,
  184. 0,
  185. 0
  186. );
  187. for ( i = 0; i < count; i++ )
  188. {
  189. ITTerminal * pTerminal;
  190. pTerminal = (ITTerminal *)SendDlgItemMessage(
  191. IDC_NOTSELECTED,
  192. LB_GETITEMDATA,
  193. i,
  194. 0
  195. );
  196. if ( NULL != pTerminal )
  197. {
  198. pTerminal->Release();
  199. }
  200. }
  201. CDialog::OnCancel();
  202. }
  203. void autoans::PopulateListBox()
  204. {
  205. ITTerminalSupport * pTerminalSupport;
  206. IEnumTerminal * pEnumTerminal;
  207. IEnumTerminalClass * pEnumClasses;
  208. HRESULT hr;
  209. if ( NULL == m_pAddress )
  210. {
  211. return;
  212. }
  213. m_pAddress->QueryInterface(
  214. IID_ITTerminalSupport,
  215. (void **) &pTerminalSupport
  216. );
  217. pTerminalSupport->EnumerateStaticTerminals( &pEnumTerminal );
  218. while (TRUE)
  219. {
  220. ITTerminal * pTerminal;
  221. hr = pEnumTerminal->Next(
  222. 1,
  223. &pTerminal,
  224. NULL
  225. );
  226. if ( S_OK != hr )
  227. {
  228. break;
  229. }
  230. AddTerminalToListBox( pTerminal, FALSE );
  231. // pTerminal->Release();
  232. }
  233. pEnumTerminal->Release();
  234. pTerminalSupport->EnumerateDynamicTerminalClasses( &pEnumClasses );
  235. while (TRUE)
  236. {
  237. GUID guid;
  238. hr = pEnumClasses->Next(
  239. 1,
  240. &guid,
  241. NULL
  242. );
  243. if ( S_OK != hr )
  244. {
  245. break;
  246. }
  247. if ( guid == CLSID_VideoWindowTerm )
  248. {
  249. AddDynamicTerminalToListBox( FALSE );
  250. }
  251. }
  252. pEnumClasses->Release();
  253. pTerminalSupport->Release();
  254. }
  255. void
  256. autoans::AddTerminalToListBox( ITTerminal * pTerminal, BOOL bSelected )
  257. {
  258. HRESULT hr;
  259. LONG i;
  260. DWORD dwLB;
  261. BSTR bstrName;
  262. WCHAR szBuffer[256];
  263. TERMINAL_DIRECTION td;
  264. dwLB = (bSelected ? IDC_SELECTED : IDC_NOTSELECTED);
  265. hr = pTerminal->get_Name( &bstrName );
  266. pTerminal->get_Direction( &td );
  267. if ( td == TD_RENDER )
  268. {
  269. wsprintfW(szBuffer, L"%s [Playback]", bstrName);
  270. }
  271. else
  272. {
  273. wsprintfW(szBuffer, L"%s [Record]", bstrName);
  274. }
  275. i = SendDlgItemMessage(
  276. dwLB,
  277. LB_ADDSTRING,
  278. 0,
  279. (LPARAM)szBuffer
  280. );
  281. SysFreeString( bstrName );
  282. SendDlgItemMessage(
  283. dwLB,
  284. LB_SETITEMDATA,
  285. (WPARAM) i,
  286. (LPARAM) pTerminal
  287. );
  288. }
  289. void
  290. autoans::AddDynamicTerminalToListBox( BOOL bSelected )
  291. {
  292. LONG i;
  293. DWORD dwLB;
  294. dwLB = (bSelected ? IDC_SELECTED : IDC_NOTSELECTED);
  295. i = SendDlgItemMessage(
  296. dwLB,
  297. LB_ADDSTRING,
  298. 0,
  299. (LPARAM)L"Video Window"
  300. );
  301. SendDlgItemMessage(
  302. dwLB,
  303. LB_SETITEMDATA,
  304. (WPARAM) i,
  305. (LPARAM) 0
  306. );
  307. return;
  308. }
  309. void autoans::AddTerminalToAAList( ITTerminal * pTerminal )
  310. {
  311. if ( NULL != pTerminal )
  312. {
  313. pTerminal->AddRef();
  314. }
  315. m_TerminalPtrList.push_back( pTerminal );
  316. }
  317. void autoans::OnClose()
  318. {
  319. LONG i, count;
  320. i = 0;
  321. count = SendDlgItemMessage(
  322. IDC_SELECTED,
  323. LB_GETCOUNT,
  324. 0,
  325. 0
  326. );
  327. for( i = 0; i < count; i++ )
  328. {
  329. ITTerminal * pTerminal;
  330. pTerminal = (ITTerminal *)SendDlgItemMessage(
  331. IDC_SELECTED,
  332. LB_GETITEMDATA,
  333. i,
  334. 0
  335. );
  336. if ( NULL != pTerminal )
  337. {
  338. pTerminal->Release();
  339. }
  340. }
  341. count = SendDlgItemMessage(
  342. IDC_NOTSELECTED,
  343. LB_GETCOUNT,
  344. 0,
  345. 0
  346. );
  347. for ( i = 0; i < count; i++ )
  348. {
  349. ITTerminal * pTerminal;
  350. pTerminal = (ITTerminal *)SendDlgItemMessage(
  351. IDC_NOTSELECTED,
  352. LB_GETITEMDATA,
  353. i,
  354. 0
  355. );
  356. if ( NULL != pTerminal )
  357. {
  358. pTerminal->Release();
  359. }
  360. }
  361. CDialog::OnClose();
  362. }
  363. void
  364. CT3testDlg::DoAutoAnswer(
  365. ITCallInfo * pCall
  366. )
  367. {
  368. ITAddress * pAddress;
  369. ITBasicCallControl * pBCC;
  370. HRESULT hr;
  371. DataPtrList::iterator iter,end;
  372. TerminalPtrList::iterator terminaliter, terminalend;
  373. DWORD dwSize;
  374. ITTerminalSupport * pTerminalSupport;
  375. BSTR bstrTerminalClass;
  376. PWSTR pwstr;
  377. StringFromIID(CLSID_VideoWindowTerm,&pwstr);
  378. bstrTerminalClass = SysAllocString( pwstr );
  379. CoTaskMemFree( pwstr );
  380. hr = pCall->get_Address( &pAddress );
  381. if ( !SUCCEEDED(hr) )
  382. {
  383. return;
  384. }
  385. hr = pAddress->QueryInterface(
  386. IID_ITTerminalSupport,
  387. (void **) &pTerminalSupport
  388. );
  389. if ( !SUCCEEDED(hr) )
  390. {
  391. pAddress->Release();
  392. return;
  393. }
  394. hr = pCall->QueryInterface(
  395. IID_ITBasicCallControl,
  396. (void **)&pBCC
  397. );
  398. if ( !SUCCEEDED(hr) )
  399. {
  400. pTerminalSupport->Release();
  401. pAddress->Release();
  402. return;
  403. }
  404. iter = gDataPtrList.begin();
  405. end = gDataPtrList.end();
  406. for ( ; iter != end ; iter++ )
  407. {
  408. if ( (*iter)->pAddress == pAddress )
  409. {
  410. break;
  411. }
  412. }
  413. pAddress->Release();
  414. if ( iter == end )
  415. {
  416. pBCC->Release();
  417. pTerminalSupport->Release();
  418. return;
  419. }
  420. dwSize = (*iter)->pTerminalPtrList->size();
  421. if ( 0 == dwSize )
  422. {
  423. pTerminalSupport->Release();
  424. pBCC->Release();
  425. return ;
  426. }
  427. terminaliter = (*iter)->pTerminalPtrList->begin();
  428. terminalend = (*iter)->pTerminalPtrList->end();
  429. for( ; terminaliter != terminalend ; terminaliter++ )
  430. {
  431. ITTerminal * pTerminal;
  432. if ( NULL == (*terminaliter) )
  433. {
  434. hr = pTerminalSupport->CreateTerminal(
  435. bstrTerminalClass,
  436. (long)LINEMEDIAMODE_VIDEO,
  437. TD_RENDER,
  438. &pTerminal
  439. );
  440. }
  441. else
  442. {
  443. pTerminal = *terminaliter;
  444. }
  445. // hr = pBCC->SelectTerminal( pTerminal );
  446. // if ( !SUCCEEDED(hr) )
  447. // {
  448. // }
  449. }
  450. hr = pBCC->Answer();
  451. if ( !SUCCEEDED(hr) )
  452. {
  453. }
  454. pBCC->Release();
  455. pTerminalSupport->Release();
  456. SysFreeString( bstrTerminalClass );
  457. }