MADARA  3.4.1
SystemCallSleep.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
10 
13  : SystemCallNode(context, nodes)
14 {
15 }
16 
17 // Dtor
19 
21  void) const
22 {
23  return madara::knowledge::KnowledgeRecord(nodes_.size());
24 }
25 
30  bool& can_change)
31 {
32  // user can always change a function, and we have no control over
33  // what it does. Consequently, a function node cannot be pruned out
34  // under any situation
35  can_change = true;
36 
38 
39  for (ComponentNodes::iterator i = nodes_.begin(); i != nodes_.end(); ++i)
40  {
41  bool arg_can_change = false;
42  result = (*i)->prune(arg_can_change);
43 
44  if (!arg_can_change && dynamic_cast<LeafNode*>(*i) == 0)
45  {
46  delete *i;
47  *i = new LeafNode(*(this->logger_), result);
48  }
49  }
50 
51  if (nodes_.size() > 1 || nodes_.size() == 0)
52  {
54  "madara::expression::SystemCallSleep: "
55  "KARL COMPILE ERROR:"
56  "System call sleep requires 1 argument in seconds format, "
57  "e.g., set_clock (5)\n");
58 
60  "madara::expression::SystemCallSleep: "
61  "KARL COMPILE ERROR: "
62  "System call sleep requires 1 argument in seconds format, "
63  "e.g., sleep (5)\n");
64  }
65 
66  return result;
67 }
68 
74 {
75  knowledge::KnowledgeRecord return_value;
76 
77  if (nodes_.size() == 1)
78  {
79  double sleep_time = nodes_[0]->evaluate(settings).to_double();
81  "madara::expression::SystemCallSleep: "
82  "System call sleep is sleeping for %f.\n",
83  sleep_time);
84 
85  return_value =
87  }
88  else
89  {
91  "madara::expression::SystemCallSleep: "
92  "KARL RUNTIME ERROR:"
93  "System call sleep requires 1 argument in seconds format, "
94  "e.g., set_clock (5)\n");
95 
97  "madara::expression::SystemCallSleep: "
98  "KARL RUNTIME ERROR: "
99  "System call sleep requires 1 argument in seconds format, "
100  "e.g., sleep (5)\n");
101  }
102 
103  return return_value;
104 }
105 
106 // accept a visitor
108  madara::expression::Visitor& visitor) const
109 {
110  visitor.visit(*this);
111 }
112 
113 #endif // _MADARA_NO_KARL_
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:21
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Definition: LeafNode.h:25
Interface for a MADARA system call.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
SystemCallSleep(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual ~SystemCallSleep(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:93
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
This class encapsulates an entry in a KnowledgeBase.
double to_double(void) const
converts the value to a float/double.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
double sleep(double sleep_time)
Sleeps for a certain amount of time.
Definition: Utility.cpp:555