Browse Source

添加web端调整分站路径时自动更新card_path

zzj 6 years ago
parent
commit
41c2d5326f
3 changed files with 14 additions and 27 deletions
  1. 3 0
      ant.cpp
  2. 11 24
      card_path.cpp
  3. 0 3
      main.cpp

+ 3 - 0
ant.cpp

@@ -6,6 +6,7 @@
 #include "event.h"
 #include "tool_time.h"
 #include "area.h"
+#include "card_path.h"
 //template<> std::shared_ptr<sit_list> single_base<sit_list, int, std::shared_ptr<site>>::m_instance=std::make_shared<sit_list>();
 
 int site::index()const
@@ -158,6 +159,8 @@ void sit_list::read_ant_path(int id)
              log_info( "修改path成功,分站id=%d\n", id );
          }
      }
+
+	 card_path::init();
 }
 
 void sit_list::init_site(int id)

+ 11 - 24
card_path.cpp

@@ -822,33 +822,20 @@ struct graph
 	}
 };
 
-
-std::atomic<int> g_init_flag(0);
-graph g_graph;
-
+safe_shared_ptr<graph> g_graph(std::make_shared<graph>());
 }//namespace
 
 void card_path::init()
 {
-    //Ensure only ont thread can init path.
-	int expect=0;
-	if(g_init_flag.compare_exchange_strong(expect,1))
-	{
-		handle_path hp;
-		//std::vector<base_path> opath=init_path(sites,v_list);
-		sit_list::instance()->accept(hp);
-		std::vector<base_path> opath=init_path(hp.ret,hp.v);
-		g_graph.init(hp.v,opath);
+	std::shared_ptr<graph> local_graph=std::make_shared<graph>();
 
-		++g_init_flag;
-	}
-    //if != 2 then wait here until init over.
-	while(g_init_flag.load()!=2)
-	{
-		std::this_thread::sleep_for (std::chrono::seconds(1));
-	}
-}
+	handle_path hp;
+	sit_list::instance()->accept(hp);
+	std::vector<base_path> opath=init_path(hp.ret,hp.v);
+	local_graph->init(hp.v,opath);
 
+	g_graph.set(local_graph);
+}
 
 card_path&card_path::inst()
 {
@@ -858,17 +845,17 @@ card_path&card_path::inst()
 
 std::vector<point> card_path::find_path(const point&from,const point&to)const
 {
-	return g_graph.find(from,to);
+	return g_graph.get()->find(from,to);
 }
 
 bool card_path::is_at_path(const point&pt)const
 {
-	return g_graph.is_at_path(pt);
+	return g_graph.get()->is_at_path(pt);
 }
 
 std::vector<line_v>  card_path::find_possible_path(const point&from,double dist) const
 {
-	return std::move(g_graph.find_possible_path(from,dist));
+	return std::move(g_graph.get()->find_possible_path(from,dist));
 }
 
 #ifdef __DEBUG__

+ 0 - 3
main.cpp

@@ -182,9 +182,6 @@ int main(int argc ,char * argv[])
     Init_Setting is;
     is.init();
 
-	card_path::init();
-//	test_find_path(point(4600,-75),point(4727,-90));
-
     module_mgr::start();
     web_connect::start_beatheart_monitor();
     atexit(&cleanup);