| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #include "OpMute.h"
- #include "VirtualChan.h"
- #include "OperationReactor.h"
- #include "FsProxy.h"
- COpMute::COpMute(COperationReactor* pParent, long Instance) : COperation(pParent, Instance), m_IsOff(false)
- {
- }
- COpMute::~COpMute(void)
- {
- }
- /*****************************************************************
- **【函数名称】 _end
- **【函数功能】 操作完成
- **【参数】 IsSucceed 操作是否成功
- lpData 随路数据
- **【返回值】
- ****************************************************************/
- void COpMute::_end(bool IsSucceed)
- {
- if (m_IsOff)
- {
- if (IsSucceed)
- LOG_INFO("{OpMute}: 分机[%lu]取消静音成功", m_pHostChan->no());
- else
- LOG_WARN("{OpMute}: 分机[%lu]取消静音失败", m_pHostChan->no());
- SqlWrite::GetInstance()->addSql(toSql(IsSucceed, "取消静音"));
- //m_pParent->onOpResult(m_InstanceCancel, IsSucceed);
- m_pParent->onOpResult(m_InstanceCancel, this, IsSucceed, std::to_string(m_pHostChan->no()),"MuteOff");
- }
- else
- {
- if (IsSucceed)
- LOG_INFO("{OpMute}: 分机[%lu]静音成功", m_pHostChan->no());
- else
- LOG_WARN("{OpMute}: 分机[%lu]静音失败", m_pHostChan->no());
- 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()),"MuteOn");
- }
- }
- /*****************************************************************
- **【函数名称】 start
- **【函数功能】 执行操作
- **【参数】
- **【返回值】
- *****************************************************************/
- bool COpMute::start(LineOpParam* pParam)
- {
- // 校验状态
- if (m_pHostChan->state() != CHAN_LOGIC_STATE_TALKING)
- return false;
- LOG_INFO("{OpMute}: 分机[%lu]执行静音", m_pHostChan->no());
- m_pAssoChan = CFsProxy::GetInstance().getAssoChanInSession(m_pHostChan);
- if (m_pAssoChan == nullptr)
- {
- LOG_WARN("{OpMute}: 分机[%lu]执行静音失败, 获取关联通道失败, caller = %s,callee = %s", m_pHostChan->no(), m_pHostChan->callerNum().c_str(), m_pHostChan->calleeNum().c_str());
- return false;
- }
- m_SessionId = m_pAssoChan->sessionId();
- m_Caller = std::to_string(m_pHostChan->no());
- m_CallerAgent = CFsProxy::GetInstance().getAgentByExten(m_Caller);
- m_OpTime = Util::CurTime();
- return CFsProxy::GetInstance().muteOn(uniqueId(), m_pAssoChan);
- //return CFsProxy::GetInstance().muteOn(uniqueId(), m_pHostChan);
- }
- /*****************************************************************
- **【函数名称】 cancel
- **【函数功能】 取消操作
- **【参数】
- **【返回值】
- *****************************************************************/
- bool COpMute::cancel(long InstanceCancel)
- {
- LOG_INFO("{OpMute}: 分机[%lu]取消静音", m_pHostChan->no());
- m_InstanceCancel = InstanceCancel;
- m_IsOff = true;
- if (m_pAssoChan != nullptr)
- return CFsProxy::GetInstance().muteOff(uniqueId(), m_pAssoChan);
- LOG_WARN("{OpMute}: 分机[%lu]取消静音失败,对端线路为空", m_pHostChan->no());
- return false;
- //return CFsProxy::GetInstance().muteOff(uniqueId(), m_pHostChan);
- }
- /*****************************************************************
- **【函数名称】 hangup
- **【函数功能】 操作中挂机
- **【参数】
- **【返回值】
- *****************************************************************/
- bool COpMute::hangup(long InstanceHangup)
- {
- if (m_InstanceCancel != FS_LINK_INSTANCE_INVALID)
- return false;
- LOG_INFO("{OpMute}: 分机[%lu]静音中挂机", m_pHostChan->no());
- m_InstanceCancel = InstanceHangup;
- if (CFsProxy::GetInstance().kill(uniqueId(), m_pHostChan))
- {
- _end(false);
- return true;
- }
- else
- {
- _end(true);
- return false;
- }
- }
- /*****************************************************************
- **【函数名称】 onBackgroudJobDone
- **【函数功能】 后台命令执行结束事件处理
- **【参数】
- **【返回值】
- *****************************************************************/
- void COpMute::onBackgroudJobDone(PBG_JOB_NOTIFY pNotify)
- {
- if (m_IsOff)
- {
- if (pNotify->JobBody.find(ESL_JOB_DONE_RES_OK) == string::npos)
- m_pParent->onOpResult(m_InstanceCancel, false); // 取消静音不成功不删该操作,以备再次取消静音之用
- else
- _end(true);
- }
- else
- {
- if (pNotify->JobBody.find(ESL_JOB_DONE_RES_OK) == string::npos)
- _end(false);
- else
- _end(true); //m_pParent->onOpResult(m_Instance, true); // 静音成功不删该操作,以备取消静音之用
- }
- }
- /*****************************************************************
- **【函数名称】 onHostChanStateUpdated
- **【函数功能】 关联通道状态更新处理
- **【参数】
- **【返回值】
- *****************************************************************/
- void COpMute::onHostChanStateUpdated(VirtualChan* pHostChan)
- {
- if (m_pHostChan->state() == CHAN_LOGIC_STATE_FREE)
- _end(false);
- }
|