GlobalInfo.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. #include "GlobalInfo.h"
  2. #include <QSettings>
  3. /* ====================================================================================
  4. * ******************************* 全局变量定义 **********************************
  5. * ====================================================================================*/
  6. int g_eventTimeVaild = 600; /* 事件时间有效性,单位秒,超过这个时间就认为是无效数据 */
  7. /* ====================================================================================
  8. * *************************** DeviceInfo成员函数 *******************************
  9. * ====================================================================================*/
  10. /* 对比是否相等 */
  11. bool DeviceInfo::operator==(const DeviceInfo& other)
  12. {
  13. if(DeviceID != other.DeviceID) {
  14. return false;
  15. }
  16. else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
  17. return false;
  18. }
  19. else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
  20. return false;
  21. }
  22. else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
  23. return false;
  24. }
  25. return true;
  26. }
  27. /* 对比设备关联的算法信息是否相等 */
  28. bool DeviceInfo::isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other)
  29. {
  30. /* 算法数目不相等,直接返回false */
  31. if(vecAlgorithmInfo.size() != other.size()) {
  32. return false;
  33. }else {
  34. /* 算法数目相等,进一步对比算法信息 */
  35. bool isEquality = true;
  36. /* 逐步对比算法信息 */
  37. for(const auto& it0 : vecAlgorithmInfo) {
  38. bool isEq2 = true;
  39. for(const auto& it1 : other) {
  40. if(it0 == it1) {
  41. continue;
  42. }else {
  43. isEq2 = false;
  44. break;
  45. }
  46. }
  47. if(!isEq2) {
  48. isEquality = false;
  49. break;
  50. }
  51. }
  52. if(!isEquality) {
  53. return false;
  54. }
  55. }
  56. return true;
  57. }
  58. /* ====================================================================================
  59. * ************************** ListActionInfo成员函数 ****************************
  60. * ====================================================================================*/
  61. /* 对比除摄像机外的基础信息是否相等 */
  62. bool ActionInfo::isEqualBaseInfo(const ActionInfo& other)
  63. {
  64. if(ChannelID != other.ChannelID) {
  65. return false;
  66. }
  67. if(RoomID != other.RoomID) {
  68. return false;
  69. }
  70. if(ActionID != other.ActionID) {
  71. return false;
  72. }
  73. if(RoomType != other.RoomType) {
  74. return false;
  75. }
  76. return true;
  77. }
  78. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  79. bool ListActionInfo::insertActionInfo(ActionInfo* info)
  80. {
  81. /* 先判断是否已经在列表中了 */
  82. if(findActionInList(info) == nullptr)
  83. {
  84. ActionInfo* pActionInfo = new ActionInfo;
  85. *pActionInfo = *info;
  86. listActionInfo.push_back(pActionInfo);
  87. }
  88. return true;
  89. }
  90. /* 删除信息 */
  91. bool ListActionInfo::deleteActionInfo(ActionInfo* info)
  92. {
  93. if(info == nullptr)
  94. {
  95. return false;
  96. }
  97. if(findActionInList(info) != nullptr)
  98. {
  99. listActionInfo.remove(info);
  100. delete info;
  101. info = nullptr;
  102. }
  103. return true;
  104. }
  105. /* 给算法添加摄像机,原有的会被替换掉 */
  106. bool ListActionInfo::addActionCamera(ActionInfo* pInfo)
  107. {
  108. auto pActionInfo = findActionIDInListNoCamera(pInfo);
  109. if(pActionInfo != nullptr)
  110. {
  111. pActionInfo->CameraID = pInfo->CameraID;
  112. }
  113. return true;
  114. }
  115. /* 清空算法中的摄像机信息 */
  116. void ListActionInfo::clearCameraList()
  117. {
  118. for(auto& it0 : listActionInfo)
  119. {
  120. it0->CameraID = -1;
  121. }
  122. }
  123. /* 清空设置成STOP或ERROR的Action */
  124. void ListActionInfo::clearStopAction()
  125. {
  126. for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();)
  127. {
  128. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  129. {
  130. delete *it0;
  131. it0 = listActionInfo.erase(it0);
  132. }else {
  133. ++it0;
  134. }
  135. }
  136. }
  137. /* 查找算法ID是否已在列表中 */
  138. ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
  139. {
  140. for(const auto& it0 : listActionInfo)
  141. {
  142. if(*it0 == *pInfo)
  143. {
  144. return it0;
  145. }
  146. }
  147. return nullptr;
  148. }
  149. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  150. ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo)
  151. {
  152. for(const auto& it0 : listActionInfo)
  153. {
  154. if(it0->isEqualBaseInfo(*pInfo))
  155. {
  156. return it0;
  157. }
  158. }
  159. return nullptr;
  160. }
  161. /* 清空容器 */
  162. void ListActionInfo::clear()
  163. {
  164. for(auto& it0 : listActionInfo)
  165. {
  166. delete it0;
  167. it0 = nullptr;
  168. }
  169. listActionInfo.clear();
  170. }
  171. /* ====================================================================================
  172. * *********************** ListRoomActionInfo成员函数 ***************************
  173. * ====================================================================================*/
  174. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  175. bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
  176. {
  177. /* 先判断是否已经在列表中了 */
  178. if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr)
  179. {
  180. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  181. *pRoomActionInfo = info;
  182. listRoomActionInfo.push_back(pRoomActionInfo);
  183. }
  184. return true;
  185. }
  186. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  187. bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID)
  188. {
  189. /* 先判断是否已经在列表中了 */
  190. if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr)
  191. {
  192. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  193. pRoomActionInfo->RoomID = RoomID;
  194. pRoomActionInfo->ActionID = strActionID;
  195. listRoomActionInfo.push_back(pRoomActionInfo);
  196. }
  197. return true;
  198. }
  199. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  200. bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo)
  201. {
  202. if(pInfo == nullptr)
  203. {
  204. return false;
  205. }
  206. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0)
  207. {
  208. if(*it0 == pInfo)
  209. {
  210. listRoomActionInfo.erase(it0);
  211. delete pInfo;
  212. pInfo = nullptr;
  213. return true;
  214. }
  215. }
  216. return false;
  217. }
  218. /* 清空容器 */
  219. void ListRoomActionInfo::clear()
  220. {
  221. for(auto& it0 : listRoomActionInfo)
  222. {
  223. delete it0;
  224. it0 = nullptr;
  225. }
  226. listRoomActionInfo.clear();
  227. }
  228. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  229. void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
  230. {
  231. auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
  232. if(pRAInfo != nullptr)
  233. {
  234. pRAInfo->listCameraID.push_back(info.CameraID);
  235. }else {
  236. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  237. pRoomActionInfo->ChannelID = info.ChannelID;
  238. pRoomActionInfo->RoomID = info.RoomID;
  239. pRoomActionInfo->ActionID = info.ActionID;
  240. pRoomActionInfo->RoomType = info.RoomType;
  241. pRoomActionInfo->strRoomName = info.strRoomName;
  242. pRoomActionInfo->listCameraID.push_back(info.CameraID);
  243. listRoomActionInfo.push_back(pRoomActionInfo);
  244. }
  245. }
  246. /* 清空算法对应的摄像机列表 */
  247. void ListRoomActionInfo::clearCameraList()
  248. {
  249. for(auto& it0 : listRoomActionInfo)
  250. {
  251. it0->listCameraID.clear();
  252. }
  253. }
  254. /* 清理设置为STOP或者ERROR的RoomAction */
  255. void ListRoomActionInfo::clearStopRoomAction()
  256. {
  257. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();)
  258. {
  259. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  260. {
  261. delete *it0;
  262. it0 = listRoomActionInfo.erase(it0);
  263. }else {
  264. ++it0;
  265. }
  266. }
  267. }
  268. /* 查找算法ID是否已在列表中 */
  269. RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
  270. {
  271. for(const auto& it0 : listRoomActionInfo)
  272. {
  273. if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
  274. {
  275. return it0;
  276. }
  277. }
  278. return nullptr;
  279. }
  280. /* ====================================================================================
  281. * ************************** GlobalConfig成员函数 ******************************
  282. * ====================================================================================*/
  283. GlobalConfig::GlobalConfig()
  284. {
  285. }
  286. /* 读取配置文件 */
  287. bool GlobalConfig::readConfig(const QString& strConfigFile)
  288. {
  289. QSettings settings(strConfigFile, QSettings::IniFormat);
  290. settings.setIniCodec("UTF-8");
  291. AppPeopleOnWork = settings.value("APPPEPOLEONWORK").toString().toInt(); /* 离岗时间 */
  292. AppBadthing = settings.value("APPBADTHING").toString().toInt(); /* 违禁物品出现的时间 */
  293. AppBadMan = settings.value("APPBADMAN").toString().toInt(); /* 非法入侵 */
  294. AppTired = settings.value("APPTIRED").toString().toInt(); /* 疲劳检测时间 */
  295. AppPeopleCont = settings.value("APPPEOPLECONT").toString().toInt(); /* 人员聚集时间 */
  296. AppPlayPhone = settings.value("APPPLAYPHONE").toString().toInt(); /* 玩手机识别 */
  297. AppMouse = settings.value("APPMOUSE").toString().toInt(); /* 手势识别 */
  298. AppMask = settings.value("APPMASK").toString().toInt(); /* 戴口罩识别 */
  299. CheckSet = settings.value("CHECKSET").toString().toInt(); /* 服务端多久检测一次配置 */
  300. EventTimeValid = settings.value("EVENTTIMEVALID").toString().toInt(); /* 事件时间有效期 */
  301. Key = settings.value("Key").toString().toStdString(); /* Key */
  302. Secret = settings.value("Secret").toString().toStdString(); /* Secret */
  303. return true;
  304. }