GlobalInfo.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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 State; /* 状态 */
  143. int OnWork; /* 是否在工作 */
  144. std::string ActionID; /* 算法ID */
  145. std::string StartTime; /* 报警开始时间 */
  146. std::string EndTime; /* 报警结束时间 */
  147. std::string EventTime; /* 事件时间(报警发生时间,在数据库里对应的是CreateTime) */
  148. std::string PicUrl; /* 报警图片URL */
  149. std::string ImageInfo; /* 图片信息 */
  150. std::string AppID; /* 客户端应用ID */
  151. std::string ActionDes; /* 算法描述信息 */
  152. std::string FaceIDList; /* 人脸ID列表 */
  153. std::string FaceNameList; /* 人脸名称列表 */
  154. std::string BboxList; /* Bbox列表,应该是图片中的报警位置 */
  155. std::vector<PersonInfo> vecPersonInfo; /* 人员信息 */
  156. AlarmInfo();
  157. AlarmInfo& operator=(AlarmInfo& other);
  158. void reInit();
  159. };
  160. /**
  161. * @brief 报警规则
  162. *
  163. */
  164. struct AlarmRuleInfo
  165. {
  166. bool LiveMinEnable; /* 启用直播间最小人数 */
  167. bool LiveMaxEnable; /* 启用直播间最大人数 */
  168. bool DicMinEnable; /* 启用导播间最小人数 */
  169. bool DicMaxEnable; /* 启用导播间最大人数 */
  170. bool LiveDicMinEnable; /* 启用直播间和导播间最小人数 */
  171. bool LiveDicMaxEnable; /* 启用直播间和导播间最大人数 */
  172. int LiveMin; /* 直播间最小人数 */
  173. int LiveMax; /* 直播间最大人数 */
  174. int DicMin; /* 导播间最小人数 */
  175. int DicMax; /* 导播间最大人数 */
  176. int LiveDicMin; /* 直播间和导播间最小人数 */
  177. int LiveDicMax; /* 直播间和导播间最大人数 */
  178. std::string RuleName; /* 规则名称 */
  179. AlarmRuleInfo();
  180. AlarmRuleInfo& operator=(AlarmRuleInfo& other);
  181. };
  182. /**
  183. * @brief 房间和摄像机关联信息,这个是从客户端配置的
  184. * 一个房间对应多个摄像机
  185. *
  186. */
  187. struct RoomCameraInfo
  188. {
  189. int RoomID; /* 房间ID */
  190. std::list<int> listCameraID; /* 摄像机列表 */
  191. RoomCameraInfo() = default;
  192. RoomCameraInfo& operator=(const RoomCameraInfo& other) {
  193. if (this != &other) {
  194. RoomID = other.RoomID;
  195. listCameraID = other.listCameraID;
  196. }
  197. return *this;
  198. }
  199. /* 这里只对比RoomID */
  200. bool operator==(const RoomCameraInfo& other) const {
  201. if(RoomID != other.RoomID) {
  202. return false;
  203. }
  204. return true;
  205. }
  206. };
  207. /* 线程运行时的状态 */
  208. enum class RunTimeState
  209. {
  210. RUN_STATE_INIT = 0, /* 初始化 */
  211. RUN_STATE_RUN, /* 运行 */
  212. RUN_STATE_STOP, /* 停止 */
  213. RUN_STATE_ERROR, /* 错误 */
  214. RUN_STATE_NONE /* 无状态 */
  215. };
  216. /**
  217. * @brief 单个算法信息,包括包含的摄像机,房间、频率信息
  218. *
  219. */
  220. struct ActionInfo
  221. {
  222. RunTimeState RunState; /* 线程运行状态 */
  223. int ChannelID; /* 通道ID */
  224. int RoomID; /* 房间ID */
  225. int CameraID; /* 摄像机ID */
  226. int RoomType; /* 房间类型 */
  227. std::string ActionID; /* 算法ID */
  228. std::string strRoomName; /* 房间名称 */
  229. std::string strActionName; /* 算法名称,这个是自定义的,不需要对比 */
  230. ActionInfo() {
  231. RunState = RunTimeState::RUN_STATE_INIT;
  232. ChannelID = -1;
  233. RoomID = -1;
  234. CameraID = -1;
  235. RoomType = -1;
  236. ActionID = "";
  237. strRoomName = "";
  238. strActionName = "";
  239. }
  240. ActionInfo& operator=(const ActionInfo& other) {
  241. if (this != &other) {
  242. ChannelID = other.ChannelID;
  243. RoomID = other.RoomID;
  244. CameraID = other.CameraID;
  245. ActionID = other.ActionID;
  246. strRoomName = other.strRoomName;
  247. RoomType = other.RoomType;
  248. }
  249. return *this;
  250. }
  251. /* 对比是否相等,这个需要完全相等,包括算法信息和摄像机信息 */
  252. bool operator==(const ActionInfo& other) const {
  253. if(ChannelID != other.ChannelID) {
  254. return false;
  255. }
  256. if(RoomID != other.RoomID) {
  257. return false;
  258. }
  259. if(CameraID != other.CameraID) {
  260. return false;
  261. }
  262. if(ActionID != other.ActionID) {
  263. return false;
  264. }
  265. if(RoomType != other.RoomType) {
  266. return false;
  267. }
  268. return true;
  269. }
  270. /* 对比除摄像机外的基础信息是否相等 */
  271. bool isEqualBaseInfo(const ActionInfo& other);
  272. };
  273. /**
  274. * @brief 算法信息列表,这个列表既可以存储房间和算法ID的关联信息,也可以用来存储运行线程的信息
  275. *
  276. */
  277. class ListActionInfo
  278. {
  279. public:
  280. ListActionInfo() = default;
  281. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  282. bool insertActionInfo(ActionInfo* info);
  283. /* 删除信息 */
  284. bool deleteActionInfo(ActionInfo* info);
  285. /* 给算法添加摄像机,原有的会被替换掉 */
  286. bool addActionCamera(ActionInfo* pInfo);
  287. /* 清空算法中的摄像机信息 */
  288. void clearCameraList();
  289. /* 清空设置成STOP或ERROR的Action */
  290. void clearStopAction();
  291. /* 查找算法ID是否已在列表中 */
  292. ActionInfo* findActionInList(ActionInfo* pInfo);
  293. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  294. ActionInfo* findActionIDInListNoCamera(ActionInfo* pInfo);
  295. /* 获取容器 */
  296. std::list<ActionInfo*>& getData() {
  297. return listActionInfo;
  298. }
  299. /* 清空容器 */
  300. void clear();
  301. std::list<ActionInfo*> listActionInfo; /* 房间和算法ID关联列表 */
  302. };
  303. /**
  304. * @brief 算法信息,以房间分类,算法包含在这干房间内所需要的摄像机ID
  305. *
  306. */
  307. struct RoomActionInfo
  308. {
  309. RunTimeState RunState; /* 线程运行状态 */
  310. int ChannelID; /* 通道ID */
  311. int RoomID; /* 房间ID */
  312. int RoomType; /* 房间类型 */
  313. std::string ActionID; /* 算法ID */
  314. std::string strRoomName; /* 房间名称 */
  315. std::list<int> listCameraID; /* 摄像机ID */
  316. RoomActionInfo() {
  317. RunState = RunTimeState::RUN_STATE_INIT;
  318. ChannelID = -1;
  319. RoomID = -1;
  320. RoomType = -1;
  321. ActionID = "";
  322. strRoomName = "";
  323. listCameraID.clear();
  324. }
  325. RoomActionInfo(const RoomActionInfo& other)
  326. : ChannelID(other.ChannelID), RoomID(other.RoomID),
  327. RoomType(other.RoomType), ActionID(other.ActionID),
  328. strRoomName(other.strRoomName), listCameraID(other.listCameraID) {}
  329. RoomActionInfo& operator=(const RoomActionInfo& other) {
  330. if (this != &other) {
  331. ChannelID = other.ChannelID;
  332. RoomID = other.RoomID;
  333. RoomType = other.RoomType;
  334. ActionID = other.ActionID;
  335. strRoomName = other.strRoomName;
  336. listCameraID = other.listCameraID;
  337. }
  338. return *this;
  339. }
  340. /* 对比频道信息、房间信息、算法ID是否相等 */
  341. bool isEqualBaseInfo(const RoomActionInfo& other);
  342. };
  343. /* 房间和算法ID关联列表 */
  344. class ListRoomActionInfo
  345. {
  346. public:
  347. ListRoomActionInfo() = default;
  348. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  349. bool insertRoomActionInfo(const RoomActionInfo& info);
  350. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  351. bool insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID);
  352. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  353. bool deleteRoomActionInfo(RoomActionInfo* pInfo);
  354. /* 清空容器 */
  355. void clear();
  356. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  357. void addActionInfo(const ActionInfo& info);
  358. /* 清空算法对应的摄像机列表 */
  359. void clearCameraList();
  360. /* 清理设置为STOP或者ERROR的RoomAction */
  361. void clearStopRoomAction();
  362. /* 查找算法ID是否已在列表中 */
  363. RoomActionInfo* findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID);
  364. /* 获取容器 */
  365. std::list<RoomActionInfo*>& getData() {
  366. return listRoomActionInfo;
  367. }
  368. std::list<RoomActionInfo*> listRoomActionInfo; /* 房间和算法ID关联列表 */
  369. };
  370. /**
  371. * @brief 读取配置文件
  372. *
  373. */
  374. class GlobalConfig
  375. {
  376. public:
  377. GlobalConfig();
  378. ~GlobalConfig() = default;
  379. /* 读取配置文件 */
  380. bool readConfig(const QString& strConfigFile);
  381. /* 打印读取到的值 */
  382. void printValue();
  383. int AppPeopleOnWork; /* 离岗时间 */
  384. int Contraband; /* 违禁物品出现的时间 */
  385. int AppBadMan; /* 非法入侵 */
  386. int AppTired; /* 疲劳检测时间 */
  387. int AppPeopleCont; /* 区域人员统计 */
  388. int AppPlayPhone; /* 玩手机识别 */
  389. int AppMouse; /* 老鼠识别 */
  390. int AppMask; /* 戴口罩识别 */
  391. int CheckSet; /* 服务端多久检测一次配置 */
  392. int EventTimeValid; /* 事件时间有效期 */
  393. int ThreadSleepMS; /* 任务线程休眠时间,单位是ms */
  394. std::string Key; /* Key */
  395. std::string Secret; /* Secret */
  396. };
  397. extern GlobalConfig g_config;
  398. #endif /* GLOBALINFO_H */