GlobalInfo.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. #ifndef GLOBALINFO_H
  2. #define GLOBALINFO_H
  3. #include <QString>
  4. #include <vector>
  5. #include <list>
  6. #include <map>
  7. #include "nlohmann/json.hpp"
  8. /* ====================================================================================
  9. * ******************************* 全局变量定义 **********************************
  10. * ====================================================================================*/
  11. extern int g_eventTimeVaild;
  12. /**
  13. * @brief 全局信息
  14. *
  15. */
  16. using nJson = nlohmann::json;
  17. /* 算法相关信息 */
  18. struct AlgorithmInfo
  19. {
  20. int PKID; /* 主键ID */
  21. int ActionTaskID; /* 算法任务ID */
  22. std::string ActionID; /* 算法ID */
  23. std::string ActionName; /* 算法名称 */
  24. AlgorithmInfo() = default;
  25. AlgorithmInfo(const AlgorithmInfo& other)
  26. : PKID(other.PKID), ActionID(other.ActionID), ActionName(other.ActionName), ActionTaskID(other.ActionTaskID) {}
  27. AlgorithmInfo& operator=(const AlgorithmInfo& other) {
  28. if (this != &other) {
  29. ActionID = other.ActionID;
  30. ActionName = other.ActionName;
  31. ActionTaskID = other.ActionTaskID;
  32. PKID = other.PKID;
  33. }
  34. return *this;
  35. }
  36. /* 对比是否相等 */
  37. bool operator==(const AlgorithmInfo& other) const {
  38. if(ActionID != other.ActionID) {
  39. return false;
  40. }
  41. if(ActionName != other.ActionName || ActionTaskID != other.ActionTaskID) {
  42. return false;
  43. }
  44. return true;
  45. }
  46. };
  47. /* 设备列表 */
  48. struct DeviceInfo
  49. {
  50. int PKID; /* 主键ID */
  51. int DeviceID; /* 设备ID */
  52. int DevicePort; /* 设备端口 */
  53. std::string DeviceName; /* 设备名称 */
  54. std::string DeviceIP; /* 设备IP */
  55. std::string DeviceSerial; /* 设备序列号 */
  56. std::string DeviceType; /* 设备类型 */
  57. std::string UserAccount; /* 用户账号 */
  58. std::string UserPassword; /* 用户密码 */
  59. std::vector<AlgorithmInfo> vecAlgorithmInfo; /* 算法信息 */
  60. DeviceInfo() = default;
  61. DeviceInfo(const DeviceInfo& other)
  62. : PKID(other.PKID),
  63. DeviceID(other.DeviceID),
  64. DevicePort(other.DevicePort),
  65. DeviceName(other.DeviceName),
  66. DeviceSerial(other.DeviceSerial),
  67. DeviceType(other.DeviceType),
  68. DeviceIP(other.DeviceIP),
  69. UserAccount(other.UserAccount),
  70. UserPassword(other.UserPassword),
  71. vecAlgorithmInfo(other.vecAlgorithmInfo) {}
  72. DeviceInfo& operator=(const DeviceInfo& other) {
  73. if (this != &other) {
  74. DeviceID = other.DeviceID;
  75. DevicePort = other.DevicePort;
  76. DeviceName = other.DeviceName;
  77. DeviceSerial = other.DeviceSerial;
  78. DeviceType = other.DeviceType;
  79. DeviceIP = other.DeviceIP;
  80. UserAccount = other.UserAccount;
  81. UserPassword = other.UserPassword;
  82. vecAlgorithmInfo = other.vecAlgorithmInfo;
  83. }
  84. return *this;
  85. }
  86. /* 对比是否相等 */
  87. bool operator==(const DeviceInfo& other);
  88. /* 对比设备关联的算法信息是否相等 */
  89. bool isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other);
  90. };
  91. /* 算法和设备关联的相关信息 */
  92. struct DeviceAlgorithmInfo
  93. {
  94. int DeviceID; /* 设备ID */
  95. int ActionTaskID; /* 算法任务ID */
  96. std::string ActionID; /* 算法ID */
  97. std::string ActionName; /* 算法名称 */
  98. };
  99. /**
  100. * @brief 摄像机线程需要的信息
  101. *
  102. */
  103. struct CameraThreadInfo
  104. {
  105. std::string RedisIP; /* Redis IP */
  106. int RedisPort; /* Redis Port */
  107. std::string RedisPWD; /* Redis Password */
  108. int DeviceID; /* 设备ID */
  109. std::vector<std::string> vecAction; /* Redis Key,一个设备可能会有多个算法ID */
  110. CameraThreadInfo() = default;
  111. CameraThreadInfo& operator=(const CameraThreadInfo& other) {
  112. if (this != &other) {
  113. RedisIP = other.RedisIP;
  114. RedisPort = other.RedisPort;
  115. RedisPWD = other.RedisPWD;
  116. DeviceID = other.DeviceID;
  117. vecAction = other.vecAction;
  118. }
  119. return *this;
  120. }
  121. };
  122. /**
  123. * @brief 人员信息
  124. *
  125. */
  126. struct PersonInfo
  127. {
  128. std::string PersonID; /* 人员ID */
  129. std::string PersonName; /* 人员名称 */
  130. };
  131. /**
  132. * @brief 报警信息
  133. *
  134. */
  135. struct AlarmInfo
  136. {
  137. bool Is_Alarm; /* 是否报警 */
  138. int AlarmID; /* 报警ID */
  139. int DeviceID; /* 设备ID,数据库表格中对应的是CamerID */
  140. int RoomID; /* 房间ID */
  141. int ChannelID; /* 通道ID */
  142. int OnWork; /* 是否在工作 */
  143. std::string ActionID; /* 算法ID */
  144. std::string StartTime; /* 报警开始时间 */
  145. std::string EndTime; /* 报警结束时间 */
  146. std::string EventTime; /* 事件时间(报警发生时间,在数据库里对应的是CreateTime) */
  147. std::string PicUrl; /* 报警图片URL */
  148. std::string ImageInfo; /* 图片信息 */
  149. std::string AppID; /* 客户端应用ID */
  150. std::string ActionDes; /* 算法描述信息 */
  151. std::string FaceIDList; /* 人脸ID列表 */
  152. std::string FaceNameList; /* 人脸名称列表 */
  153. std::string BboxList; /* Bbox列表,应该图片中的报警位置 */
  154. std::vector<PersonInfo> vecPersonInfo; /* 人员信息 */
  155. };
  156. /**
  157. * @brief 房间和摄像机关联信息,这个是从客户端配置的
  158. * 一个房间对应多个摄像机
  159. *
  160. */
  161. struct RoomCameraInfo
  162. {
  163. int RoomID; /* 房间ID */
  164. std::list<int> listCameraID; /* 摄像机列表 */
  165. RoomCameraInfo() = default;
  166. RoomCameraInfo& operator=(const RoomCameraInfo& other) {
  167. if (this != &other) {
  168. RoomID = other.RoomID;
  169. listCameraID = other.listCameraID;
  170. }
  171. return *this;
  172. }
  173. /* 这里只对比RoomID */
  174. bool operator==(const RoomCameraInfo& other) const {
  175. if(RoomID != other.RoomID) {
  176. return false;
  177. }
  178. return true;
  179. }
  180. };
  181. /* 线程运行时的状态 */
  182. enum class RunTimeState
  183. {
  184. RUN_STATE_INIT = 0, /* 初始化 */
  185. RUN_STATE_RUN, /* 运行 */
  186. RUN_STATE_STOP, /* 停止 */
  187. RUN_STATE_ERROR, /* 错误 */
  188. RUN_STATE_NONE /* 无状态 */
  189. };
  190. /**
  191. * @brief 单个算法信息,包括包含的摄像机,房间、频率信息
  192. *
  193. */
  194. struct ActionInfo
  195. {
  196. RunTimeState RunState; /* 线程运行状态 */
  197. int ChannelID; /* 通道ID */
  198. int RoomID; /* 房间ID */
  199. int CameraID; /* 摄像机ID */
  200. int RoomType; /* 房间类型 */
  201. std::string ActionID; /* 算法ID */
  202. std::string strRoomName; /* 房间名称 */
  203. ActionInfo() {
  204. RunState = RunTimeState::RUN_STATE_INIT;
  205. ChannelID = -1;
  206. RoomID = -1;
  207. CameraID = -1;
  208. RoomType = -1;
  209. ActionID = "";
  210. strRoomName = "";
  211. }
  212. ActionInfo& operator=(const ActionInfo& other) {
  213. if (this != &other) {
  214. ChannelID = other.ChannelID;
  215. RoomID = other.RoomID;
  216. CameraID = other.CameraID;
  217. ActionID = other.ActionID;
  218. strRoomName = other.strRoomName;
  219. RoomType = other.RoomType;
  220. }
  221. return *this;
  222. }
  223. /* 对比是否相等,这个需要完全相等,包括算法信息和摄像机信息 */
  224. bool operator==(const ActionInfo& other) const {
  225. if(ChannelID != other.ChannelID) {
  226. return false;
  227. }
  228. if(RoomID != other.RoomID) {
  229. return false;
  230. }
  231. if(CameraID != other.CameraID) {
  232. return false;
  233. }
  234. if(ActionID != other.ActionID) {
  235. return false;
  236. }
  237. if(RoomType != other.RoomType) {
  238. return false;
  239. }
  240. return true;
  241. }
  242. /* 对比除摄像机外的基础信息是否相等 */
  243. bool isEqualBaseInfo(const ActionInfo& other);
  244. };
  245. /**
  246. * @brief 算法信息列表,这个列表既可以存储房间和算法ID的关联信息,也可以用来存储运行线程的信息
  247. *
  248. */
  249. class ListActionInfo
  250. {
  251. public:
  252. ListActionInfo() = default;
  253. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  254. bool insertActionInfo(ActionInfo* info);
  255. /* 删除信息 */
  256. bool deleteActionInfo(ActionInfo* info);
  257. /* 给算法添加摄像机,原有的会被替换掉 */
  258. bool addActionCamera(ActionInfo* pInfo);
  259. /* 清空算法中的摄像机信息 */
  260. void clearCameraList();
  261. /* 清空设置成STOP或ERROR的Action */
  262. void clearStopAction();
  263. /* 查找算法ID是否已在列表中 */
  264. ActionInfo* findActionInList(ActionInfo* pInfo);
  265. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  266. ActionInfo* findActionIDInListNoCamera(ActionInfo* pInfo);
  267. /* 获取容器 */
  268. std::list<ActionInfo*>& getData() {
  269. return listActionInfo;
  270. }
  271. /* 清空容器 */
  272. void clear();
  273. std::list<ActionInfo*> listActionInfo; /* 房间和算法ID关联列表 */
  274. };
  275. /**
  276. * @brief 算法信息,以房间分类,算法包含在这干房间内所需要的摄像机ID
  277. *
  278. */
  279. struct RoomActionInfo
  280. {
  281. RunTimeState RunState; /* 线程运行状态 */
  282. int ChannelID; /* 通道ID */
  283. int RoomID; /* 房间ID */
  284. int RoomType; /* 房间类型 */
  285. std::string ActionID; /* 算法ID */
  286. std::string strRoomName; /* 房间名称 */
  287. std::list<int> listCameraID; /* 摄像机ID */
  288. RoomActionInfo() {
  289. RunState = RunTimeState::RUN_STATE_INIT;
  290. ChannelID = -1;
  291. RoomID = -1;
  292. RoomType = -1;
  293. ActionID = "";
  294. strRoomName = "";
  295. listCameraID.clear();
  296. }
  297. RoomActionInfo(const RoomActionInfo& other)
  298. : ChannelID(other.ChannelID), RoomID(other.RoomID),
  299. RoomType(other.RoomType), ActionID(other.ActionID),
  300. strRoomName(other.strRoomName), listCameraID(other.listCameraID) {}
  301. RoomActionInfo& operator=(const RoomActionInfo& other) {
  302. if (this != &other) {
  303. ChannelID = other.ChannelID;
  304. RoomID = other.RoomID;
  305. RoomType = other.RoomType;
  306. ActionID = other.ActionID;
  307. strRoomName = other.strRoomName;
  308. listCameraID = other.listCameraID;
  309. }
  310. return *this;
  311. }
  312. };
  313. /* 房间和算法ID关联列表 */
  314. class ListRoomActionInfo
  315. {
  316. public:
  317. ListRoomActionInfo() = default;
  318. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  319. bool insertRoomActionInfo(const RoomActionInfo& info);
  320. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  321. bool insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID);
  322. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  323. bool deleteRoomActionInfo(RoomActionInfo* pInfo);
  324. /* 清空容器 */
  325. void clear();
  326. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  327. void addActionInfo(const ActionInfo& info);
  328. /* 清空算法对应的摄像机列表 */
  329. void clearCameraList();
  330. /* 清理设置为STOP或者ERROR的RoomAction */
  331. void clearStopRoomAction();
  332. /* 查找算法ID是否已在列表中 */
  333. RoomActionInfo* findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID);
  334. /* 获取容器 */
  335. std::list<RoomActionInfo*>& getData() {
  336. return listRoomActionInfo;
  337. }
  338. std::list<RoomActionInfo*> listRoomActionInfo; /* 房间和算法ID关联列表 */
  339. };
  340. /**
  341. * @brief 读取配置文件
  342. *
  343. */
  344. class GlobalConfig
  345. {
  346. public:
  347. GlobalConfig();
  348. ~GlobalConfig() = default;
  349. /* 读取配置文件 */
  350. bool readConfig(const QString& strConfigFile);
  351. int AppPeopleOnWork; /* 离岗时间 */
  352. int AppBadthing; /* 违禁物品出现的时间 */
  353. int AppBadMan; /* 非法入侵 */
  354. int AppTired; /* 疲劳检测时间 */
  355. int AppPeopleCont; /* 区域人员统计 */
  356. int AppPlayPhone; /* 玩手机识别 */
  357. int AppMouse; /* 老鼠识别 */
  358. int AppMask; /* 戴口罩识别 */
  359. int CheckSet; /* 服务端多久检测一次配置 */
  360. int EventTimeValid; /* 事件时间有效期 */
  361. std::string Key; /* Key */
  362. std::string Secret; /* Secret */
  363. };
  364. #endif /* GLOBALINFO_H */