123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704 |
- #ifndef GLOBALINFO_H
- #define GLOBALINFO_H
- #include <QString>
- #include <vector>
- #include <list>
- #include <map>
- #include <mutex>
- #include <QDateTime>
- #include <QReadWriteLock>
- #include "nlohmann/json.hpp"
- /* ====================================================================================
- * ******************************* 全局变量定义 **********************************
- * ====================================================================================*/
- /**
- * @brief 全局信息
- *
- */
- using nJson = nlohmann::json;
- /* Rides数据时间有效性 */
- extern int g_eventTimeVaild;
- /* 线程运行时的状态 */
- enum class RunTimeState
- {
- RUN_STATE_INIT = 0, /* 初始化 */
- RUN_STATE_RUN, /* 运行 */
- RUN_STATE_STOP, /* 停止 */
- RUN_STATE_ERROR, /* 错误 */
- RUN_STATE_NONE /* 无状态 */
- };
- /* 应用功能 */
- enum class AppFunction
- {
- APP_NONE = 0, /* 无功能 */
- APP_ONWORK = 1, /* 人员在岗识别(需要多个摄像机配合) */
- APP_CONTRABAND, /* 违禁品识别 */
- APP_ILLEGAL, /* 非法入侵检测 */
- APP_FATIGUE, /* 疲劳检测 */
- APP_REGIONAL, /* 区域人员检测(需要多个摄像机配合) */
- APP_MOUSE, /* 老鼠识别 */
- APP_PLAYPHONE, /* 玩手机识别 */
- APP_NOMASK, /* 未戴口罩识别 */
- APP_ALLDOWN, /* 摔倒识别 */
- };
- /* 全局算法列表 */
- class ActionList
- {
- public:
- /* 全局算法ID */
- // std::mutex mutexActionID; /* 算法ID的互斥锁 */
- QReadWriteLock mutexRW; /* 读写锁 */
- std::string ActFace; /* 人脸识别 */
- std::string ActPersonNumber; /* 人员计数 */
- std::string ActPlayPhone; /* 玩手机 */
- std::string ActContraband; /* 违禁品物品 */
- std::string ActSleep; /* 睡岗识别 */
- std::string ActFatigueDetection; /* 疲劳检测 */
- std::string ActAnimalDetect; /* 动物识别 */
- std::string ActMouseDetect; /* 老鼠识别 */
- std::string ActMask; /* 口罩识别 */
- };
- extern ActionList g_actionList;
- /* 算法相关信息 */
- struct AlgorithmInfo
- {
- int PKID; /* 主键ID */
- int ActionTaskID; /* 算法任务ID */
- std::string ActionID; /* 算法ID */
- std::string ActionName; /* 算法名称 */
-
- AlgorithmInfo() = default;
- AlgorithmInfo(const AlgorithmInfo& other)
- : PKID(other.PKID), ActionID(other.ActionID), ActionName(other.ActionName), ActionTaskID(other.ActionTaskID) {}
- AlgorithmInfo& operator=(const AlgorithmInfo& other) {
- if (this != &other) {
- ActionID = other.ActionID;
- ActionName = other.ActionName;
- ActionTaskID = other.ActionTaskID;
- PKID = other.PKID;
- }
- return *this;
- }
- /* 对比是否相等 */
- bool operator==(const AlgorithmInfo& other) const {
- if(ActionID != other.ActionID) {
- return false;
- }
- if(ActionName != other.ActionName || ActionTaskID != other.ActionTaskID) {
- return false;
- }
- return true;
- }
- };
- /* 设备列表 */
- struct DeviceInfo
- {
- int PKID; /* 主键ID */
- int DeviceID; /* 设备ID */
- int DevicePort; /* 设备端口 */
- std::string DeviceName; /* 设备名称 */
- std::string DeviceIP; /* 设备IP */
- std::string DeviceSerial; /* 设备序列号 */
- std::string DeviceType; /* 设备类型 */
- std::string UserAccount; /* 用户账号 */
- std::string UserPassword; /* 用户密码 */
- std::vector<AlgorithmInfo> vecAlgorithmInfo; /* 算法信息 */
- DeviceInfo() = default;
- DeviceInfo(const DeviceInfo& other)
- : PKID(other.PKID),
- DeviceID(other.DeviceID),
- DevicePort(other.DevicePort),
- DeviceName(other.DeviceName),
- DeviceSerial(other.DeviceSerial),
- DeviceType(other.DeviceType),
- DeviceIP(other.DeviceIP),
- UserAccount(other.UserAccount),
- UserPassword(other.UserPassword),
- vecAlgorithmInfo(other.vecAlgorithmInfo) {}
- DeviceInfo& operator=(const DeviceInfo& other) {
- if (this != &other) {
- DeviceID = other.DeviceID;
- DevicePort = other.DevicePort;
- DeviceName = other.DeviceName;
- DeviceSerial = other.DeviceSerial;
- DeviceType = other.DeviceType;
- DeviceIP = other.DeviceIP;
- UserAccount = other.UserAccount;
- UserPassword = other.UserPassword;
- vecAlgorithmInfo = other.vecAlgorithmInfo;
- }
- return *this;
- }
- /* 对比是否相等 */
- bool operator==(const DeviceInfo& other);
- /* 对比设备关联的算法信息是否相等 */
- bool isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other);
- };
- /* 算法和设备关联的相关信息 */
- struct DeviceAlgorithmInfo
- {
- int DeviceID; /* 设备ID */
- int ActionTaskID; /* 算法任务ID */
- std::string ActionID; /* 算法ID */
- std::string ActionName; /* 算法名称 */
- };
- /**
- * @brief 摄像机线程需要的信息
- *
- */
- struct CameraThreadInfo
- {
- std::string RedisIP; /* Redis IP */
- int RedisPort; /* Redis Port */
- std::string RedisPWD; /* Redis Password */
- int DeviceID; /* 设备ID */
- std::vector<std::string> vecAction; /* Redis Key,一个设备可能会有多个算法ID */
- CameraThreadInfo() = default;
- CameraThreadInfo& operator=(const CameraThreadInfo& other) {
- if (this != &other) {
- RedisIP = other.RedisIP;
- RedisPort = other.RedisPort;
- RedisPWD = other.RedisPWD;
- DeviceID = other.DeviceID;
- vecAction = other.vecAction;
- }
- return *this;
- }
- };
- /* ====================================================================================
- * ******************************* 各种报警信息 **********************************
- * ====================================================================================*/
- /**
- * @brief 人员信息
- *
- */
- struct PersonInfo
- {
- std::string PersonID; /* 人员ID,等于-1就是无法识别出身份的人员 */
- std::string PersonName; /* 人员名称 */
- QDateTime lastOnWork; /* 最后在岗时间 */
- };
- /**
- * @brief 报警信息
- *
- */
- struct AlarmInfo
- {
- bool Is_Alarm; /* 是否报警 */
- int AlarmID; /* 报警ID */
- int DeviceID; /* 设备ID,数据库表格中对应的是CamerID */
-
- int RoomID; /* 房间ID */
- int ChannelID; /* 通道ID */
- int State; /* 状态 */
- int OnWork; /* 是否在工作 */
- std::string ActionID; /* 算法ID */
- std::string StartTime; /* 报警开始时间 */
- std::string EndTime; /* 报警结束时间 */
- std::string EventTime; /* 事件时间(报警发生时间,在数据库里对应的是CreateTime) */
- std::string PicUrl; /* 报警图片URL */
- std::string ImageInfo; /* 图片信息 */
- std::string AppID; /* 客户端应用ID */
- std::string ActionDes; /* 算法描述信息 */
- std::string FaceIDList; /* 人脸ID列表 */
- std::string FaceNameList; /* 人脸名称列表 */
- std::string BboxList; /* Bbox列表,应该是图片中的报警位置 */
- std::vector<PersonInfo> vecPersonInfo; /* 人员信息 */
- AlarmInfo();
- AlarmInfo(const AlarmInfo& other);
- AlarmInfo& operator=(AlarmInfo& other);
- void reInit();
- };
- /**
- * @brief 报警信息容器,并提供一些函数
- *
- */
- struct ListAlarmInfo
- {
- std::list<AlarmInfo> listAlarmInfo; /* 报警信息列表 */
- /* 添加报警信息 */
- bool addAlarmInfo(AlarmInfo& info);
- AlarmInfo* findAlarmInfo(AlarmInfo& info);
- };
- /**
- * @brief 房间内的人脸信息
- *
- */
- struct RoomFaceInfo
- {
- int ChannelID = 0;
- int RoomID = 0;
- int CameraID = 0;
- int MaxNum = 0;
- int MinNum = 0;
- QDateTime StartTime;
- QDateTime EndTime;
- std::list<PersonInfo> listPersonInfo;
- RoomFaceInfo() = default;
- RoomFaceInfo& operator=(const RoomFaceInfo& other) {
- if (this != &other) {
- ChannelID = other.ChannelID;
- RoomID = other.RoomID;
- CameraID = other.CameraID;
- MaxNum = other.MaxNum;
- MinNum = other.MinNum;
- StartTime = other.StartTime;
- EndTime = other.EndTime;
- listPersonInfo = other.listPersonInfo;
- }
- return *this;
- }
- /* 查找是否有相同的人脸信息 */
- bool findPersonInfo(const PersonInfo& info);
- };
- /**
- * @brief 房间内的人脸信息
- *
- */
- struct ListRoomFaceInfo
- {
- std::list<RoomFaceInfo> listRoomFaceInfo;
- void addRoomFaceInfo(RoomFaceInfo& info);
- void addRoomFaceInfo(AlarmInfo& info);
- RoomFaceInfo* findRoomFaceInfo(RoomFaceInfo& info);
- RoomFaceInfo* findRoomFaceInfo(int ChannelID, int RoomID, int CameraID);
- };
- /**
- * @brief 非法入侵检测信息结构体,作为缓存存储正在报警的信息
- *
- */
- struct IllegalInvasionInfo
- {
- bool isInsertEQM = false; /* 是否已经插入到EQM数据库的报警信息中 */
- int PKID = 0;
- int CameraID = 0;
- int RoomID = 0;
- int ChannelID = 0;
- int RoomType = 0; /* 房间类型 */
- QDateTime FirstTime; /* 最开始的报警时间 */
- std::string strActionDec; /* 算法描述 */
- std::string strImageInfo; /* 图片信息 */
- IllegalInvasionInfo() = default;
- IllegalInvasionInfo(IllegalInvasionInfo& other);
- IllegalInvasionInfo& operator=(IllegalInvasionInfo& other);
- };
- /**
- * @brief 非法入侵报警列表
- *
- */
- struct ListIllegalInvasionInfo
- {
- std::list<IllegalInvasionInfo> listIll;
- std::list<IllegalInvasionInfo>& getData() { return listIll; }
- /* 添加信息 */
- void addIllInfo(IllegalInvasionInfo& info);
- /* 查找相同的信息 */
- IllegalInvasionInfo* findIllInfo(IllegalInvasionInfo& info);
- IllegalInvasionInfo* findIllInfo(int roomID, int roomType);
- };
- /**
- * @brief 房间为单位的非法入侵信息
- *
- */
- struct RoomIllegalInvasionInfo
- {
- bool isAlarm = false; /* 是否在报警 */
- int RoomID = 0; /* 房间ID */
- int RoomType = 0; /* 房间类型 */
- int numMaxFace = 0; /* 最大人脸数 */
- int numMaxPerson = 0; /* 最大人员数 */
- int CameraID = 0; /* 摄像机ID,这个存储的是使用的哪个报警信息的ID */
- std::string strBoxList; /* box */
- std::string strMessage; /* 报警信息字符串 */
- std::string strImage; /* 报警图片 */
- std::vector<PersonInfo> vecPersonInfo; /* 人员信息 */
- RoomIllegalInvasionInfo() = default;
- RoomIllegalInvasionInfo(RoomIllegalInvasionInfo& o);
- RoomIllegalInvasionInfo& operator=(RoomIllegalInvasionInfo& o);
- };
- /**
- * @brief 房间报警数据,以房间为单位
- *
- */
- struct ListRoomIll
- {
- std::list<RoomIllegalInvasionInfo> listRoomIll;
- std::list<RoomIllegalInvasionInfo>& getData() { return listRoomIll; }
- /* 添加房间 */
- void addRoom(int RoomID, int RoomType);
- /* 查找是否有相同的房间 */
- RoomIllegalInvasionInfo* findRoom(int RoomID, int RoomType);
- };
- /**
- * @brief 报警规则
- *
- */
- struct AlarmRuleInfo
- {
- bool LiveMinEnable; /* 启用直播间最小人数 */
- bool LiveMaxEnable; /* 启用直播间最大人数 */
- bool DicMinEnable; /* 启用导播间最小人数 */
- bool DicMaxEnable; /* 启用导播间最大人数 */
- bool LiveDicMinEnable; /* 启用直播间和导播间最小人数 */
- bool LiveDicMaxEnable; /* 启用直播间和导播间最大人数 */
- int LiveMin; /* 直播间最小人数 */
- int LiveMax; /* 直播间最大人数 */
- int DicMin; /* 导播间最小人数 */
- int DicMax; /* 导播间最大人数 */
- int LiveDicMin; /* 直播间和导播间最小人数 */
- int LiveDicMax; /* 直播间和导播间最大人数 */
- std::string RuleName; /* 规则名称 */
- AlarmRuleInfo();
- AlarmRuleInfo& operator=(AlarmRuleInfo& other);
- };
- /**
- * @brief 房间和摄像机关联信息,这个是从客户端配置的
- * 一个房间对应多个摄像机
- *
- */
- struct RoomCameraInfo
- {
- int RoomID; /* 房间ID */
- std::list<int> listCameraID; /* 摄像机列表 */
- RoomCameraInfo() = default;
- RoomCameraInfo& operator=(const RoomCameraInfo& other) {
- if (this != &other) {
- RoomID = other.RoomID;
- listCameraID = other.listCameraID;
- }
- return *this;
- }
- /* 这里只对比RoomID */
- bool operator==(const RoomCameraInfo& other) const {
- if(RoomID != other.RoomID) {
- return false;
- }
- return true;
- }
- };
- /* ====================================================================================
- * **************************** 线程功能需要的结构体 *****************************
- * ====================================================================================*/
- /**
- * @brief 单个算法信息,包括包含的摄像机,房间、频率信息
- *
- */
- struct ActionInfo
- {
- RunTimeState RunState; /* 线程运行状态 */
- int ChannelID; /* 通道ID */
- int RoomID; /* 房间ID */
- int CameraID; /* 摄像机ID */
- int RoomType; /* 房间类型 */
- std::string ActionID; /* 算法ID */
- std::string strRoomName; /* 房间名称 */
- std::string strActionName; /* 算法名称,这个是自定义的,不需要对比 */
- ActionInfo();
- ActionInfo& operator=(const ActionInfo& other);
- /* 对比是否相等,这个需要完全相等,包括算法信息和摄像机信息 */
- bool operator==(const ActionInfo& other);
- /* 对比除摄像机外的基础信息是否相等 */
- bool isEqualBaseInfo(const ActionInfo& other);
-
- };
- /**
- * @brief 算法信息列表,这个列表既可以存储房间和算法ID的关联信息,也可以用来存储运行线程的信息
- *
- */
- class ListActionInfo
- {
- public:
- ListActionInfo() = default;
- /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
- bool insertActionInfo(ActionInfo* info);
- /* 删除信息 */
- bool deleteActionInfo(ActionInfo* info);
- /* 给算法添加摄像机,原有的会被替换掉 */
- bool addActionCamera(ActionInfo* pInfo);
- /* 清空算法中的摄像机信息 */
- void clearCameraList();
- /* 清空设置成STOP或ERROR的Action */
- void clearStopAction();
- /* 查找算法ID是否已在列表中 */
- ActionInfo* findActionInList(ActionInfo* pInfo);
- /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
- ActionInfo* findActionIDInListNoCamera(ActionInfo* pInfo);
-
- /* 获取容器 */
- std::list<ActionInfo*>& getData() {
- return listActionInfo;
- }
- /* 清空容器 */
- void clear();
- std::list<ActionInfo*> listActionInfo; /* 房间和算法ID关联列表 */
- };
- /**
- * @brief 算法信息,以房间分类,算法包含在这干房间内所需要的摄像机ID
- *
- */
- struct RoomActionInfo
- {
- int ChannelID; /* 通道ID */
- int RoomID; /* 房间ID */
- int RoomType; /* 房间类型 */
- std::string ActionID; /* 算法ID */
- std::string strRoomName; /* 房间名称 */
- std::list<int> listCameraID; /* 摄像机ID */
- RoomActionInfo() {
- ChannelID = -1;
- RoomID = -1;
- RoomType = -1;
- ActionID = "";
- strRoomName = "";
- listCameraID.clear();
- }
- RoomActionInfo(const RoomActionInfo& other)
- : ChannelID(other.ChannelID), RoomID(other.RoomID),
- RoomType(other.RoomType), ActionID(other.ActionID),
- strRoomName(other.strRoomName), listCameraID(other.listCameraID) {}
- RoomActionInfo& operator=(const RoomActionInfo& other) {
- if (this != &other) {
- ChannelID = other.ChannelID;
- RoomID = other.RoomID;
- RoomType = other.RoomType;
- ActionID = other.ActionID;
- strRoomName = other.strRoomName;
- listCameraID = other.listCameraID;
- }
- return *this;
- }
- /* 对比频道信息、房间信息、算法ID是否相等 */
- bool isEqualBaseInfo(const RoomActionInfo& other);
-
- };
- /* 房间和算法ID关联列表 */
- class ListRoomActionInfo
- {
- public:
- ListRoomActionInfo() = default;
- /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
- bool insertRoomActionInfo(const RoomActionInfo& info);
- /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
- bool insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID);
- /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
- bool deleteRoomActionInfo(RoomActionInfo* pInfo);
- /* 清空容器 */
- void clear();
- /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
- void addActionInfo(const ActionInfo& info);
- /* 清空算法对应的摄像机列表 */
- void clearCameraList();
- /* 清理设置为STOP或者ERROR的RoomAction */
- // void clearStopRoomAction();
- /* 查找算法ID是否已在列表中 */
- RoomActionInfo* findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID);
-
- /* 获取容器 */
- std::list<RoomActionInfo*>& getData() {
- return listRoomActionInfo;
- }
- std::list<RoomActionInfo*> listRoomActionInfo; /* 房间和算法ID关联列表 */
- };
- /**
- * @brief 房间内的摄像机和算法关联信息
- *
- */
- struct RoomCamActInfo
- {
- int RoomID; /* 房间ID */
- int RoomType; /* 房间类型 */
- std::multimap<int, std::string> mapCameraAction; /* 摄像机ID和算法ID关联信息 */
- };
- /**
- * @brief 读取到的应用信息和启用时段
- *
- */
- struct AppAndTimeInfo
- {
- uint8_t AppType; /* 应用信息,按位计算 */
- int ChannelID; /* 通道ID */
- QDateTime StartTime; /* 开始时间 */
- QDateTime EndTime; /* 结束时间 */
- AppAndTimeInfo() = default;
- AppAndTimeInfo& operator=(AppAndTimeInfo& other) {
- if (this != &other) {
- AppType = other.AppType;
- ChannelID = other.ChannelID;
- StartTime = other.StartTime;
- EndTime = other.EndTime;
- }
- return *this;
- }
- };
- /**
- * @brief 按照功能分类的线程信息,一个实例就是一个功能,
- 比如区域入侵检测,需要多个算法多个摄像机共同配合
- *
- */
- struct FuncActionInfo
- {
- int ChannelID; /* 通道ID */
- AppFunction appFunction; /* 任务功能 */
- RunTimeState RunState; /* 线程运行状态 */
- std::string strFunctionName; /* 功能名称 */
- QDateTime StartTime; /* 开始时间 */
- QDateTime EndTime; /* 结束时间 */
- std::list<RoomCamActInfo> listRoomCamActInfo; /* 房间内的摄像机和算法关联信息 */
- FuncActionInfo();
- FuncActionInfo& operator=(FuncActionInfo& other);
- /* 添加算法信息 */
- bool addActionInfo(const ActionInfo& info);
- /* 清空算法信息 */
- void clearActionList();
-
- };
- /**
- * @brief
- *
- */
- struct ListFuncActInfo
- {
- ListFuncActInfo() = default;
- /* 添加功能信息 */
- bool addFuncActionInfo(const AppAndTimeInfo& func);
- /* 添加算法信息 */
- bool addActionInfo(const ActionInfo& info);
- /* 清空无用的功能信息 */
- void clearNoneFuncActionInfo();
- /* 清空房间和算法列表 */
- void clearActionList();
- /* 获取容器 */
- std::list<FuncActionInfo*>& getData() {
- return listFuncActionInfo;
- }
- /* 查找应用信息 */
- bool findAppFunction(const AppFunction func);
- FuncActionInfo* findAppFunction(const int ChannelID, const AppFunction func);
- FuncActionInfo* findAppFunction(const FuncActionInfo& func);
- std::list<FuncActionInfo*> listFuncActionInfo; /* 功能信息列表 */
- };
- /**
- * @brief 读取配置文件
- *
- */
- class GlobalConfig
- {
- public:
- GlobalConfig();
- ~GlobalConfig() = default;
- /* 读取配置文件 */
- bool readConfig(const QString& strConfigFile);
- /* 打印读取到的值 */
- void printValue();
-
- int AppUpdateOnWorkTimeInterval;/* 更新在岗信息的时间间隔 */
- int AppPeopleOnWork; /* 离岗时间 */
- int Contraband; /* 违禁物品出现的时间 */
- int AppBadMan; /* 非法入侵 */
- int AppTired; /* 疲劳检测时间 */
- int AppPeopleCont; /* 区域人员统计 */
- int AppPlayPhone; /* 玩手机识别 */
- int AppMouse; /* 老鼠识别 */
- int AppMask; /* 戴口罩识别 */
- int CheckSet; /* 服务端多久检测一次配置 */
- int EventTimeValid; /* 事件时间有效期 */
- int ThreadSleepMS; /* 任务线程休眠时间,单位是ms */
- std::string Key; /* Key */
- std::string Secret; /* Secret */
- };
- extern GlobalConfig g_config;
- #endif /* GLOBALINFO_H */
|