SPAServer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef SPASERVER_H
  2. #define SPASERVER_H
  3. #include "FromSuperBrain.h"
  4. #include "FromRedis.h"
  5. #include "ToEQMDataBase.h"
  6. /**
  7. * 安播辅助提示系统服务类
  8. *
  9. */
  10. class SPAServer
  11. {
  12. public:
  13. SPAServer();
  14. ~SPAServer();
  15. /* 启动服务 */
  16. void startServer();
  17. private:
  18. /* 从基础平台获取算法信息和设备信息的线程函数 */
  19. void threadFromSuperBrain();
  20. /* 处理算法信息,返回值为true,说明有改变,需要重新读取 */
  21. bool processAlgorithmInfo(std::vector<AlgorithmInfo> vecNewAlgInfo);
  22. /* 处理设备信息,传入新获取到的值,返回true需要更新本地数据缓存 */
  23. bool processDeviceInfo(std::vector<DeviceInfo> vecNewDevInfo);
  24. /* 对比算法信息现有的数据和新获取到的数据,取出要删除和添加的数据 */
  25. void compareAlgorithmInfo(const std::vector<AlgorithmInfo>& vecNewInfo, std::vector<AlgorithmInfo>& vecAlgUpdate, std::vector<AlgorithmInfo>& vecAlgDelete);
  26. /* 对比设备和算法关联表是否需要更新 */
  27. void compareDeviceAlgorithmInfo(const std::vector<DeviceInfo>& vecNewInfo, std::vector<DeviceInfo>& vecDevUpdate);
  28. /* 从Redis获取数据线程函数,这个是摄像机线程 */
  29. void threadFromRedis(const CameraThreadInfo& info);
  30. /* 解析Redis基础数据 */
  31. void parseRedisData(const std::string& strData, AlarmInfo& alarmInfo);
  32. /* 判断时间是否长时间没有更新 */
  33. bool isEventTimeVaild(const std::string& strTime);
  34. /* 分派任务的线程 */
  35. void threadRoomCamera();
  36. /* 将该算法对应的摄像机放入摄像机列表 */
  37. bool insertCameraToAction(RoomActionInfo* pRAInfo, std::list<RoomCameraInfo>& listRC, std::multimap<int, std::string>& mapCameraActionID);
  38. /* 更新房间、算法需要的摄像机个数 */
  39. bool updateRoomActionCameraCount(std::shared_ptr<RoomActionInfo> pRAInfo);
  40. /* 更新算法的摄像机ID */
  41. bool updateActionCameraID(std::shared_ptr<ActionInfo> pInfo);
  42. /* 设置线程状态 */
  43. void setThreadState(std::shared_ptr<ActionInfo> pInfo, RunTimeState state);
  44. /* 人员在岗识别线程,应该是人脸识别线程,这个需要房间内多个摄像机共同识别 */
  45. void threadActPersonWork(RoomActionInfo* RAInfo);
  46. /* 区域人员检测,检测这个区域内的人数,不能少于多少人,不能多余多少人 */
  47. void threadActPersonNumber(RoomActionInfo* RAInfo);
  48. /* 违禁物品识别 */
  49. void threadActContraband(ActionInfo* info);
  50. /* 非法入侵检测 */
  51. void threadActIllegalInvasion(ActionInfo* info);
  52. private:
  53. std::shared_ptr<spdlog::logger> m_logger = nullptr;
  54. bool m_threadRunning = true; /* 线程正在运行 */
  55. FromSuperBrain m_fromSuperBrain;
  56. ToEQMDataBase m_toEQMDataBase;
  57. std::string m_keyContraband; /* 违禁品检测的Key,这个Key后面可能随时会变动 */
  58. std::string m_KeyFace; /* 人脸检测的Key */
  59. std::mutex m_mutexActionID; /* 算法ID的互斥锁 */
  60. std::string ActPersonWork; /* 人员在岗识别 */
  61. std::string ActPersonNumber; /* 区域人员检测 */
  62. std::string ActContraband; /* 违禁品检测 */
  63. std::string ActIllegalInvasion; /* 非法入侵检测 */
  64. std::string ActFatigueDetection; /* 疲劳检测 */
  65. /* 算法信息,这个就是tAction在内存中的数据,方便后续对比,程序启动的时候会先获取一份 */
  66. std::vector<AlgorithmInfo> m_vecEqmAlgInfo;
  67. /* 设备信息,这个是tActionCamer的信息 */
  68. std::vector<DeviceInfo> m_vecEqmDevInfo;
  69. /* 算法信息列表,每个算法所在的频率、房间、摄像机 */
  70. std::mutex m_mutexActionInfo;
  71. ListActionInfo m_listActionInfo;
  72. /* 设备和算法关联信息,这里存储着已经删除的设备对应的算法信息,将在这一轮循环中删除 */
  73. std::list<int> m_listDevIDDelete;
  74. /* 房间和算法关联的信息,包含所需要的摄像机ID */
  75. std::mutex m_mutexRunRAI;
  76. ListRoomActionInfo m_runListRoomActionInfo;
  77. /* 运行时的算法信息列表,这个容器存储的是不需要摄像机融合的算法 */
  78. std::mutex m_mutexRunActionInfo;
  79. ListActionInfo m_runListActionInfo;
  80. };
  81. #endif /* SPASERVER_H */