#include "OpMakeCall.h" #include "ChanExten.h" #include "OperationReactor.h" #include "FsProxy.h" COpMakeCall::COpMakeCall(COperationReactor* pParent, long Instance) : COperation(pParent, Instance) { } COpMakeCall::~COpMakeCall(void) { } bool COpMakeCall::start(LineOpParam * pParam) { // 校验状态 if (m_pHostChan->state() != CHAN_LOGIC_STATE_FREE) return false; // 保存主被叫信息 std::string CallerNum = pParam->szParam1; m_DestNumber = pParam->szParam2; std::string ExtenNum = std::to_string(m_pHostChan->no()); // 不能呼叫自己 if (ExtenNum == m_DestNumber) { LOG_WARN(("{OpMakeCall}: 分机[%lu]执行呼叫失败, 禁止分机自呼"), m_pHostChan->no()); return false; } // 通知启动日志 LOG_INFO(("{OpMakeCall}: 分机[%lu]执行呼叫, DestNum = %s"), m_pHostChan->no(), m_DestNumber.c_str()); //m_pHostChan->opNumber() = pParam->szParam2; m_Caller = CallerNum; m_CallerAgent = CFsProxy::GetInstance().getAgentByExten(m_Caller); m_Callee = m_DestNumber; m_CalleeAgent = CFsProxy::GetInstance().getAgentByExten(m_Callee); m_OpTime = Util::CurTime(); return CFsProxy::GetInstance().ExtenCall(uniqueId(), m_pHostChan, CallerNum, m_DestNumber); } bool COpMakeCall::start(PCHAN_EVENT_NOTIFY pNotify) { std::string CallerNum; CallerNum = std::to_string(m_pHostChan->no()); m_DestNumber = pNotify->Callee; // 不能呼叫自己 if (CallerNum == m_DestNumber) { LOG_WARN(("{OpMakeCall}: 分机[%lu]电话呼叫失败, 禁止分机自呼"), m_pHostChan->no()); return false; } // 检测目标分机状态 uint32_t DestExtenNoInt; sscanf(pNotify->Callee.c_str(), "%lu", &DestExtenNoInt); ChanExten* pDestExten = CFsProxy::GetInstance().getExten(DestExtenNoInt); if (pDestExten != nullptr && !pDestExten->isFree()) { LOG_WARN(("{OpMakeCall}: 分机[%lu]电话呼叫失败, 目标分机[%lu]非空闲"), m_pHostChan->no(), DestExtenNoInt); return false; } // 通知启动日志 LOG_INFO(("{OpMakeCall}: 分机[%lu]执行电话呼叫, DestNum = %s"), m_pHostChan->no(), m_DestNumber.c_str()); m_Caller = CallerNum; m_CallerAgent = CFsProxy::GetInstance().getAgentByExten(m_Caller); m_Callee = m_DestNumber; m_CalleeAgent = CFsProxy::GetInstance().getAgentByExten(m_Callee); m_OpTime = Util::CurTime(); // 通知手动外呼启动事件 m_pParent->onOpFromDev(m_pHostChan, DEV_OP_CALL_OUT, CallerNum, m_DestNumber); return true; } bool COpMakeCall::hangup(long InstanceHangup) { LOG_INFO(("{OpHoldon}: 分机[%lu]呼叫中挂机"), m_pHostChan->no()); if (m_pHostChan->isFree()) return false; m_InstanceCancel = InstanceHangup; return CFsProxy::GetInstance().kill(uniqueId(), m_pHostChan); } void COpMakeCall::onBackgroudJobDone(PBG_JOB_NOTIFY pNotify) { if (pNotify->JobCmd == ESL_CMD_MAKE_CALL) { if(pNotify->JobBody.find(ESL_JOB_DONE_RES_OK) == string::npos) _end(false); } else { if (pNotify->JobBody.find(ESL_JOB_DONE_RES_OK) == string::npos) m_pParent->onOpResult(m_InstanceCancel, false); else _end(false); } } void COpMakeCall::onHostChanStateUpdated(VirtualChan * pHostChan) { if(pHostChan == m_pHostChan) if (pHostChan->state() == CHAN_LOGIC_STATE_FREE) _end(false); } void COpMakeCall::onSessionChanStateUpdated(VirtualChan * pChan) { if (pChan == nullptr) return; switch ((int)pChan->state()) { case CHAN_LOGIC_STATE_RING_BACK: // 座席呼叫外线 //给西亚斯改动 case CHAN_LOGIC_STATE_ALERTING: // 座席呼叫座席 m_pParent->onOpProcess(m_Instance, m_pHostChan->no(), pChan->no(), pChan->type(), pChan->callerNum(), pChan->calleeNum()); break; case CHAN_LOGIC_STATE_TALKING: _end(true); break; case CHAN_LOGIC_STATE_FREE: _end(false); } } void COpMakeCall::_end(bool IsSucceed) { if (IsSucceed) { LOG_INFO(("{OpMakeCall}: 分机[%lu]呼叫成功, DestNum = %s"), m_pHostChan->no(), m_DestNumber.c_str()); } else { LOG_WARN(("{OpMakeCall}: 分机[%lu]呼叫失败, DestNum = %s"), m_pHostChan->no(), m_DestNumber.c_str()); } m_SessionId = m_pHostChan->sessionId(); SqlWrite::GetInstance()->addSql(toSql(IsSucceed, "外呼")); // 返回执行结果 if (m_InstanceCancel != FS_LINK_INSTANCE_INVALID) m_pParent->onOpResult(m_InstanceCancel, !IsSucceed); m_pParent->onOpResult(m_Instance, this, IsSucceed, std::to_string(m_pHostChan->no())); }