GlobalVariable.h 17 KB

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