Browse Source

每种区域业务处理添加(卡-区域)逻辑上绑定的类变量business_data
可以在 on_enter 中初始化这个变量,在 on_hover,on_leave 中更新使用
如果当前业务不需要使用【卡-区域】为key的变量,就无需初始化它。

zzj 6 years ago
parent
commit
ef71ed66ce
5 changed files with 178 additions and 182 deletions
  1. 30 3
      area.cpp
  2. 12 1
      area.h
  3. 126 30
      area_business.cpp
  4. 10 3
      area_business.h
  5. 0 145
      websocket/autom4te.cache/requests

+ 30 - 3
area.cpp

@@ -17,24 +17,51 @@
 template<> std::shared_ptr<area_list> 
 single_base<area_list, int, std::shared_ptr<area>>::m_instance=std::make_shared<area_list>();
 
+struct underground_area:area
+{
+    underground_area(int limit_count_person, int limit_time_person,double scale,int32_t mapid)
+        :area(-1,limit_count_person,limit_time_person,scale,mapid,(1<<1)|(1<<2)|(1<<3)|(1<<4))
+	{
+		m_area_business_list=area_business::get_instance_list(m_area_type);
+	}
+
+	void db_load_card_count()
+	{
+	
+	}
+};
+
+struct ground_area:area
+{
+
+
+
+};
+
 void area::on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
 {
  	for(auto i:m_area_business_list)
-		i->on_hover(a,c);
+	{
+		i->on_hover(a,c,*a->get_business_data(i->business_type()));
+	}
 }
 
 void area::on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
 {
 	log_info("on_enter..%d  areaId:%d",c->m_id,m_id);
  	for(auto i:m_area_business_list)
-		i->on_enter(a,c);
+	{
+		i->on_enter(a,c,a->get_business_data(i->business_type()));
+	}
 }
 
 void area::on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
 {
 	log_info("on_leave..%d  areaId:%d",c->m_id,m_id);
  	for(auto i:m_area_business_list)
-		i->on_leave(a,c);
+	{
+		i->on_leave(a,c,*a->get_business_data(i->business_type()));
+	}
 }
 
 bool area::in_area(const point & p)

+ 12 - 1
area.h

@@ -11,6 +11,7 @@
 struct area_hover;
 struct point;
 struct area_business;
+struct business_data;
 struct card_location_base;
 
 /*
@@ -136,7 +137,7 @@ struct area_hover
 		记录该业务所关心的需持续使用的数据,每个业务一个指针
 		建议该数据项在on_enter时初始化,on_leave时清除
 	*/
-	std::vector<void*> m_hover_data;
+	std::vector<std::shared_ptr<business_data>> m_data;
 
     area_hover()=default;
     area_hover(std::shared_ptr<area>&area,const point&pt,double speed)
@@ -149,6 +150,16 @@ struct area_hover
         landmark_dis=0;
     }
 
+	std::shared_ptr<business_data>*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();

+ 126 - 30
area_business.cpp

@@ -8,7 +8,6 @@ struct area_business_factory
 {
 	area_business_factory()
 	{
-	
 	}
 
 	void regist(int type,std::shared_ptr<area_business> ab)
@@ -45,6 +44,30 @@ struct area_business_factory
 	}
 };
 
+/*
+	确定需要推送人员
+	人员推送哪个区域,存储在card_localtion_base上,每次调用前清空,该类只将优先级最高的区域设定给该值即可
+*/
+
+struct area_business_post_area:area_business
+{
+	virtual int area_business_type()
+	{
+		return 1;
+	}
+	//记录所在区域
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
+	{
+	
+	}
+
+	//根据超速检测的策略,进行超速判断,超速时进行告警
+	//建议使用最近M秒内N秒超时进行判断,M=20,N=15,策略数据记录在area_hove中
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+	{
+	
+	}
+};
 /*
 	判断车辆超速,确定超速后记录日志、数据库并告警
 	每张卡在每个区域的超速相关的数据信息记录在 area_hover 对象
@@ -53,103 +76,176 @@ struct area_business_factory
 
 struct area_business_speed_checker:area_business
 {
+	virtual int area_business_type()
+	{
+		return 4;
+	
+	}
 	//在area_hover对象中初始化超速检测所需的对象
-	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
 	{
 	
 	}
 
 	//根据超速检测的策略,进行超速判断,超速时进行告警
 	//建议使用最近M秒内N秒超时进行判断,M=20,N=15,策略数据记录在area_hove中
-	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 	{
 	
 	}
 
 	//清除超速检测所需的对象
-	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 	{
 	}
 };
 
+
 /*
-	判断当前区域a中的人数是否超过设定人数,超过后告警
-	区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
+	禁区
 */
-struct area_business_person_count_checker:area_business
+struct area_business_restricted:area_business
 {
-	//增加计数,并进行判断
-	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	virtual int area_business_type()
+	{
+
+		return 7;
+	}
+	//记录进入时间等信息
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
 	{
 	
 	}
 
-	//减少计数
-	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	//卡在猴车区域移动
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 	{
 	
 	}
+
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+	{
+	}
 };
 
-//同人员计数
-struct area_business_car_count_checker:area_business
+/*
+	猴车区域
+*/
+struct area_business_monkey_area:area_business
 {
-	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	virtual int area_business_type()
+	{
+
+		return 8;
+	}
+	//记录进入时间等信息,开始考勤
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
 	{
 	
 	}
 
-	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	//记录离开考勤区域信息,结束考勤
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 	{
-	
 	}
+};
 
-	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+/*
+	车辆考勤
+*/
+
+struct area_business_car_attendance:area_business
+{
+	virtual int area_business_type()
 	{
+		return 6;
 	
 	}
+	//记录进入时间等信息,开始考勤
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
+	{
+	
+	}
+
+	//记录离开考勤区域信息,结束考勤
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+	{
+	}
 };
 
 /*
-	判断当前区域a中的人卡停留时间
-	人员进入区域时间存储在area_hover对象中,在当前类on_enter/on_leave中进行更新
-	人员&车辆的代码重用,请自行设计
+	人员考勤
 */
 
-struct area_business_person_dwell_checker:area_business
+struct area_business_person_attendance:area_business
 {
-	//初始化 area_hover 的相关数据项
-	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	virtual int area_business_type()
 	{
+		return 5;
 	
 	}
-
-	//更新 area_hover 的相关数据项,并进行超时判断
-	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	//记录进入时间等信息,开始考勤
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
 	{
 	
 	}
+
+	//记录离开考勤区域信息,结束考勤
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+	{
+	}
 };
 
+/*
+	判断当前区域a中的人数是否超过设定人数,超过后告警
+	区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
+*/
+struct area_business_count_checker:area_business
+{
+	virtual int area_business_type()
+	{
+		return 3;
+	
+	}
+	//增加计数,并进行判断
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
+	{
+	
+	}
+
+	//减少计数
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+	{
+	
+	}
+};
 
 /*
-	判断逻辑同人员超时
+	判断当前区域a中的人卡停留时间
+	人员进入区域时间存储在area_hover对象中,在当前类on_enter/on_leave中进行更新
+	人员&车辆的代码重用,请自行设计
 */
-struct area_business_car_dwell_checker:area_business
+
+struct area_business_person_dwell_checker:area_business
 {
+	virtual int area_business_type()
+	{
+		return 2;
+	}
 	//初始化 area_hover 的相关数据项
-	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
 	{
 	
 	}
 
 	//更新 area_hover 的相关数据项,并进行超时判断
-	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
 	{
 	
 	}
 };
 
+
 std::vector<std::shared_ptr<area_business>> area_business::get_instance_list(int business_type)
 {
 	return area_business_factory::instance().get_check_list(business_type);

+ 10 - 3
area_business.h

@@ -4,11 +4,18 @@
 #include <vector>
 #include <memory>
 
+struct business_data
+{
+	virtual ~business_data(){}
+};
+
 struct area_business
 {
-	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
-	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
-	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
+	virtual int business_type()=0;
+
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr){}
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr){}
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr){}
 
 	static std::vector<std::shared_ptr<area_business>> get_instance_list(int business_type);
 };

+ 0 - 145
websocket/autom4te.cache/requests

@@ -1,145 +0,0 @@
-# This file was generated.
-# It contains the lists of macros which have been traced.
-# It can be safely removed.
-
-@request = (
-             bless( [
-                      '0',
-                      1,
-                      [
-                        '/usr/share/autoconf'
-                      ],
-                      [
-                        '/usr/share/autoconf/autoconf/autoconf.m4f',
-                        '/usr/share/aclocal-1.12/amversion.m4',
-                        '/usr/share/aclocal-1.12/auxdir.m4',
-                        '/usr/share/aclocal-1.12/cond.m4',
-                        '/usr/share/aclocal-1.12/depend.m4',
-                        '/usr/share/aclocal-1.12/depout.m4',
-                        '/usr/share/aclocal-1.12/init.m4',
-                        '/usr/share/aclocal-1.12/install-sh.m4',
-                        '/usr/share/aclocal-1.12/lead-dot.m4',
-                        '/usr/share/aclocal-1.12/make.m4',
-                        '/usr/share/aclocal-1.12/missing.m4',
-                        '/usr/share/aclocal-1.12/options.m4',
-                        '/usr/share/aclocal-1.12/runlog.m4',
-                        '/usr/share/aclocal-1.12/sanity.m4',
-                        '/usr/share/aclocal-1.12/silent.m4',
-                        '/usr/share/aclocal-1.12/strip.m4',
-                        '/usr/share/aclocal-1.12/substnot.m4',
-                        '/usr/share/aclocal-1.12/tar.m4',
-                        'configure.ac'
-                      ],
-                      {
-                        'm4_pattern_forbid' => 1,
-                        'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1,
-                        '_AM_SET_OPTION' => 1,
-                        'AC_DEFUN' => 1,
-                        'AM_INIT_AUTOMAKE' => 1,
-                        'AM_AUTOMAKE_VERSION' => 1,
-                        'AM_MISSING_HAS_RUN' => 1,
-                        'AM_SUBST_NOTMAKE' => 1,
-                        'AM_MISSING_PROG' => 1,
-                        'AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
-                        'AC_DEFUN_ONCE' => 1,
-                        'AM_PROG_INSTALL_STRIP' => 1,
-                        '_m4_warn' => 1,
-                        'AM_SANITY_CHECK' => 1,
-                        'AM_SILENT_RULES' => 1,
-                        'include' => 1,
-                        '_AM_PROG_TAR' => 1,
-                        'AM_AUX_DIR_EXPAND' => 1,
-                        'AM_DEP_TRACK' => 1,
-                        '_AM_SET_OPTIONS' => 1,
-                        'AM_RUN_LOG' => 1,
-                        '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
-                        '_AM_IF_OPTION' => 1,
-                        '_AM_SUBST_NOTMAKE' => 1,
-                        '_AM_AUTOCONF_VERSION' => 1,
-                        'm4_pattern_allow' => 1,
-                        '_AM_MANGLE_OPTION' => 1,
-                        'AM_SET_LEADING_DOT' => 1,
-                        'AM_CONDITIONAL' => 1,
-                        'AM_SET_DEPDIR' => 1,
-                        '_AM_DEPENDENCIES' => 1,
-                        'm4_include' => 1,
-                        'AM_PROG_INSTALL_SH' => 1,
-                        '_AC_AM_CONFIG_HEADER_HOOK' => 1,
-                        'AU_DEFUN' => 1,
-                        'AM_MAKE_INCLUDE' => 1
-                      }
-                    ], 'Autom4te::Request' ),
-             bless( [
-                      '1',
-                      1,
-                      [
-                        '/usr/share/autoconf'
-                      ],
-                      [
-                        '/usr/share/autoconf/autoconf/autoconf.m4f',
-                        'aclocal.m4',
-                        'configure.ac'
-                      ],
-                      {
-                        '_LT_AC_TAGCONFIG' => 1,
-                        'AM_PROG_F77_C_O' => 1,
-                        'm4_pattern_forbid' => 1,
-                        'AC_INIT' => 1,
-                        '_AM_COND_IF' => 1,
-                        'AC_CANONICAL_TARGET' => 1,
-                        'AC_SUBST' => 1,
-                        'AC_CONFIG_LIBOBJ_DIR' => 1,
-                        'AC_FC_SRCEXT' => 1,
-                        'AC_CANONICAL_HOST' => 1,
-                        'AC_PROG_LIBTOOL' => 1,
-                        'AM_PROG_MKDIR_P' => 1,
-                        'AM_INIT_AUTOMAKE' => 1,
-                        'AM_PATH_GUILE' => 1,
-                        'AC_CONFIG_SUBDIRS' => 1,
-                        'AM_AUTOMAKE_VERSION' => 1,
-                        'LT_CONFIG_LTDL_DIR' => 1,
-                        'AC_REQUIRE_AUX_FILE' => 1,
-                        'AC_CONFIG_LINKS' => 1,
-                        'm4_sinclude' => 1,
-                        'LT_SUPPORTED_TAG' => 1,
-                        'AM_MAINTAINER_MODE' => 1,
-                        'AM_NLS' => 1,
-                        'AC_FC_PP_DEFINE' => 1,
-                        'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,
-                        'AM_MAKEFILE_INCLUDE' => 1,
-                        '_m4_warn' => 1,
-                        'AM_PROG_CXX_C_O' => 1,
-                        '_AM_COND_ENDIF' => 1,
-                        '_AM_MAKEFILE_INCLUDE' => 1,
-                        'AM_ENABLE_MULTILIB' => 1,
-                        'AM_SILENT_RULES' => 1,
-                        'AM_PROG_MOC' => 1,
-                        'AC_CONFIG_FILES' => 1,
-                        'LT_INIT' => 1,
-                        'include' => 1,
-                        'AM_PROG_AR' => 1,
-                        'AM_GNU_GETTEXT' => 1,
-                        'AC_LIBSOURCE' => 1,
-                        'AM_PROG_FC_C_O' => 1,
-                        'AC_CANONICAL_BUILD' => 1,
-                        'AC_FC_FREEFORM' => 1,
-                        'AH_OUTPUT' => 1,
-                        'AC_FC_PP_SRCEXT' => 1,
-                        '_AM_SUBST_NOTMAKE' => 1,
-                        'AC_CONFIG_AUX_DIR' => 1,
-                        'sinclude' => 1,
-                        'AM_PROG_CC_C_O' => 1,
-                        'm4_pattern_allow' => 1,
-                        'AM_XGETTEXT_OPTION' => 1,
-                        'AC_CANONICAL_SYSTEM' => 1,
-                        'AM_CONDITIONAL' => 1,
-                        'AC_CONFIG_HEADERS' => 1,
-                        'AC_DEFINE_TRACE_LITERAL' => 1,
-                        'AM_POT_TOOLS' => 1,
-                        'm4_include' => 1,
-                        '_AM_COND_ELSE' => 1,
-                        'AC_SUBST_TRACE' => 1
-                      }
-                    ], 'Autom4te::Request' )
-           );
-