linux版本中间件

VideoOffice.cpp 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "VideoOffice.h"
  2. #include "VideoExten.h"
  3. #include "JdbcHelper.h"
  4. #include "Log.h"
  5. CVideoOffice::CVideoOffice()
  6. {
  7. }
  8. CVideoOffice::~CVideoOffice()
  9. {
  10. }
  11. bool CVideoOffice::initVideoExten()
  12. {
  13. LOG_INFO("视频账号开始初始化");
  14. std::string strSQL = "SELECT exten ,pwd FROM rep_video_account";
  15. JdbcHelper::GetInstance()->jdbc_executeQuery(strSQL, NULL, [this](sql::ResultSet* result) {
  16. while (result->next())
  17. {
  18. auto extenId = result->getUInt(1);
  19. sql::SQLString pwd = result->getString(2);
  20. CVideoExten *pExten = new CVideoExten(extenId, pwd);
  21. m_VideoExtens.insert(std::make_pair(extenId, pExten));
  22. LOG_INFO("添加视频账号[%lu]密码[%s]", extenId, pwd.c_str());
  23. }
  24. }, NULL);
  25. LOG_INFO("视频账号结束初始化");
  26. return true;
  27. }
  28. bool CVideoOffice::findVideoExten(uint32_t & a_VideoExtId, std::string & a_VideoExtPwd)
  29. {
  30. std::unique_lock<std::mutex> lock(mut);
  31. auto it = m_VideoExtens.begin();
  32. while (it != m_VideoExtens.end())
  33. {
  34. if (it->second->isUsed() == false)
  35. {
  36. it->second->isUsed() = true;
  37. a_VideoExtId = it->second->id();
  38. a_VideoExtPwd = it->second->pwd();
  39. LOG_INFO("获取视频分机号[%lu]密码[%s]",a_VideoExtId,a_VideoExtPwd.c_str());
  40. return true;
  41. }
  42. ++it;
  43. }
  44. LOG_WARN("找不到可用视频账号");
  45. return false;
  46. }
  47. bool CVideoOffice::recoverVideoExten(uint32_t a_VideoExtId, bool bIsRm)
  48. {
  49. bool ret = false;
  50. std::unique_lock<std::mutex> lock(mut);
  51. auto it = m_VideoExtens.find(a_VideoExtId);
  52. if (it != m_VideoExtens.end()) {
  53. ret = true;
  54. it->second->isUsed() = false;
  55. if (!bIsRm) {
  56. LOG_INFO("释放视频分机号[%lu]状态[%s]", a_VideoExtId, it->second->isUsed() ? "不可用" : "可用");
  57. }
  58. else {
  59. LOG_INFO("释放视频分机号[%lu]状态[%s],话机取消注册", a_VideoExtId, it->second->isUsed() ? "不可用" : "可用");
  60. }
  61. }
  62. else {
  63. return ret;
  64. }
  65. auto iter = m_VideoExtens.begin();
  66. while (iter != m_VideoExtens.end()) {
  67. LOG_DEBUG("分机[%lu]状态[%s]", iter->second->id(), iter->second->isUsed() ? "已被用" : "可用");
  68. ++iter;
  69. }
  70. return ret;
  71. }
  72. void CVideoOffice::close()
  73. {
  74. std::unique_lock<std::mutex> lock(mut);
  75. auto it = m_VideoExtens.begin();
  76. while (it != m_VideoExtens.end()){
  77. delete it->second;
  78. it->second = nullptr;
  79. ++it;
  80. }
  81. m_VideoExtens.clear();
  82. }