22 #include <netcomm/fawkes/client.h> 24 #include <plugins/openprs/mod_utils.h> 25 #include <config/netconf.h> 26 #include <navgraph/yaml_navgraph.h> 27 #include <navgraph/navgraph.h> 28 #include <oprs_f-pub.h> 32 extern "C" void finalize();
42 action_navgraph_load(TermList terms)
44 ACTION_ASSERT_ARG_LENGTH(
"navgraph-load", terms, 0);
47 std::string graph_file =
50 if (graph_file[0] !=
'/') {
51 graph_file = std::string(CONFDIR) +
"/" + graph_file;
56 const std::vector<NavGraphNode> &nodes = g_navgraph->
nodes();
57 const std::vector<NavGraphEdge> &edges = g_navgraph->
edges();
59 TermList graph_tl = sl_make_slist();
60 graph_tl = build_term_list(graph_tl, build_string(g_navgraph->
name().c_str()));
61 graph_tl = build_term_list(graph_tl, build_string(graph_file.c_str()));
62 add_external_fact((
char *)
"navgraph", graph_tl);
64 for (
auto n : nodes) {
65 TermList props = sl_make_slist();
66 const std::map<std::string, std::string> &properties = n.properties();
67 for (
auto p : properties) {
68 TermList prop = sl_make_slist();
69 prop = build_term_list(prop, build_string(p.first.c_str()));
70 prop = build_term_list(prop, build_string(p.second.c_str()));
71 props = build_term_list(props, build_term_l_list_from_c_list(prop));
74 TermList node_tl = sl_make_slist();
75 node_tl = build_term_list(node_tl, build_string(n.name().c_str()));
76 node_tl = build_term_list(node_tl, build_float(n.x()));
77 node_tl = build_term_list(node_tl, build_float(n.y()));
78 node_tl = build_term_list(node_tl, build_term_l_list_from_c_list(props));
80 add_external_fact((
char *)
"navgraph-node", node_tl);
83 for (
auto e : edges) {
84 TermList props = sl_make_slist();
85 const std::map<std::string, std::string> &properties = e.properties();
86 for (
auto p : properties) {
87 TermList prop = sl_make_slist();
88 prop = build_term_list(prop, build_string(p.first.c_str()));
89 prop = build_term_list(prop, build_string(p.second.c_str()));
90 props = build_term_list(props, build_term_l_list_from_c_list(prop));
93 TermList edge_tl = sl_make_slist();
94 edge_tl = build_term_list(edge_tl, build_string(e.from().c_str()));
95 edge_tl = build_term_list(edge_tl, build_string(e.to().c_str()));
96 edge_tl = build_term_list(edge_tl, e.is_directed() ? build_t() : build_nil());
97 edge_tl = build_term_list(edge_tl, build_term_l_list_from_c_list(props));
99 add_external_fact((
char *)
"navgraph-edge", edge_tl);
115 printf(
"*** LOADING mod_navgraph\n");
117 std::string fawkes_host;
118 unsigned short fawkes_port = 0;
119 get_fawkes_host_port(fawkes_host, fawkes_port);
121 printf(
"Connecting to Fawkes at %s:%u\n", fawkes_host.c_str(), fawkes_port);
128 fprintf(stderr,
"Error: cannot establish network connection: %s\n",
132 make_and_declare_action(
"navgraph-load", action_navgraph_load, 0);
133 add_user_end_kernel_hook(finalize);
140 printf(
"*** DESTROYING mod_navgraph\n");
143 delete g_fnet_client;
144 g_fnet_client = NULL;
Simple Fawkes network client.
Fawkes library namespace.
void connect()
Connect to remote.
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
const std::vector< NavGraphNode > & nodes() const
Get nodes of the graph.
std::string name() const
Get graph name.
Base class for exceptions in Fawkes.
NavGraph * load_yaml_navgraph(std::string filename)
Load topological map graph stored in RCSoft format.
const std::vector< NavGraphEdge > & edges() const
Get edges of the graph.
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
virtual void set_mirror_mode(bool mirror)
Enable or disable mirror mode.
Remote configuration via Fawkes net.