GlobalVariable.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. #ifndef GLOBALVARIABLE_H
  2. #define GLOBALVARIABLE_H
  3. #include <QString>
  4. #include <vector>
  5. #include <list>
  6. #include <map>
  7. #include <mutex>
  8. #include <QDateTime>
  9. #include "nlohmann/json.hpp"
  10. class FuncBase;
  11. /* ====================================================================================
  12. * ******************************* 全局变量定义 **********************************
  13. * ====================================================================================*/
  14. /**
  15. * @brief 全局信息
  16. *
  17. */
  18. using nJson = nlohmann::json;
  19. /* Rides数据时间有效性 */
  20. extern int g_eventTimeVaild;
  21. /* 线程运行时的状态 */
  22. enum class RunTimeState
  23. {
  24. RUN_STATE_NONE = 0, /* 无状态 */
  25. RUN_STATE_INIT, /* 初始化 */
  26. RUN_STATE_RUN, /* 运行 */
  27. RUN_STATE_STOP, /* 停止,是外部给子线程的信号,让其退出 */
  28. RUN_STATE_ERROR, /* 错误 */
  29. RUN_STATE_EXITCOMPLET, /* 退出完成 */
  30. };
  31. /* 应用功能 */
  32. enum class AppFunction
  33. {
  34. APP_NONE = 0, /* 无功能 */
  35. APP_OnWork = 1, /* 人员在岗识别(需要多个摄像机配合) */
  36. APP_Contraband, /* 违禁品识别 */
  37. APP_Illegal, /* 非法入侵检测(需要多个摄像机配合) */
  38. APP_Fatigue, /* 疲劳检测 */
  39. APP_Regional, /* 区域人员检测,人员计数(需要多个摄像机配合) */
  40. APP_Mouse, /* 老鼠识别 */
  41. APP_PlayPhone, /* 玩手机识别 */
  42. APP_NoMask, /* 未戴口罩识别 */
  43. APP_AllDown, /* 摔倒识别 */
  44. };
  45. /**
  46. * @brief 房间类型
  47. *
  48. */
  49. enum class Enum_RoomType
  50. {
  51. ROOM_NONE = 0, /* 无房间 */
  52. ROOM_LIVE = 1, /* 直播间 */
  53. ROOM_DIC = 2, /* 导播间 */
  54. ROOM_ALL = 3, /* 所有房间 */
  55. };
  56. /* 算法相关信息 */
  57. struct AlgorithmInfo
  58. {
  59. int PKID; /* 主键ID */
  60. int ActionTaskID; /* 算法任务ID */
  61. std::string ActionID; /* 算法ID */
  62. std::string ActionName; /* 算法名称 */
  63. AlgorithmInfo() = default;
  64. AlgorithmInfo(const AlgorithmInfo& other)
  65. : PKID(other.PKID), ActionID(other.ActionID), ActionName(other.ActionName), ActionTaskID(other.ActionTaskID) {}
  66. AlgorithmInfo& operator=(const AlgorithmInfo& other) {
  67. if (this != &other) {
  68. ActionID = other.ActionID;
  69. ActionName = other.ActionName;
  70. ActionTaskID = other.ActionTaskID;
  71. PKID = other.PKID;
  72. }
  73. return *this;
  74. }
  75. /* 对比是否相等 */
  76. bool operator==(const AlgorithmInfo& other) const {
  77. if(ActionID != other.ActionID) {
  78. return false;
  79. }
  80. if(ActionName != other.ActionName || ActionTaskID != other.ActionTaskID) {
  81. return false;
  82. }
  83. return true;
  84. }
  85. };
  86. /* 设备列表 */
  87. struct DeviceInfo
  88. {
  89. int PKID; /* 主键ID */
  90. int DeviceID; /* 设备ID */
  91. int DevicePort; /* 设备端口 */
  92. std::string DeviceName; /* 设备名称 */
  93. std::string DeviceIP; /* 设备IP */
  94. std::string DeviceSerial; /* 设备序列号,这里好像是IP */
  95. std::string DeviceType; /* 设备类型 */
  96. std::string UserAccount; /* 用户账号 */
  97. std::string UserPassword; /* 用户密码 */
  98. std::vector<AlgorithmInfo> vecAlgorithmInfo; /* 算法信息 */
  99. DeviceInfo() = default;
  100. DeviceInfo(const DeviceInfo& other)
  101. : PKID(other.PKID),
  102. DeviceID(other.DeviceID),
  103. DevicePort(other.DevicePort),
  104. DeviceName(other.DeviceName),
  105. DeviceSerial(other.DeviceSerial),
  106. DeviceType(other.DeviceType),
  107. DeviceIP(other.DeviceIP),
  108. UserAccount(other.UserAccount),
  109. UserPassword(other.UserPassword),
  110. vecAlgorithmInfo(other.vecAlgorithmInfo) {}
  111. DeviceInfo& operator=(const DeviceInfo& other) {
  112. if (this != &other) {
  113. DeviceID = other.DeviceID;
  114. DevicePort = other.DevicePort;
  115. DeviceName = other.DeviceName;
  116. DeviceSerial = other.DeviceSerial;
  117. DeviceType = other.DeviceType;
  118. DeviceIP = other.DeviceIP;
  119. UserAccount = other.UserAccount;
  120. UserPassword = other.UserPassword;
  121. vecAlgorithmInfo = other.vecAlgorithmInfo;
  122. }
  123. return *this;
  124. }
  125. /* 对比是否相等 */
  126. bool operator==(const DeviceInfo& other);
  127. /* 对比设备关联的算法信息是否相等 */
  128. bool isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other);
  129. };
  130. /* 算法和设备关联的相关信息 */
  131. struct DeviceAlgorithmInfo
  132. {
  133. int DeviceID; /* 设备ID */
  134. int ActionTaskID; /* 算法任务ID */
  135. std::string ActionID; /* 算法ID */
  136. std::string ActionName; /* 算法名称 */
  137. };
  138. /**
  139. * @brief 摄像机线程需要的信息
  140. *
  141. */
  142. struct CameraThreadInfo
  143. {
  144. std::string RedisIP; /* Redis IP */
  145. int RedisPort; /* Redis Port */
  146. std::string RedisPWD; /* Redis Password */
  147. int DeviceID; /* 设备ID */
  148. std::vector<std::string> vecAction; /* Redis Key,一个设备可能会有多个算法ID */
  149. CameraThreadInfo() = default;
  150. CameraThreadInfo& operator=(const CameraThreadInfo& other) {
  151. if (this != &other) {
  152. RedisIP = other.RedisIP;
  153. RedisPort = other.RedisPort;
  154. RedisPWD = other.RedisPWD;
  155. DeviceID = other.DeviceID;
  156. vecAction = other.vecAction;
  157. }
  158. return *this;
  159. }
  160. };
  161. /* ====================================================================================
  162. * ******************************* 各种报警信息 **********************************
  163. * ====================================================================================*/
  164. /**
  165. * @brief 人员信息
  166. *
  167. */
  168. struct PersonInfo
  169. {
  170. std::string PersonID; /* 人员ID,等于-1就是无法识别出身份的人员 */
  171. std::string PersonName; /* 人员名称 */
  172. QDateTime lastOnWork; /* 最后在岗时间 */
  173. };
  174. /**
  175. * @brief 报警信息
  176. *
  177. */
  178. struct AlarmInfo
  179. {
  180. bool Is_Alarm; /* 是否报警 */
  181. bool Is_InsertEQM; /* 是否已经插入到EQM数据库中 */
  182. bool Is_OnWork; /* 是否在岗 */
  183. int AlarmID; /* 报警ID */
  184. int DeviceID; /* 设备ID,数据库表格中对应的是CamerID */
  185. int RoomID; /* 房间ID */
  186. int ChannelID; /* 通道ID */
  187. int State; /* 状态 */
  188. int OnWork; /* 是否在工作 */
  189. AppFunction appFunction; /* 应用功能 */
  190. std::string ActionID; /* 算法ID */
  191. std::string StartTime; /* 报警开始时间 */
  192. std::string EndTime; /* 报警结束时间 */
  193. std::string EventTime; /* 事件时间(报警发生时间,在数据库里对应的是CreateTime) */
  194. std::string PicUrl; /* 报警图片URL */
  195. std::string ImageInfo; /* 图片信息 */
  196. // std::string AppID; /* 客户端应用ID */
  197. std::string ActionDes; /* 算法描述信息 */
  198. std::string FaceIDList; /* 人脸ID列表 */
  199. std::string FaceNameList; /* 人脸名称列表 */
  200. std::list<std::string> listBbox; /* Bbox列表,应该是图片中的报警位置 */
  201. std::list<PersonInfo> listPersonInfo; /* 人员信息 */
  202. AlarmInfo();
  203. AlarmInfo(const AlarmInfo& other);
  204. AlarmInfo& operator=(AlarmInfo& other);
  205. void reInit();
  206. /* 获取人脸ID列表 */
  207. std::string getFaceIDListString();
  208. /* 获取人脸名称列表 */
  209. std::string getFaceNameListString();
  210. };
  211. /**
  212. * @brief 报警信息容器,并提供一些函数
  213. *
  214. */
  215. struct ListAlarmInfo
  216. {
  217. std::list<AlarmInfo*> listAlarmInfo; /* 报警信息列表 */
  218. /* 添加报警信息 */
  219. bool addAlarmInfo(AlarmInfo& info);
  220. /* 查找报警记录 */
  221. AlarmInfo* findAlarmInfo(AlarmInfo& info);
  222. /* 删除报警记录 */
  223. void deleteAlarmInfo(AlarmInfo& info);
  224. /* 清空报警记录 */
  225. void clearAlarmInfo();
  226. };
  227. /**
  228. * @brief 房间内的人脸信息
  229. *
  230. */
  231. struct RoomFaceInfo
  232. {
  233. int ChannelID = 0;
  234. int RoomID = 0;
  235. int CameraID = 0;
  236. int MaxNum = 0;
  237. int MinNum = 0;
  238. QDateTime StartTime;
  239. QDateTime EndTime;
  240. std::list<PersonInfo> listPersonInfo;
  241. RoomFaceInfo() = default;
  242. RoomFaceInfo& operator=(const RoomFaceInfo& other) {
  243. if (this != &other) {
  244. ChannelID = other.ChannelID;
  245. RoomID = other.RoomID;
  246. CameraID = other.CameraID;
  247. MaxNum = other.MaxNum;
  248. MinNum = other.MinNum;
  249. StartTime = other.StartTime;
  250. EndTime = other.EndTime;
  251. listPersonInfo = other.listPersonInfo;
  252. }
  253. return *this;
  254. }
  255. /* 查找是否有相同的人脸信息 */
  256. bool findPersonInfo(const PersonInfo& info);
  257. };
  258. /**
  259. * @brief 房间内的人脸信息
  260. *
  261. */
  262. struct ListRoomFaceInfo
  263. {
  264. std::list<RoomFaceInfo> listRoomFaceInfo;
  265. void addRoomFaceInfo(RoomFaceInfo& info);
  266. void addRoomFaceInfo(AlarmInfo& info);
  267. RoomFaceInfo* findRoomFaceInfo(RoomFaceInfo& info);
  268. RoomFaceInfo* findRoomFaceInfo(int ChannelID, int RoomID, int CameraID);
  269. };
  270. /**
  271. * @brief 房间和摄像机关联信息,这个是从客户端配置的
  272. * 一个房间对应多个摄像机
  273. *
  274. */
  275. struct RoomCameraInfo
  276. {
  277. int RoomID; /* 房间ID */
  278. std::list<int> listCameraID; /* 摄像机列表 */
  279. RoomCameraInfo() = default;
  280. RoomCameraInfo& operator=(const RoomCameraInfo& other) {
  281. if (this != &other) {
  282. RoomID = other.RoomID;
  283. listCameraID = other.listCameraID;
  284. }
  285. return *this;
  286. }
  287. /* 这里只对比RoomID */
  288. bool operator==(const RoomCameraInfo& other) const {
  289. if(RoomID != other.RoomID) {
  290. return false;
  291. }
  292. return true;
  293. }
  294. };
  295. /* ====================================================================================
  296. * **************************** 线程功能需要的结构体 *****************************
  297. * ====================================================================================*/
  298. /**
  299. * @brief 单个算法信息,包括包含的摄像机,房间、频率信息
  300. *
  301. */
  302. struct ActionInfo
  303. {
  304. RunTimeState RunState; /* 线程运行状态 */
  305. int ChannelID; /* 通道ID */
  306. int RoomID; /* 房间ID */
  307. int CameraID; /* 摄像机ID */
  308. Enum_RoomType RoomType; /* 房间类型 */
  309. std::string ActionID; /* 算法ID */
  310. std::string strRoomName; /* 房间名称 */
  311. std::string strActionName; /* 算法名称,这个是自定义的,不需要对比 */
  312. ActionInfo();
  313. ActionInfo& operator=(const ActionInfo& other);
  314. /* 对比是否相等,这个需要完全相等,包括算法信息和摄像机信息 */
  315. bool operator==(const ActionInfo& other);
  316. /* 对比除摄像机外的基础信息是否相等 */
  317. bool isEqualBaseInfo(const ActionInfo& other);
  318. };
  319. /**
  320. * @brief 算法信息列表,这个列表既可以存储房间和算法ID的关联信息,也可以用来存储运行线程的信息
  321. *
  322. */
  323. class ListActionInfo
  324. {
  325. public:
  326. ListActionInfo() = default;
  327. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  328. bool insertActionInfo(ActionInfo* info);
  329. /* 删除信息 */
  330. bool deleteActionInfo(ActionInfo* info);
  331. /* 给算法添加摄像机,原有的会被替换掉 */
  332. bool addActionCamera(ActionInfo* pInfo);
  333. /* 清空算法中的摄像机信息 */
  334. void clearCameraList();
  335. /* 清空设置成STOP或ERROR的Action */
  336. void clearStopAction();
  337. /* 查找算法ID是否已在列表中 */
  338. ActionInfo* findActionInList(ActionInfo* pInfo);
  339. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  340. ActionInfo* findActionIDInListNoCamera(ActionInfo* pInfo);
  341. /* 获取容器 */
  342. std::list<ActionInfo*>& getData() {
  343. return listActionInfo;
  344. }
  345. /* 清空容器 */
  346. void clear();
  347. std::list<ActionInfo*> listActionInfo; /* 房间和算法ID关联列表 */
  348. };
  349. /**
  350. * @brief 算法信息,以房间分类,算法包含在这干房间内所需要的摄像机ID
  351. *
  352. */
  353. struct RoomActionInfo
  354. {
  355. int ChannelID; /* 通道ID */
  356. int RoomID; /* 房间ID */
  357. Enum_RoomType RoomType; /* 房间类型 */
  358. std::string ActionID; /* 算法ID */
  359. std::string strRoomName; /* 房间名称 */
  360. std::list<int> listCameraID; /* 摄像机ID */
  361. RoomActionInfo() {
  362. ChannelID = -1;
  363. RoomID = -1;
  364. RoomType = Enum_RoomType::ROOM_NONE;
  365. ActionID = "";
  366. strRoomName = "";
  367. listCameraID.clear();
  368. }
  369. RoomActionInfo(const RoomActionInfo& other)
  370. : ChannelID(other.ChannelID), RoomID(other.RoomID),
  371. RoomType(other.RoomType), ActionID(other.ActionID),
  372. strRoomName(other.strRoomName), listCameraID(other.listCameraID) {}
  373. RoomActionInfo& operator=(const RoomActionInfo& other) {
  374. if (this != &other) {
  375. ChannelID = other.ChannelID;
  376. RoomID = other.RoomID;
  377. RoomType = other.RoomType;
  378. ActionID = other.ActionID;
  379. strRoomName = other.strRoomName;
  380. listCameraID = other.listCameraID;
  381. }
  382. return *this;
  383. }
  384. /* 对比频道信息、房间信息、算法ID是否相等 */
  385. bool isEqualBaseInfo(const RoomActionInfo& other);
  386. };
  387. /* 房间和算法ID关联列表 */
  388. class ListRoomActionInfo
  389. {
  390. public:
  391. ListRoomActionInfo() = default;
  392. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  393. bool insertRoomActionInfo(const RoomActionInfo& info);
  394. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  395. bool insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID);
  396. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  397. bool deleteRoomActionInfo(RoomActionInfo* pInfo);
  398. /* 清空容器 */
  399. void clear();
  400. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  401. void addActionInfo(const ActionInfo& info);
  402. /* 清空算法对应的摄像机列表 */
  403. void clearCameraList();
  404. /* 清理设置为STOP或者ERROR的RoomAction */
  405. // void clearStopRoomAction();
  406. /* 查找算法ID是否已在列表中 */
  407. RoomActionInfo* findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID);
  408. /* 获取容器 */
  409. std::list<RoomActionInfo*>& getData() {
  410. return listRoomActionInfo;
  411. }
  412. std::list<RoomActionInfo*> listRoomActionInfo; /* 房间和算法ID关联列表 */
  413. };
  414. /**
  415. * @brief 房间内的摄像机和算法关联信息
  416. *
  417. */
  418. struct RoomCamActInfo
  419. {
  420. int RoomID; /* 房间ID */
  421. Enum_RoomType RoomType; /* 房间类型 */
  422. std::string strRoomName; /* 房间名称 */
  423. std::map<int, std::list<std::string>> mapCameraAction; /* 摄像机ID和算法ID关联信息,一个摄像机可以有多个算法列表 */
  424. /* 添加摄像机算法 */
  425. void addCameraAction(int CameraID, const std::string& ActionID)
  426. {
  427. auto it = mapCameraAction.find(CameraID);
  428. if(it == mapCameraAction.end()) {
  429. std::list<std::string> list;
  430. list.push_back(ActionID);
  431. mapCameraAction.insert(std::make_pair(CameraID, list));
  432. }else {
  433. it->second.push_back(ActionID);
  434. }
  435. }
  436. };
  437. /**
  438. * @brief 读取到的应用信息和启用时段
  439. *
  440. */
  441. struct AppAndTimeInfo
  442. {
  443. uint8_t AppType; /* 应用信息,按位计算 */
  444. int ChannelID; /* 通道ID */
  445. QDateTime StartTime; /* 开始时间 */
  446. QDateTime EndTime; /* 结束时间 */
  447. AppAndTimeInfo() = default;
  448. AppAndTimeInfo& operator=(AppAndTimeInfo& other) {
  449. if (this != &other) {
  450. AppType = other.AppType;
  451. ChannelID = other.ChannelID;
  452. StartTime = other.StartTime;
  453. EndTime = other.EndTime;
  454. }
  455. return *this;
  456. }
  457. };
  458. #endif /* GLOBALVARIABLE_H */