MADARA  3.2.3
SystemCallSetClock.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
10 
11 
14  const ComponentNodes & nodes)
15  : SystemCallNode (context, nodes)
16 {
17 
18 }
19 
20 // Dtor
22 {
23 }
24 
27 {
29 }
30 
36 {
37  // user can always change a function, and we have no control over
38  // what it does. Consequently, a function node cannot be pruned out
39  // under any situation
40  can_change = true;
41 
43 
44  for (ComponentNodes::iterator i = nodes_.begin (); i != nodes_.end ();
45  ++i)
46  {
47  bool arg_can_change = false;
48  result = (*i)->prune (arg_can_change);
49 
50  if (!arg_can_change && dynamic_cast <LeafNode *> (*i) == 0)
51  {
52  delete *i;
53  *i = new LeafNode (*(this->logger_), result);
54  }
55  }
56 
57  if (nodes_.size () > 2 || nodes_.size () == 0)
58  {
60  "madara::expression::SystemCallSetClock: "
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  {
80  "madara::expression::SystemCallSetClock: "
81  "System call set_clock is setting the system clock\n");
82 
83  context_.set_clock (nodes_[0]->evaluate (settings).to_integer ());
84 
86  }
87  else if (nodes_.size () == 2)
88  {
90  "madara::expression::SystemCallSetClock: "
91  "System call set_clock is setting a variable clock\n");
92 
93  VariableNode * variable = dynamic_cast <VariableNode *> (nodes_[0]);
94  if (variable)
95  {
96  variable->get_record ()->clock =
97  (uint64_t) nodes_[1]->evaluate (settings).to_integer ();
98 
100  variable->get_record ()->clock);
101  }
102  else
103  {
105  "madara::expression::SystemCallSetClock: "
106  "KARL RUNTIME ERROR:"
107  "System call set_clock with 2 arguments "
108  "requires the first argument to be a variable\n");
109 
110  throw KarlException ("madara::expression::SystemCallSetClock: "
111  "KARL RUNTIME ERROR: "
112  "System call set_clock with 2 arguments "
113  "requires the first argument to be a variable\n");
114  }
115 
116  }
117  else
118  {
120  "madara::expression::SystemCallSetClock: "
121  "KARL RUNTIME ERROR:"
122  "System call set_clock requires 1-2 arguments, "
123  "e.g., set_clock (5) or set_clock (var, 5)\n");
124 
125  throw KarlException ("madara::expression::SystemCallSetClock: "
126  "KARL RUNTIME ERROR: "
127  "System call set_clock requires 1-2 arguments, "
128  "e.g., set_clock (5) or set_clock (var, 5)\n");
129  }
130 
131  return return_value;
132 }
133 
134 // accept a visitor
135 void
137  madara::expression::Visitor &visitor) const
138 {
139  visitor.visit (*this);
140 }
141 
142 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
virtual ~SystemCallSetClock(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
Defines a terminal node of that references the current value stored in a variable.
Definition: VariableNode.h:28
uint64_t set_clock(uint64_t clock)
Atomically sets the lamport clock.
madara::knowledge::KnowledgeRecord KnowledgeRecord
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
logger::Logger * logger_
handle the context
Definition: ComponentNode.h:97
This class stores variables and their values for use by any entity needing state information in a thr...
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
madara::knowledge::KnowledgeRecord * get_record(void)
Retrieves the underlying knowledge::KnowledgeRecord in the context (useful for system calls)...
Definition: VariableNode.h:95
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:91
Integer to_integer(void) const
converts the value to an integer.
madara::knowledge::ThreadSafeContext & context_
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
Interface for a MADARA system call.
uint64_t get_clock(void) const
Atomically gets the Lamport clock.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
uint64_t clock
last modification time
SystemCallSetClock(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.