MADARA  3.1.8
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_ (), files_ (map_)
22 {
23  //activate_transport ();
24  // no hope of transporting, so don't setup uniquehostport
25 }
26 
28  const std::string & host, int transport)
29  : settings_ (), files_ (map_)
30 {
31  // override default settings for the arguments
32  settings_.type = transport;
33 
34  id_ = setup_unique_hostport (host);
36 }
37 
39  const std::string & host, int transport,
40  const std::string & knowledge_domain)
41  : settings_ (), files_ (map_)
42 {
43  // override default settings for the arguments
44  settings_.type = transport;
45  settings_.write_domain = knowledge_domain;
46 
47  id_ = setup_unique_hostport (host);
49 }
50 
52  const std::string & host, const madara::transport::TransportSettings & config)
53  : settings_ (config), files_ (map_)
54 {
55  id_ = setup_unique_hostport (host);
58 }
59 
61 {
62  close_transport ();
63  unique_bind_.close ();
64 }
65 inline KnowledgeRecord
67  const std::string & t_key,
68  const KnowledgeReferenceSettings & settings)
69 {
70  return map_.get (t_key, settings);
71 }
72 
73 inline KnowledgeRecord
75  const VariableReference & variable,
76  const KnowledgeReferenceSettings & settings)
77 {
78  return map_.get (variable, settings);
79 }
80 
81 inline VariableReference
83  const std::string & t_key,
84  const KnowledgeReferenceSettings & settings)
85 {
86  return map_.get_ref (t_key, settings);
87 }
88 
89 inline int
91 {
92  return map_.get_log_level ();
93 }
94 
95 inline std::string
97 {
98  return map_.debug_modifieds ();
99 }
100 
101 inline madara::logger::Logger &
103 {
104  return map_.get_logger ();
105 }
106 
107 inline void
109  logger::Logger & logger) const
110 {
111  map_.attach_logger (logger);
112 }
113 
114 inline void
116 {
117  map_.set_log_level (level);
118 }
119 
120 inline KnowledgeRecord
122  const std::string & t_key,
123  size_t index,
124  const KnowledgeReferenceSettings & settings)
125 {
126  return map_.retrieve_index (t_key, index, settings);
127 }
128 
129 inline KnowledgeRecord
131  const VariableReference & variable,
132  size_t index,
133  const KnowledgeReferenceSettings & settings)
134 {
135  return map_.retrieve_index (variable, index, settings);
136 }
137 
138 inline bool
140  const std::string & key,
141  const KnowledgeReferenceSettings & settings) const
142 {
143  return map_.exists (key, settings);
144 }
145 
146 inline bool
148  const VariableReference & variable,
149  const KnowledgeReferenceSettings & settings) const
150 {
151  return map_.exists (variable, settings);
152 }
153 
160 inline int
162 const EvalSettings & settings)
163 {
164  // lock the context and apply modified flags and current clock to
165  // all global variables
166  map_.lock ();
167  map_.apply_modified ();
168 
169  int ret = 0;
170 
171  send_modifieds ("KnowledgeBaseImpl:apply_modified", settings);
172 
173  map_.unlock ();
174 
175  return ret;
176 }
177 
178 inline void
180  const VariableReference & variable,
181  const KnowledgeUpdateSettings & settings)
182 {
183  map_.mark_modified (variable, settings);
184 }
185 
186 inline void
188  const std::string & name,
189  const KnowledgeUpdateSettings & settings)
190 {
191  map_.mark_modified (name, settings);
192 }
193 
195 inline int
197 const std::string & key, const std::string & filename,
198 const EvalSettings & settings)
199 {
200  if (key == "")
201  return -1;
202 
203  int result = map_.read_file (key, filename, settings);
204 
205  send_modifieds ("KnowledgeBaseImpl:read_file", settings);
206 
207  return result;
208 }
209 
211 inline int
213 const VariableReference & variable,
214 const unsigned char * value, size_t size,
215 const EvalSettings & settings)
216 {
217  int result = map_.set_file (variable, value, size, settings);
218 
219  send_modifieds ("KnowledgeBaseImpl:set_file", settings);
220 
221  return result;
222 }
223 
225 inline int
227 const VariableReference & variable,
228 const unsigned char * value, size_t size,
229 const EvalSettings & settings)
230 {
231  int result = map_.set_jpeg (variable, value, size, settings);
232 
233  send_modifieds ("KnowledgeBaseImpl:set_jpeg", settings);
234 
235  return result;
236 }
237 
239 inline int
241 const VariableReference & variable,
242 const std::string & filename,
243 const EvalSettings & settings)
244 {
245  int result = map_.read_file (variable, filename, settings);
246 
247  send_modifieds ("KnowledgeBaseImpl:read_file", settings);
248 
249  return result;
250 }
251 
252 inline void
254 {
255  if (transports_.size () == 0)
256  {
258  }
259  else
260  {
262  "KnowledgeBaseImpl::activate_transport:" \
263  " transport already activated. If you need" \
264  " a new type, close transport first\n");
265  }
266 }
267 
268 inline void
270 const KnowledgeBaseImpl & source,
271 const KnowledgeRequirements & reqs)
272 {
273  map_.copy (source.map_, reqs);
274 }
275 
276 inline void
278 const KnowledgeBaseImpl & source,
279 const CopySet & copy_set,
280 bool clean_copy)
281 {
282  map_.copy (source.map_, copy_set, clean_copy);
283 }
284 
285 inline void
287 {
288  map_.lock ();
289 }
290 
291 inline void
293 {
294  map_.unlock ();
295 }
296 
297 
298 inline std::string
300  const std::string & statement) const
301 {
302  return map_.expand_statement (statement);
303 }
304 
306 inline int
308  const std::string & knowledge_key, const std::string & filename)
309 {
310  return files_.read_policy (knowledge_key, filename);
311 }
312 
314 inline ssize_t
316  const std::string & knowledge_key, const std::string & filename)
317 {
318  return map_.get_record (knowledge_key)->to_file (filename);
319 }
320 
322 inline void
324  const std::string & t_key, uint32_t quality,
325  const KnowledgeReferenceSettings & settings)
326 {
327  map_.set_write_quality (t_key, quality, settings);
328 }
329 
330 #ifdef _USE_CID_
331 
332 inline void
333 KnowledgeBaseImpl::print_all_redeployment_results (
334  std::ostream & output)
335 {
336  settings_.print_all_results (output);
337 }
338 
339 inline void
340 KnowledgeBaseImpl::run_all (void)
341 {
342  settings_.run_all ();
343 }
344 
345 inline void
346 KnowledgeBaseImpl::print_my_latencies (
347  std::ostream & output)
348 {
349  settings_.print_my_latencies (output);
350 }
351 
352 inline void
353 KnowledgeBaseImpl::print_all_latencies (
354  std::ostream & output)
355 {
356  settings_.print_all_latencies (output);
357 }
358 
359 inline void
360 KnowledgeBaseImpl::print_all_summations (
361  std::ostream & output)
362 {
363  settings_.print_all_summations (output);
364 }
365 
366 inline long
367 KnowledgeBaseImpl::start_latency (void)
368 {
369  if (transport_)
370  return transport_->start_latency ();
371  else
372  return -1;
373 }
374 
375 inline long
376 KnowledgeBaseImpl::vote (void)
377 {
378  if (transport_)
379  return transport_->vote ();
380  else
381  return -1;
382 }
383 
384 #endif // _USE_CID_
385 
388 {
389  return settings_;
390 }
391 
392 inline void
394  unsigned int level) const
395 {
396  map_.print (
397  "\nKnowledge in Knowledge Base:\n", logger::LOG_ALWAYS);
398 
399  map_.print (level);
400 }
401 
402 inline void
404  std::string & target,
405  const std::string & array_delimiter,
406  const std::string & record_delimiter,
407  const std::string & key_val_delimiter) const
408 {
409  map_.to_string (target,
410  array_delimiter, record_delimiter, key_val_delimiter);
411 }
412 
413 inline void
415  const std::string & statement, unsigned int level) const
416 {
417  map_.print (statement, level);
418 }
419 
420 inline bool
422  const KnowledgeReferenceSettings & settings)
423 {
424  return map_.clear (key, settings);
425 }
426 
427 inline void
429 {
430  map_.clear (erase);
431 }
432 
433 inline void
435 {
436  map_.clear ();
437 }
438 
441 inline void KnowledgeBaseImpl::acquire (void)
442 {
443  map_.lock ();
444 }
445 
447 inline void KnowledgeBaseImpl::release (void)
448 {
449  map_.unlock ();
450 }
451 
452 #ifndef _MADARA_NO_KARL_
453 
454 // Defines a function
455 inline void
457  const std::string & name, KnowledgeRecord (*func) (FunctionArguments &, Variables &))
458 {
459  map_.define_function (name, func);
460 }
461 
462 // Defines a function
463 inline void
465  const std::string & name,
466  KnowledgeRecord (*func) (const char *, FunctionArguments &, Variables &))
467 {
468  map_.define_function (name, func);
469 }
470 
471 #ifdef _MADARA_JAVA_
472 inline void
474  const std::string & name, jobject callable)
475 {
476  map_.define_function (name, callable);
477 }
478 #endif
479 
480 #ifdef _MADARA_PYTHON_CALLBACKS_
481 
482 inline void
484  const std::string & name, boost::python::object callable)
485 {
486  map_.define_function (name, callable);
487 }
488 
489 #endif
490 
494 inline void
496  const std::string & expression)
497 {
498  map_.define_function (name, expression);
499 }
500 
501 
502 inline void
504  const std::string & name,
505  const CompiledExpression & expression)
506 {
507  map_.define_function (name, expression);
508 }
509 
510 inline KnowledgeRecord
512  const std::string & expression)
513 {
514  CompiledExpression compiled = compile (expression);
515  WaitSettings settings;
516  return wait (compiled, settings);
517 }
518 
519 inline KnowledgeRecord
521  const std::string & expression)
522 {
523  CompiledExpression compiled = compile (expression);
524  EvalSettings settings;
525  return evaluate (compiled, settings);
526 }
527 
528 #endif // _MADARA_NO_KARL_
529 
530 inline size_t
532  madara::transport::Base * transport)
533 {
534  transports_.push_back (transport);
535  return transports_.size ();
536 }
537 
538 inline size_t
540 {
541  return transports_.size ();
542 }
543 
544 inline size_t
546 {
547  return transports_.erase (index);
548 }
549 
556 inline ThreadSafeContext &
558 {
559  return map_;
560 }
561 
562 
567 inline std::string
569 {
570  if (id_ == "")
571  {
573  }
574 
575  return id_;
576 }
577 
592 inline size_t
594  const std::string & subject,
595  unsigned int start,
596  unsigned int end,
597  std::vector <KnowledgeRecord> & target)
598 {
599  return map_.to_vector (subject, start, end, target);
600 }
601 
602 inline void
604  const std::string & prefix,
605  const std::string & suffix,
606  VariableReferences & matches)
607 {
608  map_.get_matches (prefix, suffix, matches);
609 }
610 
611 inline size_t
613  const std::string & expression,
614  std::map <std::string, KnowledgeRecord> & target)
615 {
616  return map_.to_map (expression, target);
617 }
618 
619 inline size_t
621  const std::string & prefix,
622  const std::string & delimiter,
623  const std::string & suffix,
624  std::vector <std::string> & next_keys,
625  std::map <std::string, KnowledgeRecord> & result,
626  bool just_keys)
627 {
628  return map_.to_map (
629  prefix, delimiter, suffix, next_keys, result, just_keys);
630 }
631 
632 inline KnowledgeMap
634  const std::string & prefix) const
635 {
636  return map_.to_map (prefix);
637 }
638 
639 inline KnowledgeMap
641  const std::string & prefix) const
642 {
643  return map_.to_map_stripped (prefix);
644 }
645 
646 
647 inline int64_t
649  const std::string & filename) const
650 {
651  return map_.save_context (filename, id_);
652 }
653 
654 inline int64_t
656  CheckpointSettings & settings) const
657 {
658  settings.originator = id_;
659  return map_.save_context (settings);
660 }
661 
662 inline int64_t
664 const std::string & filename) const
665 {
666  return map_.save_as_json (filename);
667 }
668 
669 inline int64_t
671 const CheckpointSettings & settings) const
672 {
673  return map_.save_as_json (settings);
674 }
675 
676 inline int64_t
678 const std::string & filename) const
679 {
680  return map_.save_as_karl (filename);
681 }
682 
683 inline int64_t
685 const CheckpointSettings & settings) const
686 {
687  return map_.save_as_karl (settings);
688 }
689 
690 inline void
692  void)
693 {
694  map_.reset_modified ();
695 }
696 
697 inline void
699  void) const
700 {
702 }
703 
704 inline int64_t
706  const std::string & filename,
707  bool reset_modifieds)
708 {
709  int64_t total_written = map_.save_checkpoint (filename, id_);
710 
711  if (reset_modifieds)
713 
714  return total_written;
715 }
716 
717 inline int64_t
719  CheckpointSettings & settings) const
720 {
721  settings.originator = id_;
722  return map_.save_checkpoint (settings);
723 }
724 
725 inline int64_t
727  const std::string & filename,
728  bool use_id,
729  const KnowledgeUpdateSettings & settings)
730 {
731  int64_t result = 0;
732 
733  if (use_id)
734  result = map_.load_context (filename, id_, settings);
735  else
736  {
737  std::string id;
738  result = map_.load_context (filename, id, settings);
739  }
740 
741  return result;
742 }
743 
744 inline int64_t
746 const std::string & filename,
747 FileHeader & meta,
748 bool use_id,
749 const KnowledgeUpdateSettings & settings)
750 {
751  int64_t result = 0;
752 
753  if (use_id)
754  {
755  result = map_.load_context (filename, meta, settings);
756  id_ = meta.originator;
757  }
758  else
759  {
760  result = map_.load_context (filename, meta, settings);
761  }
762 
763  return result;
764 }
765 
766 inline int64_t
768 CheckpointSettings & checkpoint_settings,
769 const KnowledgeUpdateSettings & update_settings)
770 {
771  int64_t result = 0;
772 
773  if (checkpoint_settings.originator == "")
774  {
775  result = map_.load_context (checkpoint_settings, update_settings);
776 
777  if (checkpoint_settings.originator != "")
778  id_ = checkpoint_settings.originator;
779  }
780  else
781  {
782  result = map_.load_context (checkpoint_settings, update_settings);
783  }
784 
785  return result;
786 }
787 
788 inline void
790  const VariableReferences & modifieds) const
791 {
792  map_.add_modifieds (modifieds);
793 }
794 
795 inline VariableReferences
797 {
798  return map_.save_modifieds ();
799 }
800 
801 #ifndef _MADARA_NO_KARL_
802 
803 inline void
805 {
807 }
808 
809 inline KnowledgeRecord
811 const std::string & expression,
812 const EvalSettings & settings)
813 {
814  CompiledExpression compiled = compile (expression);
815  return evaluate (compiled, settings);
816 }
817 
818 #endif // _MADARA_NO_KARL_
819 
820 } }
821 
822 
823 #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:35
MADARA_Export int read_policy(const std::string &policy_key, const std::string &policy_file)
Read a policy into the knowledge base.
Definition: Files.cpp:207
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.
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...
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
knowledge::KnowledgeMap to_map_stripped(const std::string &prefix) const
Creates a map with Knowledge Records that begin with the given prefix.
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.
void push_back(T &value)
Pushes a value onto the end of the vector.
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.
VariableReferences save_modifieds(void) const
Saves the list of modified records to use later for resending.
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.
std::string setup_unique_hostport(const std::string &host="")
Binds to an ephemeral port for unique tie breakers in global ordering.
char originator[64]
the originator of the message (host:port)
Definition: FileHeader.h:126
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)
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.
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...
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
size_t size(void) const
returns the current size of the vector
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.
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.
static constexpr struct madara::knowledge::tags::string_t string
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 wait_for_change(bool extra_release=false)
Wait for a change to happen to the context.
size_t erase(size_t index)
Erases an element.
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.
KnowledgeRecord * get_record(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge record from the key.
Encapsulates settings for an evaluation statement.
Definition: EvalSettings.h:26
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.
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.
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.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Settings for applying knowledge updates.
int read_policy(const std::string &policy_key, const std::string &policy_file)
Read a policy into the knowledge base.
void set_write_quality(const std::string &key, uint32_t quality, const KnowledgeReferenceSettings &settings)
Atomically sets write quality of this process for a variable.
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 ...
Encapsulates settings for a wait statement.
Definition: WaitSettings.h:23
madara::transport::Transports transports_
Settings for applying knowledge updates.
Base class from which all transports must be derived.
Definition: Transport.h:62
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.