GlobalInfo.h 13 KB

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