#include "VideoOffice.h" #include "VideoExten.h" #include "JdbcHelper.h" #include "Log.h" CVideoOffice::CVideoOffice() { } CVideoOffice::~CVideoOffice() { } bool CVideoOffice::initVideoExten() { LOG_INFO("视频账号开始初始化"); std::string strSQL = "SELECT exten ,pwd FROM rep_video_account"; JdbcHelper::GetInstance()->jdbc_executeQuery(strSQL, NULL, [this](sql::ResultSet* result) { while (result->next()) { auto extenId = result->getUInt(1); sql::SQLString pwd = result->getString(2); CVideoExten *pExten = new CVideoExten(extenId, pwd); m_VideoExtens.insert(std::make_pair(extenId, pExten)); LOG_INFO("添加视频账号[%lu]密码[%s]", extenId, pwd.c_str()); } }, NULL); LOG_INFO("视频账号结束初始化"); return true; } bool CVideoOffice::findVideoExten(uint32_t & a_VideoExtId, std::string & a_VideoExtPwd) { std::unique_lock lock(mut); auto it = m_VideoExtens.begin(); while (it != m_VideoExtens.end()) { if (it->second->isUsed() == false) { it->second->isUsed() = true; a_VideoExtId = it->second->id(); a_VideoExtPwd = it->second->pwd(); LOG_INFO("获取视频分机号[%lu]密码[%s]",a_VideoExtId,a_VideoExtPwd.c_str()); return true; } ++it; } LOG_WARN("找不到可用视频账号"); return false; } bool CVideoOffice::recoverVideoExten(uint32_t a_VideoExtId, bool bIsRm) { bool ret = false; std::unique_lock lock(mut); auto it = m_VideoExtens.find(a_VideoExtId); if (it != m_VideoExtens.end()) { ret = true; it->second->isUsed() = false; if (!bIsRm) { LOG_INFO("释放视频分机号[%lu]状态[%s]", a_VideoExtId, it->second->isUsed() ? "不可用" : "可用"); } else { LOG_INFO("释放视频分机号[%lu]状态[%s],话机取消注册", a_VideoExtId, it->second->isUsed() ? "不可用" : "可用"); } } else { return ret; } auto iter = m_VideoExtens.begin(); while (iter != m_VideoExtens.end()) { LOG_DEBUG("分机[%lu]状态[%s]", iter->second->id(), iter->second->isUsed() ? "已被用" : "可用"); ++iter; } return ret; } void CVideoOffice::close() { std::unique_lock lock(mut); auto it = m_VideoExtens.begin(); while (it != m_VideoExtens.end()){ delete it->second; it->second = nullptr; ++it; } m_VideoExtens.clear(); }