Cisco Cisco Computer Telephony Integration Option 8.5 Developer's Guide

Page of 640
 
Chapter 4      Building Your Application
Logging In and Logging Out an Agent
4-50
CTI OS Developer’s Guide for Cisco ICM/IPCC Enterprise & Hosted Editions Release 7.0(0)
Typical Logout Procedure
When the Logout button is clicked – the following actions need to happen:
1.
Call  Logout request on your current agent.
 
You need to call Logout and not use SetAgentState(eLogout), because Logout 
provides additional logic to support pre-Logout notification, Logout failure 
notification, and resource cleanup.
 
Here’s the sample code for the same:
if(m_ctiAgent)
{
   Arguments &rArgAgentLogout = Arguments::CreateInstance();
   //add reason code if needed
   rArgAgentLogout.AddItem(CTIOS_EVENTREASONCODE, reasonCode);
   int nRetVal = m_ctiAgent->Logout(rArgAgentLogout);
   rArgAgentLogout.Release();
}
 
2.
Receive a response for the Logout request. 
 
You can expect the following events in response to a Logout request:
  –
OnAgentStateChange (with Logout agent state)  
 
or 
 
OnControlFailure (with the reason for the failure). 
  –
OnPostLogout (you will additionally receive this event if the Logout 
request succeeds.
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) )
   {