📄 callroutingdlg.cpp
字号:
// CallRoutingDlg.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h" // replace with theApp header if needed
#include "CallRoutingDlg.h"
#include "opentsrv.h"
#include "utilities.h"
// For non-MFC folks, this map replaces the large "switch" statement found in
// straight C Windows programs. The ON_MESSAGE() lines were added manually.
// Read them as "when a message of type {first argument} is received, call
// the method {second argument}"
BEGIN_MESSAGE_MAP(CallRoutingDlg, CDialog)
ON_MESSAGE(WM_TSAPICSTACONFIRMATION, OnTsapiCstaConfirmation)
ON_MESSAGE(WM_TSAPICSTAUNSOLICITED, OnTsapiCstaUnsolicited)
ON_MESSAGE(WM_TSAPICSTAREQUEST, OnTsapiCstaRequest)
//{{AFX_MSG_MAP(CallRoutingDlg)
/*
ON_BN_CLICKED(IDC_CALL, OnCall)
ON_BN_CLICKED(IDC_HANGUP, OnHangup)
ON_EN_CHANGE(IDC_TODEVICEID, OnChangeTodeviceid)
*/
ON_WM_TIMER()
//}}AFX_MSG_MAP
//ON_LBN_SELCHANGE(IDC_LOGLIST, &CallRoutingDlg::OnLbnSelchangeLoglist)
ON_BN_CLICKED(IDC_ADD, &CallRoutingDlg::OnBnClickedAdd)
ON_BN_CLICKED(IDC_DELETE, &CallRoutingDlg::OnBnClickedDelete)
ON_BN_CLICKED(IDC_MOVEUP, &CallRoutingDlg::OnBnClickedMoveup)
ON_BN_CLICKED(IDC_MOVEDOWN, &CallRoutingDlg::OnBnClickedMovedown)
ON_BN_CLICKED(IDC_SET, &CallRoutingDlg::OnBnClickedSet)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_RULE_LIST, &CallRoutingDlg::OnLvnItemchangedRuleList)
ON_NOTIFY(NM_CLICK, IDC_RULE_LIST, &CallRoutingDlg::OnNMClickRuleList)
END_MESSAGE_MAP()
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CallRoutingDlg dialog
CallRoutingDlg::CallRoutingDlg(CWnd* pParent /*=NULL*/)
: CDialog(CallRoutingDlg::IDD, pParent)
, m_lowerBound(_T(""))
, m_upperBound(_T(""))
, m_destination(_T(""))
, m_DefaultRoute(_T(""))
, m_UUMessage(_T(""))
{
//{{AFX_DATA_INIT(CallRoutingDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_TsapiWndPtr = 0;
m_CallHandle = 0;
routeRegisterReqID = 0;
item =0;
ruleItem =0;
// m_LogListControl.InsertColumn( LOG_DIRECTION, "Time",
// LVCFMT_LEFT, 50, LOG_DIRECTION);
// UpdateData(FALSE);
}
// For non-MFC folks, this is a helper routine for passing data back-and-forth
// from this class to the Open Tserver dialog.
void CallRoutingDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COpenTsrv)
DDX_Control(pDX, IDC_LOGLIST, m_LogListControl);
//}}AFX_DATA_MAP
DDX_Text(pDX, IDC_EDIT1, m_lowerBound);
DDX_Text(pDX, IDC_EDIT2, m_upperBound);
DDX_Control(pDX, IDC_EDIT1, m_lowerBoundControl);
DDX_Control(pDX, IDC_EDIT2, m_upperBoundControl);
DDV_MaxChars(pDX, m_lowerBound, 7);
DDX_Control(pDX, IDC_EDIT3, m_destinationControl);
DDX_Text(pDX, IDC_EDIT3, m_destination);
DDV_MaxChars(pDX, m_destination, 10);
DDX_Control(pDX, IDC_RULE_LIST, m_RuleListControl);
DDX_Control(pDX, IDC_EDIT4, m_DefaultRouteControl);
DDX_Text(pDX, IDC_EDIT4, m_DefaultRoute);
DDV_MaxChars(pDX, m_DefaultRoute, 10);
DDX_Control(pDX, IDC_EDIT5, m_UUMessageControl);
DDX_Text(pDX, IDC_EDIT5, m_UUMessage);
}
CallRoutingDlg::~CallRoutingDlg()
{
// delete the hidden TSAPI window
if(m_TsapiWndPtr)
{
delete m_TsapiWndPtr;
}
}
/////////////////////////////////////////////////////////////////////////////
// CallRoutingDlg message handlers
BOOL CallRoutingDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// setting a timer allows the dialog to be displayed before initialization is
// completed - the init will be completed when the timer fires.
if(!SetTimer(1, 1, NULL))
{
// if the timer can't be set, just call the OnTimer() method manually so
// initialization can complete.
OnTimer(1);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CallRoutingDlg::OnTimer(UINT nIDEvent)
{
// finish initialization...
// ok to kill the timer even if it wasn't active (i.e. in the failure case from
// OnInitDialog().
KillTimer(nIDEvent);
// the class that calls COpenTsrv's DoModal() method is responsible
// for the CTsapiWnd object that will be created. It will be this
// classes responsibility to handle CTsapiWnd memory clean-up (delete
// the CTsapiWnd object) and also this classes responsibility to decide
// what to do on failures of the TSAPI stream.
COpenTsrv openDlg;
openDlg.m_TsapiController = (CWnd*)this;
if(openDlg.DoModal() != IDOK)
{
PostMessage(WM_COMMAND, IDCANCEL, 0);
return;
}
// retrieve the specified device to be monitored and the hidden TSAPI window
m_TsapiWndPtr = openDlg.m_TsapiWndPtr;
m_LogListControl.InsertColumn( LOG_TIME, "TIME", LVCFMT_LEFT, 185, LOG_TIME);
m_LogListControl.InsertColumn( LOG_MESSAGE, "LOG MESSAGE", LVCFMT_LEFT, 585, LOG_MESSAGE);
m_RuleListControl.InsertColumn(RULE_NUMBER, "Rule #", LVCFMT_LEFT, 60, LOWER_BOUND);
m_RuleListControl.InsertColumn(LOWER_BOUND, "From", LVCFMT_LEFT, 73, LOWER_BOUND);
m_RuleListControl.InsertColumn( UPPER_BOUND, "To ", LVCFMT_LEFT, 73, UPPER_BOUND);
m_RuleListControl.InsertColumn( DESTINATION, "Destination ", LVCFMT_LEFT,75, DESTINATION);
TO_MESSAGE_WINDOW("Registering this application as "+g_vdn+" router");
RegisterRoutingServer(g_vdn.GetString());
UpdateRuleList();
char buff[11];
_ultoa_s(g_defaultRoute,buff,10);
m_DefaultRoute.SetString(buff);
m_UUMessage.SetString(g_appendString);
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
LRESULT CallRoutingDlg::OnTsapiCstaConfirmation(WPARAM wParam, LPARAM lParam)
{
// this dialog should either get a monitor conf event or
// a universal failure event
switch(m_TsapiWndPtr->m_EventBufPtr->eventHeader.eventType)
{
case CSTA_ROUTE_REGISTER_REQ_CONF:
{
routeRegistrationSuccessful = true;
CSTAConfirmationEvent * pUns = &(m_TsapiWndPtr->m_EventBufPtr->event.cstaConfirmation);
routeRegisterReqID = pUns->u.routeRegister.registerReqID;
// AfxMessageBox("Routing Confirmed");
TO_MESSAGE_WINDOW("Received CSTA_ROUTE_REGISTER_REQ_CONF. Registration confirmed");
}
break;
case CSTA_MONITOR_CONF:
// this is what we want...
break;
case CSTA_UNIVERSAL_FAILURE_CONF:
// failure for some reason. failure codes are listed in cstadefs.h.
if(routeRegistrationSuccessful)
cstaRouteRegisterCancel(m_TsapiWndPtr->m_AcsHandle, (InvokeID_t) this,routeRegisterReqID, NULL);
acsAbortStream(m_TsapiWndPtr->m_AcsHandle, NULL);
delete m_TsapiWndPtr;
m_TsapiWndPtr = 0;
AfxMessageBox("monitor device failed");
return 0;
case CSTA_ROUTE_REQUEST:
AfxMessageBox("CSTA_ROUTE_REQUEST");
break;
default:
if(routeRegistrationSuccessful)
cstaRouteRegisterCancel(m_TsapiWndPtr->m_AcsHandle, (InvokeID_t) this,routeRegisterReqID, NULL);
acsAbortStream(m_TsapiWndPtr->m_AcsHandle, NULL);
delete m_TsapiWndPtr;
m_TsapiWndPtr = 0;
AfxMessageBox("unexpected response to cstaMonitorDevice");
return 0;
}
// now the open tserver dialog can be dismissed.
// The calling class is now responsible for the CTsapiWnd memory clean-up
return 0;
}
LRESULT CallRoutingDlg::RegisterRoutingServer(const char * device)
{
//An application may be a routing server for more that one routing device. However,
// for a specific routing device, the G3PD allows only one application registered as the
// routing server. If a routing device already has a routing server registered, subsequent
// cstaRouteRegisterReq() requests will be negatively acknowledged.
routeRegistrationSuccessful = false;
DeviceID_t vdnDevice;
lstrcpy( vdnDevice, device);
RetCode_t rc = cstaRouteRegisterReq(m_TsapiWndPtr->m_AcsHandle,(InvokeID_t)this, &vdnDevice,0);
if(rc < 0)
{
// failure for some reason, specified in rc as a RetCode_t (defined in acs.h).
rc = acsAbortStream(m_TsapiWndPtr->m_AcsHandle, NULL);
delete m_TsapiWndPtr;
m_TsapiWndPtr = 0;
TO_MESSAGE_WINDOW("Failed to register for the events");
AfxMessageBox("cstaRouteRegisterReq failed. Restart TSAPI CallRouting server");
return 0;
}
return 0;
}
LRESULT CallRoutingDlg::OnTsapiCstaUnsolicited(WPARAM wParam, LPARAM lParam)
{
// Get the device record pointer out of the lParam
// Get the unsolicited event pointer out of the event buffer (for
// code efficiency and typing efficiency)
CTsapiDevice* pTsapi = (CTsapiDevice*)lParam;
CSTAUnsolicitedEvent* pUns = &(m_TsapiWndPtr->m_EventBufPtr->event.cstaUnsolicited);
switch(m_TsapiWndPtr->m_EventBufPtr->eventHeader.eventType)
{
// this is not a call-control event. just end the app if the monitor
// of the device was terminated for any reason.
case CSTA_MONITOR_ENDED:
AfxMessageBox("monitor failure");
PostMessage(WM_COMMAND, IDCANCEL, 0);
return 0;
// these are call-control events...
case CSTA_SERVICE_INITIATED: // null -> initiated (LOCAL only)
{
break;
}
case CSTA_ORIGINATED: // null/initiated -> connected (LOCAL only)
{
break;
}
case CSTA_DELIVERED: // null -> alerting
{
break;
}
case CSTA_NETWORK_REACHED: // null -> connected (REMOTE only)
{
break;
}
case CSTA_ESTABLISHED: // alerting/connected -> connected
{
break;
}
case CSTA_CALL_CLEARED: // * -> null (for all connections in call)
{
break;
}
case CSTA_CONNECTION_CLEARED: // * -> null
{
break;
}
default:
// unhandled message - ignore it
return 0;
}
// update the status of buttons and fields
// update the contents of fields
UpdateData(FALSE);
return 0;
}
LRESULT CallRoutingDlg::OnTsapiCstaRequest(WPARAM wParam, LPARAM lParam)
{
static char func[]="CallRoutingDlg::OnTsapiCstaRequest";
CSTARequestEvent * pUns = &(m_TsapiWndPtr->m_EventBufPtr->event.cstaRequest);
//AfxMessageBox("Route Request received");
switch(m_TsapiWndPtr->m_EventBufPtr->eventHeader.eventType) {
case CSTA_ROUTE_REQUEST:
{
CSTARouteRequestEvent_t *routeRequest = &(pUns->u.routeRequest);
break;
}
case CSTA_RE_ROUTE_REQUEST:
{
RoutingCrossRefID_t routingCrossRefID;
CSTAReRouteRequest_t *reRouteRequest = &(pUns->u.reRouteRequest);
routingCrossRefID = reRouteRequest->routingCrossRefID;
DeviceID_t device;
char message[100];
RetCode_t rc;
sprintf(device,"%d",g_defaultRoute);
rc = cstaRouteSelectInv(
m_TsapiWndPtr->m_AcsHandle,
(InvokeID_t)this, // Version 2
routeRegisterReqID,
routingCrossRefID,
&device,
0,
0,
0,
0 // no privateData buffer here
);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -