📄 sampldlg.cpp
字号:
// get the caller out of callingDevice
if(callingProvided)
{
callingDevice = pCallingDevice->deviceID;
}
else
{
callingDevice = _T("Not provided");
}
m_CallListControl.SetItemText(listIndex, 0, callingDevice);
// update the remote status manually to "connected" since the remote
// connection existed before this monitor knew about the call.
m_CallListControl.SetItemText(listIndex, REMOTE_CONNECTION_STATE, _T("Connected"));
}
break;
}
case CSTA_NETWORK_REACHED: // null -> connected (REMOTE only)
{
ConnectionID_t* pConnID = &(pUns->u.networkReached.connection);
SubjectDeviceID_t* pSubjectDevice = &(pUns->u.networkReached.trunkUsed);
CalledDeviceID_t* pCalledDevice = &(pUns->u.networkReached.calledDevice);
// Find the call handle based on call ID in given connection ID
// Unfortunately, we must crack open the ConnID here (the FALSE indicates
// an inexact match - just match on callID). Looking at the callID is
// not guaranteed to work on 100% of all PBX drivers - some implementations
// do not guarantee unique call IDs, only unique connection IDs.
// There are 2 alternatives to this, neither one of which is any better
// than this (and may even be worse).
// 1. Look at the calledDevice. The app should know the number that was called,
// and could store that number with the local connection ID. When execution
// reaches here, search for the called device and return the callHandle. This
// has 2 problems: a. calledDevice is not guaranteed to be supplied from all PBX
// drivers; b. if 2 calls to the same device are in progress simultaneously, which
// callHandle is for which device?
// 2. Do a cstaSnapshotCall() on the connection ID passed in here. That will give you
// a picture of what is happening with that connID - including the connID in the
// call that is associated with the monitored device. The snapshot can be used to
// match that local connID to what is stored in the app. This delays handling of
// the event with asynchronous queries to the server - in the meantime other things
// are happening to the call!
long callHandle = pTsapi->GetCallHandle(*pConnID, FALSE);
if(callHandle == 0)
{
return 0;
}
// now add the connection to the call - while this connection is in
// the call, all future events should not need to use GetCallHandle() with FALSE,
// they should all use TRUE.
if(!pTsapi->AddConnectionToCall(callHandle, *pConnID))
{
AfxMessageBox("no memory to add new connection to call");
return 0;
}
LV_FINDINFO findInfo;
findInfo.flags = LVFI_PARAM;
findInfo.lParam = callHandle;
int listIndex = m_CallListControl.FindItem(&findInfo, -1);
// This event is always for the remote connection
m_CallListControl.SetItemText(listIndex, REMOTE_CONNECTION_STATE, _T("Connected"));
CString trunkUsed;
// get the trunk used out of subjectDevice or calledDevice
if(pSubjectDevice->deviceIDStatus == ID_PROVIDED)
{
trunkUsed = pSubjectDevice->deviceID;
}
else if(pCalledDevice->deviceIDStatus == ID_PROVIDED)
{
trunkUsed = pCalledDevice->deviceID;
}
else
{
trunkUsed = _T("Not provided");
}
m_CallListControl.SetItemText(listIndex, 0, trunkUsed);
break;
}
case CSTA_ESTABLISHED: // alerting/connected -> connected
{
ConnectionID_t* pConnID = &(pUns->u.established.establishedConnection);
SubjectDeviceID_t* pSubjectDevice = &(pUns->u.established.answeringDevice);
CallingDeviceID_t* pCallingDevice = &(pUns->u.established.callingDevice);
CalledDeviceID_t* pCalledDevice = &(pUns->u.established.calledDevice);
BOOL subjectProvided = (pSubjectDevice->deviceIDStatus == ID_PROVIDED);
BOOL callingProvided = (pCallingDevice->deviceIDStatus == ID_PROVIDED);
BOOL calledProvided = (pCalledDevice->deviceIDStatus == ID_PROVIDED);
BOOL outgoing = FALSE;
// Attempt to find the call associated with the connection ID
long callHandle = pTsapi->GetCallHandle(*pConnID, TRUE);
if(callHandle == 0)
{
// if the call is outgoing to an internal destination (no NETWORK REACHED event
// has been received) we will get here.
// is it outgoing?
if(subjectProvided)
{
outgoing = !(m_DeviceID == pSubjectDevice->deviceID);
}
else if(callingProvided)
{
outgoing = (m_DeviceID == pCallingDevice->deviceID);
}
else if(calledProvided)
{
outgoing = !(m_DeviceID == pCalledDevice->deviceID);
}
else
{
// nothing we can do if no IDs are provided!
return 0;
}
// if it is NOT outgoing, ignore event - return here
if(!outgoing)
{
return 0;
}
// Find the call handle based on call ID in given connection ID
// Unfortunately, we must crack open the ConnID here (the FALSE indicates
// an inexact match - just match on callID). Looking at the callID is
// not guaranteed to work on 100% of all PBX drivers - some implementations
// do not guarantee unique call IDs, only unique connection IDs.
// There are 2 alternatives to this, neither one of which is any better
// than this (and may even be worse).
// 1. Look at the calledDevice. The app should know the number that was called,
// and could store that number with the local connection ID. When execution
// reaches here, search for the called device and return the callHandle. This
// has 2 problems: a. calledDevice is not guaranteed to be supplied from all PBX
// drivers; b. if 2 calls to the same device are in progress simultaneously, which
// callHandle is for which device?
// 2. Do a cstaSnapshotCall() on the connection ID passed in here. That will give you
// a picture of what is happening with that connID - including the connID in the
// call that is associated with the monitored device. The snapshot can be used to
// match that local connID to what is stored in the app. This delays handling of
// the event with asynchronous queries to the server - in the meantime other things
// are happening to the call!
callHandle = pTsapi->GetCallHandle(*pConnID, FALSE);
if(callHandle == 0)
{
return 0;
}
// now add the connection to the call - while this connection is in
// the call, all future events should not need to use GetCallHandle() with FALSE,
// they should all use TRUE.
if(!pTsapi->AddConnectionToCall(callHandle, *pConnID))
{
AfxMessageBox("no memory to add new connection to call");
return 0;
}
}
LV_FINDINFO findInfo;
findInfo.flags = LVFI_PARAM;
findInfo.lParam = callHandle;
int listIndex = m_CallListControl.FindItem(&findInfo, -1);
if(outgoing)
{
m_CallListControl.SetItemText(listIndex, REMOTE_CONNECTION_STATE, _T("Connected"));
CString answeringDevice;
// get the answering device out of subjectDevice or calledDevice
if(subjectProvided)
{
answeringDevice = pSubjectDevice->deviceID;
}
else if(calledProvided)
{
answeringDevice = pCalledDevice->deviceID;
}
else
{
answeringDevice = _T("Not provided");
}
m_CallListControl.SetItemText(listIndex, 0, answeringDevice);
}
else
{
m_CallListControl.SetItemText(listIndex, LOCAL_CONNECTION_STATE, _T("Connected"));
}
break;
}
case CSTA_DIVERTED: // alerting -> null
{
ConnectionID_t* pConnID = &(pUns->u.diverted.connection);
// The conn ID is always known to the app here.
// This event is for the local connection on an incoming call only
// The call is being diverted away from the monitored device,
// so remove the call from the application
long callHandle = pTsapi->RemoveCallViaConnection(*pConnID);
if(callHandle == 0)
{
return 0;
}
LV_FINDINFO findInfo;
findInfo.flags = LVFI_PARAM;
findInfo.lParam = callHandle;
int listIndex = m_CallListControl.FindItem(&findInfo, -1);
// delete the selected list control item
m_CallListControl.DeleteItem(listIndex);
break;
}
case CSTA_HELD: // connected -> held
{
ConnectionID_t* pConnID = &(pUns->u.held.heldConnection);
// Attempt to find the call associated with the connection ID
long callHandle = pTsapi->GetCallHandle(*pConnID, TRUE);
if(callHandle == 0)
{
return 0;
}
// need to get listIndex for where this message should go
LV_FINDINFO findInfo;
findInfo.flags = LVFI_PARAM;
findInfo.lParam = callHandle;
int listIndex = m_CallListControl.FindItem(&findInfo, -1);
// If the connection ID is a "local" connection id (i.e. it is associated with
// the monitored device), then update the local connection state.
// else update the remote connection state.
// For you folks who like fancy code, use the following instead of the if-else:
// m_CallListControl.SetItemText(listIndex,
// (pTsapi->IsLocalConnection(callHandle, *pConnID)) ?
// LOCAL_CONNECTION_STATE : REMOTE_CONNECTION_STATE,
// _T("Held"));
if(pTsapi->IsLocalConnection(callHandle, *pConnID))
{
m_CallListControl.SetItemText(listIndex, LOCAL_CONNECTION_STATE, _T("Held"));
}
else
{
m_CallListControl.SetItemText(listIndex, REMOTE_CONNECTION_STATE, _T("Held"));
}
break;
}
case CSTA_RETRIEVED: // held -> connected
{
ConnectionID_t* pConnID = &(pUns->u.retrieved.retrievedConnection);
// Attempt to find the call associated with the connection ID
long callHandle = pTsapi->GetCallHandle(*pConnID, TRUE);
if(callHandle == 0)
{
return 0;
}
// need to get listIndex for where this message should go
LV_FINDINFO findInfo;
findInfo.flags = LVFI_PARAM;
findInfo.lParam = callHandle;
int listIndex = m_CallListControl.FindItem(&findInfo, -1);
// If the connection ID is a "local" connection id (i.e. it is associated with
// the monitored device), then update the local connection state.
// else update the remote connection state.
if(pTsapi->IsLocalConnection(callHandle, *pConnID))
{
m_CallListControl.SetItemText(listIndex, LOCAL_CONNECTION_STATE, _T("Connected"));
}
else
{
m_CallListControl.SetItemText(listIndex, REMOTE_CONNECTION_STATE, _T("Connected"));
}
break;
}
case CSTA_CALL_CLEARED: // * -> null (for all connections in call)
{
ConnectionID_t* pConnID = &(pUns->u.callCleared.clearedCall);
// remove the call associated with the connection ID
long callHandle = pTsapi->RemoveCallViaConnection(*pConnID);
if(callHandle == 0)
{
// If the call was not known, just return
return 0;
}
LV_FINDINFO findInfo;
findInfo.flags = LVFI_PARAM;
findInfo.lParam = callHandle;
int listIndex = m_CallListControl.FindItem(&findInfo, -1);
// delete the selected list control item
m_CallListControl.DeleteItem(listIndex);
break;
}
case CSTA_CONNECTION_CLEARED: // * -> null
{
ConnectionID_t* pConnID = &(pUns->u.connectionCleared.droppedConnection);
// remove the call associated with the connection ID
long callHandle = pTsapi->RemoveCallViaConnection(*pConnID);
if(callHandle == 0)
{
// If the call was not known, just return
return 0;
}
// need to get listIndex for where this message should go
LV_FINDINFO findInfo;
findInfo.flags = LVFI_PARAM;
findInfo.lParam = callHandle;
int listIndex = m_CallListControl.FindItem(&findInfo, -1);
// delete the selected list control item
m_CallListControl.DeleteItem(listIndex);
break;
}
default:
// unhandled message - ignore it
return 0;
}
// update the status of buttons and fields
DoButtonUpdates();
// update the contents of fields
UpdateData(FALSE);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -