| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- #include "StdAfx.h"
- #include "VsControl.h"
- #include "Config.h"
- #include "DevControl.h"
- #include "TapiLine.h"
- #include "TapiControl.h"
- #include "LineFactory.h"
- SINGLETON_IMPLEMENT(CVsControl)
- CVsControl::CVsControl(void) : m_VsDevVoc(CONST_DEV_ID_INVALID), m_VsDevRec(CONST_DEV_ID_INVALID), m_VsDevFax(CONST_DEV_ID_INVALID)
- {
- }
- CVsControl::~CVsControl(void)
- {
- }
- /*****************************************************************
- **【函数名称】 __procCmdReg
- **【函数功能】 VS注册命令处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CVsControl::__procCmdReg( CPduEntity* pCmd )
- {
- switch(pCmd->GetLocalDevType())
- {
- case PDU_DEV_TYPE_VS_PLAY: // 放音VP台
- {
- m_VsDevVoc != CONST_DEV_ID_INVALID ? pCmd->SetDataBool(0, false) : pCmd->SetDataBool(0, true);
- }
- break;
- case PDU_DEV_TYPE_VS_REC: // 录音VP台
- {
- m_VsDevRec != CONST_DEV_ID_INVALID ? pCmd->SetDataBool(0, false) : pCmd->SetDataBool(0, true);
- }
- break;
- case PDU_DEV_TYPE_VS_PLAY_REC:
- {
- (m_VsDevVoc != CONST_DEV_ID_INVALID || m_VsDevRec != CONST_DEV_ID_INVALID) ? pCmd->SetDataBool(0, false) : pCmd->SetDataBool(0, true);
- }
- break;
- case PDU_DEV_TYPE_VS_FAX:
- {
- m_VsDevFax != CONST_DEV_ID_INVALID ? pCmd->SetDataBool(0, false) : pCmd->SetDataBool(0, true);
- }
- break;
- default: // 未知设备
- pCmd->SetDataBool(0, false);
- break;
- } // end switch
- // 返回消息
- pCmd->SetToExecReturn();
- CInterfaceWindow::getCommInstance()->Send(pCmd, pCmd->GetLocalDevType(), pCmd->GetLocalDevId());
- }
- /*****************************************************************
- **【函数名称】 __procCmdPlayDtmf
- **【函数功能】 VS放音收号执行结果命令处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CVsControl::__procCmdPlayDtmf( CPduEntity* pCmd )
- {
- ASSERT(pCmd->GetIsExecReturn() == TRUE);
- CDevControl::GetInstance().onEventOpResult(pCmd->GetDataLong(17), pCmd->GetDataBool(0), pCmd->GetDataString(16));
- }
- /*****************************************************************
- **【函数名称】 __ProcCmdFax
- **【函数功能】 VS传真结果命令处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CVsControl::__procCmdFax( CPduEntity* pCmd )
- {
- ASSERT(pCmd->GetIsExecReturn() == TRUE);
- CDevControl::GetInstance().onEventOpResult(pCmd->GetDataLong(6), pCmd->GetDataBool(0));
- }
- /*****************************************************************
- **【函数名称】 __procCmdLeaveWord
- **【函数功能】 VS留言结果命令处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CVsControl::__procCmdLeaveWord( CPduEntity* pCmd )
- {
- ASSERT(pCmd->GetIsExecReturn() == TRUE);
- CDevControl::GetInstance().onEventOpResult(pCmd->GetDataLong(7), pCmd->GetDataBool(0));
- }
- /*****************************************************************
- **【函数名称】 init
- **【函数功能】 初始化
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CVsControl::init( void )
- {
- // 初始化命令配置
- #ifdef _DEBUG
- CPduDataFormat::getInstance()->Load("../NetLib/PDUFormat.ini");//"../NetLib/PDUFormat.ini
- #else
- CPduDataFormat::getInstance()->Load("./PDUFormat.ini");
- #endif
- // 注册事件响应接口
- CInterfaceWindow::getLinkInstance()->RegistPduLinkProc(this, TRUE);
- CInterfaceWindow::getCommInstance()->RegistPduCommProc(this, TRUE);
- int ListenPort = CConfig::listenPort();
- // 创建Socket服务器端
- if (CInterfaceWindow::getLinkInstance()->CreatePduServer(ListenPort, PDU_DEV_TYPE_CTI, 0))
- {
- CDevControl::GetInstance().onEventLog(LOG_LEVEL_NORMAL, _T("{VsCtrl}: 创建网络服务端成功, ListenPort = %d"), ListenPort);
- return true;
- }
- else
- {
- CDevControl::GetInstance().onEventLog(LOG_LEVEL_WARNING, _T("{VsCtrl}: 创建网络服务端失败, ListenPort = %d"), ListenPort);
- return false;
- }
- }
- /*****************************************************************
- **【函数名称】 Init
- **【函数功能】 关闭VP台控制
- **【参数】
- **【返回值】
- ****************************************************************/
- void CVsControl::release( void )
- {
- CInterfaceWindow::getLinkInstance()->StopAll();
- }
- /*****************************************************************
- **【函数名称】 OnRecvCommand
- **【函数功能】 Pdu命令到达事件处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CVsControl::OnRecvCommand( CPduEntity* a_pPduEntity )
- {
- // 根据命令类型进行相关操作
- switch(a_pPduEntity->GetCmdType())
- {
- case PDU_CMD_REG: // 注册
- __procCmdReg(a_pPduEntity);
- break;
- case PDU_CMD_IVR_LEAVE_WORD: // 留言录音
- __procCmdLeaveWord(a_pPduEntity);
- break;
- case PDU_CMD_IVR_PLAY_DTMF: // 放音
- __procCmdPlayDtmf(a_pPduEntity);
- break;
- case PDU_CMD_IVR_FAX: // 传真
- __procCmdFax(a_pPduEntity);
- break;
- } // end switch
- }
- /*****************************************************************
- **【函数名称】 OnLinkStateChanged
- **【函数功能】 Pdu连接状态变化事件处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CVsControl::OnLinkStateChanged( const PduLinkContent& linkContent )
- {
- CString strMsg;
- LOG_LEVEL Level = LOG_LEVEL_NORMAL;
- switch(linkContent.nLinkState)
- {
- case PDU_LINK_STATE_ACCEPTED: // 已接受对端连接
- {
- strMsg.Format(_T("{VsCtrl}: Far End[Ip = %s, Port = %d], Hint = 已接受远端网络连接..."),
- linkContent.szFarIp,
- linkContent.nFarPort);
- }
- break;
- case PDU_LINK_STATE_DISCONNECTED: // 连接已断开
- {
- strMsg.Format(_T("{VsCtrl}: Far End[Ip = %s, Port = %d, Type = %d, Id = %d], Hint = 网络连接已断开..."),
- linkContent.szFarIp,
- linkContent.nFarPort,
- linkContent.nFarType,
- linkContent.nFarId);
- if(linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY || linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY_REC) m_VsDevVoc = CONST_DEV_ID_INVALID;
- if(linkContent.nFarType == PDU_DEV_TYPE_VS_REC || linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY_REC) m_VsDevRec = CONST_DEV_ID_INVALID;
- if(linkContent.nFarType == PDU_DEV_TYPE_VS_FAX) m_VsDevFax = CONST_DEV_ID_INVALID;
- Level = LOG_LEVEL_WARNING;
- }
- break;
- case PDU_LINK_STATE_REG_OK: // 注册成功
- {
- strMsg.Format(_T("{VsCtrl}: Far End[Type = %d, Id = %d, Ip = %s, Port = %d], Hint = 网络连接注册成功..."),
- linkContent.nFarType,
- linkContent.nFarId,
- linkContent.szFarIp,
- linkContent.nFarPort);
- if(linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY || linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY_REC) m_VsDevVoc = linkContent.nFarType;
- if(linkContent.nFarType == PDU_DEV_TYPE_VS_REC || linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY_REC) m_VsDevRec = linkContent.nFarType;
- if(linkContent.nFarType == PDU_DEV_TYPE_VS_FAX) m_VsDevFax = linkContent.nFarType;
- }
- break;
- case PDU_LINK_STATE_REG_FAILED: // 注册失败
- {
- strMsg.Format(_T("{VsCtrl}: Far End[Ip = %s, Port = %d], Hint = 网络连接注册失败, 通讯禁止..."),
- linkContent.szFarIp,
- linkContent.nFarPort);
- Level = LOG_LEVEL_WARNING;
- }
- break;
- default:
- strMsg.Format(_T("{VsCtrl}: Far End[Type = %d, Id = %d, Ip = %s, Port = %d], Hint = "),
- linkContent.nFarType,
- linkContent.nFarId,
- linkContent.szFarIp,
- linkContent.nFarPort);
- } // end switch
- CDevControl::GetInstance().onEventLog(Level, _T("%s"), strMsg);
- }
- /*****************************************************************
- **【函数名称】 sendCmd2Rec
- **【函数功能】 发送PDU命令到录音VS
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CVsControl::sendCmd2Rec( CPduEntity* pCmd )
- {
- if(m_VsDevRec == CONST_DEV_ID_INVALID)
- return false;
- return CInterfaceWindow::getCommInstance()->Send(pCmd, (PDU_DEV_TYPE)m_VsDevRec, 0) == TRUE;
- }
- /*****************************************************************
- **【函数名称】 sendCmd2Voc
- **【函数功能】 发送PDU命令到放音VS
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CVsControl::sendCmd2Voc( CPduEntity* pCmd )
- {
- if(m_VsDevVoc == CONST_DEV_ID_INVALID)
- return false;
- return CInterfaceWindow::getCommInstance()->Send(pCmd, (PDU_DEV_TYPE)m_VsDevVoc, 0) == TRUE;
- }
- /*****************************************************************
- **【函数名称】 sendCmd2Fax
- **【函数功能】 发送PDU命令到传真VS
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CVsControl::sendCmd2Fax( CPduEntity* pCmd )
- {
- if(m_VsDevFax == CONST_DEV_ID_INVALID && m_VsDevVoc == CONST_DEV_ID_INVALID)
- return false;
- int TmpDevType = (m_VsDevFax == CONST_DEV_ID_INVALID ? m_VsDevVoc : m_VsDevFax);
- return CInterfaceWindow::getCommInstance()->Send(pCmd, (PDU_DEV_TYPE)TmpDevType, 0) == TRUE;
- }
- /*****************************************************************
- **【函数名称】 NotifyVpLineFree
- **【函数功能】 通知VP台线路释放
- **【参数】 LineId 释放的线路ID
- TypeType 释放的线路类型
- **【返回值】
- ****************************************************************/
- bool CVsControl::notifyLineFree( UINT LineId, DEV_RES_TYPE LineType )
- {
- // 初始化PDU命令
- CPduEntity cmd(PDU_CMD_CTI_VS_LINECONTROL);
- cmd.SetDataUInt(0, LineId);
- cmd.SetDataInt(1, 0);
- // 根据线路类型作分类处理
- switch(LineType)
- {
- case DEV_RES_TYPE_EXT: // 内线分机
- {
- if(CConfig::recordType() == RECORD_TYPE_EXTEN)
- return sendCmd2Rec(&cmd);
- }
- break;
- case DEV_RES_TYPE_TRUNK: // 外线
- {
- if(CConfig::recordType() == RECORD_TYPE_TRUNK)
- return sendCmd2Rec(&cmd);
- }
- break;
- case DEV_RES_TYPE_IVR: // IVR线路
- {
- return sendCmd2Voc(&cmd);
- }
- break;
- case DEV_RES_TYPE_FAX: // 传真线路
- {
- return sendCmd2Fax(&cmd);
- }
- break;
- default:
- ASSERT(FALSE);
- } // end switch
- return false;
- }
|