MADARA  3.1.8
SystemCallToBuffer.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
9 
10 
13  const ComponentNodes & nodes)
14  : SystemCallNode (context, nodes)
15 {
16 
17 }
18 
19 // Dtor
21 {
22 }
23 
26 {
28 }
29 
35 {
36  // user can always change a function, and we have no control over
37  // what it does. Consequently, a function node cannot be pruned out
38  // under any situation
39  can_change = true;
40 
42 
43  if (nodes_.size () > 0)
44  {
45  bool arg_can_change = false;
46  result = nodes_[0]->prune (arg_can_change);
47 
48  if (!arg_can_change && dynamic_cast <LeafNode *> (nodes_[0]) == 0)
49  {
50  delete nodes_[0];
51  nodes_[0] = new LeafNode (*(this->logger_), result);
52  }
53  }
54 
55  return result;
56 }
57 
63 {
64  knowledge::KnowledgeRecord return_value;
65 
66  if (nodes_.size () > 0)
67  {
69  "System call to_buffer is converting an argument to an "
70  "unmanaged buffer\n");
71 
72  size_t size;
73  unsigned char * buffer =
74  nodes_[0]->evaluate (settings).to_unmanaged_buffer (size);
75 
76  return_value.set_file (buffer, size);
77  }
78  else
79  {
81  "System call to_buffer is converting 0 to a buffer\n");
82 
83  size_t size;
84  unsigned char * buffer =
85  return_value.to_unmanaged_buffer (size);
86 
87  return_value.set_file (buffer, size);
88  }
89 
90  return return_value;
91 }
92 
93 // accept a visitor
94 void
96  madara::expression::Visitor &visitor) const
97 {
98  visitor.visit (*this);
99 }
100 
101 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
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
void set_file(const unsigned char *new_value, size_t size)
sets the value to an unknown file type
SystemCallToBuffer(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
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...
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
#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:90
Interface for a MADARA system call.
virtual ~SystemCallToBuffer(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
unsigned char * to_unmanaged_buffer(size_t &size) const
returns an unmanaged buffer that the user will have to take care of (this is a copy of the internal v...