Cisco Cisco Computer Telephony Integration Option 9.0 Guida Dello Sviluppatore

Pagina di 500
   
4-36
CTI OS Developer’s Guide for Cisco Unified ICM/Contact Center Enterprise & Hosted
Release 7.5(1)
Chapter 4      Building Your Application
Logging In and Logging Out an Agent
Note
Note that you may  disable statistics either prior to issuing the Logout request or upon receipt of 
the OnAgentStateChange to logout state. Use the OnPostLogout event to trigger session 
disconnect. This will guarantee that all event listeners can make CTIOS server requests in 
response to the logout OnAgentStateChange event.
See the following example code:
void CMyAppEventSink::OnPostLogout(Arguments & rArguments )
{
   // Do not Disconnect if the reason code is Forced Logout
   // (particular failover case):
   int nAgentState = 0;
   if ( rArguments.GetValueInt(CTIOS_AGENTSTATE, &nAgentState) )
   {
      if (nAgentState == eLogout)
      {
         int nReasonCode = 0;
         if ( rArguments.GetValueInt(CTIOS_EVENTREASONCODE,
&nReasonCode) )
         {
            if (CTIOS_IPCC_FORCED_LOGOUT_REASON_CODE == 
(unsigned short)nReasonCode)
            {
               return;
            }
         }
      }
   }
   //Disconnect otherwise
   if( IsConnected() ) //if session is connected
   {
      if(m_ctiSession)
      {
         m_ctiSession->Disconnect();
      }
   }
}
3.
If you are not concerned with whether the agent is successfully logged out prior to disconnect, issue 
a session Disconnect request without a Logout request.
4.
Additionally, you must wait for OnConnectionClosed before destroying Agent and Session objects. 
This will guarantee that the CIL has completed cleanup of the Session object prior to your calling 
Release on these objects.
5.
Ensure that the agent object is set to NULL in the session before you Release the session object. For 
example, whenever your application is exiting and you are disconnecting the session object (e.g. 
when the user closes your application's window) you should do something similar to the code below:
if (m_ctiSession)
{
m_ctiSession->Disconnect();
// stop all events for this session
int nRetVal =
m_pctiSession->RemoveAllInOneEventListener((IAllInOne *)
m_pmyEventSink);
//The application is closing, remove current agent from session