linux版本中间件

OpMeeting.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "OpMeeting.h"
  2. #include "VirtualChan.h"
  3. #include "OperationReactor.h"
  4. #include "FsProxy.h"
  5. #include "Config.h"
  6. #include "ChanExten.h"
  7. #include "Session.h"
  8. COpMeeting::COpMeeting(COperationReactor * pParent, long Instance) : COperation(pParent, Instance), m_Step(0), m_pAssoChan(nullptr)
  9. {
  10. }
  11. COpMeeting::~COpMeeting(void)
  12. {
  13. }
  14. bool COpMeeting::start(LineOpParam * pParam)
  15. {
  16. // 校验状态
  17. if (m_pHostChan->state() != CHAN_LOGIC_STATE_TALKING)
  18. return false;
  19. m_MeetingId = pParam->nParam1; // callid
  20. m_CallerNum = pParam->szParam1;
  21. m_DestNumber = pParam->szParam2;
  22. // 判断被邀请会议的是否是内线分机
  23. uint32_t ExtenNo = 0;
  24. sscanf(pParam->szParam2.c_str(), "%lu", &ExtenNo);
  25. ChanExten* pExten = CFsProxy::GetInstance().getExten(ExtenNo);
  26. if (pExten != nullptr)
  27. {
  28. if (!pExten->isFree())
  29. {
  30. LOG_WARN(("{OpMeeting}: 分机[%lu]执行会议失败, 目标分机[%lu]非空闲"), m_pHostChan->no(), ExtenNo);
  31. return false;
  32. }
  33. // 若主叫为空,则置为发起会议的分机通道号
  34. if (m_CallerNum.empty())
  35. m_CallerNum = std::to_string(m_pHostChan->no());
  36. }
  37. // 通知启动日志
  38. LOG_INFO(("{OpMeeting}: 分机[%lu]执行会议, DestNum = %s"), m_pHostChan->no(), m_DestNumber.c_str());
  39. std::string caller_agent = CFsProxy::GetInstance().getAgentByExten(m_CallerNum);
  40. std::string callee_agent = CFsProxy::GetInstance().getAgentByExten(m_DestNumber);
  41. m_SessionId = m_MeetingId;
  42. m_Caller = m_CallerNum;
  43. m_CallerAgent = caller_agent;
  44. m_Callee = m_DestNumber;
  45. m_CalleeAgent = callee_agent;
  46. m_OpTime = Util::CurTime();
  47. {
  48. Format fmt("update cdr set op_type = %d where uuid = '%s'");
  49. fmt % LINE_OP_CONFERENCE % m_MeetingId;
  50. SqlWrite::GetInstance()->addSql(fmt.str());
  51. }
  52. {
  53. Format fmt("insert into conference(uuid,caller_agent,caller,callee_agent,callee,create_time) values('%s','%s','%s','%s','%s','%s')");
  54. fmt %m_MeetingId %caller_agent %m_CallerNum %callee_agent %m_DestNumber %m_OpTime;
  55. SqlWrite::GetInstance()->addSql(fmt.str());
  56. }
  57. if (m_pHostChan->isInMeeting())
  58. {
  59. m_Step = 2;
  60. return CFsProxy::GetInstance().meeting(uniqueId(), m_CallerNum, m_DestNumber, m_MeetingId);
  61. }
  62. else
  63. {
  64. m_Step = 1;
  65. m_pAssoChan = CFsProxy::GetInstance().getAssoChanInSession(m_pHostChan);
  66. return CFsProxy::GetInstance().transfer2Context(uniqueId(), m_pHostChan->chanId(), m_MeetingId, CConfig::GetInstance()->meetingContext(), true);
  67. }
  68. }
  69. void COpMeeting::onBackgroudJobDone(PBG_JOB_NOTIFY pNotify)
  70. {
  71. if (pNotify->JobBody.find(ESL_JOB_DONE_RES_OK) == string::npos)
  72. _end(false);
  73. else
  74. {
  75. if (m_Step == 1)
  76. {
  77. m_pHostChan->isInMeeting() = true;
  78. if (m_pAssoChan != nullptr)
  79. m_pAssoChan->isInMeeting() = true;
  80. m_Step = 2;
  81. if (!CFsProxy::GetInstance().meeting(uniqueId(), m_CallerNum, m_DestNumber, m_MeetingId))
  82. _end(false);
  83. }
  84. else _end(true);
  85. }
  86. }
  87. void COpMeeting::onAssoChanStateUpdated(VirtualChan * pAssoChan)
  88. {
  89. if (pAssoChan == nullptr) return;
  90. switch ((int)pAssoChan->state())
  91. {
  92. case CHAN_LOGIC_STATE_ALERTING:
  93. case CHAN_LOGIC_STATE_RING_BACK:
  94. {
  95. m_pParent->onOpProcess(m_Instance, m_pHostChan->no(), pAssoChan->no(), pAssoChan->type(), m_CallerNum, m_DestNumber);
  96. if (m_RingTime.empty())
  97. m_RingTime = Util::CurTime();
  98. m_Callid = pAssoChan->sessionId();
  99. auto pSession = CFsProxy::GetInstance().getSession(m_Callid);
  100. if (pSession != nullptr)
  101. {
  102. pSession->ringTime() = m_RingTime;
  103. }
  104. pAssoChan->isInMeeting() = true;
  105. }
  106. break;
  107. case CHAN_LOGIC_STATE_FREE:
  108. _end(false);
  109. }
  110. }
  111. void COpMeeting::_end(bool IsSucceed)
  112. {
  113. if (IsSucceed)
  114. {
  115. LOG_INFO(("{OpMeeting}: 分机[%lu]执行会议成功, DestNum = %s"), m_pHostChan->no(), m_DestNumber.c_str());
  116. m_AnswerTime = Util::CurTime();
  117. auto pSession = CFsProxy::GetInstance().getSession(m_Callid);
  118. if (pSession != nullptr)
  119. {
  120. pSession->answerTime() = m_AnswerTime;
  121. }
  122. }
  123. else
  124. {
  125. LOG_WARN(("{OpMeeting}: 分机[%lu]执行会议失败, DestNum = %s"), m_pHostChan->no(), m_DestNumber.c_str());
  126. }
  127. Format fmt("update conference set chanid = '%s', is_success = %d,end_time = '%s' where uuid = '%s' and caller = '%s' and callee = '%s'");
  128. fmt %m_Callid %IsSucceed %Util::CurTime() % m_MeetingId %m_CallerNum %m_DestNumber;
  129. SqlWrite::GetInstance()->addSql(fmt.str());
  130. SqlWrite::GetInstance()->addSql(toSql(IsSucceed, "会议"));
  131. // 返回执行结果
  132. if (m_InstanceCancel != FS_LINK_INSTANCE_INVALID)
  133. m_pParent->onOpResult(m_InstanceCancel, !IsSucceed);
  134. m_pParent->onOpResult(m_Instance, this, IsSucceed, std::to_string(m_pHostChan->no()));
  135. }