📄 ctievent.cpp
字号:
// CTIEvent.cpp : Implementation of CCTIEvent
#include "stdafx.h"
#include "LucentCti.h"
#include "KVPair.h"
#include "KVList.h"
#include "CTIEvent.h"
/////////////////////////////////////////////////////////////////////////////
// CCTIEvent
extern void WriteLog(char* pData);
DECLARE_CREATOR(CCTIEvent, ICTIEvent)
DECLARE_CREATOR(CKVList,IKVList)
BOOL CCTIEvent::SetEvent(dnevent* pDnEvent)
{
BOOL bRet=FALSE;
if (m_cstaEvent==NULL &&m_attEvent==NULL)
{
m_cstaEvent=pDnEvent->m_cstaEvent;
m_attEvent=pDnEvent->m_attEvent;
Initialize();
m_cstaEvent=NULL;
m_attEvent=NULL;
//copy property for mapping to Genesys event
CallType=pDnEvent->CallType;
ConnID=pDnEvent->ConnID;
memcpy(&ThisDN,&pDnEvent->ThisDN,sizeof(DeviceID_t));
memcpy(&OtherDN,&pDnEvent->OtherDN,sizeof(DeviceID_t));
memcpy(&AgentID,&pDnEvent->AgentID,sizeof(AgentID_t));
memcpy(&ANI,&pDnEvent->ANI,sizeof(AgentID_t));
memcpy(&DNIS,&pDnEvent->DNIS,sizeof(AgentID_t));
bRet=TRUE;
}
return bRet;
}
BOOL CCTIEvent::SetEvent(CSTAEvent_t* cstaEvent)
{
if (m_cstaEvent)
{
m_cstaEvent=cstaEvent;
Initialize();
m_cstaEvent=NULL;
}
return TRUE;
}
BOOL CCTIEvent::Initialize()
{
BOOL bRet=TRUE;
//mapping event to Genesys
if (m_cstaEvent)
{
if (m_cstaEvent->eventHeader.eventClass==CSTAUNSOLICITED)
{
switch(m_cstaEvent->eventHeader.eventType)
{
case CSTA_DELIVERED:
m_GenesysEvent=EVT_Ringing;
break;
case CSTA_ESTABLISHED:
m_GenesysEvent=EVT_Established;
break;
case CSTA_CALL_CLEARED:
case CSTA_CONNECTION_CLEARED:
m_GenesysEvent=EVT_Released;
break;
case CSTA_RETRIEVED:
m_GenesysEvent=EVT_Retrieved;
break;
case CSTA_HELD:
m_GenesysEvent=EVT_Held;
break;
}
}
}
//mapping user info to k-v list
if (m_cstaEvent && m_attEvent)
{
if (m_cstaEvent->eventHeader.eventClass==CSTAUNSOLICITED
&& m_cstaEvent->eventHeader.eventType==CSTA_DELIVERED
&& m_attEvent->eventType==ATT_DELIVERED)
{
CKVList* pCkvlist=NULL;
if(SUCCEEDED(CreateClass(&pCkvlist,&m_lpList)))
{
// Get user data from original info
ATTUserToUserInfo_t* attData=&(m_attEvent->u.deliveredEvent.originalCallInfo.userInfo/**/);
// if (attData->type==UUI_IA5_ASCII && m_lpList)
if (attData->type!=UUI_NONE && m_lpList)
{
char temp[300]={0};
wsprintf((char*)&temp,"recieve string(originalCallInfo):%s",(char*)&(attData->data.value));
WriteLog((char*)&temp);
AppStringToKVlist((char*)&(attData->data.value),m_lpList);
}
//Get user data from delivered info
attData=&(m_attEvent->u.deliveredEvent.userInfo);
// if (attData->type==UUI_IA5_ASCII && m_lpList)
if (attData->type!=UUI_NONE && m_lpList)
{
char temp[300]={0};
wsprintf((char*)&temp,"recieve string(deliveredEventInfo):%s",(char*)&(attData->data.value));
WriteLog((char*)&temp);
AppStringToKVlist((char*)&(attData->data.value),m_lpList);
}
}
}
}
return bRet;
}
STDMETHODIMP CCTIEvent::get_AgentID(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal=C2B(AgentID);
return S_OK;
}
STDMETHODIMP CCTIEvent::get_AgentMode(AGENTMODES *pVal)
{
// TODO: Add your implementation code here
*pVal=AM_Unknown;
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ANI(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal=C2B(ANI);
return S_OK;
}
STDMETHODIMP CCTIEvent::get_CallState(CALLSTATES *pVal)
{
// TODO: Add your implementation code here
*pVal=CS_Ok;
return S_OK;
}
STDMETHODIMP CCTIEvent::get_CallType(CALLTYPES *pVal)
{
// TODO: Add your implementation code here
*pVal=CallType;
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ConnID(BSTR *pVal)
{
// TODO: Add your implementation code here
wchar_t p[64]={0};
_ltow(ConnID,(wchar_t*)&p,10);
*pVal=SysAllocString(p);
return S_OK;
}
STDMETHODIMP CCTIEvent::get_DNIS(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal=C2B((char*)&DNIS);
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ErrorCode(long *pVal)
{
// TODO: Add your implementation code here
*pVal=0;
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ErrorMessage(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal=C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_Event(EVENTCODES *pVal)
{
// TODO: Add your implementation code here
*pVal=m_GenesysEvent;
return S_OK;
}
STDMETHODIMP CCTIEvent::get_OtherDN(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal=C2B((char*)&OtherDN);
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ThirdPartyDN(BSTR *pVal)
{
*pVal=C2B("");
return S_OK;
}
STDMETHODIMP_(LPCTIEVENT) CCTIEvent::Copy()
{
// TODO: Add your implementation code here
HRESULT ret=E_FAIL;
CCTIEvent *pCEvent = NULL;
ICTIEvent *pIEvent = NULL;
if(SUCCEEDED(CreateClass(&pCEvent, &pIEvent)))
{
if (CopyProperty(pCEvent))
ret=S_OK;
else
{
pIEvent->Release();
pIEvent=NULL;
}
}
return pIEvent;
}
BOOL CCTIEvent::CopyProperty(CCTIEvent* newEvent)
{
BOOL bRet=TRUE;
newEvent->CallType=CallType;
newEvent->ConnID=ConnID;
memcpy(&newEvent->ThisDN,&ThisDN,sizeof(DeviceID_t));
memcpy(&newEvent->OtherDN,&OtherDN,sizeof(DeviceID_t));
memcpy(&newEvent->AgentID,&AgentID,sizeof(AgentID_t));
memcpy(&newEvent->DNIS,&DNIS,sizeof(DeviceID_t));
memcpy(&newEvent->ANI,&ANI,sizeof(DeviceID_t));
if (m_lpList)
{
newEvent->m_lpList=m_lpList->Dup();
if (newEvent->m_lpList==NULL)
bRet=FALSE;
}
newEvent->m_GenesysEvent=m_GenesysEvent;
return bRet;
}
STDMETHODIMP CCTIEvent::get_UserData(LPKVLIST *pVal)
{
// TODO: Add your implementation code here
*pVal=m_lpList;
if (m_lpList)
m_lpList->AddRef();
return S_OK;
}
BOOL CCTIEvent::AppStringToKVlist(char* pAppString,IKVList* pKvlist)
{
//Transform character: "/"
// /k: type : key
// /s: type: string
// /i: type: int
// /b: type: binary
// /l: type: binary length (/l23/l)
//sample: /kRick/sMyname/kName/i100
BOOL ret=TRUE;
char pKey[ATT_MAX_USER_INFO]={0}; // the key field
char pVal[ATT_MAX_USER_INFO+1]={0}; // the values field, the first char is the field type
int nAppLen=strlen(pAppString); // the app string length
int nAppPos=0; // the app string search position
while (nAppPos<nAppLen)
{
if (pAppString[nAppPos]=='/')
{
switch (pAppString[nAppPos+1])
{
case '/':
// Transform "//" to "/"
nAppPos++;
CopyCharToString('/',pKey,pVal);
break;
case 'i':
//now begin read the value field, and the type is i(int)
nAppPos++;
ZeroMemory(pVal,strlen(pVal));
pVal[0]='i';
break;
case 's':
//now begin read the value field, and the type is s(string)
nAppPos++;
ZeroMemory(pVal,strlen(pVal));
pVal[0]='s';
break;
case 'k':
//now begin read the key field.
nAppPos++;
// If there have been a pair of k-v, add them the the k-v list
if (pKey[0]!=0)
{
if (AddToKVList(pKvlist,pKey,pVal))
{
ZeroMemory(pKey,strlen(pKey));
ZeroMemory(pVal,strlen(pVal));
}
else
ret=FALSE;
}
break;
default:
// the error occurred
ret=FALSE;
break;
}
}else
{
CopyCharToString(pAppString[nAppPos],pKey,pVal);
}
if (ret) nAppPos++;
else break;
}//end while
if (ret)
if (pKey[0]!=0)
AddToKVList(pKvlist,pKey,pVal);
return ret;
}
BOOL CCTIEvent::CopyCharToString(char nChar,char* pKey,char* pVal)
{
BOOL ret=TRUE;
if (pVal[0])
strncat(pVal,&nChar,1);
else
strncat(pKey,&nChar,1);
return ret;
}
BOOL CCTIEvent::AddToKVList(IKVList* pIKvlist,char* pKey,char* pVal)
{
BOOL ret=TRUE;
BSTR key=NULL;
int nLen=MultiByteToWideChar(CP_ACP,0,pKey,-1,NULL,0);
OLECHAR* pOle=new OLECHAR[nLen];
if (pOle && MultiByteToWideChar(CP_ACP,0,pKey,-1,pOle,nLen))
{
key=SysAllocString(pOle);
if (key)
{
if (pOle)
{
delete pOle;
pOle=NULL;
}
BSTR val=NULL;
int nVal=0;
switch(pVal[0])
{
case 'i':
nVal=strtol(pVal+1,NULL,16);
if (SUCCEEDED(pIKvlist->AddInt(key,nVal)))
ret=TRUE;
else
ret=FALSE;
break;
case 's':
nLen=MultiByteToWideChar(CP_ACP,0,pVal,-1,NULL,0);
pOle=new OLECHAR[nLen];
if (pOle && MultiByteToWideChar(CP_ACP,0,pVal+1,-1,pOle,nLen))
{
val=SysAllocString(pOle);
if (val)
{
if (SUCCEEDED(pIKvlist->AddString(key,val)))
ret=TRUE;
else ret=FALSE;
SysFreeString(val);
}else
ret=FALSE;
}else
ret=FALSE;
break;
default:
ret=FALSE;
break;
}
SysFreeString(key);
}else
{
ret=FALSE;
}
if (pOle)
{
delete pOle;
pOle=NULL;
}
}else
ret=FALSE;
return ret;
}
STDMETHODIMP CCTIEvent::get_WebReqID(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebReqType(int *pVal)
{
*pVal = 0;
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebCustName(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebCustPhone(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebCustMPhone(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebCustEmail(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebCustIDBrNo(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebIPAddr(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebCallPhone(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebTMail(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebChatRoomId(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebNmRoomId(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebPrjType(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_WebAddr(BSTR *pVal)
{
*pVal = C2B("");
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ThisDN(BSTR *pVal)
{
*pVal=C2B((char*)&ThisDN);
return S_OK;
}
STDMETHODIMP CCTIEvent::get_Extensions(LPKVLIST *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_Reasons(LPKVLIST *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_CLID(BSTR *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_CallingLineName(BSTR *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ThirdPartyTrunk(long *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ThirdPartyQueue(BSTR *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_OtherDNRole(DNROLES *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_OtherTrunk(long *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_OtherQueue(BSTR *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ThisDNRole(DNROLES *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ThirdPartyDNRole(DNROLES *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ThisTrunk(long *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_ThisQueue(BSTR *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_NetNodeID(int *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_NetCallID(long *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_NodeID(int *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_CallID(long *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_PrevConnID(BSTR *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_CustomerID(BSTR *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_HomeLocation(BSTR *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CCTIEvent::get_RefID(int *pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -