#ifndef GLOBALINFO_H #define GLOBALINFO_H #include #include #include #include #include "nlohmann/json.hpp" /* ==================================================================================== * ******************************* 全局变量定义 ********************************** * ====================================================================================*/ extern int g_eventTimeVaild; /** * @brief 全局信息 * */ using nJson = nlohmann::json; /* 算法相关信息 */ 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 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& 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 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 */ std::string PersonName; /* 人员名称 */ }; /** * @brief 报警信息 * */ struct AlarmInfo { bool Is_Alarm; /* 是否报警 */ int AlarmID; /* 报警ID */ int DeviceID; /* 设备ID,数据库表格中对应的是CamerID */ int RoomID; /* 房间ID */ int ChannelID; /* 通道ID */ 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 vecPersonInfo; /* 人员信息 */ }; /** * @brief 房间和摄像机关联信息,这个是从客户端配置的 * 一个房间对应多个摄像机 * */ struct RoomCameraInfo { int RoomID; /* 房间ID */ std::list 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 { int ChannelID; /* 通道ID */ int RoomID; /* 房间ID */ int CameraID; /* 摄像机ID */ int RoomType; /* 房间类型 */ std::string ActionID; /* 算法ID */ std::string strRoomName; /* 房间名称 */ ActionInfo() = default; ActionInfo& operator=(const ActionInfo& other) { if (this != &other) { ChannelID = other.ChannelID; RoomID = other.RoomID; CameraID = other.CameraID; ActionID = other.ActionID; strRoomName = other.strRoomName; RoomType = other.RoomType; } return *this; } /* 对比 */ bool operator==(const ActionInfo& other) const { if(ChannelID != other.ChannelID) { return false; } if(RoomID != other.RoomID) { return false; } if(CameraID != other.CameraID) { return false; } if(ActionID != other.ActionID) { return false; } if(RoomType != other.RoomType) { return false; } return true; } }; /** * @brief 算法信息列表 * */ class ListActionInfo { public: ListActionInfo() = default; /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */ bool insertActionInfo(ActionInfo* info); /* 删除信息 */ bool deleteActionInfo(ActionInfo* info); /* 查找算法ID是否已在列表中 */ ActionInfo* findActionInList(ActionInfo* pInfo); /* 获取容器 */ std::list& getData() { return listActionInfo; } /* 清空容器 */ void clear(); std::list listActionInfo; /* 房间和算法ID关联列表 */ }; /** * @brief 房间ID和算法ID关联的信息,里面也包含该算法使用了哪些摄像机 * */ struct RoomActionInfo { int ChannelID; /* 通道ID */ int RoomID; /* 房间ID */ int RoomType; /* 房间类型 */ std::string ActionID; /* 算法ID */ std::string strRoomName; /* 房间名称 */ std::list listCameraID; /* 摄像机ID */ RoomActionInfo() = default; 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关联列表 */ class ListRoomActionInfo { public: ListRoomActionInfo() = default; /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */ bool insertRoomActionInfo(const RoomActionInfo& info); /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */ bool insertRoomActionInfo(const int RoomID, const std::string& strActionID); /* 清空容器 */ void clear(); /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */ void addActionInfo(const ActionInfo& info); /* 查找算法ID是否已在列表中 */ RoomActionInfo* findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID); /* 获取容器 */ std::list& getData() { return listRoomActionInfo; } std::list listRoomActionInfo; /* 房间和算法ID关联列表 */ }; #endif /* GLOBALINFO_H */