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.

864 lines
26 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. callcent.cpp
  5. Abstract:
  6. Implementation of the CAll centre interface for TAPI 3.0.
  7. CTAPI class
  8. Author:
  9. noela - 11/04/97
  10. Notes:
  11. optional-notes
  12. Revision History:
  13. --*/
  14. #define UNICODE
  15. #include "stdafx.h"
  16. #include "lmcons.h"
  17. extern CHashTable * gpAgentHandlerHashTable ;
  18. //
  19. // Tapi 3 requires all of the following proxy requests to be supported (on a line) by an acd proxy before it will
  20. // create an Agent Handler object for that proxy
  21. //
  22. #define NUMBER_OF_REQUIRED_ACD_PROXYREQUESTS 13
  23. DWORD RequiredACDProxyRequests[NUMBER_OF_REQUIRED_ACD_PROXYREQUESTS] = {
  24. LINEPROXYREQUEST_GETAGENTCAPS,
  25. LINEPROXYREQUEST_CREATEAGENT,
  26. LINEPROXYREQUEST_SETAGENTMEASUREMENTPERIOD,
  27. LINEPROXYREQUEST_GETAGENTINFO,
  28. LINEPROXYREQUEST_CREATEAGENTSESSION,
  29. LINEPROXYREQUEST_GETAGENTSESSIONLIST,
  30. LINEPROXYREQUEST_SETAGENTSESSIONSTATE,
  31. LINEPROXYREQUEST_GETAGENTSESSIONINFO,
  32. LINEPROXYREQUEST_GETQUEUELIST,
  33. LINEPROXYREQUEST_SETQUEUEMEASUREMENTPERIOD,
  34. LINEPROXYREQUEST_GETQUEUEINFO,
  35. LINEPROXYREQUEST_GETGROUPLIST,
  36. LINEPROXYREQUEST_SETAGENTSTATEEX};
  37. HRESULT
  38. WaitForReply(
  39. DWORD
  40. );
  41. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  42. //
  43. // handleAgentStatusMessage
  44. //
  45. // Handles LINE_AGENTSTATUS messages
  46. //
  47. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  48. void HandleAgentStatusMessage(PASYNCEVENTMSG pParams)
  49. {
  50. CAgentHandler * pAgentHandler;
  51. CAgent * pAgent;
  52. HAGENT hAgent;
  53. BOOL bSuccess;
  54. AGENT_EVENT agentEvent;
  55. bSuccess = FindAgentHandlerObject(
  56. (HLINE)(pParams->hDevice),
  57. &pAgentHandler
  58. );
  59. if (bSuccess)
  60. {
  61. hAgent = (HAGENT)(pParams->Param1);
  62. bSuccess = pAgentHandler->FindAgentObject(
  63. hAgent,
  64. &pAgent
  65. );
  66. if (bSuccess)
  67. {
  68. if (pParams->Param2 & LINEAGENTSTATUSEX_UPDATEINFO)
  69. {
  70. LOG((TL_INFO, "handleAgentStatusMessage - LINEAGENTSTATUSEX_UPDATEINFO"));
  71. pAgent->SetRequiresUpdate();
  72. }
  73. if (pParams->Param2 & LINEAGENTSTATUSEX_STATE)
  74. {
  75. LOG((TL_INFO, "handleAgentStatusMessage - LINEAGENTSTATUSEX_STATE"));
  76. if (pParams->Param3 & LINEAGENTSTATEEX_NOTREADY)
  77. {
  78. agentEvent = AE_NOT_READY;
  79. pAgent->SetState(AS_NOT_READY);
  80. }
  81. else if (pParams->Param3 & LINEAGENTSTATEEX_READY)
  82. {
  83. agentEvent = AE_READY;
  84. pAgent->SetState(AS_READY);
  85. }
  86. else if (pParams->Param3 & LINEAGENTSTATEEX_BUSYACD)
  87. {
  88. agentEvent = AE_BUSY_ACD;
  89. pAgent->SetState(AS_BUSY_ACD);
  90. }
  91. else if (pParams->Param3 & LINEAGENTSTATEEX_BUSYINCOMING)
  92. {
  93. agentEvent = AE_BUSY_INCOMING;
  94. pAgent->SetState(AS_BUSY_INCOMING);
  95. }
  96. else if (pParams->Param3 & LINEAGENTSTATEEX_BUSYOUTGOING)
  97. {
  98. agentEvent = AE_BUSY_OUTGOING;
  99. pAgent->SetState(AS_BUSY_OUTGOING);
  100. }
  101. else if (pParams->Param3 & LINEAGENTSTATEEX_UNKNOWN)
  102. {
  103. agentEvent = AE_UNKNOWN;
  104. pAgent->SetState(AS_UNKNOWN);
  105. }
  106. else
  107. {
  108. LOG((TL_ERROR, "handleAgentStatusMessage - invalid state %d - setting to AS_UNKNOWN", pParams->Param3));
  109. agentEvent = AE_UNKNOWN;
  110. pAgent->SetState(AS_UNKNOWN);
  111. }
  112. CAgentEvent::FireEvent(pAgent, agentEvent);
  113. }
  114. }
  115. else
  116. {
  117. LOG((TL_ERROR, "handleAgentStatusMessage - can't find agent%d", hAgent));
  118. }
  119. // find AH object addrefs the AH, so release it
  120. pAgentHandler->Release();
  121. }
  122. else
  123. {
  124. LOG((TL_ERROR, "handleAgentStatusMessage - can't find Agent Handler"));
  125. }
  126. }
  127. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  128. //
  129. // handleAgentStatusMessage
  130. //
  131. // Handles LINE_AGENTSESSIONSTATUS messages
  132. //
  133. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  134. void HandleAgentSessionStatusMessage(PASYNCEVENTMSG pParams)
  135. {
  136. CAgentHandler * pAgentHandler;
  137. CAgentSession * pAgentSession;
  138. CAgent * pAgent = NULL;
  139. ITAgent * pITAgent = NULL;
  140. HAGENTSESSION hAgentSession;
  141. BOOL bSuccess;
  142. AGENT_SESSION_EVENT sessionEvent;
  143. bSuccess = FindAgentHandlerObject(
  144. (HLINE)(pParams->hDevice),
  145. &pAgentHandler
  146. );
  147. if (bSuccess)
  148. {
  149. hAgentSession = (HAGENTSESSION)(pParams->Param1);
  150. bSuccess = pAgentHandler->FindSessionObject(
  151. hAgentSession,
  152. &pAgentSession
  153. );
  154. if (bSuccess)
  155. {
  156. if (pParams->Param2 & LINEAGENTSESSIONSTATUS_UPDATEINFO)
  157. {
  158. LOG((TL_INFO, "handleAgentSessionStatusMessage - LINEAGENTSESSIONSTATUS_UPDATEINFO"));
  159. pAgentSession->SetRequiresUpdate();
  160. }
  161. if (pParams->Param2 & LINEAGENTSESSIONSTATUS_STATE)
  162. {
  163. LOG((TL_INFO, "handleAgentSessionStatusMessage - LINEAGENTSESSIONSTATUS_STATE"));
  164. if (pParams->Param3 & LINEAGENTSESSIONSTATE_NOTREADY)
  165. {
  166. sessionEvent = ASE_NOT_READY;
  167. pAgentSession->SetState(ASST_NOT_READY);
  168. }
  169. else if (pParams->Param3 & LINEAGENTSESSIONSTATE_READY)
  170. {
  171. sessionEvent = ASE_READY;
  172. pAgentSession->SetState(ASST_READY);
  173. }
  174. else if (pParams->Param3 & LINEAGENTSESSIONSTATE_BUSYONCALL)
  175. {
  176. sessionEvent = ASE_BUSY;
  177. pAgentSession->SetState(ASST_BUSY_ON_CALL);
  178. }
  179. else if (pParams->Param3 & LINEAGENTSESSIONSTATE_BUSYWRAPUP)
  180. {
  181. sessionEvent = ASE_WRAPUP;
  182. pAgentSession->SetState(ASST_BUSY_WRAPUP);
  183. }
  184. else if (pParams->Param3 & LINEAGENTSESSIONSTATE_ENDED)
  185. {
  186. sessionEvent = ASE_END;
  187. pAgentSession->SetState(ASST_SESSION_ENDED);
  188. }
  189. else
  190. {
  191. LOG((TL_ERROR, "handleAgentSessionStatusMessage - invalid state %d - setting to ASST_NOT_READY", pParams->Param3));
  192. sessionEvent = ASE_NOT_READY;
  193. pAgentSession->SetState(ASST_NOT_READY);
  194. }
  195. CAgentSessionEvent::FireEvent(pAgentSession, sessionEvent);
  196. }
  197. }
  198. else
  199. {
  200. LOG((TL_ERROR, "handleAgentSessionStatusMessage - can't find session %d", hAgentSession));
  201. }
  202. // find AH object addrefs the AH, so release it
  203. pAgentHandler->Release();
  204. }
  205. else
  206. {
  207. LOG((TL_ERROR, "handleAgentSessionStatusMessage - can't find Agent Handler"));
  208. }
  209. }
  210. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  211. //
  212. // handleAgentStatusMessage
  213. //
  214. // Handles LINE_QUEUESTATUS messages
  215. //
  216. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  217. void HandleQueueStatusMessage(PASYNCEVENTMSG pParams)
  218. {
  219. CAgentHandler * pAgentHandler;
  220. CQueue * pQueue;
  221. DWORD dwQueueID;
  222. BOOL bSuccess;
  223. bSuccess = FindAgentHandlerObject(
  224. (HLINE)(pParams->hDevice),
  225. &pAgentHandler
  226. );
  227. if (bSuccess)
  228. {
  229. dwQueueID = (DWORD)(pParams->Param1);
  230. bSuccess = pAgentHandler->FindQueueObject(
  231. dwQueueID,
  232. &pQueue
  233. );
  234. if (bSuccess)
  235. {
  236. if (pParams->Param2 & LINEQUEUESTATUS_UPDATEINFO)
  237. {
  238. LOG((TL_INFO, "handleQueueStatusMessage - LINEQUEUESTATUS_UPDATEINFO"));
  239. pQueue->SetRequiresUpdate();
  240. }
  241. }
  242. else
  243. {
  244. LOG((TL_ERROR, "handleQueueStatusMessage - can't find Queue %d", dwQueueID));
  245. }
  246. // find AH object addrefs the AH, so release it
  247. pAgentHandler->Release();
  248. }
  249. else
  250. {
  251. LOG((TL_ERROR, "handleQueueStatusMessage - can't find Agent Handler"));
  252. }
  253. }
  254. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  255. //
  256. // handleGroupStatusMessage
  257. //
  258. // Handles LINE_GROUPSTATUS messages
  259. //
  260. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  261. void handleGroupStatusMessage(PASYNCEVENTMSG pParams)
  262. {
  263. if (pParams->Param2 & LINEGROUPSTATUS_NEWGROUP)
  264. {
  265. LOG((TL_INFO, "handleGroupStatusMessage - LINEGROUPSTATUS_NEWGROUP"));
  266. }
  267. else if (pParams->Param2 & LINEGROUPSTATUS_GROUPREMOVED)
  268. {
  269. LOG((TL_INFO, "handleGroupStatusMessage - LINEGROUPSTATUS_GROUPREMOVED"));
  270. }
  271. }
  272. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  273. //
  274. // handleProxyStatusMessage
  275. //
  276. // Handles LINE_PROXYSTATUS messages
  277. //
  278. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  279. void handleProxyStatusMessage( CTAPI * pTapi, PASYNCEVENTMSG pParams)
  280. {
  281. HRESULT hr;
  282. LOG((TL_INFO, "handleProxyStatusMessage - message %02X %02X %02X", pParams->Param1, pParams->Param2, pParams->Param3));
  283. if (pParams->Param1 & LINEPROXYSTATUS_OPEN)
  284. {
  285. LOG((TL_INFO, "handleProxyStatusMessage - LINEPROXYSTATUS_OPEN %02X", pParams->Param2));
  286. }
  287. else if (pParams->Param1 & LINEPROXYSTATUS_CLOSE)
  288. {
  289. LOG((TL_INFO, "handleProxyStatusMessage - LINEPROXYSTATUS_CLOSE %02X", pParams->Param2));
  290. }
  291. else
  292. {
  293. LOG((TL_INFO, "handleProxyStatusMessage - Unknown message"));
  294. return;
  295. }
  296. hr = pTapi->UpdateAgentHandlerArray();
  297. if (SUCCEEDED(hr))
  298. {
  299. LOG((TL_INFO, "handleProxyStatusMessage - UpdateAgentHandlerArray successfully"));
  300. }
  301. else
  302. {
  303. LOG((TL_ERROR, "handleProxyStatusMessage - UpdateAgentHandlerArray unsuccessfully"));
  304. }
  305. }
  306. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  307. //
  308. // MyBasicCallControlQI
  309. // don't give out the basiccallcontrol interface
  310. // if the application does not own the call
  311. //
  312. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  313. HRESULT
  314. WINAPI
  315. MyCallCenterQI(void* pvClassObject, REFIID riid, LPVOID* ppv, DWORD_PTR dw)
  316. {
  317. HRESULT hr = S_FALSE;
  318. LOG((TL_TRACE, "MyCallCenterQI - enter"));
  319. ((CTAPI *)pvClassObject)->UpdateAgentHandlerArray();
  320. //
  321. // S_FALSE tells atl to continue querying for the interface
  322. //
  323. LOG((TL_TRACE, hr, "MyCallCenterQI - exit"));
  324. return hr;
  325. }
  326. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  327. // Method : CheckForRequiredProxyRequests
  328. //
  329. // Must find a match for every type (S_OK) or returns E_FAIL
  330. //
  331. //
  332. //
  333. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  334. HRESULT CheckForRequiredProxyRequests( HLINEAPP hLineApp, DWORD dwDeviceID)
  335. {
  336. HRESULT hr = S_OK;
  337. LPLINEPROXYREQUESTLIST pLineProxyRequestList;
  338. DWORD i, j;
  339. LPDWORD pProxyListEntry;
  340. BOOL bFoundAMatch;
  341. LOG((TL_TRACE, "CheckForRequiredProxyRequests - enter"));
  342. hr = LineGetProxyStatus(hLineApp, dwDeviceID, TAPI_CURRENT_VERSION, &pLineProxyRequestList );
  343. if( SUCCEEDED(hr) )
  344. {
  345. // check for all required types
  346. for(i=0; i!= NUMBER_OF_REQUIRED_ACD_PROXYREQUESTS; i++)
  347. {
  348. bFoundAMatch = FALSE;
  349. pProxyListEntry = (LPDWORD) ( (LPBYTE)pLineProxyRequestList + pLineProxyRequestList->dwListOffset );
  350. for(j=0; j!= pLineProxyRequestList->dwNumEntries; j++)
  351. {
  352. if ( RequiredACDProxyRequests[i] == *pProxyListEntry++)
  353. {
  354. bFoundAMatch = TRUE;
  355. break;
  356. }
  357. }
  358. if(bFoundAMatch == FALSE)
  359. {
  360. LOG((TL_ERROR, "CheckForRequiredProxyRequests - no proxy of type %02X", RequiredACDProxyRequests[i]));
  361. hr = E_FAIL;
  362. }
  363. }
  364. }
  365. else // LineGetProxyStatus failed
  366. {
  367. LOG((TL_ERROR, "CheckForRequiredProxyRequests - LineGetProxyStatus failed"));
  368. hr = E_FAIL;
  369. }
  370. // finished with memory block so release
  371. if ( pLineProxyRequestList != NULL )
  372. {
  373. ClientFree( pLineProxyRequestList );
  374. }
  375. LOG((TL_TRACE, hr, "CheckForRequiredProxyRequests - exit"));
  376. return hr ;
  377. }
  378. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  379. // Class : CTAPI
  380. // Method : UpdateAgentHandlerArray
  381. //
  382. //
  383. //
  384. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  385. HRESULT CTAPI::UpdateAgentHandlerArray()
  386. {
  387. HRESULT hr = S_OK;
  388. LPLINEAGENTCAPS pAgentCaps = NULL;
  389. GUID proxyGUID;
  390. PWSTR proxyName = NULL;
  391. BOOL foundIt;
  392. CAgentHandler * thisAgentHandler = NULL;
  393. CAddress * pCAddress = NULL;
  394. int iCount, iCount2;
  395. AgentHandlerArray activeAgentHandlerArray;
  396. LOG((TL_TRACE, "UpdateAgentHandlerArray - enter"));
  397. Lock();
  398. if (!( m_dwFlags & TAPIFLAG_INITIALIZED ) )
  399. {
  400. LOG((TL_ERROR, "UpdateAgentHandlerArray - tapi object must be initialized first" ));
  401. Unlock();
  402. return E_INVALIDARG;
  403. }
  404. Unlock();
  405. //
  406. // go through all the addresses
  407. //
  408. for ( iCount = 0; iCount < m_AddressArray.GetSize(); iCount++ )
  409. {
  410. pCAddress = dynamic_cast<CAddress *>(m_AddressArray[iCount]);
  411. if ( (pCAddress != NULL) && (pCAddress->GetAPIVersion() >= TAPI_VERSION2_2) )
  412. {
  413. hr = CheckForRequiredProxyRequests(
  414. pCAddress->GetHLineApp(),
  415. pCAddress->GetDeviceID()
  416. );
  417. }
  418. else
  419. {
  420. hr = E_FAIL;
  421. }
  422. if( SUCCEEDED(hr) )
  423. {
  424. // Call LineGetAgentCaps to get proxy name & GUID
  425. hr = LineGetAgentCaps(
  426. pCAddress->GetHLineApp(),
  427. pCAddress->GetDeviceID(),
  428. pCAddress->GetAddressID(),
  429. TAPI_CURRENT_VERSION,
  430. &pAgentCaps
  431. );
  432. LOG((TL_TRACE, hr, "UpdateAgentHandlerArray - LineGetAgentCaps"));
  433. if( SUCCEEDED(hr) )
  434. {
  435. // Get the proxy apps name string & GUID
  436. proxyName = (PWSTR)( (PBYTE)pAgentCaps + pAgentCaps->dwAgentHandlerInfoOffset);
  437. proxyGUID = pAgentCaps->ProxyGUID;
  438. #if DBG
  439. {
  440. WCHAR guidName[100];
  441. StringFromGUID2(proxyGUID, (LPOLESTR)&guidName, 100);
  442. LOG((TL_INFO, "UpdateAgentHandlerArray - Proxy Name : %S", proxyName));
  443. LOG((TL_INFO, "UpdateAgentHandlerArray - Proxy GUID %S", guidName));
  444. }
  445. #endif
  446. // Run through the list of AgentHandlers & see if we already have this one in the list
  447. // by comparing GUIDs
  448. foundIt = FALSE;
  449. Lock();
  450. for (iCount2 = 0; iCount2 < m_AgentHandlerArray.GetSize(); iCount2++ )
  451. {
  452. thisAgentHandler = dynamic_cast<CComObject<CAgentHandler>*>(m_AgentHandlerArray[iCount2]);
  453. if (thisAgentHandler != NULL)
  454. {
  455. if ( IsEqualGUID(proxyGUID , thisAgentHandler->getHandle() ) )
  456. {
  457. foundIt = TRUE;
  458. activeAgentHandlerArray.Add(m_AgentHandlerArray[iCount2]);
  459. break;
  460. }
  461. }
  462. }
  463. Unlock();
  464. if (foundIt == FALSE)
  465. {
  466. // Didn't match so lets add this AgentHandler
  467. LOG((TL_INFO, "UpdateAgentHandlerArray - create new Agent Handler" ));
  468. CComObject<CAgentHandler> * pAgentHandler;
  469. hr = CComObject<CAgentHandler>::CreateInstance( &pAgentHandler );
  470. if( SUCCEEDED(hr) )
  471. {
  472. Lock();
  473. // initialize the AgentHandler
  474. hr = pAgentHandler->Initialize(proxyName, proxyGUID, this);
  475. if( SUCCEEDED(hr) )
  476. {
  477. ITAgentHandler * pITAgentHandler;
  478. pITAgentHandler = dynamic_cast<ITAgentHandler *>(pAgentHandler);
  479. if ( NULL != pITAgentHandler )
  480. {
  481. // add to list of Agent handlers
  482. m_AgentHandlerArray.Add(pITAgentHandler);
  483. //pAgentHandler->AddRef();
  484. activeAgentHandlerArray.Add(pITAgentHandler);
  485. }
  486. LOG((TL_INFO, "UpdateAgentHandlerArray - Added AgentHandler to list"));
  487. // Now add this address to the Agent Handlers list
  488. pAgentHandler->AddAddress(pCAddress);
  489. }
  490. else
  491. {
  492. LOG((TL_ERROR, "UpdateAgentHandlerArray - Initialize AgentHandler failed" ));
  493. delete pAgentHandler;
  494. }
  495. Unlock();
  496. }
  497. else
  498. {
  499. LOG((TL_ERROR, "UpdateAgentHandlerArray - Create AgentHandler failed" ));
  500. }
  501. }
  502. else // foundIt == TRUE
  503. {
  504. LOG((TL_INFO, "UpdateAgentHandlerArray - Agent Handler exists for this proxy" ));
  505. // So just add this address to the Agent Handlers list
  506. thisAgentHandler->AddAddress(pCAddress);
  507. }
  508. }
  509. else // LineGetAgentCaps failed
  510. {
  511. LOG((TL_ERROR, "UpdateAgentHandlerArray - LineGetAgentCaps failed"));
  512. }
  513. // finished with memory block so release
  514. if ( pAgentCaps != NULL )
  515. ClientFree( pAgentCaps );
  516. }
  517. else
  518. {
  519. LOG((TL_INFO, hr, "UpdateAgentHandlerArray - CheckForRequiredProxyRequests failed"));
  520. }
  521. } // end - for ( ; iterAddr..... )
  522. Lock();
  523. for (iCount=m_AgentHandlerArray.GetSize()-1; iCount>=0; iCount--)
  524. {
  525. if (-1 == activeAgentHandlerArray.Find(m_AgentHandlerArray[iCount])) //no longer active
  526. {
  527. HRESULT hr1;
  528. BSTR pszAgentHandlerName;
  529. thisAgentHandler = dynamic_cast<CComObject<CAgentHandler>*>(m_AgentHandlerArray[iCount]);
  530. hr1 = thisAgentHandler->get_Name(&pszAgentHandlerName);
  531. m_AgentHandlerArray.RemoveAt(iCount);
  532. if ( SUCCEEDED(hr1) )
  533. {
  534. LOG((TL_TRACE, "UpdateAgentHandlerArray - Removing one AgentHandler %s from AgentHandlerTable",
  535. pszAgentHandlerName));
  536. if ( NULL != pszAgentHandlerName)
  537. SysFreeString(pszAgentHandlerName);
  538. }
  539. else
  540. {
  541. LOG((TL_TRACE, "UpdateAgentHandlerArray - Removing one AgentHandler from AgentHandlerTable"));
  542. }
  543. }
  544. }
  545. Unlock();
  546. activeAgentHandlerArray.Shutdown();
  547. hr = S_OK;
  548. LOG((TL_TRACE, hr, "UpdateAgentHandlerArray - exit"));
  549. return hr;
  550. }
  551. /////////////////////////////////////////////////////////////////////////////
  552. // ITTAPICallCenter
  553. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  554. // Class : CTAPI
  555. // Interface : ITTAPICallCenter
  556. // Method : EnumerateAgentHandlers
  557. //
  558. //
  559. //
  560. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  561. STDMETHODIMP CTAPI::EnumerateAgentHandlers(IEnumAgentHandler ** ppEnumAgentHandler)
  562. {
  563. HRESULT hr = S_OK;
  564. LOG((TL_TRACE, "EnumerateAgentHandlers - enter"));
  565. Lock();
  566. if (!( m_dwFlags & TAPIFLAG_INITIALIZED ) )
  567. {
  568. LOG((TL_ERROR, "EnumerateAgentHandlers - tapi object must be initialized first" ));
  569. Unlock();
  570. return E_INVALIDARG;
  571. }
  572. Unlock();
  573. if(!TAPIIsBadWritePtr( ppEnumAgentHandler, sizeof(IEnumAgentHandler *) ) )
  574. {
  575. UpdateAgentHandlerArray();
  576. //
  577. // create the enumerator
  578. //
  579. CComObject< CTapiEnum<IEnumAgentHandler,
  580. ITAgentHandler,
  581. &IID_IEnumAgentHandler> > * pEnum;
  582. hr = CComObject< CTapiEnum<IEnumAgentHandler,
  583. ITAgentHandler,
  584. &IID_IEnumAgentHandler> > ::CreateInstance( &pEnum );
  585. if ( SUCCEEDED(hr) )
  586. {
  587. //
  588. // initialize it with our queue list
  589. //
  590. Lock();
  591. hr = pEnum->Initialize( m_AgentHandlerArray );
  592. Unlock();
  593. if ( SUCCEEDED(hr) )
  594. {
  595. // return it
  596. *ppEnumAgentHandler = pEnum;
  597. }
  598. else
  599. {
  600. LOG((TL_ERROR, "EnumerateAgentHandlers - could not initialize enum" ));
  601. pEnum->Release();
  602. }
  603. }
  604. else
  605. {
  606. LOG((TL_ERROR, "EnumerateAgentHandlers - could not create enum" ));
  607. }
  608. }
  609. else
  610. {
  611. LOG((TL_ERROR, "EnumerateAgentHandlers - bad ppEnumAgentHandler pointer" ));
  612. hr = E_POINTER;
  613. }
  614. LOG((TL_TRACE, hr, "EnumerateAgentHandlers - exit"));
  615. return hr;
  616. }
  617. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  618. // Class : CTAPI
  619. // Interface : ITTAPICallCenter
  620. // Method : get_AgentHandlers
  621. //
  622. // Return a collection of AgentHandlers
  623. //
  624. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  625. STDMETHODIMP CTAPI::get_AgentHandlers(VARIANT * pVariant)
  626. {
  627. HRESULT hr = S_OK;
  628. IDispatch * pDisp = NULL;
  629. LOG((TL_TRACE, "get_AgentHandlers - enter"));
  630. Lock();
  631. if (!( m_dwFlags & TAPIFLAG_INITIALIZED ) )
  632. {
  633. LOG((TL_ERROR, "get_AgentHandlers - tapi object must be initialized first" ));
  634. Unlock();
  635. return E_INVALIDARG;
  636. }
  637. Unlock();
  638. if (!TAPIIsBadWritePtr( pVariant, sizeof(VARIANT) ) )
  639. {
  640. UpdateAgentHandlerArray();
  641. //
  642. // create the collection
  643. //
  644. CComObject< CTapiCollection< ITAgentHandler > > * p;
  645. hr = CComObject< CTapiCollection< ITAgentHandler > >::CreateInstance( &p );
  646. if (SUCCEEDED(hr) )
  647. {
  648. // initialize it with our address list
  649. Lock();
  650. hr = p->Initialize( m_AgentHandlerArray );
  651. Unlock();
  652. if ( SUCCEEDED(hr) )
  653. {
  654. // get the IDispatch interface
  655. hr = p->_InternalQueryInterface( IID_IDispatch, (void **) &pDisp );
  656. if ( SUCCEEDED(hr) )
  657. {
  658. // put it in the variant
  659. VariantInit(pVariant);
  660. pVariant->vt = VT_DISPATCH;
  661. pVariant->pdispVal = pDisp;
  662. }
  663. else
  664. {
  665. LOG((TL_ERROR, "get_AgentHandlers - could not get IDispatch interface" ));
  666. delete p;
  667. }
  668. }
  669. else
  670. {
  671. LOG((TL_ERROR, "get_AgentHandlers - could not initialize collection" ));
  672. delete p;
  673. }
  674. }
  675. else
  676. {
  677. LOG((TL_ERROR, "get_AgentHandlers - could not create collection" ));
  678. }
  679. }
  680. else
  681. {
  682. LOG((TL_ERROR, "get_AgentHandlers - bad pVariant pointer" ));
  683. hr = E_POINTER;
  684. }
  685. LOG((TL_TRACE, hr, "get_AgentHandlers - exit"));
  686. return hr;
  687. }