MADARA  3.4.1
KnowledgeBaseImpl.inl
Go to the documentation of this file.
1 #ifndef _MADARA_KNOWLEDGE_BASE_IMPL_INL_
2 #define _MADARA_KNOWLEDGE_BASE_IMPL_INL_
3 
9 
17 namespace madara
18 {
19 namespace knowledge
20 {
22 {
23  // activate_transport ();
24 }
25 
27  const std::string& host, int transport)
28  : settings_()
29 {
30  // override default settings for the arguments
31  settings_.type = transport;
32 
33  id_ = setup_unique_hostport(host);
35 }
36 
38  const std::string& host, int transport, const std::string& knowledge_domain)
39  : settings_()
40 {
41  // override default settings for the arguments
42  settings_.type = transport;
43  settings_.write_domain = knowledge_domain;
44 
45  id_ = setup_unique_hostport(host);
47 }
48 
50  const std::string& host, const madara::transport::TransportSettings& config)
51  : settings_(config)
52 {
53  id_ = setup_unique_hostport(host);
56 }
57 
59 {
61 }
63  const std::string& t_key, const KnowledgeReferenceSettings& settings)
64 {
65  return map_.get(t_key, settings);
66 }
67 
69  const KnowledgeReferenceSettings& settings)
70 {
71  return map_.get(variable, settings);
72 }
73 
75  const std::string& t_key, const KnowledgeReferenceSettings& settings)
76 {
77  return map_.get_ref(t_key, settings);
78 }
79 
81 {
82  return map_.get_log_level();
83 }
84 
86 {
87  return map_.debug_modifieds();
88 }
89 
91 {
92  return map_.get_logger();
93 }
94 
96 {
98 }
99 
100 inline void KnowledgeBaseImpl::set_log_level(int level)
101 {
102  map_.set_log_level(level);
103 }
104 
106  const std::string& t_key, size_t index,
107  const KnowledgeReferenceSettings& settings)
108 {
109  return map_.retrieve_index(t_key, index, settings);
110 }
111 
113  const VariableReference& variable, size_t index,
114  const KnowledgeReferenceSettings& settings)
115 {
116  return map_.retrieve_index(variable, index, settings);
117 }
118 
120  const std::string& key, const KnowledgeReferenceSettings& settings) const
121 {
122  return map_.exists(key, settings);
123 }
124 
125 inline bool KnowledgeBaseImpl::exists(const VariableReference& variable,
126  const KnowledgeReferenceSettings& settings) const
127 {
128  return map_.exists(variable, settings);
129 }
130 
138 {
140 
141  send_modifieds("KnowledgeBaseImpl:apply_modified", settings);
142 
143  return 0;
144 }
145 
147  const VariableReference& variable, const KnowledgeUpdateSettings& settings)
148 {
149  map_.mark_modified(variable, settings);
150 }
151 
153  const std::string& name, const KnowledgeUpdateSettings& settings)
154 {
155  map_.mark_modified(name, settings);
156 }
157 
160  const std::string& filename, const EvalSettings& settings)
161 {
162  if (key == "")
163  return -1;
164 
165  int result = map_.read_file(key, filename, settings);
166 
167  send_modifieds("KnowledgeBaseImpl:read_file", settings);
168 
169  return result;
170 }
171 
174  const unsigned char* value, size_t size, const EvalSettings& settings)
175 {
176  int result = map_.set_file(variable, value, size, settings);
177 
178  send_modifieds("KnowledgeBaseImpl:set_file", settings);
179 
180  return result;
181 }
182 
185  const unsigned char* value, size_t size, const EvalSettings& settings)
186 {
187  int result = map_.set_jpeg(variable, value, size, settings);
188 
189  send_modifieds("KnowledgeBaseImpl:set_jpeg", settings);
190 
191  return result;
192 }
193 
196  const std::string& filename, const EvalSettings& settings)
197 {
198  int result = map_.read_file(variable, filename, settings);
199 
200  send_modifieds("KnowledgeBaseImpl:read_file", settings);
201 
202  return result;
203 }
204 
206 {
207  MADARA_GUARD_TYPE guard(transport_mutex_);
208 
209  if (transports_.size() == 0)
210  {
212  }
213  else
214  {
216  "KnowledgeBaseImpl::activate_transport:"
217  " transport already activated. If you need"
218  " a new type, close transport first\n");
219  }
220 }
221 
222 inline void KnowledgeBaseImpl::copy(const KnowledgeBaseImpl& source,
223  const KnowledgeRequirements& reqs, const EvalSettings& settings)
224 {
225  map_.copy(source.map_, reqs, settings);
226  send_modifieds("KnowledgeBaseImpl::copy:", settings);
227 }
228 
229 inline void KnowledgeBaseImpl::copy(const KnowledgeBaseImpl& source,
230  const CopySet& copy_set, bool clean_copy, const EvalSettings& settings)
231 {
232  map_.copy(source.map_, copy_set, clean_copy, settings);
233  send_modifieds("KnowledgeBaseImpl::copy:", settings);
234 }
235 
236 inline void KnowledgeBaseImpl::lock(void)
237 {
238  map_.lock();
239 }
240 
241 inline void KnowledgeBaseImpl::unlock(void)
242 {
243  map_.unlock();
244 }
245 
247  const std::string& statement) const
248 {
249  return map_.expand_statement(statement);
250 }
251 
254  const std::string& knowledge_key, const std::string& filename)
255 {
256  return map_.get_record(knowledge_key)->to_file(filename);
257 }
258 
261  uint32_t quality, const KnowledgeReferenceSettings& settings)
262 {
263  map_.set_write_quality(t_key, quality, settings);
264 }
265 
268 {
269  return settings_;
270 }
271 
272 inline void KnowledgeBaseImpl::print(unsigned int level) const
273 {
274  map_.print("\nKnowledge in Knowledge Base:\n", logger::LOG_ALWAYS);
275 
276  map_.print(level);
277 }
278 
280  const std::string& array_delimiter, const std::string& record_delimiter,
281  const std::string& key_val_delimiter) const
282 {
283  map_.to_string(target, array_delimiter, record_delimiter, key_val_delimiter);
284 }
285 
287  const std::string& statement, unsigned int level) const
288 {
289  map_.print(statement, level);
290 }
291 
293  const std::string& key, const KnowledgeReferenceSettings& settings)
294 {
295  return map_.clear(key, settings);
296 }
297 
298 inline void KnowledgeBaseImpl::clear(bool erase)
299 {
300  map_.clear(erase);
301 }
302 
304 {
305  map_.clear();
306 }
307 
310 inline void KnowledgeBaseImpl::acquire(void)
311 {
312  map_.lock();
313 }
314 
316 inline void KnowledgeBaseImpl::release(void)
317 {
318  map_.unlock();
319 }
320 
321 #ifndef _MADARA_NO_KARL_
322 
323 // Defines a function
326 {
327  map_.define_function(name, func);
328 }
329 
330 // Defines a function
332  KnowledgeRecord (*func)(const char*, FunctionArguments&, Variables&))
333 {
334  map_.define_function(name, func);
335 }
336 
337 #ifdef _MADARA_JAVA_
339  const std::string& name, jobject callable)
340 {
341  map_.define_function(name, callable);
342 }
343 #endif
344 
345 #ifdef _MADARA_PYTHON_CALLBACKS_
346 
348  const std::string& name, boost::python::object callable)
349 {
350  map_.define_function(name, callable);
351 }
352 
353 #endif
354 
359  const std::string& name, const std::string& expression)
360 {
361  map_.define_function(name, expression);
362 }
363 
365  const std::string& name, const CompiledExpression& expression)
366 {
367  map_.define_function(name, expression);
368 }
369 
371 {
372  CompiledExpression compiled = compile(expression);
373  WaitSettings settings;
374  return wait(compiled, settings);
375 }
376 
378  const std::string& expression)
379 {
380  CompiledExpression compiled = compile(expression);
381  EvalSettings settings;
382  return evaluate(compiled, settings);
383 }
384 
385 #endif // _MADARA_NO_KARL_
386 
388 {
389  MADARA_GUARD_TYPE guard(transport_mutex_);
390 
391  transports_.emplace_back(transport);
392  return transports_.size();
393 }
394 
396 {
397  MADARA_GUARD_TYPE guard(transport_mutex_);
398 
399  return transports_.size();
400 }
401 
402 inline size_t KnowledgeBaseImpl::remove_transport(size_t index)
403 {
404  std::shared_ptr<transport::Base> transport;
405  size_t size = 0;
406  {
407  MADARA_GUARD_TYPE guard(transport_mutex_);
408 
409  size = transports_.size();
410  if (index < size)
411  {
412  using std::swap;
413  swap(transport, transports_[index]);
414  transports_.erase(transports_.begin() + index);
415  size = transports_.size();
416  }
417  }
418 
419  if (transport)
420  {
421  transport->close();
422  }
423 
424  return size;
425 }
426 
434 {
435  return map_;
436 }
437 
443 {
444  if (id_ == "")
445  {
447  }
448 
449  return id_;
450 }
451 
466 inline size_t KnowledgeBaseImpl::to_vector(const std::string& subject,
467  unsigned int start, unsigned int end, std::vector<KnowledgeRecord>& target)
468 {
469  return map_.to_vector(subject, start, end, target);
470 }
471 
472 inline void KnowledgeBaseImpl::get_matches(const std::string& prefix,
473  const std::string& suffix, VariableReferences& matches)
474 {
475  map_.get_matches(prefix, suffix, matches);
476 }
477 
478 inline size_t KnowledgeBaseImpl::to_map(const std::string& expression,
479  std::map<std::string, KnowledgeRecord>& target)
480 {
481  return map_.to_map(expression, target);
482 }
483 
484 inline size_t KnowledgeBaseImpl::to_map(const std::string& prefix,
485  const std::string& delimiter, const std::string& suffix,
486  std::vector<std::string>& next_keys,
487  std::map<std::string, KnowledgeRecord>& result, bool just_keys)
488 {
489  return map_.to_map(prefix, delimiter, suffix, next_keys, result, just_keys);
490 }
491 
493 {
494  return map_.to_map(prefix);
495 }
496 
498  const std::string& prefix) const
499 {
500  return map_.to_map_stripped(prefix);
501 }
502 
504  const std::string& filename) const
505 {
506  return map_.save_context(filename, id_);
507 }
508 
510  CheckpointSettings& settings) const
511 {
512  settings.originator = id_;
513  return map_.save_context(settings);
514 }
515 
517  const std::string& filename) const
518 {
519  return map_.save_as_json(filename);
520 }
521 
523  const CheckpointSettings& settings) const
524 {
525  return map_.save_as_json(settings);
526 }
527 
529  const std::string& filename) const
530 {
531  return map_.save_as_karl(filename);
532 }
533 
535  const CheckpointSettings& settings) const
536 {
537  return map_.save_as_karl(settings);
538 }
539 
541 {
543 }
544 
546 {
547  map_.reset_checkpoint();
548 }
549 
551  const std::string& filename, bool reset_modifieds)
552 {
553  int64_t total_written = map_.save_checkpoint(filename, id_);
554 
555  if (reset_modifieds)
557 
558  return total_written;
559 }
560 
562  CheckpointSettings& settings) const
563 {
564  settings.originator = id_;
565  return map_.save_checkpoint(settings);
566 }
567 
568 inline int64_t KnowledgeBaseImpl::load_context(const std::string& filename,
569  bool use_id, const KnowledgeUpdateSettings& settings)
570 {
571  int64_t result = 0;
572 
573  if (use_id)
574  result = map_.load_context(filename, id_, settings);
575  else
576  {
577  std::string id;
578  result = map_.load_context(filename, id, settings);
579  }
580 
581  return result;
582 }
583 
584 inline int64_t KnowledgeBaseImpl::load_context(const std::string& filename,
585  FileHeader& meta, bool use_id, const KnowledgeUpdateSettings& settings)
586 {
587  int64_t result = 0;
588 
589  if (use_id)
590  {
591  result = map_.load_context(filename, meta, settings);
592  id_ = meta.originator;
593  }
594  else
595  {
596  result = map_.load_context(filename, meta, settings);
597  }
598 
599  return result;
600 }
601 
603  CheckpointSettings& checkpoint_settings,
604  const KnowledgeUpdateSettings& update_settings)
605 {
606  int64_t result = 0;
607 
608  if (checkpoint_settings.originator == "")
609  {
610  result = map_.load_context(checkpoint_settings, update_settings);
611 
612  if (checkpoint_settings.originator != "")
613  id_ = checkpoint_settings.originator;
614  }
615  else
616  {
617  result = map_.load_context(checkpoint_settings, update_settings);
618  }
619 
620  return result;
621 }
622 
624  CheckpointSettings& checkpoint_settings,
625  const KnowledgeUpdateSettings& update_settings)
626 {
627  KnowledgeRecord result;
628 
629  if (checkpoint_settings.originator == "")
630  {
631  result = map_.evaluate_file(checkpoint_settings, update_settings);
632 
633  if (checkpoint_settings.originator != "")
634  id_ = checkpoint_settings.originator;
635  }
636  else
637  {
638  result = map_.evaluate_file(checkpoint_settings, update_settings);
639  }
640 
641  return result;
642 }
643 
645  CheckpointSettings& checkpoint_settings)
646 {
647  return map_.file_to_string(checkpoint_settings);
648 }
649 
651  const VariableReferences& modifieds) const
652 {
653  map_.add_modifieds(modifieds);
654 }
655 
657 {
658  return map_.save_modifieds();
659 }
660 
662 {
664 }
665 
666 #ifndef _MADARA_NO_KARL_
667 
669  const std::string& expression, const EvalSettings& settings)
670 {
671  CompiledExpression compiled = compile(expression);
672  return evaluate(compiled, settings);
673 }
674 
675 #endif // _MADARA_NO_KARL_
676 }
677 }
678 
679 #endif // _MADARA_KNOWLEDGE_BASE_IMPL_INL_
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
Definition: Logger.h:20
VariableReferenceMap map_
Holds settings for checkpoints to load or save.
std::string originator
the originator id of the checkpoint
Compiled, optimized KaRL logic.
Defines a file header which is the default for KaRL checkpointing.
Definition: FileHeader.h:37
char originator[64]
the originator of the message (host:port)
Definition: FileHeader.h:127
This class provides a distributed knowledge base implementation.
madara::knowledge::KnowledgeRecord retrieve_index(const std::string &key, size_t index, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a value at a specified index within a knowledge array.
std::string expand_statement(const std::string &statement) const
Expands a statement using variable expansion.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
madara::transport::TransportSettings & transport_settings(void)
Returns a non-const reference to the Transport Settings.
void clear_map(void)
Clears the knowledge base.
void set_log_level(int level)
Sets the log level.
int get_log_level(void)
Gets the log level.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
std::string debug_modifieds(void) const
Retrieves a stringified list of all modified variables that are ready to send over transport on next ...
void release(void)
Releases a recursive lock on the knowledge base.
int64_t save_as_json(const std::string &filename) const
Saves the context to a file as JSON.
std::string get_id(void)
Returns the unique host and ephemeral binding for this Knowlede Base.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge value.
ssize_t write_file(const std::string &knowledge_key, const std::string &filename)
Write a file from the knowledge base to a specified location.
void print(unsigned int level) const
Prints all knowledge variables and values in the context.
int read_file(const std::string &knowledge_key, const std::string &filename, const EvalSettings &settings=EvalSettings())
Read a file into the knowledge base.
size_t to_vector(const std::string &subject, unsigned int start, unsigned int end, std::vector< KnowledgeRecord > &target)
Fills a vector with Knowledge Records that begin with a common subject and have a finite range of int...
void set_quality(const std::string &key, uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Sets the quality of writing to a certain variable from this entity.
std::string setup_unique_hostport(std::string host="")
Creates a random UUID for unique tie breakers in global ordering.
KnowledgeRecord evaluate_file(CheckpointSettings &checkpoint_settings, const KnowledgeUpdateSettings &update_settings=KnowledgeUpdateSettings(true, true, true, false))
Loads and evaluates a karl script from a file.
size_t attach_transport(madara::transport::Base *transport)
Attaches a transport to the Knowledge Engine.
void activate_transport(void)
Starts the transport mechanism for dissemination if it is closed.
VariableReferences save_modifieds(void) const
Saves the list of modified records to use later for resending.
int apply_modified(const EvalSettings &settings=EvalSettings())
Applies current time and modified to all global variables and tries to send them.
void acquire(void)
Acquires the recursive lock on the knowledge base.
void close_transport(void)
Closes the transport mechanism so no dissemination is possible.
int64_t save_context(const std::string &filename) const
Saves the context to a file.
void add_modifieds(const VariableReferences &modifieds) const
Adds a list of VariableReferences to the current modified list.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated.
size_t to_map(const std::string &subject, std::map< std::string, knowledge::KnowledgeRecord > &target)
Fills a variable map with Knowledge Records that match an expression.
void clear_modifieds(void)
Clear all modifications to the knowledge base.
bool clear(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Clears a variable.
size_t remove_transport(size_t index)
Removes a transport.
std::string file_to_string(CheckpointSettings &checkpoint_settings)
Loads and returns a karl script from a file with encode/decode.
void attach_logger(logger::Logger &logger) const
Attaches a logger to be used for printing.
transport::QoSTransportSettings settings_
size_t get_num_transports(void)
Gets the number of transports.
madara::knowledge::KnowledgeRecord evaluate(const std::string &expression)
Evaluates an expression.
void copy(const KnowledgeBaseImpl &source, const KnowledgeRequirements &reqs, const EvalSettings &settings=EvalSettings())
Copies variables and values from source to this context.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
void unlock(void)
Unlocks the context to allow updates over the network (is only necessary if the context has been expl...
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
void define_function(const std::string &name, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &))
Defines a function.
void get_matches(const std::string &prefix, const std::string &suffix, VariableReferences &matches)
Creates an iteration of VariableReferences to all keys matching the prefix and suffix.
void lock(void)
Locks the context to prevent updates over the network.
MADARA_EXPORT int send_modifieds(const std::string &prefix, const EvalSettings &settings=EvalSettings::SEND)
Sends all modified variables through the attached transports.
int set_jpeg(const VariableReference &variable, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings())
Atomically sets the value of a variable to a JPEG image.
int64_t load_context(const std::string &filename, bool use_id, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true, true, true, false))
Loads the context from a file.
knowledge::KnowledgeMap to_map_stripped(const std::string &prefix) const
Creates a map with Knowledge Records that begin with the given prefix.
madara::knowledge::KnowledgeRecord wait(const std::string &expression)
Waits for an expression to be non-zero.
void reset_checkpoint(void) const
Resets the local changed map, which tracks checkpointing modifieds.
int set_file(const VariableReference &variable, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings())
Atomically sets the value of a variable to the contents of a file.
int64_t save_as_karl(const std::string &filename) const
Saves the context to a file as karl assignments, rather than binary.
void wait_for_change(void)
Wait for a change to happen to the context (e.g., from transports)
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Checks if a knowledge location exists in the context.
std::vector< std::shared_ptr< transport::Base > > transports_
int64_t save_checkpoint(const std::string &filename, bool reset_modifieds=true)
Saves a checkpoint of a list of changes to a file.
void to_string(std::string &target, const std::string &array_delimiter=",", const std::string &record_delimiter=";\n", const std::string &key_val_delimiter="=") const
Saves all keys and values into a string, using the underlying knowledge::KnowledgeRecord::to_string f...
This class encapsulates an entry in a KnowledgeBase.
ssize_t to_file(const std::string &filename) const
writes the value to a file
Settings for applying knowledge updates.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
void unlock(void) const
Unlocks the mutex on this context.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
void attach_logger(logger::Logger &logger) const
Attaches a logger to be used for printing.
int64_t save_as_json(const std::string &filename) const
Saves the context to a file as JSON.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
std::string file_to_string(CheckpointSettings &checkpoint_settings)
Loads and returns a karl script from a file with encode/decode.
bool clear(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Clears a variable.
void to_string(std::string &target, const std::string &array_delimiter=",", const std::string &record_delimiter=";\n", const std::string &key_val_delimiter="=") const
Saves all keys and values into a string, using the underlying knowledge::KnowledgeRecord::to_string f...
int read_file(const std::string &key, const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically reads a file into a variable.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the current value of a variable.
KnowledgeRecord evaluate_file(CheckpointSettings &checkpoint_settings, const KnowledgeUpdateSettings &update_settings=KnowledgeUpdateSettings(true, true, true, false))
Loads and evaluates a karl script from a file.
void apply_modified(void)
Changes all global variables to modified at current clock.
void add_modifieds(const VariableReferences &modifieds) const
Adds a list of VariableReferences to the current modified list.
void define_function(const std::string &name, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &), const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Defines an external function.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for g...
std::string debug_modifieds(void) const
Retrieves a stringified list of all modified variables that are ready to send over transport on next ...
void get_matches(const std::string &prefix, const std::string &suffix, VariableReferences &matches)
Creates an iteration of VariableReferences to all keys matching the prefix and suffix.
knowledge::KnowledgeMap to_map_stripped(const std::string &prefix) const
Creates a map with Knowledge Records that begin with the given prefix.
int set_jpeg(const std::string &key, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to a JPEG image.
int64_t save_checkpoint(const std::string &filename, const std::string &id="") const
Saves a checkpoint of a list of changes to a file.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
int set_file(const std::string &key, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to an arbitrary string.
int64_t save_context(const std::string &filename, const std::string &id="") const
Saves the context to a file.
VariableReferences save_modifieds(void) const
Saves the list of modified records to use later for resending.
KnowledgeRecord * get_record(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge record from the key.
KnowledgeRecord retrieve_index(const std::string &key, size_t index, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a value at a specified index within a knowledge array.
size_t to_map(const std::string &subject, std::map< std::string, knowledge::KnowledgeRecord > &target)
Fills a variable map with Knowledge Records that match an expression.
std::string expand_statement(const std::string &statement) const
Expands a string with variable expansion.
int64_t load_context(const std::string &filename, std::string &id, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true, true, true, false))
Loads the context from a file.
int get_log_level(void)
Gets the log level.
void lock(void) const
Locks the mutex on this context.
size_t to_vector(const std::string &subject, unsigned int start, unsigned int end, std::vector< KnowledgeRecord > &target)
Fills a vector with Knowledge Records that begin with a common subject and have a finite range of int...
void set_log_level(int level)
Sets the log level.
void reset_checkpoint(void) const
Reset all checkpoint variables in the modified lists.
void copy(const ThreadSafeContext &source, const KnowledgeRequirements &reqs, const KnowledgeUpdateSettings &settings)
Copies variables and values from source to this context.
void print(unsigned int level) const
Atomically prints all variables and values in the context.
void reset_modified(void)
Reset all variables to be unmodified.
void wait_for_change(bool extra_release=false)
Wait for a change to happen to the context.
void set_write_quality(const std::string &key, uint32_t quality, const KnowledgeReferenceSettings &settings)
Atomically sets write quality of this process for a variable.
int64_t save_as_karl(const std::string &filename) const
Saves the context to a file as karl assignments, rather than binary.
Optimized reference to a variable within the knowledge base.
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
A multi-threaded logger for logging to one or more destinations.
Definition: Logger.h:165
Base class from which all transports must be derived.
Definition: Transport.h:46
Holds basic transport settings.
bool delay_launch
Delay launching transports until explicit activate call.
uint32_t type
Type of transport. See madara::transport::Types for options.
std::string write_domain
All class members are accessible to users for easy setup.
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
std::map< std::string, bool > CopySet
Typedef for set of copyable keys.
std::vector< KnowledgeRecord > FunctionArguments
::std::map< std::string, KnowledgeRecord > KnowledgeMap
std::vector< VariableReference > VariableReferences
a vector of variable references
Provides knowledge logging services to files and terminals.
Definition: GlobalLogger.h:12
Copyright(c) 2020 Galois.
Encapsulates settings for an evaluation statement.
Definition: EvalSettings.h:26
Holds settings requirements for knowledge, usually in copying.
Encapsulates settings for a wait statement.
Definition: WaitSettings.h:25