11 #include "madara/Boost.h" 15 #ifdef _MADARA_USING_ZMQ_ 19 #ifdef _USE_OPEN_SPLICE_ 21 #endif // _USE_OPEN_SPLICE_ 41 if (actual_host ==
"")
44 actual_host = boost::asio::ip::host_name();
45 }
catch (
const std::exception &) {
46 actual_host =
"localhost";
50 if (actual_host.size () > 30) {
51 actual_host.resize (30);
56 auto uuid = boost::uuids::random_generator{}();
57 auto uuid_str = boost::uuids::to_string(uuid);
58 uuid_str.erase(std::remove(uuid_str.begin(), uuid_str.end(),
'-'), uuid_str.end());
60 actual_host += uuid_str;
81 "KnowledgeBaseImpl::attach_transport:" \
82 " activating transport type %d\n", settings.
type);
96 #ifdef _USE_OPEN_SPLICE_ 98 "KnowledgeBaseImpl::activate_transport:" \
99 " creating Open Splice DDS transport.\n");
105 "KnowledgeBaseImpl::activate_transport:" \
106 " project was not generated with opensplice=1. Transport is invalid.\n");
113 "KnowledgeBaseImpl::activate_transport:" \
114 " creating NDDS transport.\n");
120 "KnowledgeBaseImpl::activate_transport:" \
121 " project was not generated with ndds=1. Transport is invalid.\n");
127 "KnowledgeBaseImpl::activate_transport:" \
128 " creating UDP transport.\n");
135 #ifdef _MADARA_USING_ZMQ_ 137 "KnowledgeBaseImpl::activate_transport:" \
138 " creating ZMQ transport.\n");
144 "KnowledgeBaseImpl::activate_transport:" \
145 " project was not generated with zmq=1. Transport is invalid.\n");
151 "KnowledgeBaseImpl::activate_transport:" \
152 " creating UDP Registry Server transport.\n");
160 "KnowledgeBaseImpl::activate_transport:" \
161 " creating UDP Registry Client transport.\n");
169 "KnowledgeBaseImpl::activate_transport:" \
170 " no transport was specified. Setting transport to null.\n");
194 for (
auto &transport : old_transports)
199 "KnowledgeBaseImpl::close_transport:" \
200 " transport has been closed\n");
205 #ifndef _MADARA_NO_KARL_ 212 "KnowledgeBaseImpl::compile:" \
213 " compiling %s\n", expression.c_str ());
223 return wait (compiled, settings);
245 "KnowledgeBaseImpl::wait:" \
246 " waiting on %s\n", ce.
logic.c_str ());
251 "KnowledgeBaseImpl::wait:" \
252 " completed first eval to get %s\n",
253 last_value.to_string ().c_str ());
263 "KnowledgeBaseImpl::wait:" \
264 " last value didn't result in success\n");
284 "KnowledgeBaseImpl::wait:" \
285 " waiting on %s\n", ce.
logic.c_str ());
290 "KnowledgeBaseImpl::wait:" \
291 " completed eval to get %s\n",
292 last_value.to_string ().c_str ());
304 "KnowledgeBaseImpl::wait:" \
305 " Evaluate did not succeed. Timeout occurred\n");
323 "KnowledgeBaseImpl::evaluate:" \
324 " evaluating %s.\n", ce.
logic.c_str ());
359 "KnowledgeBaseImpl::evaluate:" \
360 " evaluating ComponentNode rooted tree\n");
387 #endif // _MADARA_NO_KARL_ 402 if (modified.size () > 0)
409 transport->send_data (modified);
421 for (
const auto &entry : modified)
425 allowed_modifieds.emplace_hint(allowed_modifieds.end(), entry);
430 if (allowed_modifieds.size () > 0)
434 transport->send_data (allowed_modifieds);
438 for (
const auto &entry : allowed_modifieds)
453 "%s: no modifications to send\n", prefix.c_str ());
463 "%s: no transport configured\n", prefix.c_str ());
470 "%s: user requested to not send modifieds\n", prefix.c_str ());
This class encapsulates an entry in a KnowledgeBase.
double max_wait_time
Maximum time to wait for an expression to become true (in seconds)
std::map< std::string, bool > send_list
Map of record names that are allowed to be sent after operation.
Multicast-based transport for knowledge.
Broadcast-based transport for knowledge.
std::string pre_print_statement
Statement to print before evaluations.
bool signal_changes
Toggle whether to signal changes have happened.
void signal(bool lock=true) const
Signals that this thread is done with the context.
const VariableReferenceMap & get_modifieds(void) const
Retrieves a list of modified variables.
void print(unsigned int level) const
Atomically prints all variables and values in the context.
std::string logic
the logic that was compiled
void close_transport(void)
Closes the transport mechanism so no dissemination is possible.
Holds basic transport settings.
Compiled, optimized KaRL logic.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
size_t attach_transport(madara::transport::Base *transport)
Attaches a transport to the Knowledge Engine.
std::string post_print_statement
Statement to print after evaluations.
uint32_t type
Type of transport. See madara::transport::Types for options.
madara::knowledge::KnowledgeRecord wait(const std::string &expression)
Waits for an expression to be non-zero.
bool is_done(void) const
Checks to see if max duration is finished.
knowledge::KnowledgeRecord evaluate(CompiledExpression expression, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Evaluate a compiled expression.
madara::expression::ExpressionTree expression
the expression tree
std::vector< std::unique_ptr< transport::Base > > transports_
This class provides an interface into the Open Splice dissemination transport.
Enforces a periodic epoch.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
An abstract base class defines a simple abstract implementation of an expression tree node...
double poll_frequency
Frequency to poll an expression for truth (in seconds)
ZMQ-based transport for knowledge.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
Integer to_integer(void) const
converts the value to an integer.
This class provides an interface into the NDDS dissemination transport.
std::string setup_unique_hostport(std::string host="")
Creates a random UUID for unique tie breakers in global ordering.
void wait_for_change(bool extra_release=false)
Wait for a change to happen to the context.
uint64_t inc_clock(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically increments the Lamport clock and returns the new clock time (intended for sending knowledg...
std::map< const char *, VariableReference, VariableReferenceMapCompare > VariableReferenceMap
a map of variable references
Encapsulates settings for an evaluation statement.
Provides utility functions and classes for common tasks and needs.
madara::knowledge::KnowledgeRecord evaluate(const std::string &expression)
Evaluates an expression.
Provides functions and classes for the distributed knowledge base.
MADARA_EXPORT int send_modifieds(const std::string &prefix, const EvalSettings &settings=EvalSettings())
Sends all modified variables through the attached transports.
Copyright (c) 2015 Carnegie Mellon University.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
UDP-based transport for knowledge.
bool delay_sending_modifieds
Toggle for sending modifieds in a single update event after each evaluation.
Encapsulates settings for a wait statement.
UDP-based transport for knowledge.
utility::EpochEnforcer< std::chrono::steady_clock > EpochEnforcer
Base class from which all transports must be derived.
UDP-based server that handles a registry of UDP endpoints, which makes it ideal for any NAT-protected...
madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Evaluates the expression tree.
void sleep_until_next(void)
Sleeps until the next epoch.
void reset_modified(void)
Reset all variables to be unmodified.