MADARA  3.2.3
SystemCallLogLevel.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
8 
9 
12  const ComponentNodes & nodes)
13  : SystemCallNode (context, nodes)
14 {
15 
16 }
17 
18 // Dtor
20 {
21 }
22 
25 {
27 }
28 
34 {
35  // user can always change a function, and we have no control over
36  // what it does. Consequently, a function node cannot be pruned out
37  // under any situation
38  can_change = true;
39 
41 
42  if (nodes_.size () > 0)
43  {
44  bool arg_can_change = false;
45  result = nodes_[0]->prune (arg_can_change);
46 
47  if (!arg_can_change && dynamic_cast <LeafNode *> (nodes_[0]) == 0)
48  {
49  delete nodes_[0];
50  nodes_[0] = new LeafNode (*(this->logger_), result);
51  }
52  }
53 
54  if (nodes_.size () > 1)
55  {
57  "madara::expression::SystemCallLogLevel: "
58  "KARL COMPILE ERROR:"
59  "System call log_level requires 0 or 1 arguments,"
60  " e.g., log_level (10) or log_level ()--which returns the log level\n");
61 
62  throw KarlException ("madara::expression::SystemCallLogLevel: "
63  "KARL COMPILE ERROR: "
64  "System call log_level requires 0 or 1 arguments,"
65  " e.g., log_level (10) or log_level ()--which returns the log level\n");
66  }
67 
68  return result;
69 }
70 
76 {
77  knowledge::KnowledgeRecord return_value;
78 
79  if (nodes_.size () == 1)
80  {
82  "madara::expression::SystemCallLogLevel: "
83  "System call log_level is setting log level\n");
84 
85  int level = (int)nodes_[0]->evaluate (settings).to_integer ();
86 
87  logger_->set_level (level);
88 
90  "madara::expression::SystemCallLogLevel: "
91  "System call log_level has set log level to %d\n",
92  level);
93 
94  return knowledge::KnowledgeRecord (level);
95  }
96  else if (nodes_.size () == 0)
97  {
99  "madara::expression::SystemCallLogLevel: "
100  "System call log_level is returning log level.\n");
101 
103  }
104  else if (nodes_.size () > 1)
105  {
107  "madara::expression::SystemCallLogLevel: "
108  "KARL RUNTIME ERROR:"
109  "System call log_level requires 0 or 1 arguments,"
110  " e.g., log_level (10) or log_level ()--which returns the log level\n");
111 
112  throw KarlException ("madara::expression::SystemCallLogLevel: "
113  "KARL RUNTIME ERROR: "
114  "System call log_level requires 0 or 1 arguments,"
115  " e.g., log_level (10) or log_level ()--which returns the log level\n");
116  }
117 
118  return return_value;
119 }
120 
121 // accept a visitor
122 void
124  madara::expression::Visitor &visitor) const
125 {
126  visitor.visit (*this);
127 }
128 
129 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
SystemCallLogLevel(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 item(void) const
Returns the value of the node.
madara::knowledge::KnowledgeRecord KnowledgeRecord
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
logger::Logger * logger_
handle the context
Definition: ComponentNode.h:97
void set_level(int level)
Sets the maximum logging detail level.
Definition: Logger.inl:44
This class stores variables and their values for use by any entity needing state information in a thr...
virtual ~SystemCallLogLevel(void)
Destructor.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
int get_level(void)
Gets the maximum logging detail level.
Definition: Logger.inl:66
#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.
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
Interface for a MADARA system call.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.