Old fashion design for PC-104
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.

647 lines
17 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 05/11/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgVoiceModemCallCenter.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgVoiceModemCallCenter.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgVoiceModemCallCenter.h"
  16. #define MESSAGE_MAX_TIMEOUT 60000UL // 60 seconds
  17. CLgVoiceModemCallCenter::CLgVoiceModemCallCenter()
  18. {
  19. memset( m_pEvent, 0, sizeof(m_pEvent) );
  20. m_eState = STATE_NONE;
  21. m_pHandler = NULL;
  22. m_nDevice = 0;
  23. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgVoiceModemCallCenter::CLgVoiceModemCallCenter" );
  24. }
  25. CLgVoiceModemCallCenter::~CLgVoiceModemCallCenter()
  26. {
  27. Destroy();
  28. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgVoiceModemCallCenter::~CLgVoiceModemCallCenter" );
  29. }
  30. BOOL CLgVoiceModemCallCenter::Create( INT nDevice, CLgVoiceModemCallCenterHandler *pHandler )
  31. {
  32. // create command event
  33. for( INT i = 0; i < EVENT_COUNT; i++ )
  34. {
  35. m_pEvent[i] = ::CreateEvent( NULL, FALSE, FALSE, NULL );
  36. if( !m_pEvent[i] )
  37. {
  38. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::Create", "CreateEvent failed with GetLastError %d", GetLastError() );
  39. return FALSE;
  40. }
  41. }
  42. // store handler
  43. m_pHandler = pHandler;
  44. // store device id
  45. m_nDevice = nDevice;
  46. if( !CLgVoiceModem::Create() )
  47. {
  48. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::Create", "CLgVoiceModem::Create failed" );
  49. return FALSE;
  50. }
  51. // start thread
  52. return Start( FALSE );
  53. }
  54. void CLgVoiceModemCallCenter::Destroy()
  55. {
  56. // stop thread
  57. Stop( TRUE );
  58. //stop modem
  59. CLgVoiceModem::Destroy();
  60. // close events
  61. for( INT i = 0; i < EVENT_COUNT; i++ )
  62. {
  63. if( m_pEvent[i] )
  64. {
  65. CloseHandle( m_pEvent[i] );
  66. m_pEvent[i] = NULL;
  67. }
  68. }
  69. }
  70. BOOL CLgVoiceModemCallCenter::Call( LPCTSTR pNumber,
  71. DWORD dwCallDialTime,
  72. DWORD dwCallDropTime,
  73. INT nCallRepeatCount,
  74. LPCTSTR pAccessCode,
  75. LPCTSTR pCancelCode,
  76. E_VOICE_TYPE eWelcomeType,
  77. LPCTSTR pWelcomeData,
  78. E_VOICE_TYPE eMessageType,
  79. LPCTSTR pMessageData,
  80. INT nMessageRepeatCount,
  81. E_PRIORITY ePriority )
  82. {
  83. MODEM_COMMAND CallCommand;
  84. CallCommand.ePriority = ePriority;
  85. _tcscpy( CallCommand.pPhoneNumber, pNumber );
  86. CallCommand.dwPhoneDialTime = dwCallDialTime;
  87. CallCommand.dwPhoneDropTime = dwCallDropTime;
  88. CallCommand.nPhoneRedialCount = nCallRepeatCount;
  89. _tcscpy( CallCommand.pPhoneAccessCode, pAccessCode );
  90. _tcscpy( CallCommand.pPhoneCancelCode, pCancelCode );
  91. CallCommand.ePhoneWelcomeType = eWelcomeType;
  92. _tcscpy( CallCommand.pPhoneWelcomeData, pWelcomeData );
  93. CallCommand.ePhoneMessageType = eMessageType;
  94. _tcscpy( CallCommand.pPhoneMessageData, pMessageData );
  95. CallCommand.nPhoneMessageRepeatCount = nMessageRepeatCount;
  96. return Call( &CallCommand );
  97. }
  98. BOOL CLgVoiceModemCallCenter::Call( PMODEM_COMMAND pCallCommand )
  99. {
  100. // insert into command array ( take into acount priority )
  101. CLgLocker Lock( &m_CommandQueue );
  102. BOOL bInserted = FALSE;
  103. for( INT i = 0; i < m_CommandQueue.GetCount(); i++ )
  104. {
  105. if( pCallCommand->ePriority > m_CommandQueue[i].ePriority )
  106. {
  107. m_CommandQueue.InsertAt( i, *pCallCommand );
  108. bInserted = TRUE;
  109. break;
  110. }
  111. }
  112. if( !bInserted )
  113. {
  114. m_CommandQueue.Add( *pCallCommand );
  115. }
  116. // log info
  117. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgVoiceModemCallCenter::Call", "New call added <%s>", pCallCommand->pPhoneNumber );
  118. // notify thread about new command
  119. return ::SetEvent( m_pEvent[EVENT_COMMAND] );
  120. }
  121. BOOL CLgVoiceModemCallCenter::CancelAll()
  122. {
  123. // log info
  124. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgVoiceModemCallCenter::CancelAll" );
  125. // insert into command array ( take into acount priority )
  126. CLgLocker Lock( &m_CommandQueue );
  127. // remove all call tasks
  128. m_CommandQueue.RemoveAll();
  129. // notify thread about canceling
  130. return ::SetEvent( m_pEvent[EVENT_CANCEL_ALL] );
  131. }
  132. DWORD CLgVoiceModemCallCenter::ThreadProc()
  133. {
  134. __try
  135. {
  136. HANDLE pEvent[] =
  137. {
  138. GetThreadStopEvent(),
  139. m_pEvent[EVENT_COMMAND],
  140. m_pEvent[EVENT_CONNECT],
  141. m_pEvent[EVENT_DIGIT],
  142. m_pEvent[EVENT_WAVE],
  143. m_pEvent[EVENT_DISCONNECT],
  144. m_pEvent[EVENT_BUSY],
  145. m_pEvent[EVENT_CANCEL_ALL]
  146. };
  147. INT nEventCount = sizeof(pEvent) / sizeof( *pEvent );
  148. DWORD dwTimeout = INFINITE;
  149. BOOL bLoop = TRUE;
  150. while( bLoop )
  151. {
  152. DWORD dwTime = ::GetTickCount();
  153. switch( ::WaitForMultipleObjects( nEventCount, pEvent, FALSE, dwTimeout ) )
  154. {
  155. default:
  156. case WAIT_FAILED:
  157. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::ThreadProc", "WaitForMultipleObjects failed" );
  158. case WAIT_OBJECT_0:
  159. bLoop = FALSE;
  160. continue;
  161. case WAIT_TIMEOUT:
  162. dwTimeout = OnWaitTimeout();
  163. break;
  164. case WAIT_OBJECT_0+1:
  165. dwTime = ::GetTickCount() - dwTime;
  166. dwTimeout = OnEventCommand( ( dwTimeout > dwTime ) ? dwTimeout - dwTime : 0 );
  167. break;
  168. case WAIT_OBJECT_0+2:
  169. dwTime = ::GetTickCount() - dwTime;
  170. dwTimeout = OnEventConnect( ( dwTimeout > dwTime ) ? dwTimeout - dwTime : 0 );
  171. break;
  172. case WAIT_OBJECT_0+3:
  173. dwTime = ::GetTickCount() - dwTime;
  174. dwTimeout = OnEventDigit( ( dwTimeout > dwTime ) ? dwTimeout - dwTime : 0 );
  175. break;
  176. case WAIT_OBJECT_0+4:
  177. dwTime = ::GetTickCount() - dwTime;
  178. dwTimeout = OnEventWave( ( dwTimeout > dwTime ) ? dwTimeout - dwTime : 0 );
  179. break;
  180. case WAIT_OBJECT_0+5:
  181. dwTime = ::GetTickCount() - dwTime;
  182. dwTimeout = OnEventDisconnect( ( dwTimeout > dwTime ) ? dwTimeout - dwTime : 0 );
  183. break;
  184. case WAIT_OBJECT_0+6:
  185. dwTime = ::GetTickCount() - dwTime;
  186. dwTimeout = OnEventBusy( ( dwTimeout > dwTime ) ? dwTimeout - dwTime : 0 );
  187. break;
  188. case WAIT_OBJECT_0+7:
  189. dwTime = ::GetTickCount() - dwTime;
  190. dwTimeout = OnEventCancelAll( ( dwTimeout > dwTime ) ? dwTimeout - dwTime : 0 );
  191. break;
  192. }
  193. }
  194. // stop wave
  195. CLgVoiceModem::Drop();
  196. }
  197. __except( EXCEPTION_EXECUTE_HANDLER )
  198. {
  199. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgVoiceModemCallCenter::ThreadProc"), _T("Exception 0x%08X"), _exception_code() );
  200. }
  201. return 0UL;
  202. }
  203. DWORD CLgVoiceModemCallCenter::OnEventCommand( DWORD dwTimeout )
  204. {
  205. // log info
  206. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgVoiceModemCallCenter::OnEventCommand") );
  207. // insert into command array ( take into acount priority )
  208. CLgLocker Lock( &m_CommandQueue );
  209. // get first command
  210. PMODEM_COMMAND pCallComand = &m_CommandQueue[0];
  211. // if command is performing
  212. if( m_eState != STATE_NONE )
  213. {
  214. // if new command with priority less or equal with current
  215. if( pCallComand->ePriority <= m_Command.ePriority )
  216. {
  217. return dwTimeout;
  218. }
  219. // mark as availible to perform new call
  220. m_eState = STATE_DROP;
  221. }
  222. // process new command
  223. return OnWaitTimeout();
  224. }
  225. DWORD CLgVoiceModemCallCenter::OnWaitTimeout()
  226. {
  227. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgVoiceModemCallCenter::OnWaitTimeout") );
  228. // lock command queue
  229. CLgLocker Lock( &m_CommandQueue );
  230. switch( m_eState )
  231. {
  232. case STATE_WELCOME:
  233. // cancel current call & voice
  234. CLgVoiceModem::Drop();
  235. // mark state as no action
  236. m_eState = STATE_WELCOME_DROP;
  237. // pause between calls
  238. return m_Command.dwPhoneDropTime;
  239. case STATE_WELCOME_DROP:
  240. // if nessessary to perform recall
  241. if( m_Command.nPhoneRedialCount )
  242. {
  243. m_Command.nPhoneRedialCount--;
  244. // log
  245. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgVoiceModemCallCenter::OnWaitTimeout", "Redial %d number <%s>", m_Command.nPhoneRedialCount, m_Command.pPhoneNumber );
  246. // dial number
  247. if( !CLgVoiceModem::Dial( m_nDevice, m_Command.pPhoneNumber ) )
  248. {
  249. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnWaitTimeout", "Can not dial" );
  250. return 5UL;
  251. }
  252. // mark state as welcome
  253. m_eState = STATE_WELCOME;
  254. // return call processing time
  255. return m_Command.dwPhoneDialTime;
  256. }
  257. // mark state as no action
  258. m_eState = STATE_NONE;
  259. return 0;
  260. case STATE_DROP:
  261. // cancel current call & voice
  262. CLgVoiceModem::Drop();
  263. // mark state as no action
  264. m_eState = STATE_NONE;
  265. // pause between calls
  266. return m_Command.dwPhoneDropTime;
  267. case STATE_NONE:
  268. // check command queue
  269. if( !m_CommandQueue.GetCount() )
  270. {
  271. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgVoiceModemCallCenter::OnWaitTimeout", "Command queue is empty" );
  272. return INFINITE;
  273. }
  274. // store new command
  275. m_Command = m_CommandQueue[0];
  276. // remove command from list
  277. m_CommandQueue.Remove(0);
  278. // log
  279. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgVoiceModemCallCenter::OnWaitTimeout", "Dial new number <%s>", m_Command.pPhoneNumber );
  280. // dial number
  281. if( !CLgVoiceModem::Dial( m_nDevice, m_Command.pPhoneNumber ) )
  282. {
  283. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnWaitTimeout", "Can not dial" );
  284. return 5UL;
  285. }
  286. // mark state as welcome
  287. m_eState = STATE_WELCOME;
  288. // return call processing time
  289. return m_Command.dwPhoneDialTime;
  290. case STATE_MESSAGE:
  291. // mark state as no action
  292. m_eState = STATE_DROP;
  293. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, "CLgVoiceModemCallCenter::OnWaitTimeout", "Unexpected state" );
  294. return 0;
  295. }
  296. return INFINITE;
  297. }
  298. DWORD CLgVoiceModemCallCenter::OnEventConnect( DWORD dwTimeout )
  299. {
  300. // log info
  301. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgVoiceModemCallCenter::OnEventConnect") );
  302. switch( m_Command.ePhoneWelcomeType )
  303. {
  304. case VOICE_TYPE_NONE:
  305. break;
  306. case VOICE_TYPE_WAVE:
  307. // start welcome wave
  308. if( !CLgVoiceModem::Play( m_Command.pPhoneWelcomeData ) )
  309. {
  310. // log error
  311. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnEventConnect", "Can't play welcome wave" );
  312. }
  313. break;
  314. case VOICE_TYPE_TEXT2SPEECH:
  315. // start welcome text
  316. if( !CLgVoiceModem::Speak( m_Command.pPhoneWelcomeData, m_Command.nPhoneWelcomeText2SpeechVolume, m_Command.nPhoneWelcomeText2SpeechRate, m_Command.pPhoneWelcomeText2SpeechVoice ) )
  317. {
  318. // log error
  319. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnEventConnect", "Can't speak welcome text" );
  320. }
  321. break;
  322. }
  323. // current state is welcome playing state
  324. m_eState = STATE_WELCOME;
  325. return dwTimeout;
  326. }
  327. DWORD CLgVoiceModemCallCenter::OnEventDigit( DWORD dwTimeout )
  328. {
  329. // log info
  330. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgVoiceModemCallCenter::OnEventDigit") );
  331. if( m_eState != STATE_WELCOME )
  332. return dwTimeout;
  333. // stop welcome wave (if any)
  334. CLgVoiceModem::ResetWave();
  335. // stop welcome text (if any)
  336. CLgVoiceModem::ResetSpeech();
  337. // current state is message playing state
  338. m_eState = STATE_MESSAGE;
  339. switch( m_Command.ePhoneMessageType )
  340. {
  341. case VOICE_TYPE_NONE:
  342. break;
  343. case VOICE_TYPE_WAVE:
  344. // start message wave
  345. if( !CLgVoiceModem::Play( m_Command.pPhoneMessageData ) )
  346. {
  347. // log error
  348. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnEventDigit", "Can't play message wave" );
  349. // cancel playing
  350. m_eState = STATE_DROP;
  351. dwTimeout = 0;
  352. }
  353. else
  354. dwTimeout = MESSAGE_MAX_TIMEOUT; // maximal message time
  355. break;
  356. case VOICE_TYPE_TEXT2SPEECH:
  357. // start message text
  358. if( !CLgVoiceModem::Speak( m_Command.pPhoneMessageData, m_Command.nPhoneMessageText2SpeechVolume, m_Command.nPhoneMessageText2SpeechRate, m_Command.pPhoneMessageText2SpeechVoice ) )
  359. {
  360. // log error
  361. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnEventDigit", "Can't speak message text" );
  362. // cancel playing
  363. m_eState = STATE_DROP;
  364. dwTimeout = 0;
  365. }
  366. else
  367. dwTimeout = MESSAGE_MAX_TIMEOUT; // maximal message time
  368. break;
  369. }
  370. return dwTimeout;
  371. }
  372. DWORD CLgVoiceModemCallCenter::OnEventWave( DWORD dwTimeout )
  373. {
  374. // log info
  375. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgVoiceModemCallCenter::OnEventWave") );
  376. switch( m_eState )
  377. {
  378. case STATE_WELCOME:
  379. switch( m_Command.ePhoneWelcomeType )
  380. {
  381. case VOICE_TYPE_NONE:
  382. break;
  383. case VOICE_TYPE_WAVE:
  384. // play wave again and again
  385. if( !CLgVoiceModem::Play( m_Command.pPhoneWelcomeData ) )
  386. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnEventWave", "Can't play welcome wave" );
  387. break;
  388. case VOICE_TYPE_TEXT2SPEECH:
  389. // speak text again and again
  390. if( !CLgVoiceModem::Speak( m_Command.pPhoneWelcomeData, m_Command.nPhoneWelcomeText2SpeechVolume, m_Command.nPhoneWelcomeText2SpeechRate, m_Command.pPhoneWelcomeText2SpeechVoice ) )
  391. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnEventWave", "Can't speak welcome text" );
  392. break;
  393. }
  394. break;
  395. case STATE_MESSAGE:
  396. switch( m_Command.ePhoneMessageType )
  397. {
  398. case VOICE_TYPE_NONE:
  399. break;
  400. case VOICE_TYPE_WAVE:
  401. // play only requared number of times
  402. if( !CLgVoiceModem::Play( m_Command.pPhoneMessageData ) )
  403. {
  404. // log error
  405. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnEventWave", "Can't play message wave" );
  406. // cancel playing
  407. m_eState = STATE_DROP;
  408. dwTimeout = 0;
  409. }
  410. else
  411. {
  412. // if it needs to play more times
  413. if( m_Command.nPhoneMessageRepeatCount-- )
  414. dwTimeout = MESSAGE_MAX_TIMEOUT;
  415. else
  416. {
  417. // stop playing
  418. m_eState = STATE_DROP;
  419. dwTimeout = 0;
  420. }
  421. }
  422. break;
  423. case VOICE_TYPE_TEXT2SPEECH:
  424. // speak only requared number of times
  425. if( !CLgVoiceModem::Speak( m_Command.pPhoneMessageData, m_Command.nPhoneMessageText2SpeechVolume, m_Command.nPhoneMessageText2SpeechRate, m_Command.pPhoneMessageText2SpeechVoice ) )
  426. {
  427. // log error
  428. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgVoiceModemCallCenter::OnEventWave", "Can't speak message text" );
  429. // cancel playing
  430. m_eState = STATE_DROP;
  431. dwTimeout = 0;
  432. }
  433. else
  434. {
  435. // if it needs to play more times
  436. if( m_Command.nPhoneMessageRepeatCount-- )
  437. dwTimeout = MESSAGE_MAX_TIMEOUT;
  438. else
  439. {
  440. // stop playing
  441. m_eState = STATE_DROP;
  442. dwTimeout = 0;
  443. }
  444. }
  445. break;
  446. }
  447. break;
  448. }
  449. return dwTimeout;
  450. }
  451. DWORD CLgVoiceModemCallCenter::OnEventDisconnect( DWORD dwTimeout )
  452. {
  453. // log info
  454. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgVoiceModemCallCenter::OnEventDisconnect") );
  455. switch( m_eState )
  456. {
  457. case STATE_NONE:
  458. break;
  459. case STATE_WELCOME:
  460. // set timeout to 0 for immidiate caling OnTimeout for redial
  461. dwTimeout = 0;
  462. break;
  463. case STATE_MESSAGE:
  464. // finish current call
  465. m_eState = STATE_DROP;
  466. // set timeout to 0 for immidiate caling OnTimeout for new call establishing
  467. dwTimeout = 0;
  468. break;
  469. }
  470. return dwTimeout;
  471. }
  472. DWORD CLgVoiceModemCallCenter::OnEventCancelAll( DWORD dwTimeout )
  473. {
  474. // log info
  475. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgVoiceModemCallCenter::OnEventCancelAll") );
  476. switch( m_eState )
  477. {
  478. case STATE_WELCOME_DROP:
  479. case STATE_WELCOME:
  480. case STATE_MESSAGE:
  481. // finish current call
  482. m_eState = STATE_DROP;
  483. case STATE_NONE:
  484. // set timeout to 0 for immidiate caling OnTimeout for redial
  485. dwTimeout = 0;
  486. break;
  487. }
  488. return dwTimeout;
  489. }
  490. DWORD CLgVoiceModemCallCenter::OnEventBusy( DWORD dwTimeout )
  491. {
  492. // log info
  493. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgVoiceModemCallCenter::OnEventBusy") );
  494. return OnEventDisconnect( dwTimeout );
  495. }
  496. void CLgVoiceModemCallCenter::OnModemProceeding()
  497. {
  498. // call base class
  499. CLgVoiceModem::OnModemProceeding();
  500. // set dial monitoring
  501. CLgVoiceModem::MonitorDigits( TRUE );
  502. }
  503. void CLgVoiceModemCallCenter::OnModemConnect()
  504. {
  505. // call base class
  506. CLgVoiceModem::OnModemConnect();
  507. // notify
  508. ::SetEvent( m_pEvent[EVENT_CONNECT] );
  509. }
  510. void CLgVoiceModemCallCenter::OnModemDigit( INT nDigit )
  511. {
  512. // call base class
  513. CLgVoiceModem::OnModemDigit( nDigit );
  514. // notify
  515. ::SetEvent( m_pEvent[EVENT_DIGIT] );
  516. }
  517. void CLgVoiceModemCallCenter::OnModemBusy()
  518. {
  519. // call base class
  520. CLgVoiceModem::OnModemBusy();
  521. // notify
  522. ::SetEvent( m_pEvent[EVENT_BUSY] );
  523. }
  524. void CLgVoiceModemCallCenter::OnWaveDone( BOOL bReset )
  525. {
  526. // call base class
  527. CLgVoiceModem::OnWaveDone( bReset );
  528. // notify
  529. if( !bReset )
  530. ::SetEvent( m_pEvent[EVENT_WAVE] );
  531. }
  532. void CLgVoiceModemCallCenter::OnSpeechEndInputStream()
  533. {
  534. // call base class
  535. CLgVoiceModem::OnSpeechEndInputStream();
  536. ::SetEvent( m_pEvent[EVENT_WAVE] );
  537. }