123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "FuncBase.h"
- #include "GlobalVariable.h"
- #include "GlobalConfig.h"
- #include "FromRedis.h"
- #include "FromWebAPI.h"
- FuncBase::FuncBase()
- {
- m_fromRedis = std::make_shared<FromRedis>();
- m_fromWebAPI = std::make_shared<FromWebAPI>();
- }
- FuncBase::~FuncBase()
- {
- if(m_fromRedis != nullptr)
- {
- m_fromRedis.reset();
- m_fromRedis = nullptr;
- }
- if(m_fromWebAPI != nullptr)
- {
- m_fromWebAPI.reset();
- m_fromWebAPI = nullptr;
- }
- if(m_logger != nullptr)
- {
- m_logger.reset();
- m_logger = nullptr;
- }
- }
- /* 任务线程 */
- void FuncBase::thread_task()
- {
- /* 先做一些通用的初始化 */
- if(m_logger == nullptr)
- {
- m_logger = spdlog::get("SPAServer");
- if(m_logger == nullptr)
- {
- SPDLOG_ERROR("SPAServer logger is nullptr");
- return;
- }
- }
- /* 线程功能信息 */
- if(m_funcThreadInfo.appFunction == AppFunction::APP_NONE)
- {
- SPDLOG_LOGGER_ERROR(m_logger, "未设置线程功能信息");
- return;
- }
- SPDLOG_LOGGER_INFO(m_logger, "开启 {} 功能线程, ChannelID:{}",m_funcThreadInfo.strFunctionName, m_funcThreadInfo.ChannelID);
- /* 设置线程运行状态 */
- m_bRunning = true;
- /* 执行线程功能,会一直阻塞,直到退出 */
- task();
- /* 设置线程退出的状态,设置成 RUN_STATE_EXITCOMPLET ,就会被管理线程回收 */
- GThreadInfo.setThreadState(m_funcThreadInfo, RunTimeState::RUN_STATE_EXITCOMPLET);
- SPDLOG_LOGGER_INFO(m_logger, "{} 功能线程退出,Channel:{}", m_funcThreadInfo.strFunctionName, m_funcThreadInfo.ChannelID);
- m_bRunning = false;
- }
- /* 设置功能信息 */
- void FuncBase::setFuncThreadInfo(FuncThreadInfo* pFuncAct)
- {
- m_funcThreadInfo = *pFuncAct;
- }
- void FuncBase::setFuncThreadInfo(FuncThreadInfo& FuncAct)
- {
- m_funcThreadInfo = FuncAct;
- }
- /* 获取该实例的功能 */
- AppFunction FuncBase::getApp()
- {
- return m_funcThreadInfo.appFunction;
- }
- /* 获取线程运行状态 */
- bool FuncBase::getThreadRunning() const
- {
- return m_bRunning;
- }
- /* 判断是否在检测时间内 */
- bool FuncBase::isInDetectTime(const QDateTime& start, const QDateTime& end)
- {
- QDateTime now = QDateTime::currentDateTime();
- if(start.isValid() && end.isValid())
- {
- if(now >= start && now <= end)
- {
- return true;
- }
- }
- return false;
- }
|