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.

209 lines
6.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. /////////////////////////////////////////////////////////
  23. // ThreadAnswer.cpp
  24. //
  25. #include "stdafx.h"
  26. #include "TapiDialer.h"
  27. #include "AVTapi.h"
  28. #include "AVTapiCall.h"
  29. #include "ThreadAns.h"
  30. CThreadAnswerInfo::CThreadAnswerInfo()
  31. {
  32. m_pITCall = NULL;
  33. m_pITControl = NULL;
  34. m_pAVCall = NULL;
  35. m_pStreamCall = NULL;
  36. m_pStreamControl = NULL;
  37. m_bUSBAnswer = FALSE;
  38. }
  39. CThreadAnswerInfo::~CThreadAnswerInfo()
  40. {
  41. RELEASE( m_pAVCall );
  42. RELEASE( m_pITCall );
  43. RELEASE( m_pITControl );
  44. }
  45. HRESULT CThreadAnswerInfo::set_AVTapiCall( IAVTapiCall *pAVCall )
  46. {
  47. RELEASE( m_pAVCall );
  48. if ( pAVCall )
  49. return pAVCall->QueryInterface( IID_IAVTapiCall, (void **) &m_pAVCall );
  50. return E_POINTER;
  51. }
  52. HRESULT CThreadAnswerInfo::set_ITCallInfo( ITCallInfo *pInfo )
  53. {
  54. RELEASE( m_pITCall );
  55. if ( pInfo )
  56. return pInfo->QueryInterface( IID_ITCallInfo, (void **) &m_pITCall );
  57. return E_POINTER;
  58. }
  59. HRESULT CThreadAnswerInfo::set_ITBasicCallControl( ITBasicCallControl *pControl )
  60. {
  61. RELEASE( m_pITControl );
  62. if ( pControl )
  63. return pControl->QueryInterface( IID_ITBasicCallControl, (void **) &m_pITControl );
  64. return E_POINTER;
  65. }
  66. /////////////////////////////////////////////////////////////////////////////////
  67. // ThreadAnswerProc
  68. //
  69. DWORD WINAPI ThreadAnswerProc( LPVOID lpInfo )
  70. {
  71. #undef FETCH_STRING
  72. #define FETCH_STRING( _CMS_, _IDS_ ) \
  73. LoadString( _Module.GetResourceInstance(), _IDS_, szText, ARRAYSIZE(szText) ); \
  74. SysReAllocString( &bstrText, T2COLE(szText) ); \
  75. pAVTapi->fire_SetCallState_CMS( lCallID, _CMS_, bstrText );
  76. ATLTRACE(_T(".enter.ThreadAnswerProc().\n") );
  77. HANDLE hThread = NULL;
  78. BOOL bDup = DuplicateHandle( GetCurrentProcess(),
  79. GetCurrentThread(),
  80. GetCurrentProcess(),
  81. &hThread,
  82. THREAD_ALL_ACCESS,
  83. TRUE,
  84. 0 );
  85. _ASSERT( bDup );
  86. _Module.AddThread( hThread );
  87. _ASSERT( lpInfo );
  88. CThreadAnswerInfo *pAnswerInfo = (CThreadAnswerInfo *) lpInfo;
  89. // Error info information
  90. CErrorInfo er;
  91. er.set_Operation( IDS_ER_ANSWER_CALL );
  92. er.set_Details( IDS_ER_COINITIALIZE );
  93. HRESULT hr = CoInitializeEx( NULL, COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY );
  94. if ( SUCCEEDED(hr) )
  95. {
  96. ATLTRACE(_T(".1.ThreadAnswerProc() -- thread up and running.\n") );
  97. // Setting up media terminals
  98. CAVTapi *pAVTapi;
  99. if ( SUCCEEDED(hr = _Module.GetAVTapi(&pAVTapi)) )
  100. {
  101. AVCallType nCallType;
  102. long lCallID;
  103. pAnswerInfo->m_pAVCall->get_nCallType( &nCallType );
  104. pAnswerInfo->m_pAVCall->get_lCallID( &lCallID );
  105. pAnswerInfo->m_pAVCall->put_dwThreadID( GetCurrentThreadId() );
  106. // Get the mark, if the answer was a 'Take Call' answer (FALSE) or
  107. // a USB phone answer (TRUE)
  108. BOOL bUSBAnswer = pAnswerInfo->m_bUSBAnswer;
  109. USES_CONVERSION;
  110. TCHAR szText[255];
  111. BSTR bstrText = NULL;
  112. pAVTapi->fire_ClearCurrentActions( lCallID );
  113. pAVTapi->fire_AddCurrentAction( lCallID, CM_ACTIONS_DISCONNECT, NULL );
  114. FETCH_STRING( CM_STATES_RINGING, IDS_PLACECALL_FETCH_ADDRESS );
  115. // Setup media types and answer
  116. ITAddress *pITAddress = NULL;
  117. if ( SUCCEEDED(hr = pAnswerInfo->m_pITCall->get_Address(&pITAddress)) && pITAddress )
  118. {
  119. // Select a set of media terminals to use on the call
  120. if ( nCallType != AV_DATA_CALL )
  121. {
  122. er.set_Details( IDS_ER_CREATETERMINALS );
  123. hr = er.set_hr( pAVTapi->CreateTerminalArray(pITAddress, pAnswerInfo->m_pAVCall, pAnswerInfo->m_pITCall) );
  124. }
  125. // Set state to "attempting to answer"
  126. if ( SUCCEEDED(hr) && SUCCEEDED(hr = pAnswerInfo->m_pAVCall->CheckKillMe()) )
  127. {
  128. FETCH_STRING( CM_STATES_CONNECTING, IDS_PLACECALL_OFFERING_ANSWER );
  129. // Answer the call
  130. if ( SUCCEEDED(hr) && SUCCEEDED(hr = pAnswerInfo->m_pAVCall->CheckKillMe()) )
  131. {
  132. if ( nCallType != AV_DATA_CALL )
  133. {
  134. pAVTapi->ShowMedia( lCallID, NULL, false ); // initially hide video
  135. pAVTapi->ShowMediaPreview( lCallID, NULL, false );
  136. }
  137. // If the anwser was a 'Take Call' answer then we have to answer to
  138. // the call. If the answer was a USB answer, we don't answer to the call
  139. // because the USB phone already did for us.
  140. if( !bUSBAnswer )
  141. {
  142. er.set_Details( IDS_ER_TAPI_ANSWER_CALL );
  143. hr = er.set_hr(pAnswerInfo->m_pITControl->Answer());
  144. }
  145. }
  146. }
  147. pITAddress->Release();
  148. }
  149. // Failed to answer the call, update the call control window
  150. if ( FAILED(hr) )
  151. {
  152. pAVTapi->fire_ClearCurrentActions( lCallID );
  153. pAVTapi->fire_AddCurrentAction( lCallID, CM_ACTIONS_CLOSE, NULL );
  154. pAVTapi->fire_SetCallState_CMS( lCallID, CM_STATES_DISCONNECTED, NULL );
  155. }
  156. // Clean up
  157. SAFE_DELETE( pAnswerInfo );
  158. SysFreeString( bstrText );
  159. if ( SUCCEEDED(hr) )
  160. CAVTapiCall::WaitWithMessageLoop();
  161. (dynamic_cast<IUnknown *> (pAVTapi))->Release();
  162. }
  163. // Uninitialize com
  164. CoUninitialize();
  165. }
  166. // Clean-up
  167. SAFE_DELETE( pAnswerInfo );
  168. // Notify module of shutdown
  169. _Module.RemoveThread( hThread );
  170. SetEvent( _Module.m_hEventThread );
  171. ATLTRACE(_T(".exit.ThreadAnswerProc(0x%08lx).\n"), hr );
  172. return hr;
  173. }