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.

1143 lines
29 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. agentsess.cpp
  5. Abstract:
  6. Implementation of the Agent Session object for TAPI 3.0.
  7. CAgentSession class
  8. CAgentSessionEvent class
  9. Author:
  10. noela - 11/04/97
  11. Notes:
  12. optional-notes
  13. Revision History:
  14. --*/
  15. #include "stdafx.h"
  16. #include "lmcons.h"
  17. DWORD MapAgentSessionStateFrom3to2(AGENT_SESSION_STATE tapi3State);
  18. HRESULT MapAgentSessionStateFrom2to3(DWORD tapi2State, AGENT_SESSION_STATE *tapi3State);
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CAgentSession
  21. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  22. // Class : CAgentSession
  23. // Method : Initialize
  24. //
  25. //
  26. //
  27. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  28. STDMETHODIMP CAgentSession::Initialize(
  29. HAGENTSESSION hAgentSession,
  30. ITAgent * pAgent,
  31. ITACDGroup * pGroup,
  32. ITAddress * pAddress,
  33. CAgentHandler * pHandler,
  34. AddressLineStruct * pAddressLine
  35. )
  36. {
  37. HRESULT hr = S_OK;
  38. LOG((TL_TRACE, "Initialize - enter, sessionhandle :%d", hAgentSession ));
  39. m_SessionState = ASST_NOT_READY;
  40. m_hAgentSession = hAgentSession;
  41. m_pAgent = pAgent;
  42. m_pGroup = pGroup;
  43. m_pReceiveCallsOnThisAddress = pAddress;
  44. pAddress->AddRef();
  45. m_pHandler = pHandler;
  46. m_pAddressLine = pAddressLine;
  47. m_bRequiresUpdating = TRUE;
  48. // Now add to AgentHandler hash table
  49. m_pHandler->AddAgentSessionToHash(m_hAgentSession, this);
  50. // UpdateInfo();
  51. // Fire an event here
  52. CAgentSessionEvent::FireEvent(this, ASE_NOT_READY);
  53. LOG((TL_TRACE, hr, "Initialize - exit" ));
  54. return hr;
  55. }
  56. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  57. // Class : CAgentSession
  58. // Method : FinalRelease
  59. //
  60. //
  61. //
  62. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  63. void CAgentSession::FinalRelease()
  64. {
  65. LOG((TL_TRACE, "FinalRelease session %d", m_hAgentSession ));
  66. // Now Remove to AgentHandler hash table
  67. //m_pHandler->RemoveAgentSessionFromHash(m_hAgentSession);
  68. // And then close our line
  69. CAddress *pAddress = (CAddress*)m_pReceiveCallsOnThisAddress;
  70. pAddress->MaybeCloseALine (&m_pAddressLine);
  71. pAddress->Release();
  72. }
  73. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  74. // Class : CAgentSession
  75. // Method : UpdateInfo
  76. //
  77. //
  78. //
  79. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  80. STDMETHODIMP CAgentSession::UpdateInfo()
  81. {
  82. HRESULT hr2,hr = S_OK;
  83. LINEAGENTSESSIONINFO AgentSessionInfo;
  84. LOG((TL_TRACE, "UpdateInfo - enter" ));
  85. AgentSessionInfo.dwTotalSize = sizeof(LINEAGENTSESSIONINFO);
  86. AgentSessionInfo.dwNeededSize = sizeof(LINEAGENTSESSIONINFO);
  87. AgentSessionInfo.dwUsedSize = sizeof(LINEAGENTSESSIONINFO);
  88. // **************************************************
  89. // Get Agent Info from Proxy
  90. hr = lineGetAgentSessionInfo(
  91. m_pAddressLine->t3Line.hLine,
  92. m_hAgentSession,
  93. &AgentSessionInfo);
  94. if( SUCCEEDED(hr) )
  95. {
  96. // wait for async reply
  97. hr = WaitForReply( hr );
  98. if ( SUCCEEDED(hr) )
  99. {
  100. Lock();
  101. if( FAILED( MapAgentSessionStateFrom2to3(AgentSessionInfo.dwAgentSessionState, &m_SessionState) ) )
  102. {
  103. LOG((TL_ERROR, "UpdateInfo - AgentSessionState is invalid %d - setting to ASST_NOT_READY",AgentSessionInfo.dwAgentSessionState));
  104. }
  105. if( FAILED( MapAgentSessionStateFrom2to3(AgentSessionInfo.dwNextAgentSessionState, &m_NextSessionState) ) )
  106. {
  107. LOG((TL_ERROR, "UpdateInfo - NextAgentSessionState is invalid %d - setting to ASST_NOT_READY",AgentSessionInfo.dwAgentSessionState));
  108. }
  109. m_dwSessionStartTime = AgentSessionInfo.dateSessionStartTime;
  110. m_dwSessionDuration = AgentSessionInfo.dwSessionDuration;
  111. m_dwNumberOfCalls = AgentSessionInfo.dwNumberOfCalls;
  112. m_dwTotalTalkTime = AgentSessionInfo.dwTotalTalkTime;
  113. m_dwAverageTalkTime = AgentSessionInfo.dwAverageTalkTime;
  114. m_dwTotalCallTime = AgentSessionInfo.dwTotalCallTime;
  115. m_dwAverageCallTime = AgentSessionInfo.dwAverageCallTime;
  116. m_dwTotalWrapUpTime = AgentSessionInfo.dwTotalWrapUpTime;
  117. m_dwAverageWrapUpTime = AgentSessionInfo.dwAverageWrapUpTime;
  118. m_dwACDCallRate = AgentSessionInfo.cyACDCallRate;
  119. m_dwLongestTimeToAnswer = AgentSessionInfo.dwLongestTimeToAnswer;
  120. m_dwAverageTimeToAnswer = AgentSessionInfo.dwAverageTimeToAnswer;
  121. m_bRequiresUpdating = FALSE;
  122. Unlock();
  123. }
  124. else
  125. {
  126. LOG((TL_ERROR, "UpdateInfo - call to lineGetAgentSessionInfo failed async" ));
  127. }
  128. }
  129. else
  130. {
  131. LOG((TL_ERROR, "UpdateInfo - call to lineGetAgentSessionInfo failed" ));
  132. }
  133. LOG((TL_TRACE, hr, "UpdateInfo - exit" ));
  134. return hr;
  135. }
  136. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  137. // Class : CAgentSession
  138. // Method : CheckIfUpToDate
  139. //
  140. //
  141. //
  142. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  143. STDMETHODIMP CAgentSession::CheckIfUpToDate()
  144. {
  145. HRESULT hr = S_OK;
  146. if (m_bRequiresUpdating)
  147. {
  148. hr = UpdateInfo();
  149. }
  150. return hr;
  151. }
  152. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  153. // Class : CAgentSession
  154. // Interface : ITAgentSession
  155. // Method : AverageTimeToAnswer
  156. //
  157. //
  158. //
  159. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  160. STDMETHODIMP CAgentSession::get_AverageTimeToAnswer(long * pulAnswerTime)
  161. {
  162. HRESULT hr = S_OK;
  163. LOG((TL_TRACE, "AverageTimeToAnswer - enter" ));
  164. if (!TAPIIsBadWritePtr( pulAnswerTime, sizeof(long) ) )
  165. {
  166. hr = CheckIfUpToDate();
  167. if ( SUCCEEDED(hr) )
  168. {
  169. Lock();
  170. *pulAnswerTime = m_dwAverageTimeToAnswer;
  171. Unlock();
  172. }
  173. else
  174. {
  175. LOG((TL_ERROR, "get_AverageTimeToAnswer - Object update failed"));
  176. }
  177. }
  178. else
  179. {
  180. LOG((TL_ERROR, "get_AverageTimeToAnswer - bad pulAnswerTime pointer"));
  181. hr = E_POINTER;
  182. }
  183. LOG((TL_TRACE, hr, "AverageTimeToAnswer - exit" ));
  184. return hr;
  185. }
  186. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  187. // Class : CAgentSession
  188. // Interface : ITAgentSession
  189. // Method : LongestTimeToAnswer
  190. //
  191. //
  192. //
  193. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  194. STDMETHODIMP CAgentSession::get_LongestTimeToAnswer(long * pulAnswerTime)
  195. {
  196. HRESULT hr = S_OK;
  197. LOG((TL_TRACE, "LongestTimeToAnswer - enter" ));
  198. if (!TAPIIsBadWritePtr( pulAnswerTime, sizeof(long) ) )
  199. {
  200. hr = CheckIfUpToDate();
  201. if ( SUCCEEDED(hr) )
  202. {
  203. Lock();
  204. *pulAnswerTime = m_dwLongestTimeToAnswer;
  205. Unlock();
  206. }
  207. else
  208. {
  209. LOG((TL_ERROR, "get_LongestTimeToAnswer - Object update failed"));
  210. }
  211. }
  212. else
  213. {
  214. LOG((TL_ERROR, "get_LongestTimeToAnswer - bad pulAnswerTime pointer"));
  215. hr = E_POINTER;
  216. }
  217. LOG((TL_TRACE, hr, "LongestTimeToAnswer - exit" ));
  218. return hr;
  219. }
  220. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  221. // Class : CAgentSession
  222. // Interface : ITAgentSession
  223. // Method : ACDCallRate
  224. //
  225. //
  226. //
  227. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  228. STDMETHODIMP CAgentSession::get_ACDCallRate(CURRENCY * pcyCallrate)
  229. {
  230. HRESULT hr = S_OK;
  231. LOG((TL_TRACE, "ACDCallRate - enter" ));
  232. if (!TAPIIsBadWritePtr( pcyCallrate, sizeof(CURRENCY) ) )
  233. {
  234. hr = CheckIfUpToDate();
  235. if ( SUCCEEDED(hr) )
  236. {
  237. Lock();
  238. *pcyCallrate = m_dwACDCallRate;
  239. Unlock();
  240. }
  241. else
  242. {
  243. LOG((TL_ERROR, "get_ACDCallRate - Object update failed"));
  244. }
  245. }
  246. else
  247. {
  248. LOG((TL_ERROR, "get_ACDCallRate - bad pcyCallrate pointer"));
  249. hr = E_POINTER;
  250. }
  251. LOG((TL_TRACE, hr, "ACDCallRate - exit" ));
  252. return hr;
  253. }
  254. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  255. // Class : CAgentSession
  256. // Interface : ITAgentSession
  257. // Method : AverageWrapUpTime
  258. //
  259. //
  260. //
  261. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  262. STDMETHODIMP CAgentSession::get_AverageWrapUpTime(long * pulAverageWrapUpTime)
  263. {
  264. HRESULT hr = S_OK;
  265. LOG((TL_TRACE, "AverageWrapUpTime - enter" ));
  266. if (!TAPIIsBadWritePtr( pulAverageWrapUpTime, sizeof(long) ) )
  267. {
  268. hr = CheckIfUpToDate();
  269. if ( SUCCEEDED(hr) )
  270. {
  271. Lock();
  272. *pulAverageWrapUpTime = m_dwAverageWrapUpTime;
  273. Unlock();
  274. }
  275. else
  276. {
  277. LOG((TL_ERROR, "get_AverageWrapUpTime - Object update failed"));
  278. }
  279. }
  280. else
  281. {
  282. LOG((TL_ERROR, "get_AverageWrapUpTime - bad pulAverageWrapUpTime pointer"));
  283. hr = E_POINTER;
  284. }
  285. LOG((TL_TRACE, hr, "AverageWrapUpTime - exit" ));
  286. return hr;
  287. }
  288. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  289. // Class : CAgentSession
  290. // Interface : ITAgentSession
  291. // Method : TotalWrapUpTime
  292. //
  293. //
  294. //
  295. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  296. STDMETHODIMP CAgentSession::get_TotalWrapUpTime(long * pulTotalWrapUpTime)
  297. {
  298. HRESULT hr = S_OK;
  299. LOG((TL_TRACE, "TotalWrapUpTime - enter" ));
  300. if (!TAPIIsBadWritePtr( pulTotalWrapUpTime, sizeof(long) ) )
  301. {
  302. hr = CheckIfUpToDate();
  303. if ( SUCCEEDED(hr) )
  304. {
  305. Lock();
  306. *pulTotalWrapUpTime = m_dwTotalWrapUpTime;
  307. Unlock();
  308. }
  309. else
  310. {
  311. LOG((TL_ERROR, "get_TotalWrapUpTime - Object update failed"));
  312. }
  313. }
  314. else
  315. {
  316. LOG((TL_ERROR, "get_TotalWrapUpTime - bad pulTotalWrapUpTime pointer"));
  317. hr = E_POINTER;
  318. }
  319. LOG((TL_TRACE, hr, "TotalWrapUpTime - exit" ));
  320. return hr;
  321. }
  322. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  323. // Class : CAgentSession
  324. // Interface : ITAgentSession
  325. // Method : AverageCallTime
  326. //
  327. //
  328. //
  329. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  330. STDMETHODIMP CAgentSession::get_AverageCallTime(long * pulAverageCallTime)
  331. {
  332. HRESULT hr = S_OK;
  333. LOG((TL_TRACE, "AverageCallTime - enter" ));
  334. if (!TAPIIsBadWritePtr( pulAverageCallTime, sizeof(long) ) )
  335. {
  336. hr = CheckIfUpToDate();
  337. if ( SUCCEEDED(hr) )
  338. {
  339. Lock();
  340. *pulAverageCallTime = m_dwTotalCallTime;
  341. Unlock();
  342. }
  343. else
  344. {
  345. LOG((TL_ERROR, "get_AverageCallTime - Object update failed"));
  346. }
  347. }
  348. else
  349. {
  350. LOG((TL_ERROR, "get_AverageCallTime - bad pulAverageCallTime pointer"));
  351. hr = E_POINTER;
  352. }
  353. LOG((TL_TRACE, hr, "AverageCallTime - exit" ));
  354. return hr;
  355. }
  356. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  357. // Class : CAgentSession
  358. // Interface : ITAgentSession
  359. // Method : TotalCallTime
  360. //
  361. //
  362. //
  363. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  364. STDMETHODIMP CAgentSession::get_TotalCallTime(long * pulTotalCallTime)
  365. {
  366. HRESULT hr = S_OK;
  367. LOG((TL_TRACE, "TotalCallTime - enter" ));
  368. if (!TAPIIsBadWritePtr( pulTotalCallTime, sizeof(long) ) )
  369. {
  370. hr = CheckIfUpToDate();
  371. if ( SUCCEEDED(hr) )
  372. {
  373. Lock();
  374. *pulTotalCallTime = m_dwTotalCallTime;
  375. Unlock();
  376. }
  377. else
  378. {
  379. LOG((TL_ERROR, "get_TotalCallTime - Object update failed"));
  380. }
  381. }
  382. else
  383. {
  384. LOG((TL_ERROR, "get_TotalCallTime - bad pulTotalCallTime pointer"));
  385. hr = E_POINTER;
  386. }
  387. LOG((TL_TRACE, hr, "TotalCallTime - exit" ));
  388. return hr;
  389. }
  390. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  391. // Class : CAgentSession
  392. // Interface : ITAgentSession
  393. // Method : AverageTalkTime
  394. //
  395. //
  396. //
  397. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  398. STDMETHODIMP CAgentSession::get_AverageTalkTime(long * pulAverageTalkTime)
  399. {
  400. HRESULT hr = S_OK;
  401. LOG((TL_TRACE, "AverageTalkTime - enter" ));
  402. if (!TAPIIsBadWritePtr( pulAverageTalkTime, sizeof(long) ) )
  403. {
  404. hr = CheckIfUpToDate();
  405. if ( SUCCEEDED(hr) )
  406. {
  407. Lock();
  408. *pulAverageTalkTime = m_dwAverageTalkTime;
  409. Unlock();
  410. }
  411. else
  412. {
  413. LOG((TL_ERROR, "get_AverageTalkTime - Object update failed"));
  414. }
  415. }
  416. else
  417. {
  418. LOG((TL_ERROR, "get_AverageTalkTime - bad pulAverageTalkTime pointer"));
  419. hr = E_POINTER;
  420. }
  421. LOG((TL_TRACE, hr, "AverageTalkTime - exit" ));
  422. return hr;
  423. }
  424. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  425. // Class : CAgentSession
  426. // Interface : ITAgentSession
  427. // Method : TotalTalkTime
  428. //
  429. //
  430. //
  431. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  432. STDMETHODIMP CAgentSession::get_TotalTalkTime(long * pulTotalTalkTime)
  433. {
  434. HRESULT hr = S_OK;
  435. LOG((TL_TRACE, "TotalTalkTime - enter" ));
  436. if (!TAPIIsBadWritePtr( pulTotalTalkTime, sizeof(long) ) )
  437. {
  438. hr = CheckIfUpToDate();
  439. if ( SUCCEEDED(hr) )
  440. {
  441. Lock();
  442. *pulTotalTalkTime = m_dwTotalTalkTime;
  443. Unlock();
  444. }
  445. else
  446. {
  447. LOG((TL_ERROR, "get_TotalTalkTime - Object update failed"));
  448. }
  449. }
  450. else
  451. {
  452. LOG((TL_ERROR, "get_TotalTalkTime - bad pulTotalTalkTime pointer"));
  453. hr = E_POINTER;
  454. }
  455. LOG((TL_TRACE, hr, "TotalTalkTime - exit" ));
  456. return hr;
  457. }
  458. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  459. // Class : CAgentSession
  460. // Interface : ITAgentSession
  461. // Method : NumberOfCalls
  462. //
  463. //
  464. //
  465. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  466. STDMETHODIMP CAgentSession::get_NumberOfCalls(long * pulNumberOfCalls)
  467. {
  468. HRESULT hr = S_OK;
  469. LOG((TL_TRACE, "NumberOfCalls - enter" ));
  470. if (!TAPIIsBadWritePtr( pulNumberOfCalls, sizeof(long) ) )
  471. {
  472. hr = CheckIfUpToDate();
  473. if ( SUCCEEDED(hr) )
  474. {
  475. Lock();
  476. *pulNumberOfCalls = m_dwNumberOfCalls;
  477. Unlock();
  478. }
  479. else
  480. {
  481. LOG((TL_ERROR, "get_NumberOfCalls - Object update failed"));
  482. }
  483. }
  484. else
  485. {
  486. LOG((TL_ERROR, "get_NumberOfCalls - bad pulNumberOfCalls pointer"));
  487. hr = E_POINTER;
  488. }
  489. LOG((TL_TRACE, hr, "NumberOfCalls - exit" ));
  490. return hr;
  491. }
  492. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  493. // Class : CAgentSession
  494. // Interface : ITAgentSession
  495. // Method : SessionDuration
  496. //
  497. //
  498. //
  499. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  500. STDMETHODIMP CAgentSession::get_SessionDuration(long * pulSessionDuration)
  501. {
  502. HRESULT hr = S_OK;
  503. LOG((TL_TRACE, "SessionDuration - enter" ));
  504. if (!TAPIIsBadWritePtr( pulSessionDuration, sizeof(long) ) )
  505. {
  506. hr = CheckIfUpToDate();
  507. if ( SUCCEEDED(hr) )
  508. {
  509. Lock();
  510. *pulSessionDuration = m_dwSessionDuration;
  511. Unlock();
  512. }
  513. else
  514. {
  515. LOG((TL_ERROR, "get_SessionDuration - Object update failed"));
  516. }
  517. }
  518. else
  519. {
  520. LOG((TL_ERROR, "get_SessionDuration - bad pulSessionDuration pointer"));
  521. hr = E_POINTER;
  522. }
  523. LOG((TL_TRACE, hr, "SessionDuration - exit" ));
  524. return hr;
  525. }
  526. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  527. // Class : CAgentSession
  528. // Interface : ITAgentSession
  529. // Method : SessionStartTime
  530. //
  531. //
  532. //
  533. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  534. STDMETHODIMP CAgentSession::get_SessionStartTime(DATE * dateSessionStart)
  535. {
  536. HRESULT hr = S_OK;
  537. LOG((TL_TRACE, "SessionStartTime - enter" ));
  538. if (!TAPIIsBadWritePtr( dateSessionStart, sizeof(DATE) ) )
  539. {
  540. hr = CheckIfUpToDate();
  541. if ( SUCCEEDED(hr) )
  542. {
  543. Lock();
  544. *dateSessionStart = m_dwSessionStartTime;
  545. Unlock();
  546. }
  547. else
  548. {
  549. LOG((TL_ERROR, "get_SessionStartTime - Object update failed"));
  550. }
  551. }
  552. else
  553. {
  554. LOG((TL_ERROR, "get_SessionStartTime - bad dateSessionStart pointer"));
  555. hr = E_POINTER;
  556. }
  557. LOG((TL_TRACE, hr, "SessionStartTime - exit" ));
  558. return hr;
  559. }
  560. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  561. // Class : CAgentSession
  562. // Interface : ITAgentSession
  563. // Method : get_State
  564. //
  565. //
  566. //
  567. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  568. STDMETHODIMP CAgentSession::get_State(AGENT_SESSION_STATE * pSessionState)
  569. {
  570. HRESULT hr = S_OK;
  571. LOG((TL_TRACE, "get_State - enter" ));
  572. if (!TAPIIsBadWritePtr( pSessionState, sizeof(AGENT_SESSION_STATE) ) )
  573. {
  574. Lock();
  575. *pSessionState = m_SessionState;
  576. Unlock();
  577. }
  578. else
  579. {
  580. LOG((TL_ERROR, "get_State - bad pSessionState pointer"));
  581. hr = E_POINTER;
  582. }
  583. LOG((TL_TRACE, hr, "get_State - exit" ));
  584. return hr;
  585. }
  586. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  587. // Class : CAgentSession
  588. // Interface : ITAgentSession
  589. // Method : put_State
  590. //
  591. //
  592. //
  593. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  594. STDMETHODIMP CAgentSession::put_State(AGENT_SESSION_STATE sessionState)
  595. {
  596. HRESULT hr = S_OK;
  597. HLINE hLine;
  598. DWORD dwSessionState = 0;
  599. LOG((TL_TRACE, "put_State - enter" ));
  600. Lock();
  601. hLine = m_pAddressLine->t3Line.hLine;
  602. Unlock();
  603. dwSessionState = MapAgentSessionStateFrom3to2(sessionState);
  604. if( 0 == dwSessionState )
  605. {
  606. hr = E_INVALIDARG;
  607. }
  608. else
  609. {
  610. hr = lineSetAgentSessionState
  611. (hLine,
  612. m_hAgentSession,
  613. dwSessionState,
  614. 0 // MapAgentSessionStateFrom3to2(m_NextSessionState)
  615. );
  616. if( SUCCEEDED(hr) )
  617. {
  618. // wait for async reply
  619. hr = WaitForReply( hr );
  620. if ( SUCCEEDED(hr) )
  621. {
  622. Lock();
  623. m_SessionState = sessionState;
  624. Unlock();
  625. switch( sessionState )
  626. {
  627. case ASST_NOT_READY:
  628. CAgentSessionEvent::FireEvent(this, ASE_NOT_READY);
  629. break;
  630. case ASST_READY:
  631. CAgentSessionEvent::FireEvent(this, ASE_READY);
  632. break;
  633. case ASST_BUSY_ON_CALL:
  634. CAgentSessionEvent::FireEvent(this, ASE_BUSY);
  635. break;
  636. case ASST_BUSY_WRAPUP:
  637. CAgentSessionEvent::FireEvent(this, ASE_WRAPUP);
  638. break;
  639. case ASST_SESSION_ENDED:
  640. CAgentSessionEvent::FireEvent(this, ASE_END);
  641. break;
  642. }
  643. }
  644. else
  645. {
  646. LOG((TL_ERROR, "put_State - lineSetAgentSessionState failed async" ));
  647. }
  648. }
  649. else
  650. {
  651. LOG((TL_ERROR, "put_State - lineSetAgentSessionState failed" ));
  652. }
  653. }
  654. LOG((TL_TRACE, hr, "put_State - exit" ));
  655. return hr;
  656. }
  657. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  658. // Class : CAgentSession
  659. // Interface : ITAgentSession
  660. // Method : ACDGroup
  661. //
  662. //
  663. //
  664. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  665. STDMETHODIMP CAgentSession::get_ACDGroup(ITACDGroup **ppACDGroup)
  666. {
  667. HRESULT hr = S_OK;
  668. LOG((TL_TRACE, "ACDGroup - enter" ));
  669. if (!TAPIIsBadWritePtr( ppACDGroup, sizeof(ITACDGroup *) ) )
  670. {
  671. Lock();
  672. *ppACDGroup = m_pGroup;
  673. Unlock();
  674. }
  675. else
  676. {
  677. LOG((TL_ERROR, "get_ACDGroup - bad ppACDGroup pointer"));
  678. hr = E_POINTER;
  679. }
  680. LOG((TL_TRACE, hr, "ACDGroup - exit" ));
  681. return hr;
  682. }
  683. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  684. // Class : CAgentSession
  685. // Interface : ITAgentSession
  686. // Method : Address
  687. //
  688. //
  689. //
  690. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  691. STDMETHODIMP CAgentSession::get_Address(ITAddress **ppAddress)
  692. {
  693. HRESULT hr = S_OK;
  694. LOG((TL_TRACE, "Address - enter" ));
  695. if (!TAPIIsBadWritePtr( ppAddress, sizeof(ITAddress *) ) )
  696. {
  697. Lock();
  698. *ppAddress = m_pReceiveCallsOnThisAddress;
  699. Unlock();
  700. }
  701. else
  702. {
  703. LOG((TL_ERROR, "get_Address - bad ppAddress pointer"));
  704. hr = E_POINTER;
  705. }
  706. LOG((TL_TRACE, hr, "Address - exit" ));
  707. return hr;
  708. }
  709. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  710. // Class : CAgentSession
  711. // Interface : ITAgentSession
  712. // Method : Agent
  713. //
  714. //
  715. //
  716. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  717. STDMETHODIMP CAgentSession::get_Agent(ITAgent **ppAgent)
  718. {
  719. HRESULT hr = S_OK;
  720. LOG((TL_TRACE, "Agent - enter" ));
  721. if (!TAPIIsBadWritePtr( ppAgent, sizeof(ITAgent *) ) )
  722. {
  723. Lock();
  724. *ppAgent = m_pAgent;
  725. Unlock();
  726. }
  727. else
  728. {
  729. LOG((TL_ERROR, "get_Agent - bad ppAgent pointer"));
  730. hr = E_POINTER;
  731. }
  732. LOG((TL_TRACE, hr, "Agent - exit" ));
  733. return hr;
  734. }
  735. /////////////////////////////////////////////////////////////////////////////
  736. /////////////////////////////////////////////////////////////////////////////
  737. /////////////////////////////////////////////////////////////////////////////
  738. // CAgentSessionEvent
  739. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  740. // Class : CAgentSessionEvent
  741. // Method : FireEvent
  742. //
  743. //
  744. //
  745. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  746. HRESULT CAgentSessionEvent::FireEvent(CAgentSession * pAgentSession, AGENT_SESSION_EVENT event)
  747. {
  748. HRESULT hr = S_OK;
  749. CComObject<CAgentSessionEvent> * pEvent;
  750. IDispatch * pIDispatch;
  751. CAgentHandler * pAgentHandler = NULL;
  752. //
  753. // create event
  754. //
  755. hr = CComObject<CAgentSessionEvent>::CreateInstance( &pEvent );
  756. if ( SUCCEEDED(hr) )
  757. {
  758. //
  759. // initialize
  760. //
  761. pEvent->m_SessionEvent = event;
  762. pEvent->m_pSession= dynamic_cast<ITAgentSession *>(pAgentSession);
  763. pEvent->m_pSession->AddRef();
  764. //
  765. // get idisp interface
  766. //
  767. hr = pEvent->QueryInterface( IID_IDispatch, (void **)&pIDispatch );
  768. if ( SUCCEEDED(hr) )
  769. {
  770. //
  771. // get callback & fire event
  772. //
  773. pAgentHandler = pAgentSession->GetAgentHandler();
  774. if( pAgentHandler != NULL)
  775. {
  776. CTAPI *pTapi = pAgentHandler->GetTapi();
  777. pTapi->Event( TE_AGENTSESSION, pIDispatch );
  778. }
  779. // release stuff
  780. //
  781. pIDispatch->Release();
  782. }
  783. else
  784. {
  785. STATICLOG((TL_ERROR, "(Event)FireEvent - Could not get disp interface of AgentSessionEvent object"));
  786. delete pEvent;
  787. }
  788. }
  789. else
  790. {
  791. STATICLOG((TL_ERROR, "(Event)FireEvent - Could not create AgentSessionEvent object"));
  792. }
  793. STATICLOG((TL_TRACE, hr, "(Event)FireEvent - exit"));
  794. return hr;
  795. }
  796. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  797. // Class : CAgentSessionEvent
  798. // Method : FinalRelease
  799. //
  800. //
  801. //
  802. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  803. void CAgentSessionEvent::FinalRelease()
  804. {
  805. m_pSession->Release();
  806. }
  807. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  808. // Class : CAgentSessionEvent
  809. // Interface : ITAgentSessionEvent
  810. // Method : Session
  811. //
  812. //
  813. //
  814. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  815. STDMETHODIMP CAgentSessionEvent::get_Session(ITAgentSession * * ppSession)
  816. {
  817. HRESULT hr = S_OK;
  818. LOG((TL_TRACE, "(Event)Session - enter" ));
  819. if (!TAPIIsBadWritePtr( ppSession, sizeof(ITAgentSession *) ) )
  820. {
  821. *ppSession = m_pSession;
  822. m_pSession->AddRef();
  823. }
  824. else
  825. {
  826. LOG((TL_ERROR, "(Event)Session - bad ppSession pointer"));
  827. hr = E_POINTER;
  828. }
  829. LOG((TL_TRACE, hr, "(Event)Session - exit"));
  830. return hr;
  831. }
  832. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  833. // Class : CAgentSessionEvent .
  834. // Interface : ITAgentSessionEvent
  835. // Method : Event
  836. //
  837. //
  838. //
  839. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  840. STDMETHODIMP CAgentSessionEvent::get_Event(AGENT_SESSION_EVENT * pEvent)
  841. {
  842. HRESULT hr = S_OK;
  843. LOG((TL_TRACE, "Event - enter" ));
  844. if (!TAPIIsBadWritePtr( pEvent, sizeof(AGENT_SESSION_EVENT) ) )
  845. {
  846. *pEvent = m_SessionEvent;
  847. }
  848. else
  849. {
  850. LOG((TL_ERROR, "Event - bad pEvent pointer"));
  851. hr = E_POINTER;
  852. }
  853. LOG((TL_TRACE, hr, "Event - exit"));
  854. return hr;
  855. }
  856. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  857. // Function : MapAgentSessionStateFrom3to2
  858. //
  859. //
  860. //
  861. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  862. DWORD MapAgentSessionStateFrom3to2(AGENT_SESSION_STATE tapi3State)
  863. {
  864. DWORD tapi2State = 0;
  865. switch(tapi3State)
  866. {
  867. case ASST_NOT_READY:
  868. tapi2State = LINEAGENTSESSIONSTATE_NOTREADY;
  869. break;
  870. case ASST_READY:
  871. tapi2State = LINEAGENTSESSIONSTATE_READY;
  872. break;
  873. case ASST_BUSY_ON_CALL:
  874. tapi2State = LINEAGENTSESSIONSTATE_BUSYONCALL;
  875. break;
  876. case ASST_BUSY_WRAPUP:
  877. tapi2State = LINEAGENTSESSIONSTATE_BUSYWRAPUP;
  878. break;
  879. case ASST_SESSION_ENDED:
  880. tapi2State = LINEAGENTSESSIONSTATE_ENDED;
  881. break;
  882. default:
  883. break;
  884. }
  885. /*Nikhilb:Assuming that 0 is not a valid state. So if this function
  886. returns 0 then it is assumed that it was passed an invalid state*/
  887. return tapi2State;
  888. }
  889. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  890. // Function : MapAgentSessionStateFrom2to3
  891. //
  892. //
  893. //
  894. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  895. HRESULT MapAgentSessionStateFrom2to3(DWORD tapi2State, AGENT_SESSION_STATE *tapi3State)
  896. {
  897. HRESULT hr = S_OK;
  898. if (tapi2State & LINEAGENTSESSIONSTATE_NOTREADY)
  899. {
  900. *tapi3State = ASST_NOT_READY;
  901. }
  902. else if (tapi2State & LINEAGENTSESSIONSTATE_READY)
  903. {
  904. *tapi3State = ASST_READY;
  905. }
  906. else if (tapi2State & LINEAGENTSESSIONSTATE_BUSYONCALL)
  907. {
  908. *tapi3State = ASST_BUSY_ON_CALL;
  909. }
  910. else if (tapi2State & LINEAGENTSESSIONSTATE_BUSYWRAPUP)
  911. {
  912. *tapi3State = ASST_BUSY_WRAPUP;
  913. }
  914. else if (tapi2State & LINEAGENTSESSIONSTATE_ENDED)
  915. {
  916. *tapi3State = ASST_SESSION_ENDED;
  917. }
  918. else
  919. {
  920. *tapi3State = ASST_NOT_READY; // default
  921. hr = E_INVALIDARG;
  922. }
  923. return hr;
  924. }