Source code of Windows XP (NT5)
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.

1579 lines
39 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. agent.cpp
  5. Abstract:
  6. Implementation of the Agent object for TAPI 3.0.
  7. CAgent class
  8. CAgentEvent class
  9. Author:
  10. noela - 11/04/97
  11. Notes:
  12. optional-notes
  13. Revision History:
  14. --*/
  15. #include "stdafx.h"
  16. DWORD MapAgentStateFrom3to2(AGENT_STATE tapi3State);
  17. HRESULT MapAgentStateFrom2to3(DWORD tapi2State, AGENT_STATE *tapi3State);
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CAgent
  20. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  21. // Class : CAgent
  22. // Method : Initialize
  23. //
  24. //
  25. //
  26. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  27. STDMETHODIMP CAgent::Initialize(
  28. HAGENT hAgent,
  29. PWSTR pszUserName,
  30. PWSTR pszID,
  31. PWSTR pszPIN,
  32. CAgentHandler * pHandler
  33. )
  34. {
  35. HRESULT hr = S_OK;
  36. LOG((TL_TRACE, "Initialize - enter" ));
  37. m_bRegisteredForAgentEvents = FALSE;
  38. m_bRegisteredForAgentSessionEvents = FALSE;
  39. m_bRequiresUpdating = TRUE;
  40. m_pHandler = pHandler;
  41. m_hAgent = hAgent;
  42. m_AgentState = AS_UNKNOWN;
  43. m_szAgentUserName = NULL;
  44. m_szAgentID = NULL;
  45. m_szPIN = NULL;
  46. if (pszUserName != NULL)
  47. {
  48. m_szAgentUserName = (PWSTR) ClientAlloc((lstrlenW(pszUserName) + 1) * sizeof (WCHAR));
  49. if (m_szAgentUserName != NULL)
  50. {
  51. // Copy the name string
  52. lstrcpyW(m_szAgentUserName,pszUserName);
  53. }
  54. else
  55. {
  56. LOG((TL_ERROR, "Initialize - Alloc m_szAgentUserName failed" ));
  57. hr = E_OUTOFMEMORY;
  58. }
  59. }
  60. else // Agent Name is aNULL string
  61. {
  62. LOG((TL_ERROR, "Initialize - Agent Name is NULL" ));
  63. }
  64. // Now do the Agent ID
  65. if (pszID != NULL)
  66. {
  67. m_szAgentID = (PWSTR) ClientAlloc((lstrlenW(pszID) + 1) * sizeof (WCHAR));
  68. if (m_szAgentID != NULL)
  69. {
  70. lstrcpyW(m_szAgentID,pszID);
  71. }
  72. else
  73. {
  74. LOG((TL_ERROR, "Initialize - Alloc m_szAgentID failed" ));
  75. hr = E_OUTOFMEMORY;
  76. }
  77. }
  78. else // ID is a NULL string
  79. {
  80. LOG((TL_INFO, "Initialize - Agent ID is NULL" ));
  81. }
  82. // Now do the Agent PIN
  83. if (pszPIN != NULL)
  84. {
  85. m_szPIN = (PWSTR) ClientAlloc((lstrlenW(pszPIN) + 1) * sizeof (WCHAR));
  86. if (m_szPIN != NULL)
  87. {
  88. lstrcpyW(m_szPIN,pszPIN);
  89. }
  90. else
  91. {
  92. LOG((TL_ERROR, "Initialize - Alloc m_szPIN failed" ));
  93. hr = E_OUTOFMEMORY;
  94. }
  95. }
  96. else // PIN is a NULL string
  97. {
  98. LOG((TL_INFO, "Initialize - Agent PIN is NULL" ));
  99. }
  100. // Get Agent Info from Proxy
  101. // UpdateInfo();
  102. if ( SUCCEEDED(hr) )
  103. {
  104. // Fire an event here
  105. CAgentEvent::FireEvent(this, AE_UNKNOWN);
  106. }
  107. LOG((TL_TRACE, "Initialize Agent - %S, %S", m_szAgentUserName, m_szAgentID ));
  108. LOG((TL_TRACE, hr, "Initialize - exit" ));
  109. return hr;
  110. }
  111. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  112. // Class : CAgent
  113. // Method : FinalRelease
  114. //
  115. //
  116. //
  117. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  118. void CAgent::FinalRelease()
  119. {
  120. LOG((TL_TRACE, "FinalRelease Agent - %S", m_szAgentUserName ));
  121. if ( m_szAgentUserName != NULL )
  122. {
  123. ClientFree(m_szAgentUserName);
  124. }
  125. if ( m_szAgentID != NULL )
  126. {
  127. ClientFree(m_szAgentID);
  128. }
  129. if (m_szPIN != NULL)
  130. {
  131. ClientFree(m_szPIN);
  132. }
  133. m_AgentSessionArray.Shutdown();
  134. LOG((TL_TRACE, "FinalRelease Agent - exit"));
  135. }
  136. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  137. // Class : CAgent
  138. // Method : UpdateInfo
  139. //
  140. //
  141. //
  142. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  143. STDMETHODIMP CAgent::UpdateInfo()
  144. {
  145. HRESULT hr = S_OK;
  146. LINEAGENTINFO AgentInfo;
  147. LOG((TL_TRACE, "UpdateInfo - enter" ));
  148. AgentInfo.dwTotalSize = sizeof(LINEAGENTINFO);
  149. AgentInfo.dwNeededSize = sizeof(LINEAGENTINFO);
  150. AgentInfo.dwUsedSize = sizeof(LINEAGENTINFO);
  151. // **************************************************
  152. // Get Agent Info from Proxy
  153. hr = lineGetAgentInfo(
  154. m_pHandler->getHLine(),
  155. m_hAgent,
  156. &AgentInfo);
  157. if( SUCCEEDED(hr) )
  158. {
  159. // wait for async reply
  160. hr = WaitForReply( hr );
  161. if ( SUCCEEDED(hr) )
  162. {
  163. Lock();
  164. if( FAILED( MapAgentStateFrom2to3(AgentInfo.dwAgentState, &m_AgentState) ) )
  165. {
  166. LOG((TL_ERROR, "UpdateInfo - AgentState is invalid %d - setting to AS_UNKNOWN", AgentInfo.dwAgentState));
  167. }
  168. if( FAILED( MapAgentStateFrom2to3(AgentInfo.dwNextAgentState, &m_NextAgentState) ) )
  169. {
  170. LOG((TL_ERROR, "UpdateInfo - NextAgentState is invalid %d - setting to AS_UNKNOWN",AgentInfo.dwNextAgentState));
  171. }
  172. m_dwMeasurementPeriod = AgentInfo.dwMeasurementPeriod;
  173. m_cyOverallCallRate = AgentInfo.cyOverallCallRate;
  174. m_dwNumberOfACDCalls = AgentInfo.dwNumberOfACDCalls;
  175. m_dwNumberOfIncomingCalls = AgentInfo.dwNumberOfIncomingCalls;
  176. m_dwNumberOfOutgoingCalls = AgentInfo.dwNumberOfOutgoingCalls;
  177. m_dwTotalACDTalkTime = AgentInfo.dwTotalACDTalkTime;
  178. m_dwTotalACDCallTime = AgentInfo.dwTotalACDCallTime;
  179. m_dwTotalACDWrapUpTime = AgentInfo.dwTotalACDWrapUpTime;
  180. m_bRequiresUpdating = FALSE;
  181. Unlock();
  182. }
  183. else
  184. {
  185. LOG((TL_ERROR, "UpdateInfo - call to lineGetAgentInfo failed async" ));
  186. }
  187. }
  188. else
  189. {
  190. LOG((TL_ERROR, "UpdateInfo - call to lineGetAgentInfo failed" ));
  191. }
  192. LOG((TL_TRACE, hr, "UpdateInfo - exit" ));
  193. return hr;
  194. }
  195. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  196. // Class : CAgent
  197. // Method : CheckIfUpToDate
  198. //
  199. //
  200. //
  201. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  202. STDMETHODIMP CAgent::CheckIfUpToDate()
  203. {
  204. HRESULT hr = S_OK;
  205. if (m_bRequiresUpdating)
  206. {
  207. hr = UpdateInfo();
  208. }
  209. return hr;
  210. }
  211. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  212. // Class : CAgent
  213. // Interface : ITAgent
  214. // Method : EnumerateAgentSessions
  215. //
  216. //
  217. //
  218. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  219. STDMETHODIMP CAgent::EnumerateAgentSessions(IEnumAgentSession ** ppEnumAgentSession)
  220. {
  221. ITAgent* pITAgent;
  222. CAgent * pAgent;
  223. HRESULT hr = S_OK;
  224. LOG((TL_TRACE, "EnumerateAgentSessions - enter" ));
  225. LOG((TL_TRACE, "EnumerateAgentSessions - ppEnumAgentSessions %p", ppEnumAgentSession ));
  226. if(!TAPIIsBadWritePtr( ppEnumAgentSession, sizeof(IEnumAgentSession *) ) )
  227. {
  228. Lock();
  229. //
  230. // create the enumerator
  231. //
  232. CComObject< CTapiEnum<IEnumAgentSession, ITAgentSession, &IID_IEnumAgentSession> > * pEnum;
  233. hr = CComObject< CTapiEnum<IEnumAgentSession, ITAgentSession, &IID_IEnumAgentSession> > ::CreateInstance( &pEnum );
  234. if ( SUCCEEDED (hr) )
  235. {
  236. //
  237. // initialize it with our Session list
  238. //
  239. pEnum->Initialize(m_AgentSessionArray);
  240. //
  241. // return it
  242. *ppEnumAgentSession = pEnum;
  243. }
  244. else
  245. {
  246. LOG((TL_TRACE, "EnumerateAgentSessions - could not create enum" ));
  247. }
  248. Unlock();
  249. }
  250. else
  251. {
  252. LOG((TL_ERROR, "EnumerateAgentSessions - bad ppEnumAgentSession pointer" ));
  253. hr = E_POINTER;
  254. }
  255. LOG((TL_ERROR, hr, "EnumerateAgentSessions - exit" ));
  256. return hr;
  257. }
  258. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  259. // Class : CAgent
  260. // Interface : ITAgent
  261. // Method : get_AgentSessions
  262. //
  263. // Return a collection of agent sessions
  264. //
  265. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  266. STDMETHODIMP CAgent::get_AgentSessions(VARIANT * pVariant)
  267. {
  268. HRESULT hr = S_OK;
  269. IDispatch * pDisp = NULL;
  270. LOG((TL_TRACE, "get_AgentSessions - enter"));
  271. if (!TAPIIsBadWritePtr( pVariant, sizeof(VARIANT) ) )
  272. {
  273. //
  274. // create the collection
  275. //
  276. CComObject< CTapiCollection< ITAgentSession > > * p;
  277. hr = CComObject< CTapiCollection< ITAgentSession > >::CreateInstance( &p );
  278. if (SUCCEEDED(hr) )
  279. {
  280. // initialize it with our address list
  281. Lock();
  282. hr = p->Initialize( m_AgentSessionArray );
  283. Unlock();
  284. if ( SUCCEEDED(hr) )
  285. {
  286. // get the IDispatch interface
  287. hr = p->_InternalQueryInterface( IID_IDispatch, (void **) &pDisp );
  288. if ( SUCCEEDED(hr) )
  289. {
  290. // put it in the variant
  291. VariantInit(pVariant);
  292. pVariant->vt = VT_DISPATCH;
  293. pVariant->pdispVal = pDisp;
  294. }
  295. else
  296. {
  297. LOG((TL_ERROR, "get_AgentSessions - could not get IDispatch interface" ));
  298. delete p;
  299. }
  300. }
  301. else
  302. {
  303. LOG((TL_ERROR, "get_AgentSessions - could not initialize collection" ));
  304. delete p;
  305. }
  306. }
  307. else
  308. {
  309. LOG((TL_ERROR, "get_AgentSessions - could not create collection" ));
  310. }
  311. }
  312. else
  313. {
  314. LOG((TL_ERROR, "get_AgentSessions - bad pVariant pointer" ));
  315. hr = E_POINTER;
  316. }
  317. LOG((TL_TRACE, hr, "get_AgentSessions - exit"));
  318. return hr;
  319. }
  320. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  321. // Class : CAgent
  322. // Interface : ITAgent
  323. // Method : RegisterAgentEvents
  324. //
  325. //
  326. //
  327. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  328. STDMETHODIMP CAgent::RegisterAgentEvents(VARIANT_BOOL bNotify)
  329. {
  330. HRESULT hr = S_OK;
  331. LOG((TL_TRACE, "RegisterAgentEvents - enter" ));
  332. m_bRegisteredForAgentEvents = bNotify;
  333. LOG((TL_TRACE, "RegisterAgentEvents - exit" ));
  334. return hr;
  335. }
  336. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  337. // Class : CAgent
  338. // Interface : ITAgent
  339. // Method : RegisterAgentSessionEvents
  340. //
  341. //
  342. //
  343. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  344. STDMETHODIMP CAgent::RegisterAgentSessionEvents(VARIANT_BOOL bNotify)
  345. {
  346. HRESULT hr = S_OK;
  347. LOG((TL_TRACE, "RegisterAgentSessionEvents - enter" ));
  348. m_bRegisteredForAgentSessionEvents = bNotify;
  349. LOG((TL_TRACE, hr, "RegisterAgentSessionEvents - exit" ));
  350. return hr;
  351. }
  352. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  353. // Class : CAgent
  354. // Interface : ITAgent
  355. // Method : CreateSessionWithPIN
  356. //
  357. //
  358. //
  359. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  360. STDMETHODIMP CAgent::CreateSessionWithPIN(ITACDGroup * pACDGroup,
  361. ITAddress * pAddress,
  362. BSTR pPIN,
  363. ITAgentSession ** ppAgentSession
  364. )
  365. {
  366. HRESULT hr = S_OK;
  367. LOG((TL_TRACE, "CreateSessionWithPIN - enter" ));
  368. if ( agentHasID() )
  369. {
  370. if(!TAPIIsBadWritePtr( ppAgentSession, sizeof(ITAgentSession *) ) )
  371. {
  372. if (!IsBadStringPtrW( pPIN, -1 ))
  373. {
  374. // Pointer OK, is it empty ?
  375. if( pPIN != NULL)
  376. {
  377. hr = InternalCreateSession(pACDGroup, pAddress, pPIN, ppAgentSession);
  378. }
  379. else // PIN is NULL
  380. {
  381. LOG((TL_ERROR, "CreateSessionWithPIN - failed, PIN is NULL"));
  382. hr = E_INVALIDARG;
  383. }
  384. }
  385. else // bad BSTR pointer
  386. {
  387. LOG((TL_ERROR, "CreateSessionWithPIN - invalid pPIN pointer" ));
  388. hr = E_POINTER;
  389. }
  390. }
  391. else
  392. {
  393. LOG((TL_ERROR, "CreateSessionWithPIN - invalid ppAgentSession pointer" ));
  394. hr = E_POINTER;
  395. }
  396. }
  397. else // no ID
  398. {
  399. LOG((TL_ERROR, "CreateSessionWithPIN - Agent not created by CreateAgentWithID()" ));
  400. hr = TAPI_E_CALLCENTER_NO_AGENT_ID;
  401. }
  402. LOG((TL_TRACE, hr, "CreateSessionWithPIN - exit" ));
  403. return hr;
  404. }
  405. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  406. // Class : CAgent
  407. // Interface : ITAgent
  408. // Method : CreateSession
  409. //
  410. //
  411. //
  412. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  413. STDMETHODIMP CAgent::CreateSession(ITACDGroup * pACDGroup,
  414. ITAddress * pAddress,
  415. ITAgentSession ** ppAgentSession
  416. )
  417. {
  418. HRESULT hr = S_OK;
  419. LOG((TL_TRACE, "CreateSession - enter" ));
  420. if(!TAPIIsBadWritePtr( ppAgentSession, sizeof(ITAgentSession *) ) )
  421. {
  422. hr = InternalCreateSession(pACDGroup, pAddress, m_szPIN, ppAgentSession);
  423. }
  424. else
  425. {
  426. LOG((TL_ERROR, "CreateSession - invalid ppAgentSession pointer" ));
  427. hr = E_POINTER;
  428. }
  429. LOG((TL_TRACE, hr, "CreateSession - exit" ));
  430. return hr;
  431. }
  432. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  433. // Class : CAgent
  434. // Interface : ITAgent
  435. // Method : CreateSession
  436. //
  437. //
  438. //
  439. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  440. STDMETHODIMP CAgent::InternalCreateSession(ITACDGroup * pACDGroup,
  441. ITAddress * pAddress,
  442. PWSTR pszPIN,
  443. ITAgentSession ** ppAgentSession)
  444. {
  445. HAGENTSESSION hAgentSession;
  446. LINEAGENTENTRY Agent;
  447. DWORD dwAddressID;
  448. GUID GroupID;
  449. CACDGroup * pGroup = NULL;
  450. CAddress * pCAddress = NULL;
  451. CComObject<CAgentSession> * pAgentSession;
  452. AddressLineStruct * pAddressLine;
  453. HRESULT hr = S_OK;
  454. LOG((TL_TRACE, "InternalCreateSession - enter" ));
  455. // check for a valid ACD group & get its address ID
  456. pGroup = dynamic_cast<CComObject<CACDGroup>*>(pACDGroup);
  457. if (pGroup != NULL)
  458. {
  459. GroupID = pGroup->getID();
  460. // check for a valid address & get its address ID
  461. pCAddress = dynamic_cast<CComObject<CAddress>*>(pAddress);
  462. if (pCAddress != NULL)
  463. {
  464. dwAddressID = pCAddress->GetAddressID();
  465. hr = pCAddress->FindOrOpenALine (LINEMEDIAMODE_INTERACTIVEVOICE, &pAddressLine);
  466. if(SUCCEEDED(hr) )
  467. {
  468. // All OK so far, try to create session (sends request to proxy)
  469. hr = LineCreateAgentSession(
  470. pAddressLine->t3Line.hLine,
  471. m_hAgent,
  472. pszPIN,
  473. dwAddressID,
  474. &GroupID,
  475. &hAgentSession
  476. );
  477. if ( SUCCEEDED(hr) )
  478. {
  479. hr = WaitForReply( hr );
  480. if ( SUCCEEDED(hr) )
  481. {
  482. LOG((TL_INFO, "InternalCreateSession - create new session" ));
  483. hr = CComObject<CAgentSession>::CreateInstance( &pAgentSession );
  484. if ( SUCCEEDED(hr) )
  485. {
  486. ITAgentSession * pITAgentSession;
  487. hr = pAgentSession->QueryInterface(IID_ITAgentSession, (void **)&pITAgentSession);
  488. if ( SUCCEEDED(hr) )
  489. {
  490. // initialize the Agent
  491. hr = pAgentSession->Initialize(
  492. hAgentSession,
  493. this,
  494. pACDGroup,
  495. pAddress,
  496. m_pHandler,
  497. pAddressLine
  498. );
  499. if ( SUCCEEDED(hr) )
  500. {
  501. // add to list
  502. Lock();
  503. m_AgentSessionArray.Add( pITAgentSession );
  504. Unlock();
  505. pITAgentSession->Release();
  506. // This is the clients reference
  507. pAgentSession->AddRef();
  508. try
  509. {
  510. // set return value
  511. *ppAgentSession = pAgentSession;
  512. }
  513. catch(...)
  514. {
  515. hr = E_POINTER;
  516. }
  517. }
  518. else //(FAILED (hr) ) pAgentSession->Initialize
  519. {
  520. LOG((TL_ERROR, "InternalCreateSession - failed to initialize new object" ));
  521. delete pAgentSession;
  522. }
  523. }
  524. else //(FAILED (hr) ) pAgentSession->QueryInterface
  525. {
  526. LOG((TL_ERROR, "InternalCreateSession - failed to query interface" ));
  527. delete pAgentSession;
  528. }
  529. }
  530. else //(FAILED (hr) ) CreateInstance
  531. {
  532. LOG((TL_ERROR, "InternalCreateSession - createInstance failed for COM object" ));
  533. }
  534. }
  535. else // LineCreateAgentSession failed async
  536. {
  537. LOG((TL_ERROR, "InternalCreateSession - LineCreateAgentSession failed async" ));
  538. }
  539. }
  540. else //(FAILED (hr) ) LineCreateAgentSession
  541. {
  542. LOG((TL_ERROR, "InternalCreateSession - LineCreateAgentSession failed" ));
  543. }
  544. }
  545. else
  546. {
  547. LOG((TL_ERROR, "InternalCreateSession - Failed to open a line for the target Address" ));
  548. hr = E_UNEXPECTED;
  549. }
  550. }
  551. else //(pCAddress == NULL)
  552. {
  553. LOG((TL_ERROR, "InternalCreateSession - invalid Destination Address" ));
  554. hr = E_INVALIDARG;
  555. }
  556. }
  557. else //(pGroup == NULL)
  558. {
  559. LOG((TL_ERROR, "InternalCreateSession - invalid ACDGroup" ));
  560. hr = E_INVALIDARG;
  561. }
  562. LOG((TL_TRACE, hr, "InternalCreateSession - exit" ));
  563. return hr;
  564. }
  565. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  566. // Class : CAgent
  567. // Interface : ITAgent
  568. // Method : ID
  569. //
  570. //
  571. //
  572. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  573. STDMETHODIMP CAgent::get_ID(BSTR * pID)
  574. {
  575. HRESULT hr = S_OK;
  576. LOG((TL_TRACE, "ID - enter" ));
  577. Lock();
  578. if ( !agentHasID() )
  579. {
  580. LOG((TL_ERROR, "ID - Agent not created by CreateAgentWithID()" ));
  581. hr = TAPI_E_CALLCENTER_NO_AGENT_ID;
  582. }
  583. if(!TAPIIsBadWritePtr( pID, sizeof(BSTR) ) )
  584. {
  585. if (m_szAgentID == NULL)
  586. {
  587. *pID = NULL;
  588. }
  589. else
  590. {
  591. *pID = SysAllocString(m_szAgentID);
  592. if (*pID == NULL)
  593. {
  594. hr = E_OUTOFMEMORY;
  595. }
  596. }
  597. }
  598. else
  599. {
  600. LOG((TL_ERROR, "ID - bad pID pointer" ));
  601. hr = E_POINTER;
  602. }
  603. Unlock();
  604. LOG((TL_TRACE, hr, "ID - exit" ));
  605. return hr;
  606. }
  607. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  608. // Class : CAgent
  609. // Interface : ITAgent
  610. // Method : User
  611. //
  612. //
  613. //
  614. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  615. STDMETHODIMP CAgent::get_User(BSTR * ppUser)
  616. {
  617. HRESULT hr = S_OK;
  618. LOG((TL_TRACE, "User - enter" ));
  619. Lock();
  620. if(!TAPIIsBadWritePtr( ppUser, sizeof(BSTR) ) )
  621. {
  622. *ppUser = SysAllocString(m_szAgentUserName);
  623. if (*ppUser == NULL)
  624. {
  625. hr = E_OUTOFMEMORY;
  626. }
  627. }
  628. else
  629. {
  630. LOG((TL_ERROR, "User - bad ppUser pointer" ));
  631. hr = E_POINTER;
  632. }
  633. Unlock();
  634. LOG((TL_TRACE, hr, "User - exit" ));
  635. return hr;
  636. }
  637. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  638. // Class : CAgent
  639. // Interface : ITAgent
  640. // Method : put_State
  641. //
  642. //
  643. //
  644. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  645. STDMETHODIMP CAgent::put_State(AGENT_STATE AgentState)
  646. {
  647. HRESULT hr = S_OK;
  648. HLINE hLine;
  649. DWORD dwState = 0;
  650. LOG((TL_TRACE, "put_State - enter" ));
  651. Lock();
  652. hLine = (GetAgentHandler() )->getHLine();
  653. Unlock();
  654. dwState = MapAgentStateFrom3to2(AgentState);
  655. hr = lineSetAgentStateEx
  656. (hLine,
  657. m_hAgent,
  658. dwState,
  659. 0 //MapAgentStateFrom3to2(m_NextAgentState)
  660. );
  661. if( SUCCEEDED(hr) )
  662. {
  663. // wait for async reply
  664. hr = WaitForReply( hr );
  665. if ( SUCCEEDED(hr) )
  666. {
  667. Lock();
  668. m_AgentState = AgentState;
  669. Unlock();
  670. switch(AgentState) {
  671. case AS_NOT_READY:
  672. CAgentEvent::FireEvent(this, AE_NOT_READY);
  673. break;
  674. case AS_READY:
  675. CAgentEvent::FireEvent(this, AE_READY);
  676. break;
  677. case AS_BUSY_ACD:
  678. CAgentEvent::FireEvent(this, AE_BUSY_ACD);
  679. break;
  680. case AS_BUSY_INCOMING:
  681. CAgentEvent::FireEvent(this, AE_BUSY_INCOMING);
  682. break;
  683. case AS_BUSY_OUTGOING:
  684. CAgentEvent::FireEvent(this, AE_BUSY_OUTGOING);
  685. case AS_UNKNOWN:
  686. CAgentEvent::FireEvent(this, AE_UNKNOWN);
  687. break;
  688. }
  689. }
  690. else
  691. {
  692. LOG((TL_ERROR, "put_State - lineSetAgentStateEx failed async" ));
  693. }
  694. }
  695. else
  696. {
  697. LOG((TL_ERROR, "put_State - lineSetAgentStateEx failed" ));
  698. }
  699. LOG((TL_TRACE, hr, "put_State - exit" ));
  700. return hr;
  701. }
  702. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  703. // Class : CAgent
  704. // Interface : ITAgent
  705. // Method : get_State
  706. //
  707. //
  708. //
  709. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  710. STDMETHODIMP CAgent::get_State(AGENT_STATE * pAgentState)
  711. {
  712. HRESULT hr = S_OK;
  713. LOG((TL_TRACE, "get_State - enter" ));
  714. if(!TAPIIsBadWritePtr( pAgentState, sizeof(AGENT_STATE) ) )
  715. {
  716. Lock();
  717. *pAgentState = m_AgentState;
  718. Unlock();
  719. }
  720. else
  721. {
  722. LOG((TL_ERROR, "get_State - bad pAgentState pointer"));
  723. hr = E_POINTER;
  724. }
  725. LOG((TL_TRACE, hr, "get_State - exit" ));
  726. return hr;
  727. }
  728. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  729. // Class : CAgent
  730. // Interface : ITAgent
  731. // Method : put_MeasurementPeriod
  732. //
  733. //
  734. //
  735. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  736. STDMETHODIMP CAgent::put_MeasurementPeriod(long ulPeriod)
  737. {
  738. HRESULT hr = S_OK;
  739. LOG((TL_TRACE, "put_MeasurementPeriod - enter" ));
  740. // Tell Proxy
  741. hr = lineSetAgentMeasurementPeriod(
  742. m_pHandler->getHLine(),
  743. m_hAgent,
  744. ulPeriod);
  745. if( SUCCEEDED(hr) )
  746. {
  747. // wait for async reply
  748. hr = WaitForReply( hr );
  749. if ( SUCCEEDED(hr) )
  750. {
  751. Lock();
  752. m_dwMeasurementPeriod = ulPeriod;
  753. Unlock();
  754. }
  755. else
  756. {
  757. LOG((TL_ERROR, "put_MeasurementPeriod - call to LineSetAgentMeasurementPeriod failed async" ));
  758. }
  759. }
  760. else
  761. {
  762. LOG((TL_ERROR, "put_MeasurementPeriod - call to LineSetAgentMeasurementPeriod failed" ));
  763. }
  764. LOG((TL_TRACE, hr, "put_MeasurementPeriod - exit" ));
  765. return hr;
  766. }
  767. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  768. // Class : CAgent
  769. // Interface : ITAgent
  770. // Method : get_MeasurementPeriod
  771. //
  772. //
  773. //
  774. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  775. STDMETHODIMP CAgent::get_MeasurementPeriod(long * pulPeriod)
  776. {
  777. HRESULT hr = S_OK;
  778. DWORD period;
  779. LOG((TL_TRACE, "get_MeasurementPeriod - enter" ));
  780. if(!TAPIIsBadWritePtr( pulPeriod, sizeof(long) ) )
  781. {
  782. hr = CheckIfUpToDate();
  783. if ( SUCCEEDED(hr) )
  784. {
  785. Lock();
  786. *pulPeriod = m_dwMeasurementPeriod;
  787. Unlock();
  788. }
  789. else
  790. {
  791. LOG((TL_ERROR, "get_MeasurementPeriod - Object update failed"));
  792. }
  793. }
  794. else
  795. {
  796. LOG((TL_ERROR, "get_MeasurementPeriod -bad pulPeriod pointer" ));
  797. hr = E_POINTER;
  798. }
  799. LOG((TL_TRACE, hr, "get_MeasurementPeriod - exit" ));
  800. return hr;
  801. }
  802. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  803. // Class : CAgent
  804. // Interface : ITAgent
  805. // Method : OverallCallrate
  806. //
  807. //
  808. //
  809. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  810. STDMETHODIMP CAgent::get_OverallCallRate(CURRENCY * pcyCallrate)
  811. {
  812. HRESULT hr = S_OK;
  813. LOG((TL_TRACE, "OverallCallrate - enter" ));
  814. if (!TAPIIsBadWritePtr( pcyCallrate, sizeof(CURRENCY) ) )
  815. {
  816. hr = CheckIfUpToDate();
  817. if ( SUCCEEDED(hr) )
  818. {
  819. Lock();
  820. *pcyCallrate = m_cyOverallCallRate;
  821. Unlock();
  822. }
  823. else
  824. {
  825. LOG((TL_ERROR, "get_OverallCallRate - Object update failed"));
  826. }
  827. }
  828. else
  829. {
  830. LOG((TL_ERROR, "get_OverallCallRate - bad pcyCallrate pointer"));
  831. hr = E_POINTER;
  832. }
  833. LOG((TL_TRACE, hr, "OverallCallrate - exit" ));
  834. return hr;
  835. }
  836. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  837. // Class : CAgent
  838. // Interface : ITAgent
  839. // Method : NumberOfACDCalls
  840. //
  841. //
  842. //
  843. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  844. STDMETHODIMP CAgent::get_NumberOfACDCalls(long * pulCalls)
  845. {
  846. HRESULT hr = S_OK;
  847. LOG((TL_TRACE, "NumberOfACDCalls - enter" ));
  848. if (!TAPIIsBadWritePtr( pulCalls, sizeof(long) ) )
  849. {
  850. hr = CheckIfUpToDate();
  851. if ( SUCCEEDED(hr) )
  852. {
  853. Lock();
  854. *pulCalls = m_dwNumberOfACDCalls;
  855. Unlock();
  856. }
  857. else
  858. {
  859. LOG((TL_ERROR, "get_NumberOfACDCalls - Object update failed"));
  860. }
  861. }
  862. else
  863. {
  864. LOG((TL_ERROR, "get_NumberOfACDCalls - bad pulCalls pointer"));
  865. hr = E_POINTER;
  866. }
  867. LOG((TL_TRACE, hr, "NumberOfACDCalls - exit" ));
  868. return hr;
  869. }
  870. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  871. // Class : CAgent
  872. // Interface : ITAgent
  873. // Method : NumberOfIncomingCalls
  874. //
  875. //
  876. //
  877. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  878. STDMETHODIMP CAgent::get_NumberOfIncomingCalls(long * pulCalls)
  879. {
  880. HRESULT hr = S_OK;
  881. LOG((TL_TRACE, "NumberOfIncomingCalls - enter" ));
  882. if (!TAPIIsBadWritePtr( pulCalls, sizeof(long) ) )
  883. {
  884. hr = CheckIfUpToDate();
  885. if ( SUCCEEDED(hr) )
  886. {
  887. Lock();
  888. *pulCalls = m_dwNumberOfIncomingCalls;
  889. Unlock();
  890. }
  891. else
  892. {
  893. LOG((TL_ERROR, "get_NumberOfIncomingCalls - Object update failed"));
  894. }
  895. }
  896. else
  897. {
  898. LOG((TL_ERROR, "get_NumberOfIncomingCalls - bad pulCalls pointer"));
  899. hr = E_POINTER;
  900. }
  901. LOG((TL_TRACE, hr, "NumberOfIncomingCalls - exit" ));
  902. return hr;
  903. }
  904. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  905. // Class : CAgent
  906. // Interface : ITAgent
  907. // Method : NumberOfOutgoingCalls
  908. //
  909. //
  910. //
  911. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  912. STDMETHODIMP CAgent::get_NumberOfOutgoingCalls(long * pulCalls)
  913. {
  914. HRESULT hr = S_OK;
  915. LOG((TL_TRACE, "NumberOfOutgoingCalls - enter" ));
  916. if (!TAPIIsBadWritePtr( pulCalls, sizeof(long) ) )
  917. {
  918. hr = CheckIfUpToDate();
  919. if ( SUCCEEDED(hr) )
  920. {
  921. Lock();
  922. *pulCalls = m_dwNumberOfOutgoingCalls;
  923. Unlock();
  924. }
  925. else
  926. {
  927. LOG((TL_ERROR, "get_NumberOfOutgoingCalls - Object update failed"));
  928. }
  929. }
  930. else
  931. {
  932. LOG((TL_ERROR, "get_NumberOfOutgoingCalls - bad pulCalls pointer"));
  933. hr = E_POINTER;
  934. }
  935. LOG((TL_TRACE, hr, "NumberOfOutgoingCalls - exit" ));
  936. return hr;
  937. }
  938. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  939. // Class : CAgent
  940. // Interface : ITAgent
  941. // Method : TotalACDTalkTime
  942. //
  943. //
  944. //
  945. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  946. STDMETHODIMP CAgent::get_TotalACDTalkTime(long * pulTalkTime)
  947. {
  948. HRESULT hr = S_OK;
  949. LOG((TL_TRACE, "TotalACDTalkTime - enter" ));
  950. if (!TAPIIsBadWritePtr( pulTalkTime, sizeof(long) ) )
  951. {
  952. hr = CheckIfUpToDate();
  953. if ( SUCCEEDED(hr) )
  954. {
  955. Lock();
  956. *pulTalkTime = m_dwTotalACDTalkTime;
  957. Unlock();
  958. }
  959. else
  960. {
  961. LOG((TL_ERROR, "get_TotalACDTalkTime - Object update failed"));
  962. }
  963. }
  964. else
  965. {
  966. LOG((TL_ERROR, "get_TotalACDTalkTime - bad pulTalkTime pointer"));
  967. hr = E_POINTER;
  968. }
  969. LOG((TL_TRACE, hr, "TotalACDTalkTime - exit" ));
  970. return hr;
  971. }
  972. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  973. // Class : CAgent
  974. // Interface : ITAgent
  975. // Method : TotalACDCallTime
  976. //
  977. //
  978. //
  979. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  980. STDMETHODIMP CAgent::get_TotalACDCallTime(long * pulCallTime)
  981. {
  982. HRESULT hr = S_OK;
  983. LOG((TL_TRACE, "TotalACDCallTime - enter" ));
  984. if (!TAPIIsBadWritePtr( pulCallTime, sizeof(long) ) )
  985. {
  986. hr = CheckIfUpToDate();
  987. if ( SUCCEEDED(hr) )
  988. {
  989. Lock();
  990. *pulCallTime = m_dwTotalACDCallTime;
  991. Unlock();
  992. }
  993. else
  994. {
  995. LOG((TL_ERROR, "get_TotalACDCallTime - Object update failed"));
  996. }
  997. }
  998. else
  999. {
  1000. LOG((TL_ERROR, "get_TotalACDCallTime - bad pulCallTime pointer"));
  1001. hr = E_POINTER;
  1002. }
  1003. LOG((TL_TRACE, hr, "TotalACDCallTime - exit" ));
  1004. return hr;
  1005. }
  1006. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1007. // Class : CAgent
  1008. // Interface : ITAgent
  1009. // Method : TotalWrapUpTime
  1010. //
  1011. //
  1012. //
  1013. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1014. STDMETHODIMP CAgent::get_TotalWrapUpTime(long * pulWrapUpTime)
  1015. {
  1016. HRESULT hr = S_OK;
  1017. LOG((TL_TRACE, "TotalWrapUpTime - enter" ));
  1018. if (!TAPIIsBadWritePtr( pulWrapUpTime, sizeof(long) ) )
  1019. {
  1020. hr = CheckIfUpToDate();
  1021. if ( SUCCEEDED(hr) )
  1022. {
  1023. Lock();
  1024. *pulWrapUpTime = m_dwTotalACDWrapUpTime;
  1025. Unlock();
  1026. }
  1027. else
  1028. {
  1029. LOG((TL_ERROR, "get_TotalWrapUpTime - Object update failed"));
  1030. }
  1031. }
  1032. else
  1033. {
  1034. LOG((TL_ERROR, "get_TotalWrapUpTime - bad pulWrapUpTime pointer"));
  1035. hr = E_POINTER;
  1036. }
  1037. LOG((TL_TRACE, hr, "TotalWrapUpTime - exit" ));
  1038. return hr;
  1039. }
  1040. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1041. // Class : CAgent
  1042. // Interface : ITAgent
  1043. // Method : put_PIN
  1044. //
  1045. //
  1046. //
  1047. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1048. STDMETHODIMP CAgent::put_PIN(BSTR pPIN)
  1049. {
  1050. HRESULT hr = S_OK;
  1051. LOG((TL_TRACE, "put_PIN - enter" ));
  1052. if (!IsBadStringPtrW( pPIN, -1 ))
  1053. {
  1054. // Pointer OK, is it empty ?
  1055. if( pPIN != NULL)
  1056. {
  1057. // do we have an existng PIN ?
  1058. if (m_szPIN != NULL)
  1059. {
  1060. LOG((TL_INFO, "put_PIN - Overwrite exising PIN"));
  1061. ClientFree(m_szPIN);
  1062. }
  1063. // Alloc space for new PIN
  1064. m_szPIN = (PWSTR) ClientAlloc((lstrlenW(pPIN) + 1) * sizeof (WCHAR));
  1065. if (m_szPIN != NULL)
  1066. {
  1067. lstrcpyW(m_szPIN, pPIN);
  1068. }
  1069. else
  1070. {
  1071. LOG((TL_ERROR, "put_PIN - ClientAlloc m_szPIN failed" ));
  1072. hr = E_OUTOFMEMORY;
  1073. }
  1074. }
  1075. else // PIN is NULL
  1076. {
  1077. LOG((TL_ERROR, "put_PIN - failed, PIN is NULL"));
  1078. hr = E_INVALIDARG;
  1079. }
  1080. }
  1081. else // bad BSTR pointer
  1082. {
  1083. LOG((TL_ERROR, "put_PIN - invalid pointer" ));
  1084. return E_POINTER;
  1085. }
  1086. LOG((TL_TRACE, hr, "put_PIN - exit" ));
  1087. return hr;
  1088. }
  1089. /////////////////////////////////////////////////////////////////////////////
  1090. /////////////////////////////////////////////////////////////////////////////
  1091. /////////////////////////////////////////////////////////////////////////////
  1092. // CAgentEvent
  1093. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1094. // Class : CAgentEvent
  1095. // Method : FireEvent
  1096. //
  1097. //
  1098. //
  1099. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1100. HRESULT CAgentEvent::FireEvent(CAgent* pAgent, AGENT_EVENT Event)
  1101. {
  1102. HRESULT hr = S_OK;
  1103. CComObject<CAgentEvent> * pEvent;
  1104. IDispatch * pIDispatch;
  1105. //
  1106. // create event
  1107. //
  1108. hr = CComObject<CAgentEvent>::CreateInstance( &pEvent );
  1109. if ( SUCCEEDED(hr) )
  1110. {
  1111. //
  1112. // initialize
  1113. //
  1114. pEvent->m_AgentEvent = Event;
  1115. pEvent->m_pAgent= dynamic_cast<ITAgent *>(pAgent);
  1116. pEvent->m_pAgent->AddRef();
  1117. //
  1118. // get idisp interface
  1119. //
  1120. hr = pEvent->QueryInterface( IID_IDispatch, (void **)&pIDispatch );
  1121. if ( SUCCEEDED(hr) )
  1122. {
  1123. //
  1124. // get callback & fire event
  1125. //
  1126. CTAPI *pTapi = (pAgent->GetAgentHandler() )->GetTapi();
  1127. pTapi->Event( TE_AGENT, pIDispatch );
  1128. // release stuff
  1129. //
  1130. pIDispatch->Release();
  1131. }
  1132. else
  1133. {
  1134. STATICLOG((TL_ERROR, "(Event)FireEvent - Could not get disp interface of AgentEvent object"));
  1135. delete pEvent;
  1136. }
  1137. }
  1138. else
  1139. {
  1140. STATICLOG((TL_ERROR, "(Event)FireEvent - Could not create AgentEvent object"));
  1141. }
  1142. STATICLOG((TL_TRACE, hr, "(Event)FireEvent - exit"));
  1143. return hr;
  1144. }
  1145. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1146. // Class : CAgentEvent
  1147. // Method : FinalRelease
  1148. //
  1149. //
  1150. //
  1151. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1152. void CAgentEvent::FinalRelease()
  1153. {
  1154. m_pAgent->Release();
  1155. }
  1156. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1157. // Class : CAgentEvent
  1158. // Interface : ITAgentEvent
  1159. // Method : Agent
  1160. //
  1161. //
  1162. //
  1163. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1164. STDMETHODIMP CAgentEvent::get_Agent(ITAgent ** ppAgent)
  1165. {
  1166. HRESULT hr = S_OK;
  1167. LOG((TL_TRACE, "(Event)Agent - enter" ));
  1168. if(!TAPIIsBadWritePtr( ppAgent, sizeof(ITAgent *) ) )
  1169. {
  1170. *ppAgent = m_pAgent;
  1171. m_pAgent->AddRef();
  1172. }
  1173. else
  1174. {
  1175. LOG((TL_ERROR, "(Event)Agent - bad ppAgent pointer"));
  1176. hr = E_POINTER;
  1177. }
  1178. LOG((TL_TRACE, hr, "(Event)Agent - exit"));
  1179. return hr;
  1180. }
  1181. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1182. // Class : CAgentEvent
  1183. // Interface : ITAgentEvent
  1184. // Method : Event
  1185. //
  1186. //
  1187. //
  1188. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1189. STDMETHODIMP CAgentEvent::get_Event(AGENT_EVENT * pEvent)
  1190. {
  1191. HRESULT hr = S_OK;
  1192. LOG((TL_TRACE, "Event - enter" ));
  1193. if(!TAPIIsBadWritePtr( pEvent, sizeof(AGENT_EVENT) ) )
  1194. {
  1195. *pEvent = m_AgentEvent;
  1196. }
  1197. else
  1198. {
  1199. LOG((TL_ERROR, "Event - bad pEvent pointer"));
  1200. hr = E_POINTER;
  1201. }
  1202. LOG((TL_TRACE, hr, "Event - exit"));
  1203. return hr;
  1204. }
  1205. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1206. // Function : MapAgentStateFrom3to2
  1207. //
  1208. //
  1209. //
  1210. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1211. DWORD MapAgentStateFrom3to2(AGENT_STATE tapi3State)
  1212. {
  1213. DWORD tapi2State = 0;
  1214. switch(tapi3State)
  1215. {
  1216. case AS_NOT_READY:
  1217. tapi2State = LINEAGENTSTATEEX_NOTREADY;
  1218. break;
  1219. case AS_READY:
  1220. tapi2State = LINEAGENTSTATEEX_READY;
  1221. break;
  1222. case AS_BUSY_ACD:
  1223. tapi2State = LINEAGENTSTATEEX_BUSYACD;
  1224. break;
  1225. case AS_BUSY_INCOMING:
  1226. tapi2State = LINEAGENTSTATEEX_BUSYINCOMING;
  1227. break;
  1228. case AS_BUSY_OUTGOING:
  1229. tapi2State = LINEAGENTSTATEEX_BUSYOUTGOING;
  1230. break;
  1231. case AS_UNKNOWN:
  1232. tapi2State = LINEAGENTSTATEEX_UNKNOWN;
  1233. break;
  1234. default:
  1235. break;
  1236. }
  1237. return tapi2State;
  1238. }
  1239. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1240. // Function : MapAgentStateFrom2to3
  1241. //
  1242. //
  1243. //
  1244. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1245. HRESULT MapAgentStateFrom2to3(DWORD tapi2State, AGENT_STATE *tapi3State)
  1246. {
  1247. HRESULT hr = S_OK;
  1248. if (tapi2State & LINEAGENTSTATEEX_NOTREADY)
  1249. {
  1250. *tapi3State = AS_NOT_READY;
  1251. }
  1252. else if (tapi2State & LINEAGENTSTATEEX_READY)
  1253. {
  1254. *tapi3State = AS_READY;
  1255. }
  1256. else if (tapi2State & LINEAGENTSTATEEX_BUSYACD)
  1257. {
  1258. *tapi3State = AS_BUSY_ACD;
  1259. }
  1260. else if (tapi2State & LINEAGENTSTATEEX_BUSYINCOMING)
  1261. {
  1262. *tapi3State = AS_BUSY_INCOMING;
  1263. }
  1264. else if (tapi2State & LINEAGENTSTATEEX_BUSYOUTGOING)
  1265. {
  1266. *tapi3State = AS_BUSY_OUTGOING;
  1267. }
  1268. else if (tapi2State & LINEAGENTSTATEEX_UNKNOWN)
  1269. {
  1270. *tapi3State = AS_UNKNOWN;
  1271. }
  1272. else
  1273. {
  1274. *tapi3State = AS_UNKNOWN; // default
  1275. hr = E_INVALIDARG;
  1276. }
  1277. return hr;
  1278. }