FuncBase.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "FuncBase.h"
  2. #include "GlobalVariable.h"
  3. #include "GlobalConfig.h"
  4. #include "FromRedis.h"
  5. #include "FromWebAPI.h"
  6. FuncBase::FuncBase()
  7. {
  8. m_fromRedis = std::make_shared<FromRedis>();
  9. m_fromWebAPI = std::make_shared<FromWebAPI>();
  10. }
  11. FuncBase::~FuncBase()
  12. {
  13. if(m_fromRedis != nullptr)
  14. {
  15. m_fromRedis.reset();
  16. m_fromRedis = nullptr;
  17. }
  18. if(m_fromWebAPI != nullptr)
  19. {
  20. m_fromWebAPI.reset();
  21. m_fromWebAPI = nullptr;
  22. }
  23. if(m_logger != nullptr)
  24. {
  25. m_logger.reset();
  26. m_logger = nullptr;
  27. }
  28. }
  29. /* 任务线程 */
  30. void FuncBase::thread_task()
  31. {
  32. /* 先做一些通用的初始化 */
  33. if(m_logger == nullptr)
  34. {
  35. m_logger = spdlog::get("SPAServer");
  36. if(m_logger == nullptr)
  37. {
  38. SPDLOG_ERROR("SPAServer logger is nullptr");
  39. return;
  40. }
  41. }
  42. /* 线程功能信息 */
  43. if(m_funcThreadInfo.appFunction == AppFunction::APP_NONE)
  44. {
  45. SPDLOG_LOGGER_ERROR(m_logger, "未设置线程功能信息");
  46. return;
  47. }
  48. SPDLOG_LOGGER_INFO(m_logger, "开启频道: [{}:{}] {}功能线程", m_funcThreadInfo.ChannelID, m_funcThreadInfo.strChannelName, m_funcThreadInfo.strFunctionName);
  49. for(auto& room : m_funcThreadInfo.listRoomCamActInfo)
  50. {
  51. for(auto& cam : room.mapCameraAction)
  52. {
  53. for(auto& act : cam.second)
  54. {
  55. SPDLOG_LOGGER_DEBUG(m_logger, "房间ID: {}, 摄像机ID: {}, 算法ID: {}", room.RoomID, cam.first, act);
  56. }
  57. }
  58. }
  59. /* 设置线程运行状态 */
  60. m_bRunning = true;
  61. /* 执行线程功能,会一直阻塞,直到退出 */
  62. // task();
  63. /* 设置线程退出的状态,设置成 RUN_STATE_EXITCOMPLET ,就会被管理线程回收 */
  64. GThreadInfo.setThreadState(m_funcThreadInfo, RunTimeState::RUN_STATE_EXITCOMPLET);
  65. SPDLOG_LOGGER_INFO(m_logger, "{} 功能线程退出,Channel:{}", m_funcThreadInfo.strFunctionName, m_funcThreadInfo.ChannelID);
  66. m_bRunning = false;
  67. }
  68. /* 设置功能信息 */
  69. void FuncBase::setFuncThreadInfo(FuncThreadInfo* pFuncAct)
  70. {
  71. m_funcThreadInfo = *pFuncAct;
  72. }
  73. void FuncBase::setFuncThreadInfo(FuncThreadInfo& FuncAct)
  74. {
  75. m_funcThreadInfo = FuncAct;
  76. }
  77. /* 获取该实例的功能 */
  78. AppFunction FuncBase::getApp()
  79. {
  80. return m_funcThreadInfo.appFunction;
  81. }
  82. /* 获取线程运行状态 */
  83. bool FuncBase::getThreadRunning() const
  84. {
  85. return m_bRunning;
  86. }
  87. /* 判断是否在检测时间内 */
  88. bool FuncBase::isInDetectTime(const QDateTime& start, const QDateTime& end)
  89. {
  90. QDateTime now = QDateTime::currentDateTime();
  91. if(start.isValid() && end.isValid())
  92. {
  93. if(now >= start && now <= end)
  94. {
  95. return true;
  96. }
  97. }
  98. return false;
  99. }