📄 callroutingdlg.cpp
字号:
sprintf(message, "Reroute request received. Sending to default route %d",g_defaultRoute);
TO_MESSAGE_WINDOW(message);
DBG1_OUT(func,"%s",message);
}
break;
case CSTA_ROUTE_REQUEST_EXT:
{
//We need to obtain this handle from the
// event and use that handle to re route the call
RoutingCrossRefID_t routingCrossRefID;
CSTARouteRequestExtEvent_t *routeRequestExt = &(pUns->u.routeRequestExt);
routingCrossRefID = routeRequestExt->routingCrossRefID;
//get calling device id
CallingDeviceID_t * callingDeviceID = &(routeRequestExt->callingDevice);
//get called device id
CalledDeviceID_t * deviceID = &(routeRequestExt->currentRoute);
// SetUpValues_t *setupValue = & (routeRequestExt->setupInformation);
if ( m_TsapiWndPtr->m_AttPrivateData.length > 0 )
{
//get user dialed digits (CollectDigits setup from vector)
char *data = m_TsapiWndPtr->m_AttEvent.u.routeRequest.userEnteredCode.data;
char buffer[100];
memset(buffer, 0, sizeof(buffer));
switch (m_TsapiWndPtr->m_AttEvent.eventType)
{
case ATT_ROUTE_REQUEST:
{
char message[100];
int acctNum = atoi(data);
DeviceID_t device;
ATTPrivateData_t privateData;
RetCode_t rc;
sprintf(message,"Received CSTA_ROUTE_REQUEST_EXT. Calling Device %s Account Number %s",callingDeviceID->deviceID,data);
TO_MESSAGE_WINDOW(message);
DBG1_OUT( func, "%s", message);
//In this case the message tye is ASCII.
// strcpy(buffer,data);
//strcat(buffer,g_appendString);
if(g_appendString.GetLength() > 0)
{
ATTUserToUserInfo_t userInfo;
userInfo.type = UUI_IA5_ASCII;
strcpy(buffer,g_appendString);
userInfo.data.length = strlen(buffer);
(void)strcpy((char *)userInfo.data.value,buffer);
//The private data version we are using is V7
//create the private data structure with the UUI data
rc = attV7RouteSelect(&privateData, 0, 0, false, 0,0,0,&userInfo, (ATTRedirectType_t )g_callRoutingType);
} else
{
rc = attV7RouteSelect(&privateData, 0, 0, false, 0,0,0,0, (ATTRedirectType_t )g_callRoutingType);
}
if(rc < 0)
{
// failure for some reason, specified in rc as a RetCode_t (defined in acs.h).
sprintf(message,"Failed to Initiate private data attV7RouteSelect");
DBG1_OUT( func, message);
TO_MESSAGE_WINDOW(message);
return 0;
}
//get the route information from rule database.
int deviceId = getRoute(acctNum);
sprintf(device,"%d",deviceId);
//Route the call for according to the selected route
rc = cstaRouteSelectInv(
m_TsapiWndPtr->m_AcsHandle,
(InvokeID_t)this, // Version 2
routeRegisterReqID,
routingCrossRefID,
&device,
0,
0,
0,
(PrivateData_t *)&privateData // pass a pointer to the privateData buffer here
);
if(rc == 0)
sprintf(message,"Routed incoming call from %s to %d\0", callingDeviceID->deviceID,deviceId);
else
sprintf(message, "Failed to Route incoming call from %s to %d\0", callingDeviceID->deviceID,deviceId);
DBG1_OUT( func, "%s", message);
TO_MESSAGE_WINDOW(message);
break;
}
case ATTV5_ROUTE_REQUEST:
break;
default:
break;
}
}
}
break;
default:
break;
}
return 0;
}
void CallRoutingDlg::toMessageWindow(CString message)
{
char timeStamp[50];
int nIndex = m_LogListControl.InsertItem(item++,TimeStamp(timeStamp));
m_LogListControl.SetItemText(nIndex,LOG_MESSAGE,message.GetString());
}
int CallRoutingDlg::getRoute(int account) {
int i = 0;
for(rulesIt = rules.begin(); rulesIt != rules.end(); i++, rulesIt++)
{
if(((CRule)*rulesIt).belongs(account)) {
char message[200];
char ruleBuff[100];
((CRule)*rulesIt).toString(ruleBuff);
sprintf(message, "Rule %d [ %s ] matched", i, ruleBuff);
TO_MESSAGE_WINDOW(message);
return (((CRule)*rulesIt).getRoute());
}
}
TO_MESSAGE_WINDOW("No Rule Matched. Sending to Default Route "+g_defaultRoute);
return g_defaultRoute;
}
void CallRoutingDlg::OnBnClickedAdd()
{
UpdateData(TRUE);
// TODO: Add your control notification handler code here
int lb = atoi((const char *) m_lowerBound.GetString());
int up = atoi((const char * )m_upperBound.GetString());
int dest = atoi((const char * )m_destination.GetString());
CRule r(lb,up,dest);
rules.push_back(r);
char temp[50];
char message[100];
r.toString(temp);
sprintf(message, "New Rule %d Added [ %s ] ",(rules.size()-1),r.toString( temp));
TO_MESSAGE_WINDOW(message);
UpdateRuleList();
}
void CallRoutingDlg::OnBnClickedDelete()
{
// TODO: Add your control notification handler code here
UINT position = GetSelectedRuleNumber();
DeleteRule(position) ;
char message[100];
sprintf(message, "Rule %d deleted ", position);
TO_MESSAGE_WINDOW(message);
UpdateRuleList();
}
void CallRoutingDlg::UpdateRuleList() {
m_RuleListControl.DeleteAllItems();
ruleItem =1;
for(rulesIt = rules.begin(); rulesIt != rules.end(); rulesIt++)
{
CRule r = ((CRule)*rulesIt);
char buff[50];
_ultoa_s(ruleItem,buff,10);
int nIndex = m_RuleListControl.InsertItem(ruleItem++, buff);
_ultoa_s(r.getLowerBound(),buff,10);
m_RuleListControl.SetItemText(nIndex,LOWER_BOUND, buff);
_ultoa_s(r.getUpperBound(),buff,10);
m_RuleListControl.SetItemText(nIndex,UPPER_BOUND, buff);
_ultoa_s(r.getRoute(),buff,10);
m_RuleListControl.SetItemText(nIndex,DESTINATION, buff);
}
// m_LogListControl.SetItemText(nIndex,LOG_MESSAGE,message.GetString());
}
void CallRoutingDlg::OnBnClickedMoveup()
{
//m_RuleListControl.GetSelectedColumn
// TODO: Add your control notification handler code here
UINT position = GetSelectedRuleNumber();
if(position > 1) {
ChangeRulePosition(position, (position -1), false);
char message[100];
sprintf(message, "Rule %d moved to %d ", position, (position -1));
TO_MESSAGE_WINDOW(message);
}
}
void CallRoutingDlg::OnBnClickedMovedown()
{
// TODO: Add your control notification handler code here
UINT position = GetSelectedRuleNumber();
if(position < rules.size()) {
ChangeRulePosition(position, (position + 1), true);
char message[100];
sprintf(message, "Rule %d moved to %d ", position, (position + 1));
TO_MESSAGE_WINDOW(message);
}
}
void CallRoutingDlg::OnBnClickedSet()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
g_appendString.SetString(m_UUMessage);
g_defaultRoute = atoi((const char *)m_DefaultRoute.GetString());
}
UINT CallRoutingDlg::GetSelectedRuleNumber() {
static char func[] = "CallRoutingDlg::GetSelectedRuleNumber";
CString text;
LV_ITEM lvItem;
lvItem.iItem = m_RuleListControl.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
lvItem.iSubItem = 0;
lvItem.mask = LVIF_PARAM;
if ( m_RuleListControl.GetItem(&lvItem) )
{
// we got it ... now set the "To" device ID to what is stored in the LOG_DEVICEID field
text = m_RuleListControl.GetItemText(lvItem.iItem, RULE_NUMBER);
}
DBG3_OUT (func, "Selected text [%d]", atoi((const char *)text));
return (atoi((const char *)text));
}
void CallRoutingDlg::OnLvnItemchangedRuleList(NMHDR *pNMHDR, LRESULT *pResult)
{
}
void CallRoutingDlg::OnNMClickRuleList(NMHDR *pNMHDR, LRESULT *pResult)
{
static char func[] = "CallRoutingDlg::OnNMClickRuleList";
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CallRoutingDlg::DeleteRule(UINT position)
{
int i;
rulesIt = rules.begin();
for(i =0; rulesIt != rules.end(); i++,rulesIt++)
{
if(i < position) {
continue;
} else if (i == position) {
rules.erase(rulesIt);
break;
} else {
break;
}
}
}
void CallRoutingDlg::ChangeRulePosition(int currentPosition, int newPosition, bool down)
{
int i;
rulesIt = rules.begin();
CRule r = rulesIt[currentPosition -1];
vector<CRule>::iterator newPositionIt;
for(i =1; rulesIt != rules.end(); i++,rulesIt++)
{
if(i < currentPosition) {
newPositionIt = rulesIt;
continue;
} else if (i == currentPosition) {
rules.erase(rulesIt);
if(down)
newPositionIt = ++rulesIt;
rules.insert(newPositionIt,r);
break;
} else {
break;
}
}
UpdateRuleList();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -