| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "Session.h"
- #include <algorithm>
- #include "Log.h"
- Session::Session(const std::string & strId) :m_strId(strId), m_transSentenceIndex(0)
- {
- }
- Session::~Session()
- {
- m_lstChan.clear();
- }
- void Session::addChan(const std::shared_ptr<Chan>&spChan)
- {
- auto it = std::find_if(m_lstChan.begin(), m_lstChan.end(), [=](const std::shared_ptr<Chan>&pChan) {return pChan->ChanID().compare(spChan->ChanID()) == 0; });
- if (it == m_lstChan.end()) {
- m_lstChan.emplace_back(spChan);
- auto bk = m_lstChan.back();
- LOG_DEBUG_S(boost::str(Format("添加通道信息\n src[%s] \n dst[%s]")% spChan->to_string() % bk->to_string()));
- }
- else {
- LOG_WARN_S(boost::str(Format("会话[%s]已存在该通道[%s],查到通道[%s]") % spChan->CallID() % spChan->ChanID() % (*it)->to_string()));
- }
- LOG_DEBUG_S(boost::str(Format("会话[%s]添加通道[%s][%s]当前数量[%ld]") % m_strId % spChan->CallID() %spChan->ChanID() % m_lstChan.size()));
- }
- void Session::delChan(const std::shared_ptr<Chan>&spChan)
- {
- auto it = std::find_if(m_lstChan.begin(), m_lstChan.end(), [=](const std::shared_ptr<Chan>&pChan) {return pChan->ChanID().compare(spChan->ChanID())==0; });
- if (it != m_lstChan.end()) {
- m_lstChan.erase(it);
- }
-
- LOG_DEBUG_S(boost::str(Format("会话[%s]删除通道[%s]当前数量[%ld]") % m_strId %spChan->ChanID() % m_lstChan.size()));
- }
- const std::shared_ptr<Chan> Session::getChan(const std::string&strChanID)
- {
- std::shared_ptr<Chan> pChan = nullptr;
- auto it = std::find_if(m_lstChan.begin(), m_lstChan.end(), [=](const std::shared_ptr<Chan>&pChan) {return pChan->ChanID().compare(strChanID) == 0; });
- if (it != m_lstChan.end()) {
- pChan = *it;
- }
- return pChan;
- }
- const std::shared_ptr<Chan> Session::getFirstChan()
- {
- if (!m_lstChan.empty()) {
- return m_lstChan.front();
- }
- return nullptr;
- }
- const std::shared_ptr<Chan> Session::getAssoChan(const std::shared_ptr<Chan>& spChan)
- {
- auto it = std::find_if(m_lstChan.begin(), m_lstChan.end(), [=](const std::shared_ptr<Chan>&pChan) {return pChan->ChanID().compare(spChan->ChanID())!=0; });
- if (it != m_lstChan.end()) {
- return *it;
- }
-
- return nullptr;
- }
- const std::shared_ptr<Chan> Session::getAssoChan(const std::string & strChanID)
- {
- auto it = std::find_if(m_lstChan.begin(), m_lstChan.end(), [=](const std::shared_ptr<Chan>&pChan) {return pChan->ChanID().compare(strChanID)!=0; });
- if (it != m_lstChan.end()) {
- return *it;
- }
- return nullptr;
- }
- void Session::printfChanList()
- {
- for (auto it = m_lstChan.begin(); it != m_lstChan.end(); ++it) {
- auto pChan = *it;
- LOG_DEBUG_S(boost::str(Format("会话[%s]存在通道[%s][%s]") % m_strId %pChan->CallID() % pChan->ChanID()));
- }
- }
|