linux版本中间件

OpMute.cpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "OpMute.h"
  2. #include "VirtualChan.h"
  3. #include "OperationReactor.h"
  4. #include "FsProxy.h"
  5. COpMute::COpMute(COperationReactor* pParent, long Instance) : COperation(pParent, Instance), m_IsOff(false)
  6. {
  7. }
  8. COpMute::~COpMute(void)
  9. {
  10. }
  11. /*****************************************************************
  12. **【函数名称】 _end
  13. **【函数功能】 操作完成
  14. **【参数】 IsSucceed 操作是否成功
  15. lpData 随路数据
  16. **【返回值】
  17. ****************************************************************/
  18. void COpMute::_end(bool IsSucceed)
  19. {
  20. if (m_IsOff)
  21. {
  22. if (IsSucceed)
  23. LOG_INFO("{OpMute}: 分机[%lu]取消静音成功", m_pHostChan->no());
  24. else
  25. LOG_WARN("{OpMute}: 分机[%lu]取消静音失败", m_pHostChan->no());
  26. SqlWrite::GetInstance()->addSql(toSql(IsSucceed, "取消静音"));
  27. //m_pParent->onOpResult(m_InstanceCancel, IsSucceed);
  28. m_pParent->onOpResult(m_InstanceCancel, this, IsSucceed, std::to_string(m_pHostChan->no()),"MuteOff");
  29. }
  30. else
  31. {
  32. if (IsSucceed)
  33. LOG_INFO("{OpMute}: 分机[%lu]静音成功", m_pHostChan->no());
  34. else
  35. LOG_WARN("{OpMute}: 分机[%lu]静音失败", m_pHostChan->no());
  36. SqlWrite::GetInstance()->addSql(toSql(IsSucceed, "静音"));
  37. // 返回执行结果
  38. if (m_InstanceCancel != FS_LINK_INSTANCE_INVALID)
  39. m_pParent->onOpResult(m_InstanceCancel, !IsSucceed);
  40. m_pParent->onOpResult(m_Instance, this, IsSucceed,std::to_string(m_pHostChan->no()),"MuteOn");
  41. }
  42. }
  43. /*****************************************************************
  44. **【函数名称】 start
  45. **【函数功能】 执行操作
  46. **【参数】
  47. **【返回值】
  48. *****************************************************************/
  49. bool COpMute::start(LineOpParam* pParam)
  50. {
  51. // 校验状态
  52. if (m_pHostChan->state() != CHAN_LOGIC_STATE_TALKING)
  53. return false;
  54. LOG_INFO("{OpMute}: 分机[%lu]执行静音", m_pHostChan->no());
  55. m_pAssoChan = CFsProxy::GetInstance().getAssoChanInSession(m_pHostChan);
  56. if (m_pAssoChan == nullptr)
  57. {
  58. LOG_WARN("{OpMute}: 分机[%lu]执行静音失败, 获取关联通道失败, caller = %s,callee = %s", m_pHostChan->no(), m_pHostChan->callerNum().c_str(), m_pHostChan->calleeNum().c_str());
  59. return false;
  60. }
  61. m_SessionId = m_pAssoChan->sessionId();
  62. m_Caller = std::to_string(m_pHostChan->no());
  63. m_CallerAgent = CFsProxy::GetInstance().getAgentByExten(m_Caller);
  64. m_OpTime = Util::CurTime();
  65. return CFsProxy::GetInstance().muteOn(uniqueId(), m_pAssoChan);
  66. //return CFsProxy::GetInstance().muteOn(uniqueId(), m_pHostChan);
  67. }
  68. /*****************************************************************
  69. **【函数名称】 cancel
  70. **【函数功能】 取消操作
  71. **【参数】
  72. **【返回值】
  73. *****************************************************************/
  74. bool COpMute::cancel(long InstanceCancel)
  75. {
  76. LOG_INFO("{OpMute}: 分机[%lu]取消静音", m_pHostChan->no());
  77. m_InstanceCancel = InstanceCancel;
  78. m_IsOff = true;
  79. if (m_pAssoChan != nullptr)
  80. return CFsProxy::GetInstance().muteOff(uniqueId(), m_pAssoChan);
  81. LOG_WARN("{OpMute}: 分机[%lu]取消静音失败,对端线路为空", m_pHostChan->no());
  82. return false;
  83. //return CFsProxy::GetInstance().muteOff(uniqueId(), m_pHostChan);
  84. }
  85. /*****************************************************************
  86. **【函数名称】 hangup
  87. **【函数功能】 操作中挂机
  88. **【参数】
  89. **【返回值】
  90. *****************************************************************/
  91. bool COpMute::hangup(long InstanceHangup)
  92. {
  93. if (m_InstanceCancel != FS_LINK_INSTANCE_INVALID)
  94. return false;
  95. LOG_INFO("{OpMute}: 分机[%lu]静音中挂机", m_pHostChan->no());
  96. m_InstanceCancel = InstanceHangup;
  97. if (CFsProxy::GetInstance().kill(uniqueId(), m_pHostChan))
  98. {
  99. _end(false);
  100. return true;
  101. }
  102. else
  103. {
  104. _end(true);
  105. return false;
  106. }
  107. }
  108. /*****************************************************************
  109. **【函数名称】 onBackgroudJobDone
  110. **【函数功能】 后台命令执行结束事件处理
  111. **【参数】
  112. **【返回值】
  113. *****************************************************************/
  114. void COpMute::onBackgroudJobDone(PBG_JOB_NOTIFY pNotify)
  115. {
  116. if (m_IsOff)
  117. {
  118. if (pNotify->JobBody.find(ESL_JOB_DONE_RES_OK) == string::npos)
  119. m_pParent->onOpResult(m_InstanceCancel, false); // 取消静音不成功不删该操作,以备再次取消静音之用
  120. else
  121. _end(true);
  122. }
  123. else
  124. {
  125. if (pNotify->JobBody.find(ESL_JOB_DONE_RES_OK) == string::npos)
  126. _end(false);
  127. else
  128. _end(true); //m_pParent->onOpResult(m_Instance, true); // 静音成功不删该操作,以备取消静音之用
  129. }
  130. }
  131. /*****************************************************************
  132. **【函数名称】 onHostChanStateUpdated
  133. **【函数功能】 关联通道状态更新处理
  134. **【参数】
  135. **【返回值】
  136. *****************************************************************/
  137. void COpMute::onHostChanStateUpdated(VirtualChan* pHostChan)
  138. {
  139. if (m_pHostChan->state() == CHAN_LOGIC_STATE_FREE)
  140. _end(false);
  141. }