MADARA  3.2.3
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 
10 
18 namespace madara { namespace knowledge {
19 
21  : settings_ ()
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,
39  const std::string & knowledge_domain)
40  : settings_ ()
41 {
42  // override default settings for the arguments
43  settings_.type = transport;
44  settings_.write_domain = knowledge_domain;
45 
46  id_ = setup_unique_hostport (host);
48 }
49 
51  const std::string & host, const madara::transport::TransportSettings & config)
52  : settings_ (config)
53 {
54  id_ = setup_unique_hostport (host);
57 }
58 
60 {
61  close_transport ();
62 }
63 inline KnowledgeRecord
65  const std::string & t_key,
66  const KnowledgeReferenceSettings & settings)
67 {
68  return map_.get (t_key, settings);
69 }
70 
71 inline KnowledgeRecord
73  const VariableReference & variable,
74  const KnowledgeReferenceSettings & settings)
75 {
76  return map_.get (variable, settings);
77 }
78 
79 inline VariableReference
81  const std::string & t_key,
82  const KnowledgeReferenceSettings & settings)
83 {
84  return map_.get_ref (t_key, settings);
85 }
86 
87 inline int
89 {
90  return map_.get_log_level ();
91 }
92 
93 inline std::string
95 {
96  return map_.debug_modifieds ();
97 }
98 
101 {
102  return map_.get_logger ();
103 }
104 
105 inline void
107  logger::Logger & logger) const
108 {
109  map_.attach_logger (logger);
110 }
111 
112 inline void
114 {
115  map_.set_log_level (level);
116 }
117 
118 inline KnowledgeRecord
120  const std::string & t_key,
121  size_t index,
122  const KnowledgeReferenceSettings & settings)
123 {
124  return map_.retrieve_index (t_key, index, settings);
125 }
126 
127 inline KnowledgeRecord
129  const VariableReference & variable,
130  size_t index,
131  const KnowledgeReferenceSettings & settings)
132 {
133  return map_.retrieve_index (variable, index, settings);
134 }
135 
136 inline bool
138  const std::string & key,
139  const KnowledgeReferenceSettings & settings) const
140 {
141  return map_.exists (key, settings);
142 }
143 
144 inline bool
146  const VariableReference & variable,
147  const KnowledgeReferenceSettings & settings) const
148 {
149  return map_.exists (variable, settings);
150 }
151 
158 inline int
160 const EvalSettings & settings)
161 {
162  // lock the context and apply modified flags and current clock to
163  // all global variables
164  MADARA_GUARD_TYPE guard (map_.mutex_);
165 
166  map_.apply_modified ();
167 
168  int ret = 0;
169 
170  send_modifieds ("KnowledgeBaseImpl:apply_modified", settings);
171 
172  return ret;
173 }
174 
175 inline void
177  const VariableReference & variable,
178  const KnowledgeUpdateSettings & settings)
179 {
180  map_.mark_modified (variable, settings);
181 }
182 
183 inline void
185  const std::string & name,
186  const KnowledgeUpdateSettings & settings)
187 {
188  map_.mark_modified (name, settings);
189 }
190 
192 inline int
194 const std::string & key, const std::string & filename,
195 const EvalSettings & settings)
196 {
197  if (key == "")
198  return -1;
199 
200  int result = map_.read_file (key, filename, settings);
201 
202  send_modifieds ("KnowledgeBaseImpl:read_file", settings);
203 
204  return result;
205 }
206 
208 inline int
210 const VariableReference & variable,
211 const unsigned char * value, size_t size,
212 const EvalSettings & settings)
213 {
214  int result = map_.set_file (variable, value, size, settings);
215 
216  send_modifieds ("KnowledgeBaseImpl:set_file", settings);
217 
218  return result;
219 }
220 
222 inline int
224 const VariableReference & variable,
225 const unsigned char * value, size_t size,
226 const EvalSettings & settings)
227 {
228  int result = map_.set_jpeg (variable, value, size, settings);
229 
230  send_modifieds ("KnowledgeBaseImpl:set_jpeg", settings);
231 
232  return result;
233 }
234 
236 inline int
238 const VariableReference & variable,
239 const std::string & filename,
240 const EvalSettings & settings)
241 {
242  int result = map_.read_file (variable, filename, settings);
243 
244  send_modifieds ("KnowledgeBaseImpl:read_file", settings);
245 
246  return result;
247 }
248 
249 inline void
251 {
252  MADARA_GUARD_TYPE guard (map_.mutex_);
253 
254  if (transports_.size () == 0)
255  {
257  }
258  else
259  {
261  "KnowledgeBaseImpl::activate_transport:" \
262  " transport already activated. If you need" \
263  " a new type, close transport first\n");
264  }
265 }
266 
267 inline void
269 const KnowledgeBaseImpl & source,
270 const KnowledgeRequirements & reqs)
271 {
272  map_.copy (source.map_, reqs);
273 }
274 
275 inline void
277 const KnowledgeBaseImpl & source,
278 const CopySet & copy_set,
279 bool clean_copy)
280 {
281  map_.copy (source.map_, copy_set, clean_copy);
282 }
283 
284 inline void
286 {
287  map_.lock ();
288 }
289 
290 inline void
292 {
293  map_.unlock ();
294 }
295 
296 
297 inline std::string
299  const std::string & statement) const
300 {
301  return map_.expand_statement (statement);
302 }
303 
305 inline ssize_t
307  const std::string & knowledge_key, const std::string & filename)
308 {
309  return map_.get_record (knowledge_key)->to_file (filename);
310 }
311 
313 inline void
315  const std::string & t_key, uint32_t quality,
316  const KnowledgeReferenceSettings & settings)
317 {
318  map_.set_write_quality (t_key, quality, settings);
319 }
320 
323 {
324  return settings_;
325 }
326 
327 inline void
329  unsigned int level) const
330 {
331  map_.print (
332  "\nKnowledge in Knowledge Base:\n", logger::LOG_ALWAYS);
333 
334  map_.print (level);
335 }
336 
337 inline void
339  std::string & target,
340  const std::string & array_delimiter,
341  const std::string & record_delimiter,
342  const std::string & key_val_delimiter) const
343 {
344  map_.to_string (target,
345  array_delimiter, record_delimiter, key_val_delimiter);
346 }
347 
348 inline void
350  const std::string & statement, unsigned int level) const
351 {
352  map_.print (statement, level);
353 }
354 
355 inline bool
357  const KnowledgeReferenceSettings & settings)
358 {
359  return map_.clear (key, settings);
360 }
361 
362 inline void
364 {
365  map_.clear (erase);
366 }
367 
368 inline void
370 {
371  map_.clear ();
372 }
373 
376 inline void KnowledgeBaseImpl::acquire (void)
377 {
378  map_.lock ();
379 }
380 
382 inline void KnowledgeBaseImpl::release (void)
383 {
384  map_.unlock ();
385 }
386 
387 #ifndef _MADARA_NO_KARL_
388 
389 // Defines a function
390 inline void
392  const std::string & name, KnowledgeRecord (*func) (FunctionArguments &, Variables &))
393 {
394  map_.define_function (name, func);
395 }
396 
397 // Defines a function
398 inline void
400  const std::string & name,
401  KnowledgeRecord (*func) (const char *, FunctionArguments &, Variables &))
402 {
403  map_.define_function (name, func);
404 }
405 
406 #ifdef _MADARA_JAVA_
407 inline void
409  const std::string & name, jobject callable)
410 {
411  map_.define_function (name, callable);
412 }
413 #endif
414 
415 #ifdef _MADARA_PYTHON_CALLBACKS_
416 
417 inline void
419  const std::string & name, boost::python::object callable)
420 {
421  map_.define_function (name, callable);
422 }
423 
424 #endif
425 
429 inline void
431  const std::string & expression)
432 {
433  map_.define_function (name, expression);
434 }
435 
436 
437 inline void
439  const std::string & name,
440  const CompiledExpression & expression)
441 {
442  map_.define_function (name, expression);
443 }
444 
445 inline KnowledgeRecord
447  const std::string & expression)
448 {
449  CompiledExpression compiled = compile (expression);
450  WaitSettings settings;
451  return wait (compiled, settings);
452 }
453 
454 inline KnowledgeRecord
456  const std::string & expression)
457 {
458  CompiledExpression compiled = compile (expression);
459  EvalSettings settings;
460  return evaluate (compiled, settings);
461 }
462 
463 #endif // _MADARA_NO_KARL_
464 
465 inline size_t
467  transport::Base * transport)
468 {
469  MADARA_GUARD_TYPE guard (map_.mutex_);
470 
471  transports_.emplace_back (transport);
472  return transports_.size ();
473 }
474 
475 inline size_t
477 {
478  MADARA_GUARD_TYPE guard (map_.mutex_);
479 
480  return transports_.size ();
481 }
482 
483 inline size_t
485 {
486  std::unique_ptr<transport::Base> transport;
487  size_t size = 0;
488  {
489  MADARA_GUARD_TYPE guard (map_.mutex_);
490  size = transports_.size ();
491  if (index < size) {
492  using std::swap;
493  swap (transport, transports_[index]);
494  transports_.erase (transports_.begin() + index);
495  size = transports_.size ();
496  }
497  }
498 
499  if (transport) {
500  transport->close ();
501  }
502 
503  return size;
504 }
505 
512 inline ThreadSafeContext &
514 {
515  return map_;
516 }
517 
518 
523 inline std::string
525 {
526  if (id_ == "")
527  {
529  }
530 
531  return id_;
532 }
533 
548 inline size_t
550  const std::string & subject,
551  unsigned int start,
552  unsigned int end,
553  std::vector <KnowledgeRecord> & target)
554 {
555  return map_.to_vector (subject, start, end, target);
556 }
557 
558 inline void
560  const std::string & prefix,
561  const std::string & suffix,
562  VariableReferences & matches)
563 {
564  map_.get_matches (prefix, suffix, matches);
565 }
566 
567 inline size_t
569  const std::string & expression,
570  std::map <std::string, KnowledgeRecord> & target)
571 {
572  return map_.to_map (expression, target);
573 }
574 
575 inline size_t
577  const std::string & prefix,
578  const std::string & delimiter,
579  const std::string & suffix,
580  std::vector <std::string> & next_keys,
581  std::map <std::string, KnowledgeRecord> & result,
582  bool just_keys)
583 {
584  return map_.to_map (
585  prefix, delimiter, suffix, next_keys, result, just_keys);
586 }
587 
588 inline KnowledgeMap
590  const std::string & prefix) const
591 {
592  return map_.to_map (prefix);
593 }
594 
595 inline KnowledgeMap
597  const std::string & prefix) const
598 {
599  return map_.to_map_stripped (prefix);
600 }
601 
602 
603 inline int64_t
605  const std::string & filename) const
606 {
607  return map_.save_context (filename, id_);
608 }
609 
610 inline int64_t
612  CheckpointSettings & settings) const
613 {
614  settings.originator = id_;
615  return map_.save_context (settings);
616 }
617 
618 inline int64_t
620 const std::string & filename) const
621 {
622  return map_.save_as_json (filename);
623 }
624 
625 inline int64_t
627 const CheckpointSettings & settings) const
628 {
629  return map_.save_as_json (settings);
630 }
631 
632 inline int64_t
634 const std::string & filename) const
635 {
636  return map_.save_as_karl (filename);
637 }
638 
639 inline int64_t
641 const CheckpointSettings & settings) const
642 {
643  return map_.save_as_karl (settings);
644 }
645 
646 inline void
648  void)
649 {
650  map_.reset_modified ();
651 }
652 
653 inline void
655  void) const
656 {
658 }
659 
660 inline int64_t
662  const std::string & filename,
663  bool reset_modifieds)
664 {
665  int64_t total_written = map_.save_checkpoint (filename, id_);
666 
667  if (reset_modifieds)
669 
670  return total_written;
671 }
672 
673 inline int64_t
675  CheckpointSettings & settings) const
676 {
677  settings.originator = id_;
678  return map_.save_checkpoint (settings);
679 }
680 
681 inline int64_t
683  const std::string & filename,
684  bool use_id,
685  const KnowledgeUpdateSettings & settings)
686 {
687  int64_t result = 0;
688 
689  if (use_id)
690  result = map_.load_context (filename, id_, settings);
691  else
692  {
693  std::string id;
694  result = map_.load_context (filename, id, settings);
695  }
696 
697  return result;
698 }
699 
700 inline int64_t
702 const std::string & filename,
703 FileHeader & meta,
704 bool use_id,
705 const KnowledgeUpdateSettings & settings)
706 {
707  int64_t result = 0;
708 
709  if (use_id)
710  {
711  result = map_.load_context (filename, meta, settings);
712  id_ = meta.originator;
713  }
714  else
715  {
716  result = map_.load_context (filename, meta, settings);
717  }
718 
719  return result;
720 }
721 
722 inline int64_t
724 CheckpointSettings & checkpoint_settings,
725 const KnowledgeUpdateSettings & update_settings)
726 {
727  int64_t result = 0;
728 
729  if (checkpoint_settings.originator == "")
730  {
731  result = map_.load_context (checkpoint_settings, update_settings);
732 
733  if (checkpoint_settings.originator != "")
734  id_ = checkpoint_settings.originator;
735  }
736  else
737  {
738  result = map_.load_context (checkpoint_settings, update_settings);
739  }
740 
741  return result;
742 }
743 
744 inline void
746  const VariableReferences & modifieds) const
747 {
748  map_.add_modifieds (modifieds);
749 }
750 
751 inline VariableReferences
753 {
754  return map_.save_modifieds ();
755 }
756 
757 #ifndef _MADARA_NO_KARL_
758 
759 inline void
761 {
763 }
764 
765 inline KnowledgeRecord
767 const std::string & expression,
768 const EvalSettings & settings)
769 {
770  CompiledExpression compiled = compile (expression);
771  return evaluate (compiled, settings);
772 }
773 
774 #endif // _MADARA_NO_KARL_
775 
776 } }
777 
778 
779 #endif // _MADARA_KNOWLEDGE_BASE_IMPL_INL_
This class encapsulates an entry in a KnowledgeBase.
int64_t save_context(const std::string &filename) const
Saves the context 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...
std::map< std::string, bool > CopySet
Typedef for set of copyable keys.
size_t remove_transport(size_t index)
Removes a transport.
This class provides a distributed knowledge base implementation.
int read_file(const std::string &knowledge_key, const std::string &filename, const EvalSettings &settings=EvalSettings())
Read a file into the knowledge base.
Defines a file header which is the default for KaRL checkpointing.
Definition: FileHeader.h:36
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 print(unsigned int level) const
Prints all knowledge variables and values in the context.
ssize_t write_file(const std::string &knowledge_key, const std::string &filename)
Write a file from the knowledge base to a specified location.
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...
int64_t save_context(const std::string &filename, const std::string &id="") const
Saves the context to a file.
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.
int apply_modified(const EvalSettings &settings=EvalSettings())
Applies current time and modified to all global variables and tries to send them. ...
size_t get_num_transports(void)
Gets the number of transports.
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.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge value.
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.
std::string expand_statement(const std::string &statement) const
Expands a statement using variable expansion.
void copy(const ThreadSafeContext &source, const KnowledgeRequirements &settings)
Copies variables and values from source to this context.
char originator[64]
the originator of the message (host:port)
Definition: FileHeader.h:129
void lock(void) const
Locks the mutex on this context.
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.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
void set_log_level(int level)
Sets the log level.
ssize_t to_file(const std::string &filename) const
writes the value to a file
std::string get_id(void)
Returns the unique host and ephemeral binding for this Knowlede Base.
This class stores variables and their values for use by any entity needing state information in a thr...
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.
void lock(void)
Locks the context to prevent updates over the network.
void print(unsigned int level) const
Atomically prints all variables and values in the context.
void wait_for_change(void)
Wait for a change to happen to the context (e.g., from transports)
VariableReferences save_modifieds(void) const
Saves the list of modified records to use later for resending.
Holds settings for checkpoints to load or save.
void attach_logger(logger::Logger &logger) const
Attaches a logger to be used for printing.
void copy(const KnowledgeBaseImpl &source, const KnowledgeRequirements &reqs)
Copies variables and values from source to this context.
int64_t save_as_karl(const std::string &filename) const
Saves the context to a file as karl assignments, rather than binary.
void close_transport(void)
Closes the transport mechanism so no dissemination is possible.
Provides knowledge logging services to files and terminals.
Definition: GlobalLogger.h:11
VariableReferences save_modifieds(void) const
Saves the list of modified records to use later for resending.
Holds basic transport settings.
int get_log_level(void)
Gets the log level.
Optimized reference to a variable within the knowledge base.
Compiled, optimized KaRL logic.
std::vector< KnowledgeRecord > FunctionArguments
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...
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
Definition: Logger.h:20
void define_function(const std::string &name, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &))
Defines a function.
void define_function(const std::string &name, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &), const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Defines an external function.
size_t attach_transport(madara::transport::Base *transport)
Attaches a transport to the Knowledge Engine.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
uint32_t type
Type of transport. See madara::transport::Types for options.
std::string debug_modifieds(void) const
Retrieves a stringified list of all modified variables that are ready to send over transport on next ...
A multi-threaded logger for logging to one or more destinations.
Definition: Logger.h:88
std::string originator
the originator id of the checkpoint
void apply_modified(void)
Changes all global variables to modified at current clock.
madara::knowledge::KnowledgeRecord wait(const std::string &expression)
Waits for an expression to be non-zero.
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_checkpoint(const std::string &filename, const std::string &id="") const
Saves a checkpoint of a list of changes to a file.
void clear_map(void)
Clears the knowledge base.
static struct madara::knowledge::tags::string_t string
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 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...
std::vector< std::unique_ptr< transport::Base > > transports_
int64_t save_as_json(const std::string &filename) const
Saves the context to a file as JSON.
Holds settings requirements for knowledge, usually in copying.
std::string write_domain
All class members are accessible to users for easy setup.
void release(void)
Releases a recursive lock on the knowledge base.
void unlock(void) const
Unlocks the mutex on this context.
::std::map< std::string, KnowledgeRecord > KnowledgeMap
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.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Checks if a knowledge location exists in the context.
int get_log_level(void)
Gets the log level.
bool clear(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Clears a variable.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
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 setup_unique_hostport(std::string host="")
Creates a random UUID for unique tie breakers in global ordering.
void wait_for_change(bool extra_release=false)
Wait for a change to happen to the context.
std::vector< VariableReference > VariableReferences
a vector of variable references
void reset_checkpoint(void) const
Resets the local changed map, which tracks checkpointing modifieds.
std::string expand_statement(const std::string &statement) const
Expands a string with variable expansion.
knowledge::KnowledgeMap to_map_stripped(const std::string &prefix) const
Creates a map with Knowledge Records that begin with the given prefix.
Encapsulates settings for an evaluation statement.
Definition: EvalSettings.h:27
void acquire(void)
Acquires the recursive lock on the knowledge base.
madara::transport::TransportSettings & transport_settings(void)
Returns a non-const reference to the Transport Settings.
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.
madara::knowledge::KnowledgeRecord evaluate(const std::string &expression)
Evaluates an expression.
Provides functions and classes for the distributed knowledge base.
void activate_transport(void)
Starts the transport mechanism for dissemination if it is closed.
KnowledgeRecord * get_record(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge record from the key.
void reset_checkpoint(void) const
Reset all checkpoint variables in the modified lists.
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.
int64_t save_as_karl(const std::string &filename) const
Saves the context to a file as karl assignments, rather than binary.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
knowledge::KnowledgeMap to_map_stripped(const std::string &prefix) const
Creates a map with Knowledge Records that begin with the given prefix.
void add_modifieds(const VariableReferences &modifieds) const
Adds a list of VariableReferences to the current modified list.
bool clear(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Clears a variable.
Settings for applying knowledge updates.
void set_write_quality(const std::string &key, uint32_t quality, const KnowledgeReferenceSettings &settings)
Atomically sets write quality of this process for a variable.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
MADARA_EXPORT int send_modifieds(const std::string &prefix, const EvalSettings &settings=EvalSettings())
Sends all modified variables through the attached transports.
Copyright (c) 2015 Carnegie Mellon University.
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 ...
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.
Encapsulates settings for a wait statement.
Definition: WaitSettings.h:23
Settings for applying knowledge updates.
Base class from which all transports must be derived.
Definition: Transport.h:45
void attach_logger(logger::Logger &logger) const
Attaches a logger to be used for printing.
int64_t save_checkpoint(const std::string &filename, bool reset_modifieds=true)
Saves a checkpoint of a list of changes to a file.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
Provides an interface for external functions into the MADARA KaRL variable settings.
transport::QoSTransportSettings settings_
void clear_modifieds(void)
Clear all modifications to the knowledge base.
void unlock(void)
Unlocks the context to allow updates over the network (is only necessary if the context has been expl...
void add_modifieds(const VariableReferences &modifieds) const
Adds a list of VariableReferences to the current modified list.
int read_file(const std::string &key, const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically reads a file into a variable.
bool delay_launch
delay launching transports
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...
int64_t save_as_json(const std::string &filename) const
Saves the context to a file as JSON.
void set_log_level(int level)
Sets the log level.
void reset_modified(void)
Reset all variables to be unmodified.