123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*
- * @file
- * @brief
- * @version
- * @author
- * @date
- * @note
- * @warning
- * @bug
- * @copyright
- * */
- #ifndef _area_business_count_checker_hpp_
- #define _area_business_count_checker_hpp_
- #include "area_business.h"
- #include "atomic"
- /*
- 判断当前区域a中的人数是否超过设定人数,超过后告警
- 区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
- 整个井下的超员和某个区域的超员都使用这个代码
- */
- struct area_business_count_checker:area_business
- {
- area_business_count_checker()
- {
- m_mutex=0;
- }
- //服务器重启加载数据
- 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);
- //增加计数,并进行判断
- void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);
- void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
- //减少计数
- void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
- private:
- //添加人数超出限制告警
- void _add_person_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc);
- //移除人数超出限制告警
- void _remove_person_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc);
- //添加车数量超出限制告警
- void _add_vehicle_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc = "");
- //移除车数量超出告警
- void _remove_vehicle_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc = "");
- private:
- std::atomic<int> m_mutex;
- void lock()
- {
- int expected=0;
- while(!m_mutex.compare_exchange_strong(expected,1))
- expected=0;
- assert(m_mutex.load()==1);
- }
- void unlock()
- {
- m_mutex.store(0);
- }
- };
- #endif
|