📄 eventsink.java
字号:
/* //////////////////////////////////////////////////////////////////////////
EventSink.java
-------------------------------------------------------------------------
Copyright (c) 2003
Cisco Systems, Inc.
All rights reserved.
Confidential restricted material. This work contains confidential trade
secrets of Cisco Systems, Inc. Use, examination, copying, transfer and/or
disclosure to others are prohibited, except with the express written
agreement of Cisco Systems, Inc.
The JavaPhone sample is intended to serve as an example of opening an
AgentMode connection to CTIOS for a programmer using the CTIOS JavaCIL
to develop a client application such as an Agent Desktop.
This sample illustrates how to connect to the server, login an agent,
make calls, set a call variable, recieve events and look at their
contents, and other operations.
This is only a sample and is NOT intended to be a production quality
application and will not be supported as such. It is NOT guaranteed to
be bug free. It is merely provided as a guide for a programmer to see
how to establish a AgentMode connection, control an Agent, receive events,
and manipulate Session objects.
///////////////////////////////////////////////////////////////////////// */
import java.awt.*;
import javax.swing.SwingUtilities;
import java.util.*;
import java.lang.*;
import java.io.*;
import com.cisco.cti.ctios.cil.*;
import com.cisco.cti.ctios.util.*;
///////////////////////////////////////////////////////////////////////////
/**
* The <code>EventSink</code> implements the IGenericEvents interface and
* serves as the CTI event listener. It contains handlers for all the
* events that we're interested in.
*/
///////////////////////////////////////////////////////////////////////////
public class EventSink implements IGenericEvents,
CtiOs_IKeywordIDs,
CtiOs_Enums.CilError,
CtiOs_Enums.EventID,
CtiOs_Enums.AgentState,
CtiOs_Enums.ButtonEnablement
{
protected JavaPhoneFrame m_appFrame; // Reference to main app Frame
protected CtiOsSession m_ctiSession; // Reference to CTI OS Session object (created in Frame
protected String m_cs; // String to use as Sync object
protected boolean m_bLoginPending = false; // Login in progress flag
protected LogManager m_log = LogManager.Instance(); // Tracing Mechanism
///////////////////////////////////////////////////////////////////////////
/**
* Constructor for the EventSink object. It takes a reference to the main
* app frame that created it so it can update the GUI
*/
///////////////////////////////////////////////////////////////////////////
public EventSink(JavaPhoneFrame appFrame)
{
// Initialize the object we're going to use for thread synchronization
m_cs = "EventSink_cs_" + this.hashCode();
m_ctiSession = appFrame.GetCtiosSession();
m_appFrame = appFrame;
} // Constructor
///////////////////////////////////////////////////////////////////////////
/**
* Implementation of the OnEvent() handler from the IGenericEvents
* interface. All CTI Events will be posted to this method once the
* EventSink object is subscribed for events with the Session. This method
* then checks for the events it's interested in and calls a separate
* event handler for the particular event.
*/
///////////////////////////////////////////////////////////////////////////
public void OnEvent(int iEventID, Arguments rArguments)
{
switch (iEventID)
{
case eAgentStateEvent:
OnAgentStateChange(rArguments);
break;
case eButtonEnablementMaskChange:
OnButtonEnablementChange(rArguments);
break;
case eCallBeginEvent:
OnCallBegin(rArguments);
break;
case eCallConferencedEvent:
OnCallConferenced(rArguments);
break;
case eCallConnectionClearedEvent:
OnCallConnectionCleared(rArguments);
break;
case eCallDeliveredEvent:
OnCallDelivered(rArguments);
break;
case eCallEndEvent:
OnCallEnd(rArguments);
break;
case eCallEstablishedEvent:
OnCallEstablished(rArguments);
break;
case eCallHeldEvent:
OnCallHeld(rArguments);
break;
case eCallRetrievedEvent:
OnCallRetrieved(rArguments);
break;
case eCallTransferredEvent:
OnCallTransferred(rArguments);
break;
case eOnConnection:
OnConnection(rArguments);
break;
case eOnConnectionClosed:
OnConnectionClosed(rArguments);
break;
case eOnConnectionFailure:
OnConnectionFailure(rArguments);
break;
case eOnConnectionRejected:
OnConnectionRejected(rArguments);
break;
case eQueryAgentStateConf:
OnQueryAgentStateConf(rArguments);
break;
case eSetAgentModeEvent:
OnSetAgentModeEvent(rArguments);
break;
case eSnapshotCallConf:
OnSnapshotCallConf(rArguments);
break;
case eControlFailureConf:
OnControlFailureConf(rArguments);
break;
case eFailureEvent:
OnFailure(rArguments);
break;
case eFailureConf:
OnFailureConf(rArguments);
break;
case eCallFailedEvent:
OnCallFailed(rArguments);
break;
case eCTIOSFailureEvent:
OnCTIOSFailure(rArguments);
break;
}
} // OnEvent
// Session Events
///////////////////////////////////////////////////////////////////////////
/**
* Event signifying successful connection to the CTI OS server
*/
///////////////////////////////////////////////////////////////////////////
public void OnConnection(Arguments rArguments)
{
m_appFrame.LogEvent("OnConnection", rArguments);
SetLoginPending(false);
m_appFrame.Log("You can Login now!");
m_appFrame.SetSessionConnected(true);
// Transfer modifacation of the GUI objects to the EventDispatchThread
// or we could have a thread sync issue. We're currently on the
// CtiOsSession's event thread
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
m_appFrame.m_edtConnection.setText("Connected");
m_appFrame.m_btnLogin.setEnabled(true);
}
});
} // OnConnection
///////////////////////////////////////////////////////////////////////////
/**
* Event signifying connection to the CTI OS server was lost unexpectedly
*/
///////////////////////////////////////////////////////////////////////////
public void OnConnectionFailure(Arguments rArguments)
{
m_appFrame.LogEvent("OnConnectionFailure", rArguments);
SetLoginPending(false);
DisableAllButtons();
} // OnConnectionFailure
///////////////////////////////////////////////////////////////////////////
/**
* Event signifying connection to the CTI OS server was rejected by the
* server because it is unable to support the requested protocol.
*/
///////////////////////////////////////////////////////////////////////////
public void OnConnectionRejected(Arguments rArguments)
{
m_appFrame.LogEvent("OnConnectionRejected", rArguments);
SetLoginPending(false);
// Transfer modifacation of the GUI objects to the EventDispatchThread
// or we could have a thread sync issue. We're currently on the
// CtiOsSession's event thread
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
m_appFrame.m_edtConnection.setText("Offline");
}
});
m_appFrame.SetSessionConnected(false);
DisableAllButtons();
} // OnConnectionRejected
///////////////////////////////////////////////////////////////////////////
/**
* Event signifying connection to the CTI OS server was closed after
* requesting to close it.
*/
///////////////////////////////////////////////////////////////////////////
public void OnConnectionClosed(Arguments rArguments)
{
m_appFrame.LogEvent("OnConnectionClosed", rArguments);
SetLoginPending(false);
// Transfer modifacation of the GUI objects to the EventDispatchThread
// or we could have a thread sync issue. We're currently on the
// CtiOsSession's event thread
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
m_appFrame.m_edtConnection.setText("Offline");
}
});
m_appFrame.SetSessionConnected(false);
DisableAllButtons();
} // OnConnectionClosed
///////////////////////////////////////////////////////////////////////////
/**
* Indicates the current Agent's state has changed for a particular
* skillgroup.
*/
///////////////////////////////////////////////////////////////////////////
public void OnAgentStateChange(Arguments rArguments)
{
if (IsMonitoredEvent(rArguments))
return;
m_appFrame.LogEvent("OnAgentStateChange", rArguments);
// Retrieve new agent state from event args and display it on the dialog
Integer IState = rArguments.GetValueIntObj(CTIOS_AGENTSTATE);
int iState = (null==IState) ? eUnknown : IState.intValue();
m_appFrame.SetAgentStateText( iState );
if (m_appFrame.IsLoginInProgress())
{
if (iState != eUnknown && iState != eLogout)
{
m_appFrame.SetLoginInProgress(false);
}
}
} // OnAgentStateChange
///////////////////////////////////////////////////////////////////////////
/**
* Response to a request inquiring for the Agent's current state.
*/
///////////////////////////////////////////////////////////////////////////
public void OnQueryAgentStateConf(Arguments rArguments)
{
if (IsMonitoredEvent(rArguments))
return;
m_appFrame.LogEvent("OnQueryAgentStateConf", rArguments);
// Retrieve new agent state from event args and display it on the dialog
Integer IState = rArguments.GetValueIntObj(CTIOS_AGENTSTATE);
int iState = (null==IState) ? eUnknown : IState.intValue();
m_appFrame.SetAgentStateText( iState );
if (m_appFrame.IsLoginInProgress())
{
if (iState != eUnknown && iState != eLogout)
{
m_appFrame.SetLoginInProgress(false);
}
}
} // OnQueryAgentStateConf
// Methods derived from ICallEvents
///////////////////////////////////////////////////////////////////////////
/**
* Event indicating a new Call started.
*/
///////////////////////////////////////////////////////////////////////////
public void OnCallBegin(Arguments rArguments)
{
if (IsMonitoredEvent(rArguments))
return;
m_appFrame.LogEvent("OnCallBegin", rArguments);
DisplayCallInfo(rArguments);
// Get a reference to the call object, reset as our default call
String sUID = rArguments.GetValueString(CTIOS_UNIQUEOBJECTID);
Call rCall = (Call) m_ctiSession.GetObjectFromObjectID(sUID);
m_ctiSession.SetCurrentCall(rCall);
// Dump the properties out to the Trace mechanism
m_log.Trace(Logger.TRACE_MASK_ALWAYS, rCall.DumpProperties());
} // OnCallBegin
///////////////////////////////////////////////////////////////////////////
/**
* Response to a request by the CIL to "snapshot" a call. This event
* provides the current context for the requested call. This usually
* occurs after a login/failover when there is a call on the device or
* there was before a failover.
*/
///////////////////////////////////////////////////////////////////////////
public void OnSnapshotCallConf(Arguments rArguments)
{
if (IsMonitoredEvent(rArguments))
return;
m_appFrame.LogEvent("OnSnapshotCallConf", rArguments);
} // OnSnapshotCallConf
///////////////////////////////////////////////////////////////////////////
/**
* Response to a request by the CIL to "snapshot" a device to find out
* what calls are on it.
*/
///////////////////////////////////////////////////////////////////////////
public void OnSnapshotDeviceConf(Arguments rArguments)
{
if (IsMonitoredEvent(rArguments))
return;
m_appFrame.LogEvent("OnSnapshotDeviceConf", rArguments);
} // OnSnapshotDeviceConf
///////////////////////////////////////////////////////////////////////////
/**
* Notification that a particular call has ended.
*/
///////////////////////////////////////////////////////////////////////////
public void OnCallEnd(Arguments rArguments)
{
if (IsMonitoredEvent(rArguments))
return;
m_appFrame.LogEvent("OnCallEnd", rArguments);
// Transfer modifacation of the GUI objects to the EventDispatchThread
// or we could have a thread sync issue. We're currently on the
// CtiOsSession's event thread
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
m_appFrame.m_edtCallID.setText("no call");
}
});
} // OnCallEnd
///////////////////////////////////////////////////////////////////////////
/**
* Notification that a call has been delivered to a device and is alerting
* (ringing)
*/
///////////////////////////////////////////////////////////////////////////
public void OnCallDelivered(Arguments rArguments)
{
if (IsMonitoredEvent(rArguments))
return;
m_appFrame.LogEvent("OnCallDelivered", rArguments);
} // OnCallDelivered
///////////////////////////////////////////////////////////////////////////
/**
* Notification that a call has been answered by the alerting device
*/
///////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -