#ifndef _AREA_HPP_ #define _AREA_HPP_ #include #include #include #include #include "common.h" #include struct area_hover; struct point; struct area_business; struct business_data; struct card_location_base; /* 每个区域对应一个area对象。 */ struct area { area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type) :m_id(id) ,m_area_type(type) ,m_limit_person_second(limit_time_person) ,m_limit_person_count(limit_count_person) ,m_scale(scale) ,m_mapid(mapid) ,m_person_count(0) ,m_vehicle_count(0) { } virtual void on_hover(std::shared_ptr&a,std::shared_ptr&c); virtual void on_enter(std::shared_ptr&a,std::shared_ptr&c); virtual void on_leave(std::shared_ptr&a,std::shared_ptr&c); bool in_area(const point & p); int id()const { return m_id; } int mapid()const { return m_mapid; } double scale()const { return m_scale; } bool special()const { return m_area_type == AREA_TYPE_NO_COVER; } virtual ~area() {} ///区域卡数 int card_count()const { return m_person_count + m_vehicle_count; } void update(int limit_count_person, int limit_time_person,double scale,int32_t mapid, int32_t type,int limit_count_vehicle, int limit_time_vehicle) { m_area_type=type; m_limit_person_second=limit_time_person; m_limit_person_count=limit_count_person; m_scale=scale; m_mapid=mapid; m_limit_vehicle_count=limit_count_vehicle; m_limit_vehicle_second=limit_time_vehicle; } public: std::vector m_area_business_list; public: std::vector m_bound; //std::atomic m_card_count; //数据库唯一ID int m_id; ///区域类型 AREA_TYPE //用户定义的业务类型,BIT集合 /* 1:位置[优先级] 2:超时[超时时间分钟数] 3:超员[人员数量、车辆数量] 4:超速[超速值、判断策略N/M] 5:人员考勤 6:车辆考勤[离开最小,离开最小距离] 7:禁区[进入时长] 8:猴车区域 */ int m_area_type; //人卡超时及超员数量 int m_limit_person_second; int m_limit_person_count; //人卡超时及超员数量 int m_limit_vehicle_second; int m_limit_vehicle_count; double m_scale; int32_t m_mapid; ///区域人卡数 std::atomic m_person_count; ///区域车卡数 std::atomic m_vehicle_count; }; struct area_list:single_base> { area_list(); std::shared_ptr get_area(const point&pt); std::vector init_path(std::string &str); ///id=-1为初始化所有 void init_from_db(int id=-1); void init_monkeycar_area(int id=-1); private: //禁区功能-给禁区中的卡发送警告及呼叫 void CheckAreaType(int area_id,int new_area_type,int old_area_type); void CheckAreaType( std::shared_ptr pArea,int new_area_type,int old_area_type); }; struct area_hover { std::shared_ptr m_area; time_t m_enter_time,m_last_time; point m_enter_point,m_last_point; int landmark_id; int landmark_dir; double landmark_dis; /* 记录该业务所关心的需持续使用的数据,每个业务一个指针 建议该数据项在on_enter时初始化,on_leave时清除 */ std::vector> m_data; area_hover()=default; area_hover(std::shared_ptr&area,const point&pt,double speed) :m_area(area) { m_enter_time=m_last_time=time(0); m_enter_point=m_last_point=pt; landmark_id=0; landmark_dir=0; landmark_dis=0; } std::shared_ptr get_business_data(int type) { if(type>=(int)m_data.size()) { m_data.resize(type+1); } return m_data[type]; } int id()const { return m_area->id(); } int mapid()const { return m_area->mapid(); } double scale()const { return m_area->scale(); } bool operator == (const area_hover&o)const { return m_area->id()==o.m_area->id(); } bool operator < (const area_hover&o)const { return m_area->id()id(); } std::tuple getLandmark() { return std::make_tuple(m_enter_time,m_last_time,mapid(),id(),landmark_id,landmark_dir,landmark_dis,scale()); } void setLandmark(const point &pt); void set(const point&pt) { m_last_time=time(0); m_last_point = pt; } }; //每张卡包含一个对象 //在解析出数据点时,调用on_point struct site; struct area_tool { std::shared_ptr m_area_hover=nullptr; void on_point(const std::shared_ptr&s,std::shared_ptr c,const point&pt); void setLandmark(const point &pt) { if(m_area_hover) { m_area_hover->setLandmark(pt); } } //special area or no area att.,return true;else return false. bool special_area() { if(m_area_hover==nullptr) return true; return m_area_hover->m_area->special(); } std::tuple getLandmark() { if(m_area_hover) return m_area_hover->getLandmark(); else return std::make_tuple(0,0,0,0,0,0,0,0); } void do_hover_biz(uint32_t card_id,double speed,int16_t type) { // m_area_hover->m_area->on_hover(card_id,m_area_hover,speed,type); } void do_enter_biz(uint32_t card_id,double speed,int16_t type) { // m_area_hover->m_area->on_enter(card_id,m_area_hover,speed,type); } void do_leave_biz(uint32_t card_id,double speed,int16_t type) { // m_area_hover->m_area->on_leave(card_id,m_area_hover,speed,type); } void change_area(uint32_t card_id,double speed,int16_t type,int32_t new_areaid) { #if 0 do_leave_biz(card_id,speed,type); auto area = area_list::instance()->get(new_areaid); point pt; m_area_hover.reset(new area_hover(area,pt,speed)); do_enter_biz(card_id,speed,type); #endif } }; #endif