MADARA  3.1.8
SystemCallSleep.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
10 #include "madara/utility/Utility.h"
11 
12 
15  const ComponentNodes & nodes)
16  : SystemCallNode (context, nodes)
17 {
18 
19 }
20 
21 // Dtor
23 {
24 }
25 
28 {
30 }
31 
37 {
38  // user can always change a function, and we have no control over
39  // what it does. Consequently, a function node cannot be pruned out
40  // under any situation
41  can_change = true;
42 
44 
45  for (ComponentNodes::iterator i = nodes_.begin (); i != nodes_.end ();
46  ++i)
47  {
48  bool arg_can_change = false;
49  result = (*i)->prune (arg_can_change);
50 
51  if (!arg_can_change && dynamic_cast <LeafNode *> (*i) == 0)
52  {
53  delete *i;
54  *i = new LeafNode (*(this->logger_), result);
55  }
56  }
57 
58  if (nodes_.size () > 2 || nodes_.size () == 0)
59  {
61  "KARL COMPILE ERROR: System call set_clock requires 1-2 arguments, "
62  "e.g., set_clock (5) or set_clock (var, 5)\n");
63  }
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  "System call sleep is sleeping for %f.\n", sleep_time);
82 
83  return_value = knowledge::KnowledgeRecord (
84  madara::utility::sleep (sleep_time));
85  }
86  else
87  {
89  "KARL RUNTIME ERROR: System call set_clock requires 1-2 arguments, "
90  "e.g., set_clock (5) or set_clock (var, 5).\n");
91  }
92 
93  return return_value;
94 }
95 
96 // accept a visitor
97 void
99  madara::expression::Visitor &visitor) const
100 {
101  visitor.visit (*this);
102 }
103 
104 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
madara::knowledge::KnowledgeRecord KnowledgeRecord
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
logger::Logger * logger_
handle the context
Definition: ComponentNode.h:96
This class stores variables and their values for use by any entity needing state information in a thr...
SystemCallSleep(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
MADARA_Export double sleep(double sleep_time)
Sleeps for a certain amount of time.
Definition: Utility.cpp:856
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual ~SystemCallSleep(void)
Destructor.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
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:90
Interface for a MADARA system call.
Settings for applying knowledge updates.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.