#ifndef GLOBALFUNCTHREAD_H #define GLOBALFUNCTHREAD_H #include "GlobalVariable.h" /** * @brief 按照功能分类的线程信息,一个实例就是一个功能, 比如区域入侵检测,需要多个算法多个摄像机共同配合 * */ struct FuncThreadInfo { int ChannelID; /* 频率ID */ std::string strChannelName; /* 频率名称 */ AppFunction appFunction; /* 任务功能 */ RunTimeState RunState; /* 线程运行状态 */ std::string strFunctionName; /* 功能名称 */ QDateTime StartTime; /* 开始时间 */ QDateTime EndTime; /* 结束时间 */ std::list listRoomCamActInfo; /* 房间内的摄像机和算法关联信息 */ std::map mapCameraName; /* 摄像机名称 */ FuncThreadInfo(); ~FuncThreadInfo(); FuncThreadInfo& operator=(FuncThreadInfo& other); /* 添加算法信息 */ bool addActionInfo(const ActionInfo& info); /* 清空算法信息 */ void clearActionList(); /* 获取摄像机名称 */ std::string getCameraName(int CameraID); }; /** * @brief 线程功能块 * */ struct ListFuncActInfo { ListFuncActInfo() = default; /* 添加功能信息 */ bool addFuncThreadInfo(const AppAndTimeInfo& func); /* 添加算法信息 */ bool addActionInfo(const ActionInfo& info); /* 清空无用的功能信息 */ void clearNoneFuncThreadInfo(); /* 清空房间和算法列表 */ void clearActionList(); /* 获取容器 */ std::list& getData() { return listFuncThreadInfo; } /* 查找应用信息 */ bool findAppFunction(const AppFunction func); FuncThreadInfo* findAppFunction(const int ChannelID, const AppFunction func); FuncThreadInfo* findAppFunction(const FuncThreadInfo& func); std::list listFuncThreadInfo; /* 功能信息列表 */ }; /* ==================================================================================== * ************************ GlobalThreadInfo成员函数 **************************** * ====================================================================================*/ #define GThreadInfo GlobalThreadInfo::getInstance() /** * @brief 线程信息,也是应用功能块列表,每个频率下的每个功能就是一个线程 * */ class GlobalThreadInfo { GlobalThreadInfo() {} ~GlobalThreadInfo() {} GlobalThreadInfo(const GlobalThreadInfo& other) = delete; GlobalThreadInfo& operator=(const GlobalThreadInfo& other) = delete; public: static GlobalThreadInfo& getInstance() { static GlobalThreadInfo instance; return instance; } /* 获取线程运行标志位 */ bool getRunning() const; /* 设置线程运行标志位 */ void setRunning(bool bRunning); /* 手动给功能块列表加锁 */ void lockRunFAI(); /* 手动解锁 */ void unlockRunFAI(); /* 添加功能信息 */ bool addFuncThreadInfo(const AppAndTimeInfo& func); /* 添加算法信息 */ bool addActionInfo(const ActionInfo& info); /* 清空无用的功能信息 */ void clearNoneFuncThreadInfo(); /* 清空房间和算法列表 */ void clearActionList(); /* 设置没有配置摄像机的功能退出 */ void setNoneCameraFuncStop(); /* 获取容器 */ std::list& getList() { return m_listFuncThreadInfo; } /* 查找应用信息 */ bool findAppFunction(const AppFunction func); FuncThreadInfo* findAppFunction(const int ChannelID, const AppFunction func); FuncThreadInfo* findAppFunction(const FuncThreadInfo& func); /* 设置线程状态 */ void setThreadState(FuncThreadInfo* pInfo, RunTimeState state); void setThreadState(FuncThreadInfo& pInfo, RunTimeState state); /* 更新算法的摄像机ID */ bool updateFuncInfo(FuncThreadInfo* pInfo); bool updateFuncInfo(FuncThreadInfo& pInfo); /* 更新频率信息 */ // void setChannelInfo(std::map mapChannelName); /* 设置摄像机信息 */ void setCameraInfo(std::map mapCameraName); private: std::atomic_bool m_bRunning; /* 线程运行状态 */ /* 运行时应用线程功能相关信息 */ std::mutex m_mutexRunFAI; std::list m_listFuncThreadInfo; /* 功能信息列表 */ }; #endif // GLOBALFUNCTHREAD_H