GlobalVariable.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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_LIVEDIC = 3, /* 直播间和导播间 */
  55. };
  56. /**
  57. * @brief 时段类型
  58. *
  59. */
  60. enum class Enum_PeriodType
  61. {
  62. PERIOD_ALL = 0, /* 所有时段 */
  63. PERIOD_DAY, /* 按天 */
  64. PERIOD_WEEK, /* 按周 */
  65. };
  66. /* 算法相关信息 */
  67. struct AlgorithmInfo
  68. {
  69. int PKID; /* 主键ID */
  70. int ActionTaskID; /* 算法任务ID */
  71. std::string ActionID; /* 算法ID */
  72. std::string ActionName; /* 算法名称 */
  73. AlgorithmInfo() = default;
  74. AlgorithmInfo(const AlgorithmInfo& other)
  75. : PKID(other.PKID), ActionID(other.ActionID), ActionName(other.ActionName), ActionTaskID(other.ActionTaskID) {}
  76. AlgorithmInfo& operator=(const AlgorithmInfo& other) {
  77. if (this != &other) {
  78. ActionID = other.ActionID;
  79. ActionName = other.ActionName;
  80. ActionTaskID = other.ActionTaskID;
  81. PKID = other.PKID;
  82. }
  83. return *this;
  84. }
  85. /* 对比是否相等 */
  86. bool operator==(const AlgorithmInfo& other) const {
  87. if(ActionID != other.ActionID) {
  88. return false;
  89. }
  90. if(ActionName != other.ActionName || ActionTaskID != other.ActionTaskID) {
  91. return false;
  92. }
  93. return true;
  94. }
  95. };
  96. /* 设备列表 */
  97. struct DeviceInfo
  98. {
  99. int PKID; /* 主键ID */
  100. int DeviceID; /* 设备ID */
  101. int DevicePort; /* 设备端口 */
  102. std::string DeviceName; /* 设备名称 */
  103. std::string DeviceIP; /* 设备IP */
  104. std::string DeviceSerial; /* 设备序列号,这里好像是IP */
  105. std::string DeviceType; /* 设备类型 */
  106. std::string UserAccount; /* 用户账号 */
  107. std::string UserPassword; /* 用户密码 */
  108. std::vector<AlgorithmInfo> vecAlgorithmInfo; /* 算法信息 */
  109. DeviceInfo() = default;
  110. DeviceInfo(const DeviceInfo& other)
  111. : PKID(other.PKID),
  112. DeviceID(other.DeviceID),
  113. DevicePort(other.DevicePort),
  114. DeviceName(other.DeviceName),
  115. DeviceSerial(other.DeviceSerial),
  116. DeviceType(other.DeviceType),
  117. DeviceIP(other.DeviceIP),
  118. UserAccount(other.UserAccount),
  119. UserPassword(other.UserPassword),
  120. vecAlgorithmInfo(other.vecAlgorithmInfo) {}
  121. DeviceInfo& operator=(const DeviceInfo& other) {
  122. if (this != &other) {
  123. DeviceID = other.DeviceID;
  124. DevicePort = other.DevicePort;
  125. DeviceName = other.DeviceName;
  126. DeviceSerial = other.DeviceSerial;
  127. DeviceType = other.DeviceType;
  128. DeviceIP = other.DeviceIP;
  129. UserAccount = other.UserAccount;
  130. UserPassword = other.UserPassword;
  131. vecAlgorithmInfo = other.vecAlgorithmInfo;
  132. }
  133. return *this;
  134. }
  135. /* 对比是否相等 */
  136. bool operator==(const DeviceInfo& other);
  137. /* 对比设备关联的算法信息是否相等 */
  138. bool isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other);
  139. };
  140. /* 算法和设备关联的相关信息 */
  141. struct DeviceAlgorithmInfo
  142. {
  143. int DeviceID; /* 设备ID */
  144. int ActionTaskID; /* 算法任务ID */
  145. std::string ActionID; /* 算法ID */
  146. std::string ActionName; /* 算法名称 */
  147. };
  148. /**
  149. * @brief 摄像机线程需要的信息
  150. *
  151. */
  152. struct CameraThreadInfo
  153. {
  154. std::string RedisIP; /* Redis IP */
  155. int RedisPort; /* Redis Port */
  156. std::string RedisPWD; /* Redis Password */
  157. int DeviceID; /* 设备ID */
  158. std::vector<std::string> vecAction; /* Redis Key,一个设备可能会有多个算法ID */
  159. CameraThreadInfo() = default;
  160. CameraThreadInfo& operator=(const CameraThreadInfo& other) {
  161. if (this != &other) {
  162. RedisIP = other.RedisIP;
  163. RedisPort = other.RedisPort;
  164. RedisPWD = other.RedisPWD;
  165. DeviceID = other.DeviceID;
  166. vecAction = other.vecAction;
  167. }
  168. return *this;
  169. }
  170. };
  171. /**
  172. * @brief 一周某一天的时间
  173. *
  174. */
  175. struct WeekTime
  176. {
  177. int WeekDay; /* 星期几,0是按天计算的,可以直接无视 */
  178. QDateTime StartTime; /* 开始时间 */
  179. QDateTime EndTime; /* 结束时间 */
  180. };
  181. /**
  182. * @brief 功能检测时间段信息
  183. *
  184. */
  185. struct DetectPeriodInfo
  186. {
  187. int ChannelID; /* 通道ID */
  188. AppFunction appFunction; /* 应用功能 */
  189. std::string PeriodName; /* 时段名称 */
  190. Enum_PeriodType PeriodType; /* 时段类型 */
  191. QDateTime lastTime; /* 上次更新时间 */
  192. std::list<WeekTime> listWeekTime; /* 一周的时间段 */
  193. DetectPeriodInfo();
  194. DetectPeriodInfo(const DetectPeriodInfo& other);
  195. DetectPeriodInfo& operator=(const DetectPeriodInfo& other);
  196. };
  197. /* ====================================================================================
  198. * ******************************* 各种报警信息 **********************************
  199. * ====================================================================================*/
  200. /**
  201. * @brief 人员信息
  202. *
  203. */
  204. struct PersonInfo
  205. {
  206. std::string PersonID; /* 人员ID,等于-1就是无法识别出身份的人员 */
  207. std::string PersonName; /* 人员名称 */
  208. QDateTime lastOnWork; /* 最后在岗时间 */
  209. };
  210. /**
  211. * @brief 报警信息
  212. *
  213. */
  214. struct AlarmInfo
  215. {
  216. bool Is_Alarm; /* 是否报警 */
  217. bool Is_InsertEQM; /* 是否已经插入到EQM数据库中 */
  218. bool Is_OnWork; /* 是否在岗 */
  219. int PKID; /* 主键ID,主要用来判断是否已经写入数据库 */
  220. int AlarmID; /* 报警ID */
  221. int DeviceID; /* 设备ID,数据库表格中对应的是CamerID */
  222. int RoomID; /* 房间ID */
  223. int ChannelID; /* 通道ID */
  224. int State; /* 状态 */
  225. int OnWork; /* 是否在工作 */
  226. AppFunction appFunction; /* 应用功能 */
  227. std::string ActionID; /* 算法ID */
  228. QDateTime StartTime; /* 报警开始时间 */
  229. QDateTime EndTime; /* 报警结束时间 */
  230. QDateTime EventTime; /* 事件时间(报警发生时间,在数据库里对应的是CreateTime) */
  231. // std::string PicUrl; /* 报警图片URL */
  232. std::string ImageInfo; /* 图片信息 */
  233. std::string ActionDes; /* 算法描述信息 */
  234. std::string FaceIDList; /* 人脸ID列表 */
  235. std::string FaceNameList; /* 人脸名称列表 */
  236. std::list<std::string> listBbox; /* Bbox列表,应该是图片中的报警位置 */
  237. std::list<PersonInfo> listPersonInfo; /* 人员信息 */
  238. AlarmInfo();
  239. AlarmInfo(const AlarmInfo& other);
  240. AlarmInfo& operator=(AlarmInfo& other);
  241. void reInit();
  242. /* 获取人脸ID列表 */
  243. std::string getFaceIDListString();
  244. /* 获取人脸名称列表 */
  245. std::string getFaceNameListString();
  246. };
  247. /**
  248. * @brief 报警信息容器,并提供一些函数
  249. *
  250. */
  251. struct ListAlarmInfo
  252. {
  253. ~ListAlarmInfo() {
  254. clearAlarmInfo();
  255. }
  256. std::list<AlarmInfo*> listAlarmInfo; /* 报警信息列表 */
  257. /* 添加报警信息 */
  258. bool addAlarmInfo(AlarmInfo& info);
  259. /* 查找报警记录 */
  260. AlarmInfo* findAlarmInfo(AlarmInfo& info);
  261. /* 删除报警记录 */
  262. void deleteAlarmInfo(AlarmInfo& info);
  263. /* 清空报警记录 */
  264. void clearAlarmInfo();
  265. };
  266. /**
  267. * @brief 房间内的人脸信息
  268. *
  269. */
  270. struct RoomFaceInfo
  271. {
  272. int ChannelID = 0;
  273. int RoomID = 0;
  274. int CameraID = 0;
  275. int MaxNum = 0;
  276. int MinNum = 0;
  277. QDateTime StartTime;
  278. QDateTime EndTime;
  279. std::list<PersonInfo> listPersonInfo;
  280. RoomFaceInfo() = default;
  281. RoomFaceInfo& operator=(const RoomFaceInfo& other) {
  282. if (this != &other) {
  283. ChannelID = other.ChannelID;
  284. RoomID = other.RoomID;
  285. CameraID = other.CameraID;
  286. MaxNum = other.MaxNum;
  287. MinNum = other.MinNum;
  288. StartTime = other.StartTime;
  289. EndTime = other.EndTime;
  290. listPersonInfo = other.listPersonInfo;
  291. }
  292. return *this;
  293. }
  294. /* 查找是否有相同的人脸信息 */
  295. bool findPersonInfo(const PersonInfo& info);
  296. };
  297. /**
  298. * @brief 房间内的人脸信息
  299. *
  300. */
  301. struct ListRoomFaceInfo
  302. {
  303. std::list<RoomFaceInfo> listRoomFaceInfo;
  304. void addRoomFaceInfo(RoomFaceInfo& info);
  305. void addRoomFaceInfo(AlarmInfo& info);
  306. RoomFaceInfo* findRoomFaceInfo(RoomFaceInfo& info);
  307. RoomFaceInfo* findRoomFaceInfo(int ChannelID, int RoomID, int CameraID);
  308. };
  309. /**
  310. * @brief 房间和摄像机关联信息,这个是从客户端配置的
  311. * 一个房间对应多个摄像机
  312. *
  313. */
  314. struct RoomCameraInfo
  315. {
  316. int RoomID; /* 房间ID */
  317. std::list<int> listCameraID; /* 摄像机列表 */
  318. RoomCameraInfo() = default;
  319. RoomCameraInfo& operator=(const RoomCameraInfo& other) {
  320. if (this != &other) {
  321. RoomID = other.RoomID;
  322. listCameraID = other.listCameraID;
  323. }
  324. return *this;
  325. }
  326. /* 这里只对比RoomID */
  327. bool operator==(const RoomCameraInfo& other) const {
  328. if(RoomID != other.RoomID) {
  329. return false;
  330. }
  331. return true;
  332. }
  333. };
  334. /* ====================================================================================
  335. * **************************** 线程功能需要的结构体 *****************************
  336. * ====================================================================================*/
  337. /**
  338. * @brief 单个算法信息,包括包含的摄像机,房间、频率信息
  339. *
  340. */
  341. struct ActionInfo
  342. {
  343. RunTimeState RunState; /* 线程运行状态 */
  344. int ChannelID; /* 通道ID */
  345. int RoomID; /* 房间ID */
  346. int CameraID; /* 摄像机ID */
  347. Enum_RoomType RoomType; /* 房间类型 */
  348. std::string ActionID; /* 算法ID */
  349. std::string strRoomName; /* 房间名称 */
  350. std::string strActionName; /* 算法名称,这个是自定义的,不需要对比 */
  351. ActionInfo();
  352. ActionInfo& operator=(const ActionInfo& other);
  353. /* 对比是否相等,这个需要完全相等,包括算法信息和摄像机信息 */
  354. bool operator==(const ActionInfo& other);
  355. /* 对比除摄像机外的基础信息是否相等 */
  356. bool isEqualBaseInfo(const ActionInfo& other);
  357. };
  358. /**
  359. * @brief 算法信息列表,这个列表既可以存储房间和算法ID的关联信息,也可以用来存储运行线程的信息
  360. *
  361. */
  362. class ListActionInfo
  363. {
  364. public:
  365. ListActionInfo() = default;
  366. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  367. bool insertActionInfo(ActionInfo* info);
  368. /* 删除信息 */
  369. bool deleteActionInfo(ActionInfo* info);
  370. /* 给算法添加摄像机,原有的会被替换掉 */
  371. bool addActionCamera(ActionInfo* pInfo);
  372. /* 清空算法中的摄像机信息 */
  373. void clearCameraList();
  374. /* 清空设置成STOP或ERROR的Action */
  375. void clearStopAction();
  376. /* 查找算法ID是否已在列表中 */
  377. ActionInfo* findActionInList(ActionInfo* pInfo);
  378. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  379. ActionInfo* findActionIDInListNoCamera(ActionInfo* pInfo);
  380. /* 获取容器 */
  381. std::list<ActionInfo*>& getData() {
  382. return listActionInfo;
  383. }
  384. /* 清空容器 */
  385. void clear();
  386. std::list<ActionInfo*> listActionInfo; /* 房间和算法ID关联列表 */
  387. };
  388. /**
  389. * @brief 算法信息,以房间分类,算法包含在这干房间内所需要的摄像机ID
  390. *
  391. */
  392. struct RoomActionInfo
  393. {
  394. int ChannelID; /* 通道ID */
  395. int RoomID; /* 房间ID */
  396. Enum_RoomType RoomType; /* 房间类型 */
  397. std::string ActionID; /* 算法ID */
  398. std::string strRoomName; /* 房间名称 */
  399. std::list<int> listCameraID; /* 摄像机ID */
  400. RoomActionInfo() {
  401. ChannelID = -1;
  402. RoomID = -1;
  403. RoomType = Enum_RoomType::ROOM_NONE;
  404. ActionID = "";
  405. strRoomName = "";
  406. listCameraID.clear();
  407. }
  408. RoomActionInfo(const RoomActionInfo& other)
  409. : ChannelID(other.ChannelID), RoomID(other.RoomID),
  410. RoomType(other.RoomType), ActionID(other.ActionID),
  411. strRoomName(other.strRoomName), listCameraID(other.listCameraID) {}
  412. RoomActionInfo& operator=(const RoomActionInfo& other) {
  413. if (this != &other) {
  414. ChannelID = other.ChannelID;
  415. RoomID = other.RoomID;
  416. RoomType = other.RoomType;
  417. ActionID = other.ActionID;
  418. strRoomName = other.strRoomName;
  419. listCameraID = other.listCameraID;
  420. }
  421. return *this;
  422. }
  423. /* 对比频道信息、房间信息、算法ID是否相等 */
  424. bool isEqualBaseInfo(const RoomActionInfo& other);
  425. };
  426. /* 房间和算法ID关联列表 */
  427. class ListRoomActionInfo
  428. {
  429. public:
  430. ListRoomActionInfo() = default;
  431. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  432. bool insertRoomActionInfo(const RoomActionInfo& info);
  433. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  434. bool insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID);
  435. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  436. bool deleteRoomActionInfo(RoomActionInfo* pInfo);
  437. /* 清空容器 */
  438. void clear();
  439. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  440. void addActionInfo(const ActionInfo& info);
  441. /* 清空算法对应的摄像机列表 */
  442. void clearCameraList();
  443. /* 清理设置为STOP或者ERROR的RoomAction */
  444. // void clearStopRoomAction();
  445. /* 查找算法ID是否已在列表中 */
  446. RoomActionInfo* findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID);
  447. /* 获取容器 */
  448. std::list<RoomActionInfo*>& getData() {
  449. return listRoomActionInfo;
  450. }
  451. std::list<RoomActionInfo*> listRoomActionInfo; /* 房间和算法ID关联列表 */
  452. };
  453. /**
  454. * @brief 房间内的摄像机和算法关联信息
  455. *
  456. */
  457. struct RoomCamActInfo
  458. {
  459. int RoomID; /* 房间ID */
  460. Enum_RoomType RoomType; /* 房间类型 */
  461. std::string strRoomName; /* 房间名称 */
  462. std::map<int, std::list<std::string>> mapCameraAction; /* 摄像机ID和算法ID关联信息,一个摄像机可以有多个算法列表 */
  463. RoomCamActInfo();
  464. RoomCamActInfo(const RoomCamActInfo& other);
  465. RoomCamActInfo& operator=(const RoomCamActInfo& other);
  466. /* 添加摄像机算法 */
  467. void addCameraAction(int CameraID, const std::string& ActionID);
  468. };
  469. /**
  470. * @brief 通道和应用信息
  471. *
  472. */
  473. struct ChannelAppInfo
  474. {
  475. uint32_t AppType; /* 应用信息,按位计算 */
  476. int ChannelID; /* 通道ID */
  477. std::string strChannelName; /* 通道名称 */
  478. std::string strAppName; /* 应用名称 */
  479. ChannelAppInfo() = default;
  480. ChannelAppInfo& operator=(ChannelAppInfo& other) {
  481. if (this != &other) {
  482. AppType = other.AppType;
  483. ChannelID = other.ChannelID;
  484. strChannelName = other.strChannelName;
  485. strAppName = other.strAppName;
  486. }
  487. return *this;
  488. }
  489. };
  490. #endif /* GLOBALVARIABLE_H */