GlobalInfo.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #include "GlobalInfo.h"
  2. /* ====================================================================================
  3. * ******************************* 全局变量定义 **********************************
  4. * ====================================================================================*/
  5. int g_eventTimeVaild = 600; /* 事件时间有效性,单位秒,超过这个时间就认为是无效数据 */
  6. /* ====================================================================================
  7. * *************************** DeviceInfo成员函数 *******************************
  8. * ====================================================================================*/
  9. /* 对比是否相等 */
  10. bool DeviceInfo::operator==(const DeviceInfo& other)
  11. {
  12. if(DeviceID != other.DeviceID) {
  13. return false;
  14. }
  15. else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
  16. return false;
  17. }
  18. else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
  19. return false;
  20. }
  21. else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
  22. return false;
  23. }
  24. return true;
  25. }
  26. /* 对比设备关联的算法信息是否相等 */
  27. bool DeviceInfo::isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other)
  28. {
  29. /* 算法数目不相等,直接返回false */
  30. if(vecAlgorithmInfo.size() != other.size()) {
  31. return false;
  32. }else {
  33. /* 算法数目相等,进一步对比算法信息 */
  34. bool isEquality = true;
  35. /* 逐步对比算法信息 */
  36. for(const auto& it0 : vecAlgorithmInfo) {
  37. bool isEq2 = true;
  38. for(const auto& it1 : other) {
  39. if(it0 == it1) {
  40. continue;
  41. }else {
  42. isEq2 = false;
  43. break;
  44. }
  45. }
  46. if(!isEq2) {
  47. isEquality = false;
  48. break;
  49. }
  50. }
  51. if(!isEquality) {
  52. return false;
  53. }
  54. }
  55. return true;
  56. }
  57. /* ====================================================================================
  58. * ************************** ListActionInfo成员函数 ****************************
  59. * ====================================================================================*/
  60. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  61. bool ListActionInfo::insertActionInfo(ActionInfo* info)
  62. {
  63. /* 先判断是否已经在列表中了 */
  64. if(findActionInList(info) == nullptr)
  65. {
  66. ActionInfo* pActionInfo = new ActionInfo;
  67. *pActionInfo = *info;
  68. listActionInfo.push_back(pActionInfo);
  69. }
  70. return true;
  71. }
  72. /* 删除信息 */
  73. bool ListActionInfo::deleteActionInfo(ActionInfo* info)
  74. {
  75. if(info == nullptr)
  76. {
  77. return false;
  78. }
  79. if(findActionInList(info) != nullptr)
  80. {
  81. listActionInfo.remove(info);
  82. delete info;
  83. info = nullptr;
  84. }
  85. return true;
  86. }
  87. /* 查找算法ID是否已在列表中 */
  88. ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
  89. {
  90. for(const auto& it0 : listActionInfo)
  91. {
  92. if(*it0 == *pInfo)
  93. {
  94. return it0;
  95. }
  96. }
  97. return nullptr;
  98. }
  99. /* 清空容器 */
  100. void ListActionInfo::clear()
  101. {
  102. for(auto& it0 : listActionInfo)
  103. {
  104. delete it0;
  105. it0 = nullptr;
  106. }
  107. listActionInfo.clear();
  108. }
  109. /* ====================================================================================
  110. * *********************** ListRoomActionInfo成员函数 ***************************
  111. * ====================================================================================*/
  112. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  113. bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
  114. {
  115. /* 先判断是否已经在列表中了 */
  116. if(findActionIDInList(info.RoomID, info.ActionID) == nullptr)
  117. {
  118. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  119. *pRoomActionInfo = info;
  120. listRoomActionInfo.push_back(pRoomActionInfo);
  121. }
  122. return true;
  123. }
  124. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  125. bool ListRoomActionInfo::insertRoomActionInfo(const int RoomID, const std::string& strActionID)
  126. {
  127. /* 先判断是否已经在列表中了 */
  128. if(findActionIDInList(RoomID, strActionID) == nullptr)
  129. {
  130. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  131. pRoomActionInfo->RoomID = RoomID;
  132. pRoomActionInfo->ActionID = strActionID;
  133. listRoomActionInfo.push_back(pRoomActionInfo);
  134. }
  135. return true;
  136. }
  137. /* 清空容器 */
  138. void ListRoomActionInfo::clear()
  139. {
  140. for(auto& it0 : listRoomActionInfo)
  141. {
  142. delete it0;
  143. it0 = nullptr;
  144. }
  145. listRoomActionInfo.clear();
  146. }
  147. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  148. void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
  149. {
  150. auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
  151. if(pRAInfo != nullptr)
  152. {
  153. pRAInfo->listCameraID.push_back(info.CameraID);
  154. }else {
  155. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  156. pRoomActionInfo->ChannelID = info.ChannelID;
  157. pRoomActionInfo->RoomID = info.RoomID;
  158. pRoomActionInfo->ActionID = info.ActionID;
  159. pRoomActionInfo->RoomType = info.RoomType;
  160. pRoomActionInfo->strRoomName = info.strRoomName;
  161. pRoomActionInfo->listCameraID.push_back(info.CameraID);
  162. listRoomActionInfo.push_back(pRoomActionInfo);
  163. }
  164. }
  165. /* 查找算法ID是否已在列表中 */
  166. RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
  167. {
  168. for(const auto& it0 : listRoomActionInfo)
  169. {
  170. if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
  171. {
  172. return it0;
  173. }
  174. }
  175. return nullptr;
  176. }