FuncBase.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "FuncBase.h"
  2. #include "GlobalVariable.h"
  3. #include "GlobalConfig.h"
  4. #include "FromRedis.h"
  5. #include "ToEQMDataBase.h"
  6. FuncBase::FuncBase()
  7. {
  8. m_fromRedis = std::make_shared<FromRedis>();
  9. m_toEQMDataBase = std::make_shared<ToEQMDataBase>();
  10. }
  11. FuncBase::~FuncBase()
  12. {
  13. }
  14. /* 任务线程 */
  15. void FuncBase::thread_task()
  16. {
  17. /* 先做一些通用的初始化 */
  18. if(m_logger == nullptr)
  19. {
  20. m_logger = spdlog::get("SPAServer");
  21. if(m_logger == nullptr)
  22. {
  23. SPDLOG_ERROR("SPAServer logger is nullptr");
  24. return;
  25. }
  26. }
  27. /* 线程功能信息 */
  28. if(m_funcAct.appFunction == AppFunction::APP_NONE)
  29. {
  30. SPDLOG_LOGGER_ERROR(m_logger, "未设置线程功能信息");
  31. return;
  32. }
  33. SPDLOG_LOGGER_INFO(m_logger, "开启 {} 功能线程, ChannelID:{}",m_funcAct.strFunctionName, m_funcAct.ChannelID);
  34. /* 设置线程运行状态 */
  35. m_bRunning = true;
  36. /* 执行线程功能,会一直阻塞,直到退出 */
  37. task();
  38. /* 设置线程退出的状态,设置成 RUN_STATE_EXITCOMPLET ,就会被管理线程回收 */
  39. GThreadInfo.setThreadState(m_funcAct, RunTimeState::RUN_STATE_EXITCOMPLET);
  40. SPDLOG_LOGGER_INFO(m_logger, "{} 功能线程退出,Channel:{}", m_funcAct.strFunctionName, m_funcAct.ChannelID);
  41. m_bRunning = false;
  42. }
  43. /* 设置功能信息 */
  44. void FuncBase::setFuncActionInfo(FuncActionInfo* pFuncAct)
  45. {
  46. m_funcAct = *pFuncAct;
  47. }
  48. void FuncBase::setFuncActionInfo(FuncActionInfo& FuncAct)
  49. {
  50. m_funcAct = FuncAct;
  51. }
  52. /* 获取该实例的功能 */
  53. AppFunction FuncBase::getApp()
  54. {
  55. return m_funcAct.appFunction;
  56. }
  57. /* 获取线程运行状态 */
  58. bool FuncBase::getThreadRunning() const
  59. {
  60. return m_bRunning;
  61. }
  62. /* 判断是否在检测时间内 */
  63. bool FuncBase::isInDetectTime(const QDateTime& start, const QDateTime& end)
  64. {
  65. QDateTime now = QDateTime::currentDateTime();
  66. if(start.isValid() && end.isValid())
  67. {
  68. if(now >= start && now <= end)
  69. {
  70. return true;
  71. }
  72. }
  73. return false;
  74. }