area_business_count_checker.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * @file
  3. * @brief
  4. * @version
  5. * @author
  6. * @date
  7. * @note
  8. * @warning
  9. * @bug
  10. * @copyright
  11. * */
  12. #ifndef _area_business_count_checker_hpp_
  13. #define _area_business_count_checker_hpp_
  14. #include "area_business.h"
  15. #include "atomic"
  16. /*
  17. 判断当前区域a中的人数是否超过设定人数,超过后告警
  18. 区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
  19. 整个井下的超员和某个区域的超员都使用这个代码
  20. */
  21. struct area_business_count_checker:area_business
  22. {
  23. area_business_count_checker()
  24. {
  25. m_mutex=0;
  26. }
  27. //服务器重启加载数据
  28. void on_load_his(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);
  29. //增加计数,并进行判断
  30. void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);
  31. void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
  32. //减少计数
  33. void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
  34. private:
  35. //添加人数超出限制告警
  36. void _add_person_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc);
  37. //移除人数超出限制告警
  38. void _remove_person_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc);
  39. //添加车数量超出限制告警
  40. void _add_vehicle_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc = "");
  41. //移除车数量超出告警
  42. void _remove_vehicle_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc = "");
  43. private:
  44. std::atomic<int> m_mutex;
  45. void lock()
  46. {
  47. int expected=0;
  48. while(!m_mutex.compare_exchange_strong(expected,1))
  49. expected=0;
  50. assert(m_mutex.load()==1);
  51. }
  52. void unlock()
  53. {
  54. m_mutex.store(0);
  55. }
  56. };
  57. #endif