GlobalInfo.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. #include "GlobalInfo.h"
  2. #include <QSettings>
  3. #include "spdlog/spdlog.h"
  4. /* ====================================================================================
  5. * ******************************* 全局变量定义 **********************************
  6. * ====================================================================================*/
  7. int g_eventTimeVaild = 600; /* 事件时间有效性,单位秒,超过这个时间就认为是无效数据 */
  8. /* ====================================================================================
  9. * *************************** DeviceInfo成员函数 *******************************
  10. * ====================================================================================*/
  11. /* 对比是否相等 */
  12. bool DeviceInfo::operator==(const DeviceInfo& other)
  13. {
  14. if(DeviceID != other.DeviceID) {
  15. return false;
  16. }
  17. else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
  18. return false;
  19. }
  20. else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
  21. return false;
  22. }
  23. else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
  24. return false;
  25. }
  26. return true;
  27. }
  28. /* 对比设备关联的算法信息是否相等 */
  29. bool DeviceInfo::isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other)
  30. {
  31. /* 算法数目不相等,直接返回false */
  32. if(vecAlgorithmInfo.size() != other.size()) {
  33. return false;
  34. }else {
  35. /* 算法数目相等,进一步对比算法信息 */
  36. bool isEquality = true;
  37. /* 逐步对比算法信息 */
  38. for(const auto& it0 : vecAlgorithmInfo) {
  39. bool isEq2 = true;
  40. for(const auto& it1 : other) {
  41. if(it0 == it1) {
  42. continue;
  43. }else {
  44. isEq2 = false;
  45. break;
  46. }
  47. }
  48. if(!isEq2) {
  49. isEquality = false;
  50. break;
  51. }
  52. }
  53. if(!isEquality) {
  54. return false;
  55. }
  56. }
  57. return true;
  58. }
  59. /* ====================================================================================
  60. * ************************** AlarmInfo成员函数 ****************************
  61. * ====================================================================================*/
  62. AlarmInfo::AlarmInfo()
  63. {
  64. Is_Alarm = false;
  65. AlarmID = 0;
  66. DeviceID = 0;
  67. RoomID = 0;
  68. ChannelID = 0;
  69. State = 0;
  70. OnWork = 0;
  71. StartTime = "";
  72. EndTime = "";
  73. EventTime = "";
  74. PicUrl = "";
  75. ImageInfo = "";
  76. AppID = "";
  77. ActionID = "";
  78. ActionDes = "";
  79. FaceIDList = "";
  80. FaceNameList = "";
  81. BboxList = "";
  82. }
  83. AlarmInfo& AlarmInfo::operator=(AlarmInfo& other)
  84. {
  85. if(this != &other)
  86. {
  87. Is_Alarm = other.Is_Alarm;
  88. AlarmID = other.AlarmID;
  89. DeviceID = other.DeviceID;
  90. RoomID = other.RoomID;
  91. ChannelID = other.ChannelID;
  92. State = other.State;
  93. OnWork = other.OnWork;
  94. StartTime = other.StartTime;
  95. EndTime = other.EndTime;
  96. EventTime = other.EventTime;
  97. PicUrl = other.PicUrl;
  98. ImageInfo = other.ImageInfo;
  99. AppID = other.AppID;
  100. ActionID = other.ActionID;
  101. ActionDes = other.ActionDes;
  102. FaceIDList = other.FaceIDList;
  103. FaceNameList = other.FaceNameList;
  104. BboxList = other.BboxList;
  105. vecPersonInfo = other.vecPersonInfo;
  106. }
  107. return *this;
  108. }
  109. /* 清空内容 */
  110. void AlarmInfo::reInit()
  111. {
  112. Is_Alarm = false;
  113. AlarmID = 0;
  114. DeviceID = 0;
  115. RoomID = 0;
  116. ChannelID = 0;
  117. State = 0;
  118. OnWork = 0;
  119. StartTime = "";
  120. EndTime = "";
  121. EventTime = "";
  122. PicUrl = "";
  123. ImageInfo = "";
  124. AppID = "";
  125. ActionID = "";
  126. ActionDes = "";
  127. FaceIDList = "";
  128. FaceNameList = "";
  129. BboxList = "";
  130. }
  131. AlarmRuleInfo::AlarmRuleInfo()
  132. {
  133. LiveMinEnable = false;
  134. LiveMaxEnable = false;
  135. DicMinEnable = false;
  136. DicMaxEnable = false;
  137. LiveDicMinEnable = false;
  138. LiveDicMaxEnable = false;
  139. LiveMin = 0;
  140. LiveMax = 0;
  141. DicMin = 0;
  142. DicMax = 0;
  143. LiveDicMin = 0;
  144. LiveDicMax = 0;
  145. RuleName = "";
  146. }
  147. AlarmRuleInfo& AlarmRuleInfo::operator=(AlarmRuleInfo& other)
  148. {
  149. if(this != &other)
  150. {
  151. LiveMinEnable = other.LiveMinEnable;
  152. LiveMaxEnable = other.LiveMaxEnable;
  153. DicMinEnable = other.DicMinEnable;
  154. DicMaxEnable = other.DicMaxEnable;
  155. LiveDicMinEnable = other.LiveDicMinEnable;
  156. LiveDicMaxEnable = other.LiveDicMaxEnable;
  157. LiveMin = other.LiveMin;
  158. LiveMax = other.LiveMax;
  159. DicMin = other.DicMin;
  160. DicMax = other.DicMax;
  161. LiveDicMin = other.LiveDicMin;
  162. LiveDicMax = other.LiveDicMax;
  163. RuleName = other.RuleName;
  164. }
  165. return *this;
  166. }
  167. /* ====================================================================================
  168. * ************************** ListActionInfo成员函数 ****************************
  169. * ====================================================================================*/
  170. ActionInfo::ActionInfo()
  171. {
  172. RunState = RunTimeState::RUN_STATE_INIT;
  173. ChannelID = -1;
  174. RoomID = -1;
  175. CameraID = -1;
  176. RoomType = -1;
  177. ActionID = "";
  178. strRoomName = "";
  179. strActionName = "";
  180. }
  181. ActionInfo& ActionInfo::operator=(const ActionInfo& other)
  182. {
  183. if (this != &other)
  184. {
  185. ChannelID = other.ChannelID;
  186. RoomID = other.RoomID;
  187. CameraID = other.CameraID;
  188. ActionID = other.ActionID;
  189. strRoomName = other.strRoomName;
  190. RoomType = other.RoomType;
  191. }
  192. return *this;
  193. }
  194. bool ActionInfo::operator==(const ActionInfo& other)
  195. {
  196. if(ChannelID != other.ChannelID) {
  197. return false;
  198. }
  199. if(RoomID != other.RoomID) {
  200. return false;
  201. }
  202. if(CameraID != other.CameraID) {
  203. return false;
  204. }
  205. if(ActionID != other.ActionID) {
  206. return false;
  207. }
  208. if(RoomType != other.RoomType) {
  209. return false;
  210. }
  211. return true;
  212. }
  213. /* 对比除摄像机外的基础信息是否相等 */
  214. bool ActionInfo::isEqualBaseInfo(const ActionInfo& other)
  215. {
  216. if(ChannelID != other.ChannelID) {
  217. return false;
  218. }
  219. if(RoomID != other.RoomID) {
  220. return false;
  221. }
  222. if(ActionID != other.ActionID) {
  223. return false;
  224. }
  225. if(RoomType != other.RoomType) {
  226. return false;
  227. }
  228. return true;
  229. }
  230. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  231. bool ListActionInfo::insertActionInfo(ActionInfo* info)
  232. {
  233. /* 先判断是否已经在列表中了 */
  234. if(findActionInList(info) == nullptr)
  235. {
  236. ActionInfo* pActionInfo = new ActionInfo;
  237. *pActionInfo = *info;
  238. listActionInfo.push_back(pActionInfo);
  239. }
  240. return true;
  241. }
  242. /* 删除信息 */
  243. bool ListActionInfo::deleteActionInfo(ActionInfo* info)
  244. {
  245. if(info == nullptr)
  246. {
  247. return false;
  248. }
  249. if(findActionInList(info) != nullptr)
  250. {
  251. listActionInfo.remove(info);
  252. delete info;
  253. info = nullptr;
  254. }
  255. return true;
  256. }
  257. /* 给算法添加摄像机,原有的会被替换掉 */
  258. bool ListActionInfo::addActionCamera(ActionInfo* pInfo)
  259. {
  260. auto pActionInfo = findActionIDInListNoCamera(pInfo);
  261. if(pActionInfo != nullptr)
  262. {
  263. pActionInfo->CameraID = pInfo->CameraID;
  264. }
  265. return true;
  266. }
  267. /* 清空算法中的摄像机信息 */
  268. void ListActionInfo::clearCameraList()
  269. {
  270. for(auto& it0 : listActionInfo)
  271. {
  272. it0->CameraID = -1;
  273. }
  274. }
  275. /* 清空设置成STOP或ERROR的Action */
  276. void ListActionInfo::clearStopAction()
  277. {
  278. for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();)
  279. {
  280. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  281. {
  282. delete *it0;
  283. it0 = listActionInfo.erase(it0);
  284. }else {
  285. ++it0;
  286. }
  287. }
  288. }
  289. /* 查找算法ID是否已在列表中 */
  290. ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
  291. {
  292. for(const auto& it0 : listActionInfo)
  293. {
  294. if(*it0 == *pInfo)
  295. {
  296. return it0;
  297. }
  298. }
  299. return nullptr;
  300. }
  301. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  302. ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo)
  303. {
  304. for(const auto& it0 : listActionInfo)
  305. {
  306. if(it0->isEqualBaseInfo(*pInfo))
  307. {
  308. return it0;
  309. }
  310. }
  311. return nullptr;
  312. }
  313. /* 清空容器 */
  314. void ListActionInfo::clear()
  315. {
  316. for(auto& it0 : listActionInfo)
  317. {
  318. delete it0;
  319. it0 = nullptr;
  320. }
  321. listActionInfo.clear();
  322. }
  323. /* ====================================================================================
  324. * *********************** ListRoomActionInfo成员函数 ***************************
  325. * ====================================================================================*/
  326. /* 对比频道信息、房间信息、算法ID是否相等 */
  327. bool RoomActionInfo::isEqualBaseInfo(const RoomActionInfo& other)
  328. {
  329. if(ChannelID != other.ChannelID) {
  330. return false;
  331. }
  332. if(RoomID != other.RoomID) {
  333. return false;
  334. }
  335. if(ActionID != other.ActionID) {
  336. return false;
  337. }
  338. if(RoomType != other.RoomType) {
  339. return false;
  340. }
  341. return true;
  342. }
  343. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  344. bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
  345. {
  346. /* 先判断是否已经在列表中了 */
  347. if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr)
  348. {
  349. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  350. *pRoomActionInfo = info;
  351. listRoomActionInfo.push_back(pRoomActionInfo);
  352. }
  353. return true;
  354. }
  355. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  356. bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID)
  357. {
  358. /* 先判断是否已经在列表中了 */
  359. if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr)
  360. {
  361. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  362. pRoomActionInfo->RoomID = RoomID;
  363. pRoomActionInfo->ActionID = strActionID;
  364. listRoomActionInfo.push_back(pRoomActionInfo);
  365. }
  366. return true;
  367. }
  368. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  369. bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo)
  370. {
  371. if(pInfo == nullptr)
  372. {
  373. return false;
  374. }
  375. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0)
  376. {
  377. if(*it0 == pInfo)
  378. {
  379. listRoomActionInfo.erase(it0);
  380. delete pInfo;
  381. pInfo = nullptr;
  382. return true;
  383. }
  384. }
  385. return false;
  386. }
  387. /* 清空容器 */
  388. void ListRoomActionInfo::clear()
  389. {
  390. for(auto& it0 : listRoomActionInfo)
  391. {
  392. delete it0;
  393. it0 = nullptr;
  394. }
  395. listRoomActionInfo.clear();
  396. }
  397. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  398. void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
  399. {
  400. auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
  401. if(pRAInfo != nullptr)
  402. {
  403. pRAInfo->listCameraID.push_back(info.CameraID);
  404. }else {
  405. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  406. pRoomActionInfo->ChannelID = info.ChannelID;
  407. pRoomActionInfo->RoomID = info.RoomID;
  408. pRoomActionInfo->ActionID = info.ActionID;
  409. pRoomActionInfo->RoomType = info.RoomType;
  410. pRoomActionInfo->strRoomName = info.strRoomName;
  411. pRoomActionInfo->listCameraID.push_back(info.CameraID);
  412. listRoomActionInfo.push_back(pRoomActionInfo);
  413. }
  414. }
  415. /* 清空算法对应的摄像机列表 */
  416. void ListRoomActionInfo::clearCameraList()
  417. {
  418. for(auto& it0 : listRoomActionInfo)
  419. {
  420. it0->listCameraID.clear();
  421. }
  422. }
  423. /* 清理设置为STOP或者ERROR的RoomAction */
  424. void ListRoomActionInfo::clearStopRoomAction()
  425. {
  426. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();)
  427. {
  428. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  429. {
  430. delete *it0;
  431. it0 = listRoomActionInfo.erase(it0);
  432. }else {
  433. ++it0;
  434. }
  435. }
  436. }
  437. /* 查找算法ID是否已在列表中 */
  438. RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
  439. {
  440. for(const auto& it0 : listRoomActionInfo)
  441. {
  442. if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
  443. {
  444. return it0;
  445. }
  446. }
  447. return nullptr;
  448. }
  449. FuncActionInfo::FuncActionInfo()
  450. {
  451. ChannelID = -1;
  452. appFunction = AppFunction::APP_NONE;
  453. RunState = RunTimeState::RUN_STATE_NONE;
  454. strFunctionName = "";
  455. StartTime = std::chrono::system_clock::now();
  456. EndTime = std::chrono::system_clock::now();
  457. listRoomCamActInfo.clear();
  458. }
  459. FuncActionInfo& FuncActionInfo::operator=(FuncActionInfo& other)
  460. {
  461. if(this != &other)
  462. {
  463. ChannelID = other.ChannelID;
  464. appFunction = other.appFunction;
  465. RunState = other.RunState;
  466. strFunctionName = other.strFunctionName;
  467. StartTime = other.StartTime;
  468. EndTime = other.EndTime;
  469. listRoomCamActInfo = other.listRoomCamActInfo;
  470. }
  471. return *this;
  472. }
  473. /* 添加算法信息 */
  474. bool FuncActionInfo::addActionInfo(const ActionInfo& info)
  475. {
  476. /* 根据此类的功能,添加算法信息 */
  477. if(appFunction == AppFunction::APP_NONE)
  478. {
  479. return false;
  480. }
  481. return true;
  482. }
  483. /* ====================================================================================
  484. * ************************** GlobalConfig成员函数 ******************************
  485. * ====================================================================================*/
  486. /* 创建实例 */
  487. GlobalConfig g_config;
  488. GlobalConfig::GlobalConfig()
  489. {
  490. ThreadSleepMS = 300;
  491. }
  492. /* 读取配置文件 */
  493. bool GlobalConfig::readConfig(const QString& strConfigFile)
  494. {
  495. if(strConfigFile.isEmpty())
  496. {
  497. SPDLOG_ERROR("读取配置文件失败! 配置文件名为空");
  498. return false;
  499. }
  500. SPDLOG_DEBUG("读取配置文件: {}", strConfigFile.toStdString());
  501. QSettings settings(strConfigFile, QSettings::IniFormat);
  502. settings.setIniCodec("UTF-8");
  503. settings.beginGroup("System");
  504. AppPeopleOnWork = settings.value("APPPEPOLEONWORK", 300).toInt(); /* 离岗时间 */
  505. Contraband = settings.value("APPBADTHING", 50).toInt(); /* 违禁物品出现的时间 */
  506. AppBadMan = settings.value("APPBADMAN", 50).toInt(); /* 非法入侵 */
  507. AppTired = settings.value("APPTIRED", 50).toInt(); /* 疲劳检测时间 */
  508. AppPeopleCont = settings.value("APPPEPOLECONT", 50).toInt(); /* 人员聚集时间 */
  509. AppPlayPhone = settings.value("APPPLAYPHONE", 50).toInt(); /* 玩手机识别 */
  510. AppMouse = settings.value("APPMOUSE", 50).toInt(); /* 手势识别 */
  511. AppMask = settings.value("APPMASK", 5).toInt(); /* 戴口罩识别 */
  512. CheckSet = settings.value("CHECKSET", 300).toInt(); /* 服务端多久检测一次配置 */
  513. EventTimeValid = settings.value("EventTimeValid", 300).toInt(); /* 事件时间有效期 */
  514. Key = settings.value("Key").toString().toStdString(); /* Key */
  515. Secret = settings.value("Secret").toString().toStdString(); /* Secret */
  516. settings.endGroup();
  517. if(Key.empty() || Secret.empty())
  518. {
  519. SPDLOG_ERROR("读取配置文件失败! Key或Secret为空");
  520. return false;
  521. }
  522. return true;
  523. }
  524. /* 打印读取到的值 */
  525. void GlobalConfig::printValue()
  526. {
  527. SPDLOG_INFO("APPPEPOLEONWORK: {}", AppPeopleOnWork);
  528. SPDLOG_INFO("APPBADTHING: {}", Contraband);
  529. SPDLOG_INFO("APPBADMAN: {}", AppBadMan);
  530. SPDLOG_INFO("APPTIRED: {}", AppTired);
  531. SPDLOG_INFO("APPPEOPLECONT: {}", AppPeopleCont);
  532. SPDLOG_INFO("APPPLAYPHONE: {}", AppPlayPhone);
  533. SPDLOG_INFO("APPMOUSE: {}", AppMouse);
  534. SPDLOG_INFO("APPMASK: {}", AppMask);
  535. SPDLOG_INFO("CHECKSET: {}", CheckSet);
  536. SPDLOG_INFO("EventTimeValid: {}", EventTimeValid);
  537. }