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