MADARA  3.1.8
KnowledgeBase.inl
Go to the documentation of this file.
1 #ifndef _MADARA_KNOWLEDGE_BASE_INL_
2 #define _MADARA_KNOWLEDGE_BASE_INL_
3 
4 #include <fstream>
5 
6 #include "ace/streams.h"
7 
8 namespace madara { namespace knowledge {
9 
18 : impl_ (new KnowledgeBaseImpl ()), context_ (0)
19 {
20 }
21 
23  const std::string & host, int transport)
24 : impl_ (new KnowledgeBaseImpl (host, transport)), context_ (0)
25 {
26 }
27 
29  const std::string & host, int transport,
30  const std::string & knowledge_domain)
31 : impl_ (new KnowledgeBaseImpl (host, transport, knowledge_domain)),
32  context_ (0)
33 {
34 }
35 
37  const std::string & host, const madara::transport::TransportSettings & settings)
38 : impl_ (new KnowledgeBaseImpl (host, settings)), context_ (0)
39 {
40 }
41 
42 template<typename T,
43  typename std::enable_if<std::is_integral<T>::value,
44  void*>::type>
45 inline int
47  const std::string & key,
48  T value,
49  const EvalSettings & settings)
50 {
51  int result = 0;
52 
53  if (impl_.get ())
54  {
55  result = impl_->set (key, (KnowledgeRecord::Integer)value, settings);
56  }
57  else if (context_)
58  {
59  result = context_->set (key, (KnowledgeRecord::Integer)value, settings);
60  }
61 
62  return result;
63 }
64 
65 template<typename T,
66  typename std::enable_if<std::is_integral<T>::value,
67  void*>::type>
68 inline int
70  const VariableReference & variable,
71  T value,
72  const EvalSettings & settings)
73 {
74  int result = 0;
75 
76  if (impl_.get ())
77  {
78  result = impl_->set (variable, (KnowledgeRecord::Integer)value, settings);
79  }
80  else if (context_)
81  {
82  result = context_->set (variable, (KnowledgeRecord::Integer)value, settings);
83  }
84 
85  return result;
86 }
87 
88 template<typename T,
89  typename std::enable_if<std::is_floating_point<T>::value,
90  void*>::type>
91 inline int
93  const std::string & key,
94  T value,
95  const EvalSettings & settings)
96 {
97  int result = 0;
98 
99  if (impl_.get ())
100  {
101  result = impl_->set (key, (double)value, settings);
102  }
103  else if (context_)
104  {
105  result = context_->set (key, (double)value, settings);
106  }
107 
108  return result;
109 }
110 
111 template<typename T,
112  typename std::enable_if<std::is_floating_point<T>::value,
113  void*>::type>
114 inline int
116  const VariableReference & variable,
117  T value,
118  const EvalSettings & settings)
119 {
120  int result = 0;
121 
122  if (impl_.get ())
123  {
124  result = impl_->set (variable, (double)value, settings);
125  }
126  else if (context_)
127  {
128  result = context_->set (variable, (double)value, settings);
129  }
130 
131  return result;
132 }
133 
134 inline void
136  ThreadSafeContext & original)
137 {
138  impl_ = 0;
139  context_ = &original;
140 }
141 
142 inline void
144 {
145  if (impl_.get ())
146  {
147  impl_->lock ();
148  }
149  else if (context_)
150  {
151  context_->lock ();
152  }
153 }
154 
155 inline void
157 {
158  if (impl_.get ())
159  {
160  impl_->unlock ();
161  }
162  else if (context_)
163  {
164  context_->unlock ();
165  }
166 }
167 
168 inline int
170 {
171  int result (0);
172 
173  if (impl_.get ())
174  {
175  result = impl_->get_log_level ();
176  }
177  else if (context_)
178  {
179  result = context_->get_log_level ();
180  }
181 
182  return result;
183 }
184 
185 inline madara::logger::Logger &
187 {
188  if (impl_.get ())
189  {
190  return impl_->get_logger ();
191  }
192  else
193  {
194  return context_->get_logger ();
195  }
196 }
197 
198 inline void
200  logger::Logger & logger) const
201 {
202  if (impl_.get ())
203  {
204  impl_->attach_logger (logger);
205  }
206  else
207  {
208  context_->attach_logger (logger);
209  }
210 }
211 
212 inline void
214 {
215  if (impl_.get ())
216  {
217  impl_->set_log_level (level);
218  }
219  else if (context_)
220  {
221  context_->set_log_level (level);
222  }
223 }
224 
225 
226 inline void
228  const KnowledgeBase & source,
229  const KnowledgeRequirements & reqs)
230 {
231  if (impl_.get () && source.impl_.get () != 0)
232  {
233  impl_->copy (*source.impl_.get (), reqs);
234  }
235  else if (context_ && source.impl_.get () != 0)
236  {
237  KnowledgeBaseImpl * source_impl =
238  (KnowledgeBaseImpl *)source.impl_.get ();
239  ThreadSafeContext * source_context = &(source_impl->get_context ());
240 
241  context_->copy (*source_context, reqs);
242  }
243 }
244 
245 inline void
247  const KnowledgeBase & source,
248  const CopySet & copy_set,
249  bool clean_copy)
250 {
251  if (impl_.get () && source.impl_.get () != 0)
252  {
253  impl_->copy (*source.impl_.get (), copy_set, clean_copy);
254  }
255  else if (context_ && source.impl_.get () != 0)
256  {
257  KnowledgeBaseImpl * source_impl =
258  (KnowledgeBaseImpl *)source.impl_.get ();
259  ThreadSafeContext * source_context = &(source_impl->get_context ());
260 
261  context_->copy (*source_context, copy_set, clean_copy);
262  }
263 }
264 
267 inline int
269  const EvalSettings & settings)
270 {
271  int result = 0;
272 
273  if (impl_.get ())
274  {
275  result = impl_->apply_modified (settings);
276  }
277  else if (context_)
278  {
280  }
281 
282  return result;
283 }
284 
285 inline void
287 {
288  if (impl_.get ())
289  {
290  impl_->close_transport ();
291  }
292 }
293 
294 inline KnowledgeRecord
296  const KnowledgeReferenceSettings & settings)
297 {
298  KnowledgeRecord result;
299 
300  if (impl_.get ())
301  {
302  result = impl_->get (key, settings);
303  }
304  else if (context_)
305  {
306  result = context_->get (key, settings);
307  }
308 
309  return result;
310 }
311 
312 inline VariableReference
314  const KnowledgeReferenceSettings & settings)
315 {
316  VariableReference var;
317 
318  if (impl_.get ())
319  {
320  var = impl_->get_ref (key, settings);
321  }
322  else if (context_)
323  {
324  var = context_->get_ref (key, settings);
325  }
326 
327  return var;
328 }
329 
330 inline KnowledgeRecord
332  const VariableReference & variable,
333  const KnowledgeReferenceSettings & settings)
334 {
335  KnowledgeRecord result;
336 
337  if (impl_.get ())
338  {
339  result = impl_->get (variable, settings);
340  }
341  else if (context_)
342  {
343  result = context_->get (variable, settings);
344  }
345 
346  return result;
347 }
348 
349 inline KnowledgeRecord
351  const std::string & key, size_t index,
352  const KnowledgeReferenceSettings & settings)
353 {
354  KnowledgeRecord result;
355 
356  if (impl_.get ())
357  {
358  result = impl_->retrieve_index (key, index, settings);
359  }
360  else if (context_)
361  {
362  result = context_->retrieve_index (key, index, settings);
363  }
364 
365  return result;
366 }
367 
368 inline KnowledgeRecord
370  const VariableReference & variable, size_t index,
371  const KnowledgeReferenceSettings & settings)
372 {
373  KnowledgeRecord result;
374 
375  if (impl_.get ())
376  {
377  result = impl_->retrieve_index (variable, index, settings);
378  }
379  else if (context_)
380  {
381  result = context_->retrieve_index (variable, index, settings);
382  }
383 
384  return result;
385 }
386 
387 
388 inline int
390  const std::string & knowledge_key,
391  const std::string & filename,
392  const EvalSettings & settings)
393 {
394  int result = 0;
395 
396  if (impl_.get ())
397  {
398  result = impl_->read_file (knowledge_key, filename, settings);
399  }
400  else if (context_)
401  {
402  result = context_->read_file (knowledge_key, filename, settings);
403  }
404 
405  return result;
406 }
407 
408 inline int
410  const VariableReference & variable,
411  const std::string & filename,
412  const EvalSettings & settings)
413 {
414  int result = 0;
415 
416  if (impl_.get ())
417  {
418  result = impl_->read_file (variable, filename, settings);
419  }
420  else if (context_)
421  {
422  result = context_->read_file (variable, filename, settings);
423  }
424 
425  return result;
426 }
427 
428 inline int
430  const std::string & key,
431  const unsigned char * value, size_t size,
432  const EvalSettings & settings)
433 {
434  int result = -1;
435 
436  if (key != "")
437  {
438  if (impl_.get ())
439  {
440  result = impl_->set_file (
441  impl_->get_ref (key, settings), value, size, settings);
442  }
443  else if (context_)
444  {
445  result = context_->set_file (
446  context_->get_ref (key, settings), value, size, settings);
447  }
448  }
449 
450  return result;
451 }
452 
453 inline int
455  const VariableReference & variable,
456  const unsigned char * value, size_t size,
457  const EvalSettings & settings)
458 {
459  int result = 0;
460 
461  if (impl_.get ())
462  {
463  result = impl_->set_file (variable, value, size, settings);
464  }
465  else if (context_)
466  {
467  result = context_->set_file (variable, value, size, settings);
468  }
469 
470  return result;
471 }
472 
473 inline int
475  const std::string & key,
476  const unsigned char * value, size_t size,
477  const EvalSettings & settings)
478 {
479  int result = -1;
480 
481  if (key != "")
482  {
483  if (impl_.get ())
484  {
485  result = impl_->set_jpeg (
486  impl_->get_ref (key, settings), value, size, settings);
487  }
488  else if (context_)
489  {
490  result = context_->set_jpeg (
491  impl_->get_ref (key, settings), value, size, settings);
492  }
493  }
494 
495  return result;
496 }
497 
498 inline int
500  const VariableReference & variable,
501  const unsigned char * value, size_t size,
502  const EvalSettings & settings)
503 {
504  int result = 0;
505 
506  if (impl_.get ())
507  {
508  result = impl_->set_jpeg (variable, value, size, settings);
509  }
510  else if (context_)
511  {
512  result = context_->set_jpeg (variable, value, size, settings);
513  }
514 
515  return result;
516 }
517 
518 inline int
520  const std::string & knowledge_key,
521  const std::string & filename)
522 {
523  int result = 0;
524 
525  if (impl_.get ())
526  {
527  result = impl_->read_policy (knowledge_key, filename);
528  }
529 
530  return result;
531 }
532 
533 inline ssize_t
534 KnowledgeBase::write_file (const std::string & knowledge_key,
535  const std::string & filename)
536 {
537  ssize_t result = 0;
538 
539  if (impl_.get ())
540  {
541  result = impl_->write_file (knowledge_key, filename);
542  }
543 
544  return result;
545 }
546 
547 
548 inline std::string
550  const std::string & statement)
551 {
552  std::string result;
553 
554  if (impl_.get ())
555  {
556  result = impl_->expand_statement (statement);
557  }
558  else if (context_)
559  {
560  result = context_->expand_statement (statement);
561  }
562 
563  return result;
564 }
565 
566 inline void
568  const VariableReference & variable,
569  const KnowledgeUpdateSettings & /*settings*/)
570 {
571  if (impl_.get ())
572  {
573  impl_->mark_modified (variable);
574  }
575  else if (context_)
576  {
577  context_->mark_modified (variable);
578  }
579 }
580 
581 inline void
583  const std::string & name,
584  const KnowledgeUpdateSettings & settings)
585 {
586  if (impl_.get ())
587  {
588  impl_->mark_modified (name, settings);
589  }
590  else if (context_)
591  {
592  context_->mark_modified (name, settings);
593  }
594 }
595 
596 inline int
598  const VariableReference & variable,
599  KnowledgeRecord && value,
600  const EvalSettings & settings)
601 {
602  int result = 0;
603 
604  if (impl_.get ())
605  {
606  result = impl_->set (variable, std::move(value), settings);
607  }
608  else if (context_)
609  {
610  result = context_->set (variable, std::move(value), settings);
611  }
612 
613  return result;
614 }
615 
616 inline int
618  const std::string & key,
619  const KnowledgeRecord & value,
620  const EvalSettings & settings)
621 {
622  int result = 0;
623 
624  if (impl_.get ())
625  {
626  result = impl_->set (key, value, settings);
627  }
628  else if (context_)
629  {
630  result = context_->set (key, value, settings);
631  }
632 
633  return result;
634 }
635 
636 inline int
638  const std::string & key,
639  KnowledgeRecord && value,
640  const EvalSettings & settings)
641 {
642  int result = 0;
643 
644  if (impl_.get ())
645  {
646  result = impl_->set (key, std::move(value), settings);
647  }
648  else if (context_)
649  {
650  result = context_->set (key, std::move(value), settings);
651  }
652 
653  return result;
654 }
655 
656 inline int
658  const VariableReference & variable,
659  const KnowledgeRecord & value,
660  const EvalSettings & settings)
661 {
662  int result = 0;
663 
664  if (impl_.get ())
665  {
666  result = impl_->set (variable, value, settings);
667  }
668  else if (context_)
669  {
670  result = context_->set (variable, value, settings);
671  }
672 
673  return result;
674 }
675 
676 template<typename T>
677 inline int
679  const std::string & key,
680  size_t index, T&& value,
681  const EvalSettings & settings)
682 {
683  int result = 0;
684 
685  if (impl_.get ())
686  {
687  result = impl_->set_index (key, index, std::forward<T>(value), settings);
688  }
689  else if (context_)
690  {
691  result = context_->set_index (key, index, std::forward<T>(value), settings);
692  }
693 
694  return result;
695 }
696 
697 template<typename T>
698 inline int
700  const VariableReference & variable,
701  size_t index, T&& value,
702  const EvalSettings & settings)
703 {
704  int result = 0;
705 
706  if (impl_.get ())
707  {
708  result = impl_->set_index (variable, index, std::forward<T>(value), settings);
709  }
710  else if (context_)
711  {
712  result = context_->set_index (variable, index, std::forward<T>(value), settings);
713  }
714 
715  return result;
716 }
717 
718 inline int
720  const std::string & key,
721  const KnowledgeRecord::Integer * value,
722  uint32_t size,
723  const EvalSettings & settings)
724 {
725  int result = 0;
726 
727  if (impl_.get ())
728  {
729  result = impl_->set (key, value, size, settings);
730  }
731  else if (context_)
732  {
733  result = context_->set (key, value, size, settings);
734  }
735 
736  return result;
737 }
738 
739 inline int
741  const VariableReference & variable,
742  const KnowledgeRecord::Integer * value,
743  uint32_t size,
744  const EvalSettings & settings)
745 {
746  int result = 0;
747 
748  if (impl_.get ())
749  {
750  result = impl_->set (variable, value, size, settings);
751  }
752  else if (context_)
753  {
754  result = context_->set (variable, value, size, settings);
755  }
756 
757  return result;
758 }
759 
760 inline int
762  const std::string & key,
763  const std::vector <KnowledgeRecord::Integer> & value,
764  const EvalSettings & settings)
765 {
766  int result = 0;
767 
768  if (impl_.get ())
769  {
770  result = impl_->set (key, value, settings);
771  }
772  else if (context_)
773  {
774  result = context_->set (key, value, settings);
775  }
776 
777  return result;
778 }
779 
780 inline int
782  const VariableReference & variable,
783  const std::vector <KnowledgeRecord::Integer> & value,
784  const EvalSettings & settings)
785 {
786  int result = 0;
787 
788  if (impl_.get ())
789  {
790  result = impl_->set (variable, value, settings);
791  }
792  else if (context_)
793  {
794  result = context_->set (variable, value, settings);
795  }
796 
797  return result;
798 }
799 
800 inline int
802  const std::string & key,
803  std::vector <KnowledgeRecord::Integer> && value,
804  const EvalSettings & settings)
805 {
806  int result = 0;
807 
808  if (impl_.get ())
809  {
810  result = impl_->set (key, std::move(value), settings);
811  }
812  else if (context_)
813  {
814  result = context_->set (key, std::move(value), settings);
815  }
816 
817  return result;
818 }
819 
820 inline int
822  const VariableReference & variable,
823  std::vector <KnowledgeRecord::Integer> && value,
824  const EvalSettings & settings)
825 {
826  int result = 0;
827 
828  if (impl_.get ())
829  {
830  result = impl_->set (variable, std::move(value), settings);
831  }
832  else if (context_)
833  {
834  result = context_->set (variable, std::move(value), settings);
835  }
836 
837  return result;
838 }
839 
840 inline int
842  const std::string & key,
843  const double * value,
844  uint32_t size,
845  const EvalSettings & settings)
846 {
847  int result = 0;
848 
849  if (impl_.get ())
850  {
851  result = impl_->set (key, value, size, settings);
852  }
853  else if (context_)
854  {
855  result = context_->set (key, value, size, settings);
856  }
857 
858  return result;
859 }
860 
861 inline int
863  const VariableReference & variable,
864  const double * value,
865  uint32_t size,
866  const EvalSettings & settings)
867 {
868  int result = 0;
869 
870  if (impl_.get ())
871  {
872  result = impl_->set (variable, value, size, settings);
873  }
874  else if (context_)
875  {
876  result = context_->set (variable, value, size, settings);
877  }
878 
879  return result;
880 }
881 
882 inline int
884  const std::string & key,
885  const std::vector <double> & value,
886  const EvalSettings & settings)
887 {
888  int result = 0;
889 
890  if (impl_.get ())
891  {
892  result = impl_->set (key, value, settings);
893  }
894  else if (context_)
895  {
896  result = context_->set (key, value, settings);
897  }
898 
899  return result;
900 }
901 
902 inline int
904  const std::string & key,
905  std::vector <double> && value,
906  const EvalSettings & settings)
907 {
908  int result = 0;
909 
910  if (impl_.get ())
911  {
912  result = impl_->set (key, std::move(value), settings);
913  }
914  else if (context_)
915  {
916  result = context_->set (key, std::move(value), settings);
917  }
918 
919  return result;
920 }
921 
922 inline int
924  const VariableReference & variable,
925  const std::vector <double> & value,
926  const EvalSettings & settings)
927 {
928  int result = 0;
929 
930  if (impl_.get ())
931  {
932  result = impl_->set (variable, value, settings);
933  }
934  else if (context_)
935  {
936  result = context_->set (variable, value, settings);
937  }
938 
939  return result;
940 }
941 
942 inline int
944  const VariableReference & variable,
945  std::vector <double> && value,
946  const EvalSettings & settings)
947 {
948  int result = 0;
949 
950  if (impl_.get ())
951  {
952  result = impl_->set (variable, std::move(value), settings);
953  }
954  else if (context_)
955  {
956  result = context_->set (variable, std::move(value), settings);
957  }
958 
959  return result;
960 }
961 
962 inline int
964  const std::string & value,
965  const EvalSettings & settings)
966 {
967  int result = 0;
968 
969  if (impl_.get ())
970  {
971  result = impl_->set (key, value, settings);
972  }
973  else if (context_)
974  {
975  result = context_->set (key, value, settings);
976  }
977 
978  return result;
979 }
980 
981 inline int
983  const VariableReference & variable,
984  const std::string & value,
985  const EvalSettings & settings)
986 {
987  int result = 0;
988 
989  if (impl_.get ())
990  {
991  result = impl_->set (variable, value, settings);
992  }
993  else if (context_)
994  {
995  result = context_->set (variable, value, settings);
996  }
997 
998  return result;
999 }
1000 
1001 inline int
1003  std::string && value,
1004  const EvalSettings & settings)
1005 {
1006  int result = 0;
1007 
1008  if (impl_.get ())
1009  {
1010  result = impl_->set (key, std::move(value), settings);
1011  }
1012  else if (context_)
1013  {
1014  result = context_->set (key, std::move(value), settings);
1015  }
1016 
1017  return result;
1018 }
1019 
1020 inline int
1022  const VariableReference & variable,
1023  std::string && value,
1024  const EvalSettings & settings)
1025 {
1026  int result = 0;
1027 
1028  if (impl_.get ())
1029  {
1030  result = impl_->set (variable, std::move(value), settings);
1031  }
1032  else if (context_)
1033  {
1034  result = context_->set (variable, std::move(value), settings);
1035  }
1036 
1037  return result;
1038 }
1039 
1040 
1042 inline void
1044  const std::string & key, uint32_t quality,
1045  const KnowledgeReferenceSettings & settings)
1046 {
1047  if (impl_.get ())
1048  {
1049  impl_->set_quality (key, quality, settings);
1050  }
1051  else if (context_)
1052  {
1053  context_->set_quality (key, quality, true, settings);
1054  }
1055 }
1056 
1057 
1058 inline bool
1060  const std::string & key,
1061  const KnowledgeReferenceSettings & settings) const
1062 {
1063  bool result = false;
1064 
1065  if (impl_.get ())
1066  {
1067  result = impl_->exists (key, settings);
1068  }
1069  else if (context_)
1070  {
1071  result = context_->exists (key, settings);
1072  }
1073 
1074  return result;
1075 }
1076 
1077 inline bool
1079  const VariableReference & variable,
1080  const KnowledgeReferenceSettings & settings) const
1081 {
1082  bool result = false;
1083 
1084  if (impl_.get ())
1085  {
1086  result = impl_->exists (variable, settings);
1087  }
1088  else if (context_)
1089  {
1090  result = context_->exists (variable, settings);
1091  }
1092 
1093  return result;
1094 }
1095 
1096 #ifdef _USE_CID_
1097 
1098 inline void
1099 KnowledgeBase::print_all_redeployment_results (
1100  std::ostream & output)
1101 {
1102  return impl_->print_all_redeployment_results (output);
1103 }
1104 
1105 inline void
1106 KnowledgeBase::run_all (void)
1107 {
1108  return impl_->run_all ();
1109 }
1110 
1111 inline long
1112 KnowledgeBase::start_latency (void)
1113 {
1114  return impl_->start_latency ();
1115 }
1116 
1117 inline void
1118 KnowledgeBase::print_my_latencies (
1119  std::ostream & output)
1120 {
1121  impl_->print_my_latencies (output);
1122 }
1123 
1124 inline void
1125 KnowledgeBase::print_all_latencies (
1126  std::ostream & output)
1127 {
1128  impl_->print_all_latencies (output);
1129 }
1130 
1131 inline void
1132 KnowledgeBase::print_all_summations (
1133  std::ostream & output)
1134 {
1135  impl_->print_all_summations (output);
1136 }
1137 
1138 inline long
1139 KnowledgeBase::vote (void)
1140 {
1141  return impl_->vote ();
1142 }
1143 
1144 #endif // _USE_CID_
1147 {
1148  return impl_->transport_settings ();
1149 }
1150 
1151 inline void
1153  unsigned int level) const
1154 {
1155  if (impl_.get ())
1156  {
1157  impl_->print (level);
1158  }
1159  else if (context_)
1160  {
1161  context_->print (level);
1162  }
1163 }
1164 
1165 inline void
1167  unsigned int level) const
1168 {
1169  if (impl_.get ())
1170  {
1171  impl_->print (level);
1172  }
1173  else if (context_)
1174  {
1175  context_->print (level);
1176  }
1177 }
1178 
1179 inline void
1181  std::string & target,
1182  const std::string & array_delimiter,
1183  const std::string & record_delimiter,
1184  const std::string & key_val_delimiter) const
1185 {
1186  if (impl_.get ())
1187  {
1188  impl_->to_string (target,
1189  array_delimiter, record_delimiter, key_val_delimiter);
1190  }
1191  else if (context_)
1192  {
1193  context_->to_string (target,
1194  array_delimiter, record_delimiter, key_val_delimiter);
1195  }
1196 }
1197 
1198 
1199 inline void
1201  const std::string & statement, unsigned int level) const
1202 {
1203  if (impl_.get ())
1204  {
1205  impl_->print (statement, level);
1206  }
1207  else if (context_)
1208  {
1209  context_->print (level);
1210  }
1211 }
1212 
1213 inline bool
1215  const KnowledgeReferenceSettings & settings)
1216 {
1217  bool result (false);
1218 
1219  if (impl_.get ())
1220  {
1221  result = impl_->clear (key, settings);
1222  }
1223  else if (context_)
1224  {
1225  result = context_->clear (key, settings);
1226  }
1227 
1228  return result;
1229 }
1230 
1231 inline void
1233 {
1234  if (impl_.get ())
1235  {
1236  impl_->clear (erase);
1237  }
1238  else if (context_)
1239  {
1240  context_->clear (erase);
1241  }
1242 }
1243 
1244 inline void
1246 {
1247  if (impl_.get ())
1248  {
1249  impl_->clear_map ();
1250  }
1251  else if (context_)
1252  {
1253  context_->clear ();
1254  }
1255 }
1256 
1257 inline void
1259 {
1260  if (impl_.get ())
1261  {
1262  impl_->acquire ();
1263  }
1264  else if (context_)
1265  {
1266  context_->lock ();
1267  }
1268 }
1269 
1270 inline void
1272 {
1273  if (impl_.get ())
1274  {
1275  impl_->release ();
1276  }
1277  else if (context_)
1278  {
1279  context_->unlock ();
1280  }
1281 }
1282 
1283 #ifndef _MADARA_NO_KARL_
1284 
1285 inline CompiledExpression
1287  const std::string & expression)
1288 {
1289  CompiledExpression result;
1290 
1291  if (impl_.get ())
1292  {
1293  result = impl_->compile (expression);
1294  }
1295 
1296  return result;
1297 }
1298 
1299 // evaluate a knowledge expression and choose to send any modifications
1300 inline KnowledgeRecord
1302  const std::string & expression,
1303  const EvalSettings & settings)
1304 {
1305  KnowledgeRecord result;
1306 
1307  if (impl_.get ())
1308  {
1309  result = impl_->evaluate (expression, settings);
1310  }
1311  else if (context_)
1312  {
1313  CompiledExpression ce = context_->compile (expression);
1314  result = context_->evaluate (ce, settings);
1315  }
1316 
1317  return result;
1318 }
1319 
1320 // evaluate a knowledge expression and choose to send any modifications
1321 inline KnowledgeRecord
1323  CompiledExpression & expression,
1324  const EvalSettings & settings)
1325 {
1326  KnowledgeRecord result;
1327 
1328  if (impl_.get ())
1329  {
1330  result = impl_->evaluate (expression, settings);
1331  }
1332  else if (context_)
1333  {
1334  result = context_->evaluate (expression, settings);
1335  }
1336 
1337  return result;
1338 }
1339 
1340 // evaluate a knowledge expression and choose to send any modifications
1341 inline KnowledgeRecord
1344  const EvalSettings & settings)
1345 {
1346  KnowledgeRecord result;
1347 
1348  if (impl_.get ())
1349  {
1350  result = impl_->evaluate (root, settings);
1351  }
1352  else if (context_)
1353  {
1354  result = context_->evaluate (root, settings);
1355  }
1356 
1357  return result;
1358 }
1359 
1360 
1361 // Defines a function
1362 inline void
1364  const std::string & name,
1365  KnowledgeRecord (*func) (const char *, FunctionArguments &, Variables &))
1366 {
1367  if (impl_.get ())
1368  {
1369  impl_->define_function (name, func);
1370  }
1371  else if (context_)
1372  {
1373  context_->define_function (name, func);
1374  }
1375 }
1376 
1377 // Defines a function
1378 inline void
1380  const std::string & name,
1382 {
1383  if (impl_.get ())
1384  {
1385  impl_->define_function (name, func);
1386  }
1387  else if (context_)
1388  {
1389  context_->define_function (name, func);
1390  }
1391 }
1392 
1393 #ifdef _MADARA_JAVA_
1394 // Defines a function
1395 inline void
1397  const std::string & name, jobject func)
1398 {
1399  if (impl_.get ())
1400  {
1401  impl_->define_function (name, func);
1402  }
1403  else if (context_)
1404  {
1405  context_->define_function (name, func);
1406  }
1407 }
1408 #endif
1409 
1410 #ifdef _MADARA_PYTHON_CALLBACKS_
1411 
1412 // Defines a function
1413 inline void
1415  const std::string & name, boost::python::object callable)
1416 {
1417  if (impl_.get ())
1418  {
1419  impl_->define_function (name, callable);
1420  }
1421  else if (context_)
1422  {
1423  context_->define_function (name, callable);
1424  }
1425 }
1426 
1427 #endif
1428 
1434 inline void
1436  const std::string & expression)
1437 {
1438  if (impl_.get ())
1439  {
1440  impl_->define_function (name, expression);
1441  }
1442  else if (context_)
1443  {
1444  context_->define_function (name, expression);
1445  }
1446 }
1447 
1453 inline void
1455  const CompiledExpression & expression)
1456 {
1457  if (impl_.get ())
1458  {
1459  impl_->define_function (name, expression);
1460  }
1461  else if (context_)
1462  {
1463  context_->define_function (name, expression);
1464  }
1465 }
1466 
1467 inline KnowledgeRecord
1469  const std::string & expression,
1470  const WaitSettings & settings)
1471 {
1472  KnowledgeRecord result;
1473 
1474  if (context_)
1475  {
1476  CompiledExpression ce = context_->compile (expression);
1477  result = this->wait (ce, settings);
1478  }
1479  else if (impl_.get ())
1480  {
1481  result = impl_->wait (expression, settings);
1482  }
1483 
1484  return result;
1485 }
1486 
1487 #endif // _MADARA_NO_KARL_
1488 inline void
1490 {
1491  if (impl_.get ())
1492  {
1493  impl_->activate_transport ();
1494  }
1495 }
1496 
1497 inline size_t
1499  madara::transport::Base * transport)
1500 {
1501  size_t result = 0;
1502 
1503  if (impl_.get ())
1504  {
1505  result = impl_->attach_transport (transport);
1506  }
1507 
1508  return result;
1509 }
1510 
1511 inline size_t
1513 {
1514  size_t result (0);
1515 
1516  if (impl_.get ())
1517  {
1518  result = impl_->get_num_transports ();
1519  }
1520 
1521  return result;
1522 }
1523 
1524 inline size_t
1526  transport::TransportSettings & settings)
1527 {
1528  size_t result = 0;
1529 
1530  if (impl_.get ())
1531  {
1532  result = impl_->attach_transport (id, settings);
1533  }
1534 
1535  return result;
1536 }
1537 
1538 inline size_t
1540  size_t index)
1541 {
1542  size_t result = 0;
1543 
1544  if (impl_.get ())
1545  {
1546  result = impl_->remove_transport (index);
1547  }
1548 
1549  return result;
1550 }
1551 
1552 inline ThreadSafeContext &
1554 {
1555  ThreadSafeContext * result = 0;
1556 
1557  if (context_)
1558  {
1559  result = context_;
1560  }
1561  else if (impl_.get ())
1562  {
1563  result = &(impl_->get_context ());
1564  }
1565 
1566  return *result;
1567 }
1568 
1569 inline void
1571 {
1572  if (context_)
1573  {
1575  }
1576  else if (impl_.get ())
1577  {
1578  impl_->clear_modifieds ();
1579  }
1580 }
1581 
1582 inline void
1584 {
1585  if (context_)
1586  {
1587  context_->add_modifieds (modifieds);
1588  }
1589  else if (impl_.get ())
1590  {
1591  impl_->add_modifieds (modifieds);
1592  }
1593 }
1594 
1595 inline VariableReferences
1597 {
1598  VariableReferences default_result;
1599 
1600  if (context_)
1601  {
1602  return context_->save_modifieds ();
1603  }
1604  else if (impl_.get ())
1605  {
1606  return impl_->save_modifieds ();
1607  }
1608 
1609  return default_result;
1610 }
1611 
1612 inline int
1614  const std::string & prefix,
1615  const EvalSettings & settings)
1616 {
1617  int result = 0;
1618 
1619  if (impl_.get ())
1620  {
1621  result = impl_->send_modifieds (prefix, settings);
1622  }
1623 
1624  return result;
1625 }
1626 
1627 inline std::string
1629 {
1630  std::string result = "";
1631 
1632  if (context_)
1633  {
1634  result = context_->debug_modifieds ();
1635  }
1636  else if (impl_.get ())
1637  {
1638  result = impl_->debug_modifieds ();
1639  }
1640 
1641  return result;
1642 }
1643 
1648 inline std::string
1650 {
1651  std::string result;
1652 
1653  if (impl_.get ())
1654  {
1655  result = impl_->get_id ();
1656  }
1657 
1658  return result;
1659 }
1660 
1675 inline size_t
1677  const std::string & subject,
1678  unsigned int start,
1679  unsigned int end,
1680  std::vector <KnowledgeRecord> & target)
1681 {
1682  size_t result = 0;
1683 
1684  if (context_)
1685  {
1686  result = context_->to_vector (subject, start, end, target);
1687  }
1688  else if (impl_.get ())
1689  {
1690  result = impl_->to_vector (subject, start, end, target);
1691  }
1692 
1693  return result;
1694 }
1695 
1696 inline void
1698  const std::string & suffix, VariableReferences & matches)
1699 {
1700  if (context_)
1701  {
1702  context_->get_matches (prefix, suffix, matches);
1703  }
1704  else if (impl_.get ())
1705  {
1706  impl_->get_matches (prefix, suffix, matches);
1707  }
1708 }
1709 
1711  ThreadSafeContext & context)
1712 {
1713  context_ = &context;
1714  impl_ = 0;
1715 }
1716 
1717 inline size_t
1719  const std::string & expression,
1720  std::map <std::string, KnowledgeRecord> & target)
1721 {
1722  size_t result = 0;
1723 
1724  if (context_)
1725  {
1726  result = context_->to_map (expression, target);
1727  }
1728  else if (impl_.get ())
1729  {
1730  result = impl_->to_map (expression, target);
1731  }
1732 
1733  return result;
1734 }
1735 
1736 inline size_t
1738  const std::string & prefix,
1739  const std::string & delimiter,
1740  const std::string & suffix,
1741  std::vector <std::string> & next_keys,
1742  std::map <std::string, KnowledgeRecord> & result,
1743  bool just_keys)
1744 {
1745  size_t result_size = 0;
1746 
1747  if (context_)
1748  {
1749  result_size = context_->to_map (
1750  prefix, delimiter, suffix, next_keys, result, just_keys);
1751  }
1752  else if (impl_.get ())
1753  {
1754  result_size = impl_->to_map (
1755  prefix, delimiter, suffix, next_keys, result, just_keys);
1756  }
1757 
1758  return result_size;
1759 }
1760 
1761 inline KnowledgeMap
1763  const std::string & prefix) const
1764 {
1765  if (context_)
1766  {
1767  return context_->to_map (prefix);
1768  }
1769  else if (impl_.get ())
1770  {
1771  return impl_->to_map (prefix);
1772  }
1773 
1774  return KnowledgeMap();
1775 }
1776 
1777 inline KnowledgeMap
1779  const std::string & prefix) const
1780 {
1781  if (context_)
1782  {
1783  return context_->to_map_stripped (prefix);
1784  }
1785  else if (impl_.get ())
1786  {
1787  return impl_->to_map_stripped (prefix);
1788  }
1789 
1790  return KnowledgeMap();
1791 }
1792 
1793 inline int64_t
1795  const std::string & filename) const
1796 {
1797  int64_t result = 0;
1798 
1799  if (context_)
1800  {
1801  result = context_->save_context (filename);
1802  }
1803  else if (impl_.get ())
1804  {
1805  result = impl_->save_context (filename);
1806  }
1807 
1808  return result;
1809 }
1810 
1811 inline int64_t
1813  CheckpointSettings & settings) const
1814 {
1815  int64_t result = 0;
1816 
1817  if (context_)
1818  {
1819  result = context_->save_context (settings);
1820  }
1821  else if (impl_.get ())
1822  {
1823  result = impl_->save_context (settings);
1824  }
1825 
1826  return result;
1827 }
1828 
1829 
1830 inline int64_t
1832  const std::string & filename) const
1833 {
1834  int64_t result = 0;
1835 
1836  if (context_)
1837  {
1838  result = context_->save_as_json (filename);
1839  }
1840  else if (impl_.get ())
1841  {
1842  result = impl_->save_as_json (filename);
1843  }
1844 
1845  return result;
1846 }
1847 
1848 inline int64_t
1850  const CheckpointSettings & settings) const
1851 {
1852  int64_t result = 0;
1853 
1854  if (context_)
1855  {
1856  result = context_->save_as_json (settings);
1857  }
1858  else if (impl_.get ())
1859  {
1860  result = impl_->save_as_json (settings);
1861  }
1862 
1863  return result;
1864 }
1865 
1866 inline int64_t
1868  const std::string & filename) const
1869 {
1870  int64_t result = 0;
1871 
1872  if (context_)
1873  {
1874  result = context_->save_as_karl (filename);
1875  }
1876  else if (impl_.get ())
1877  {
1878  result = impl_->save_as_karl (filename);
1879  }
1880 
1881  return result;
1882 }
1883 
1884 inline int64_t
1886  const CheckpointSettings & settings) const
1887 {
1888  int64_t result = 0;
1889 
1890  if (context_)
1891  {
1892  result = context_->save_as_karl (settings);
1893  }
1894  else if (impl_.get ())
1895  {
1896  result = impl_->save_as_karl (settings);
1897  }
1898 
1899  return result;
1900 }
1901 
1902 
1903 inline int64_t
1905  const std::string & filename,
1906  bool reset_modifieds)
1907 {
1908  int64_t result = 0;
1909 
1910  if (context_)
1911  {
1912  result = context_->save_checkpoint (filename);
1913  }
1914  else if (impl_.get ())
1915  {
1916  result = impl_->save_checkpoint (filename, reset_modifieds);
1917  }
1918 
1919  return result;
1920 }
1921 
1922 inline int64_t
1924  CheckpointSettings & settings) const
1925 {
1926  int64_t result = 0;
1927 
1928  if (context_)
1929  {
1930  result = context_->save_checkpoint (settings);
1931  }
1932  else if (impl_.get ())
1933  {
1934  result = impl_->save_checkpoint (settings);
1935  }
1936 
1937  return result;
1938 }
1939 
1940 inline int64_t
1942  const std::string & filename,
1943  bool use_id,
1944  const KnowledgeUpdateSettings & settings)
1945 {
1946  int64_t result = 0;
1947 
1948  if (context_)
1949  {
1950  std::string id;
1951  result = context_->load_context (filename, id, settings);
1952  }
1953  else if (impl_.get ())
1954  {
1955  result = impl_->load_context (filename, use_id, settings);
1956  }
1957 
1958  return result;
1959 }
1960 
1961 inline int64_t
1963 const std::string & filename,
1964 FileHeader & meta,
1965 bool use_id,
1966 const KnowledgeUpdateSettings & settings)
1967 {
1968  int64_t result = 0;
1969 
1970  if (context_)
1971  {
1972  result = context_->load_context (filename, meta, settings);
1973  }
1974  else if (impl_.get ())
1975  {
1976  result = impl_->load_context (filename, meta, use_id, settings);
1977  }
1978 
1979  return result;
1980 }
1981 
1982 inline int64_t
1984 CheckpointSettings & checkpoint_settings,
1985 const KnowledgeUpdateSettings & update_settings)
1986 {
1987  int64_t result = 0;
1988 
1989  if (context_)
1990  {
1991  result = context_->load_context (checkpoint_settings, update_settings);
1992  }
1993  else if (impl_.get ())
1994  {
1995  result = impl_->load_context (checkpoint_settings, update_settings);
1996  }
1997 
1998  return result;
1999 }
2000 
2001 inline void
2003 {
2004  if (context_)
2005  {
2007  }
2008  else if (impl_.get ())
2009  {
2010  impl_->wait_for_change ();
2011  }
2012 }
2013 
2014 inline std::string
2016  const std::string & host)
2017 {
2018  std::string result;
2019 
2020  if (impl_.get ())
2021  {
2022  result = impl_->setup_unique_hostport (host);
2023  }
2024 
2025  return result;
2026 }
2027 
2028 inline int
2030 {
2031  return apply_modified (settings);
2032 }
2033 
2034 } }
2035 
2036 #endif // _MADARA_KNOWLEDGE_BASE_INL_
This class encapsulates an entry in a KnowledgeBase.
std::map< std::string, bool > CopySet
Typedef for set of copyable keys.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
This class provides a distributed knowledge base implementation.
int read_file(const std::string &knowledge_key, const std::string &filename, const EvalSettings &settings=EvalSettings(false, false, true, false, false))
Read a file into the knowledge base.
int apply_modified(const EvalSettings &settings=EvalSettings())
Applies current time and modified to all global variables and tries to send them. ...
Defines a file header which is the default for KaRL checkpointing.
Definition: FileHeader.h:35
size_t remove_transport(size_t index)
Removes a transport.
int64_t save_context(const std::string &filename) const
Saves the context to a file.
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.
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.
VariableReferences save_modifieds(void) const
Saves the list of modified records to use later for resending.
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 unlock(void)
Unlocks the context to allow updates over the network (is only necessary if the context has been expl...
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.
size_t get_num_transports(void)
Gets the number of transports.
VariableReferences save_modifieds(void) const
Saves the list of modified records to use later for resending.
void copy(const ThreadSafeContext &source, const KnowledgeRequirements &settings)
Copies variables and values from source to this context.
std::string debug_modifieds(void) const
Retrieves a stringified list of all modified variables that are ready to send over transport on next ...
int set_index(const VariableReference &variable, size_t index, T &&value, const EvalSettings &settings=EvalSettings(false, false, true, false, false))
Atomically sets the value of an array index to a value.
void lock(void) const
Locks the mutex on this context.
int send_modifieds(const std::string &prefix="KnowledgeBase::send_modifieds", const EvalSettings &settings=EvalSettings())
Sends all modified variables through the attached transports.
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.
std::string get_id(void)
Returns the unique host and ephemeral binding for this Knowlede Base.
void print(unsigned int level) const
Atomically prints all variables and values in the context.
int get_log_level(void)
Gets the log level.
Holds settings for checkpoints to load or save.
void attach_logger(logger::Logger &logger) const
Attaches a logger to be used for printing.
int64_t save_as_karl(const std::string &filename) const
Saves the context to a file as karl assignments, rather than binary.
std::string setup_unique_hostport(const std::string &host="")
Binds to an ephemeral port for unique tie breakers in global ordering.
Provides knowledge logging services to files and terminals.
Definition: GlobalLogger.h:11
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
void lock(void)
Locks the context to prevent updates over the network.
int set_index(const std::string &key, size_t index, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of an array index to a value.
void define_function(const std::string &name, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &), const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Defines an external function.
ssize_t write_file(const std::string &knowledge_key, const std::string &filename)
Write a file from the knowledge base to a specified location.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Retrieves a knowledge value.
std::shared_ptr< KnowledgeBaseImpl > impl_
Pointer to actual implementation, i.e., the "bridge", which is reference counted to automate memory m...
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
void add_modifieds(const VariableReferences &modifieds) const
Adds a list of VariableReferences to the current modified list.
madara::transport::TransportSettings & transport_settings(void)
Returns a non-const reference to the Transport Settings.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
bool clear(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Clears a variable.
A multi-threaded logger for logging to one or more destinations.
Definition: Logger.h:88
void apply_modified(void)
Changes all global variables to modified at current clock.
knowledge::KnowledgeMap to_map_stripped(const std::string &prefix) const
Creates a map with Knowledge Records that begin with the given prefix.
void print_knowledge(unsigned int level=0) const
Deprecated alias for.
void define_function(const std::string &name, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &))
Defines a function.
int64_t save_checkpoint(const std::string &filename, const std::string &id="") const
Saves a checkpoint of a list of changes to a file.
knowledge::KnowledgeRecord evaluate(CompiledExpression expression, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Evaluate a compiled expression.
void attach_logger(logger::Logger &logger) const
Attaches a logger to be used for printing.
ThreadSafeContext * context_
A knowledge base can also be a facade for another knowledge base.
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...
madara::knowledge::KnowledgeRecord wait(const std::string &expression, const WaitSettings &settings=WaitSettings())
Waits for an expression to be non-zero.
void facade_for(ThreadSafeContext &target)
Change the knowledge base to become a facade for another context.
void clear_modifieds(void)
Clear all modifications to the knowledge base.
Holds settings requirements for knowledge, usually in copying.
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:44
void unlock(void) const
Unlocks the mutex on this context.
int64_t save_checkpoint(const std::string &filename, bool reset_modifieds=true)
Saves a checkpoint of a list of changes to a file.
::std::map< std::string, KnowledgeRecord > KnowledgeMap
int64_t save_as_karl(const std::string &filename) const
Saves the context to a file as karl assignments, rather than binary.
An abstract base class defines a simple abstract implementation of an expression tree node...
Definition: ComponentNode.h:35
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)
Expands a statement using variable expansion.
int modify(const EvalSettings &settings=EvalSettings())
Alias for apply_modified.
int set_jpeg(const std::string &key, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings(false, false, true, false, false))
Atomically sets the value of a variable to a JPEG image.
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.
static constexpr struct madara::knowledge::tags::string_t string
int set_file(const std::string &key, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings(false, false, true, false, false))
Atomically sets the value of a variable to an arbitrary string.
void wait_for_change(bool extra_release=false)
Wait for a change to happen to the 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 copy(const KnowledgeBase &source, const KnowledgeRequirements &settings)
Copies variables and values from source to this context.
std::vector< VariableReference > VariableReferences
a vector of variable references
void clear_map(void)
Clears the knowledge base.
void close_transport(void)
Closes the transport mechanism so no dissemination is possible.
void set_quality(const std::string &key, uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to a certain variable from this entity.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
std::string expand_statement(const std::string &statement) const
Expands a string with variable expansion.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
Encapsulates settings for an evaluation statement.
Definition: EvalSettings.h:26
int set(const VariableReference &variable, const std::string &value, const EvalSettings &settings=EvalSettings(false, false, true, false, false))
Atomically sets the value of a variable to a string.
Provides functions and classes for the distributed knowledge base.
madara::knowledge::KnowledgeRecord retrieve_index(const std::string &key, size_t index, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Retrieves a value at a specified index within a knowledge array.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false)) const
Checks if a knowledge location exists in the context.
madara::knowledge::KnowledgeRecord evaluate(const std::string &expression, const EvalSettings &settings=EvalSettings())
Evaluates an expression.
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.
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 load_context(const std::string &filename, bool use_id=true, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true, true, true, false))
Loads the context from a file.
Copyright (c) 2015 Carnegie Mellon University.
int64_t save_as_json(const std::string &filename) const
Saves the context to a file as JSON.
uint32_t set_quality(const std::string &key, uint32_t quality, bool force_update, const KnowledgeReferenceSettings &settings)
Atomically sets quality of this process for a variable.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated.
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 activate_transport(void)
Starts the transport mechanism for dissemination if it is closed.
Encapsulates settings for a wait statement.
Definition: WaitSettings.h:23
size_t attach_transport(madara::transport::Base *transport)
Attaches a transport to the Knowledge Engine.
Settings for applying knowledge updates.
Base class from which all transports must be derived.
Definition: Transport.h:62
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
Provides an interface for external functions into the MADARA KaRL variable settings.
int read_policy(const std::string &policy_key, const std::string &policy_file)
Read a policy into the knowledge base.
int read_file(const std::string &key, const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically reads a file into a variable.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Atomically returns a reference to the variable.
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...
void acquire(void)
Acquires the recursive lock on the knowledge base.
void set_log_level(int level)
Sets the log level.
int64_t save_as_json(const std::string &filename) const
Saves the context to a file as JSON.
void print(unsigned int level=0) const
Prints all knowledge variables and values in the context.
void set_log_level(int level)
Sets the log level.
void use(ThreadSafeContext &original)
Refer to and use another knowledge base&#39;s context.
void wait_for_change(void)
Wait for a change to happen to the context (e.g., from transports)
void release(void)
Releases a recursive lock on the knowledge base.
void reset_modified(void)
Reset all variables to be unmodified.