10 #include "ace/OS_NS_Thread.h" 11 #include "ace/High_Res_Timer.h" 12 #include "ace/OS_NS_sys_socket.h" 16 #ifndef _MADARA_NO_KARL_ 37 ACE_Time_Value current = ACE_High_Res_Timer::gettimeofday ();
38 ACE_Time_Value max_wait, sleep_time, next_epoch;
39 ACE_Time_Value poll_frequency, last = current;
44 max_wait = current + max_wait;
47 next_epoch = current + poll_frequency;
58 "KnowledgeBase::wait:" \
59 " waiting on %s\n", expression.
logic.c_str ());
64 "KnowledgeBase::wait:" \
65 " completed first eval to get %s\n",
66 last_value.to_string ().c_str ());
72 current = ACE_High_Res_Timer::gettimeofday ();
75 while (!last_value.to_integer () &&
79 "KnowledgeBase::wait:" \
80 " current is %llu.%llu and max is %llu.%llu (poll freq is %f)\n",
81 (
unsigned long long)current.sec (),
82 (
unsigned long long)current.usec (),
83 (
unsigned long long)max_wait.sec (),
84 (
unsigned long long)max_wait.usec (),
88 "KnowledgeBase::wait:" \
89 " last value didn't result in success\n");
95 if (current < next_epoch)
97 sleep_time = next_epoch - current;
101 next_epoch = next_epoch + poll_frequency;
113 "KnowledgeBase::wait:" \
114 " waiting on %s\n", expression.
logic.c_str ());
119 "KnowledgeBase::wait:" \
120 " completed eval to get %s\n",
121 last_value.to_string ().c_str ());
129 current = ACE_High_Res_Timer::gettimeofday ();
133 if (current >= max_wait)
136 "KnowledgeBase::wait:" \
137 " Evaluate did not succeed. Timeout occurred\n");
146 else if (
impl_.get ())
148 result =
impl_->wait (expression, settings);
153 #endif // _MADARA_NO_KARL_ This class encapsulates an entry in a KnowledgeBase.
double max_wait_time
Maximum time to wait for an expression to become true (in seconds)
void lock(void) const
Locks the mutex on this context.
std::string pre_print_statement
Statement to print before evaluations.
int send_modifieds(const std::string &prefix="KnowledgeBase::send_modifieds", const EvalSettings &settings=EvalSettings())
Sends all modified variables through the attached transports.
void signal(bool lock=true) const
Signals that this thread is done with the context.
void print(unsigned int level) const
Atomically prints all variables and values in the context.
std::string logic
the logic that was compiled
MADARA_Export double sleep(double sleep_time)
Sleeps for a certain amount of time.
Compiled, optimized KaRL logic.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
std::string post_print_statement
Statement to print after evaluations.
std::shared_ptr< KnowledgeBaseImpl > impl_
Pointer to actual implementation, i.e., the "bridge", which is reference counted to automate memory m...
madara::expression::ExpressionTree expression
the expression tree
ThreadSafeContext * context_
A knowledge base can also be a facade for another knowledge base.
madara::knowledge::KnowledgeRecord wait(const std::string &expression, const WaitSettings &settings=WaitSettings())
Waits for an expression to be non-zero.
void unlock(void) const
Unlocks the mutex on this context.
double poll_frequency
Frequency to poll an expression for truth (in seconds)
void wait_for_change(bool extra_release=false)
Wait for a change to happen to the context.
Provides functions and classes for the distributed knowledge base.
Copyright (c) 2015 Carnegie Mellon University.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
Encapsulates settings for a wait statement.
madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Evaluates the expression tree.