1 #ifndef MADARA_THREADSAFECONTEXT_H 2 #define MADARA_THREADSAFECONTEXT_H 11 #include "ace/Guard_T.h" 12 #include "ace/Recursive_Thread_Mutex.h" 13 #include "ace/Condition_Recursive_Thread_Mutex.h" 14 #include "ace/Synch.h" 18 #ifndef ACE_LACKS_PRAGMA_ONCE 26 #include "madara/MADARA_export.h" 27 #include "madara/LockType.h" 38 #include "madara_jni.h" 41 #ifdef _MADARA_PYTHON_CALLBACKS_ 42 #include "boost/python/object.hpp" 50 class CompositeArrayReference;
67 typedef std::map <std::string, bool>
CopySet;
169 template<
typename T, MethodType<T> Get,
typename K>
173 auto rec = with (std::forward<K>(key), settings);
175 return (rec->*Get) ();
183 template<
typename T, ConstMethodType<T> Get,
typename K>
187 auto rec = with (std::forward<K>(key), settings);
189 return (rec->*Get) ();
203 return get_shared<std::string, &KnowledgeRecord::share_string>(key, settings);
214 return get_shared<std::string, &KnowledgeRecord::share_string>(key, settings);
225 return get_shared<std::string, &KnowledgeRecord::take_string>(key, settings);
236 return get_shared<std::string, &KnowledgeRecord::take_string>(key, settings);
243 std::shared_ptr<std::vector<KnowledgeRecord::Integer>>
248 return get_shared<std::vector<KnowledgeRecord::Integer>,
256 std::shared_ptr<std::vector<KnowledgeRecord::Integer>>
261 return get_shared<std::vector<KnowledgeRecord::Integer>,
269 std::shared_ptr<std::vector<KnowledgeRecord::Integer>>
274 return get_shared<std::vector<KnowledgeRecord::Integer>,
282 std::shared_ptr<std::vector<KnowledgeRecord::Integer>>
287 return get_shared<std::vector<KnowledgeRecord::Integer>,
295 std::shared_ptr<std::vector<double>>
300 return get_shared<std::vector<double>,
308 std::shared_ptr<std::vector<double>>
313 return get_shared<std::vector<double>,
321 std::shared_ptr<std::vector<double>>
326 return get_shared<std::vector<double>,
334 std::shared_ptr<std::vector<double>>
339 return get_shared<std::vector<double>,
347 std::shared_ptr<std::vector<unsigned char>>
352 return get_shared<std::vector<unsigned char>,
360 std::shared_ptr<std::vector<unsigned char>>
365 return get_shared<std::vector<unsigned char>,
373 std::shared_ptr<std::vector<unsigned char>>
378 return get_shared<std::vector<unsigned char>,
386 std::shared_ptr<std::vector<unsigned char>>
391 return get_shared<std::vector<unsigned char>,
467 const char * value,
size_t size,
480 const char * value,
size_t size,
493 const unsigned char * value,
size_t size,
506 const unsigned char * value,
size_t size,
519 const unsigned char * value,
size_t size,
532 const unsigned char * value,
size_t size,
545 const char * value,
size_t size,
558 const char * value,
size_t size,
572 size_t index, T&& value,
586 size_t index, T&& value,
601 size_t index, T&& value,
734 uint32_t quality, uint64_t clock,
750 uint32_t quality, uint64_t clock,
766 uint32_t quality, uint64_t clock,
780 int update_record_from_external (
795 int update_record_from_external (
817 uint32_t get_write_quality (
const std::string & key,
830 uint32_t quality,
bool force_update,
836 void set_changed (
void);
844 void set_write_quality (
const std::string & key, uint32_t quality,
888 void reset_modified (
void);
894 void reset_checkpoint (
void)
const;
899 void apply_modified (
void);
985 void wait_for_change (
bool extra_release =
false);
1052 bool delete_expression (
const std::string & expression);
1079 void print (
unsigned int level)
const;
1087 void print (
const std::string & statement,
unsigned int level)
const;
1094 void clear (
bool erase =
false);
1100 void lock (
void)
const;
1105 void unlock (
void)
const;
1132 uint64_t set_clock (uint64_t clock);
1151 uint64_t get_clock (
void)
const;
1159 uint64_t get_clock (
1168 void signal (
bool lock =
true)
const;
1212 const CopySet & copy_set = CopySet (),
1213 bool clean_copy =
false);
1216 #ifndef _MADARA_NO_KARL_ 1250 #ifdef _MADARA_JAVA_ 1257 void define_function (
const std::string & name, jobject callable,
1262 #ifdef _MADARA_PYTHON_CALLBACKS_ 1269 void define_function (
const std::string & name, boost::python::object callable,
1331 #endif // _MADARA_NO_KARL_ 1358 const std::string & key_val_delimiter =
"=")
const;
1378 std::vector <KnowledgeRecord> & target);
1403 std::map <std::string, knowledge::KnowledgeRecord> & target);
1454 std::vector <std::string> & next_keys,
1455 std::map <std::string, knowledge::KnowledgeRecord> & result,
1490 int64_t save_context (
const std::string & filename,
1507 int64_t save_as_json (
const std::string & filename)
const;
1521 int64_t save_as_karl (
const std::string & filename)
const;
1540 int64_t load_context (
const std::string & filename,
1555 int64_t load_context (
const std::string & filename,
1581 int64_t save_checkpoint (
const std::string & filename,
1593 int64_t save_checkpoint (
1633 void mark_to_send_unsafe (
const std::string & key,
1644 void mark_to_checkpoint_unsafe (
const std::string & key,
1654 void mark_and_signal (
const char * name,
1658 template<
typename... Args>
1663 template<
typename T>
1665 size_t index, T&& value,
1669 std::pair<KnowledgeMap::const_iterator, KnowledgeMap::const_iterator>
1670 get_prefix_range(
const std::string &prefix)
const;
1672 std::pair<KnowledgeMap::iterator, KnowledgeMap::iterator>
This class encapsulates an entry in a KnowledgeBase.
std::map< std::string, bool > CopySet
Typedef for set of copyable keys.
This class provides a distributed knowledge base implementation.
madara::knowledge::KnowledgeMap map_
Hash table containing variable names and values.
std::shared_ptr< std::vector< double > > share_doubles() const
Returns a shared_ptr, sharing with the internal one.
std::shared_ptr< T >(KnowledgeRecord::*)(void) MethodType
std::shared_ptr< std::vector< unsigned char > > share_binary() const
Returns a shared_ptr, sharing with the internal one.
Defines a terminal node of that references the current value stored in a variable.
std::vector< std::string > expansion_splitters_
This class stores a function definition.
MADARA_CONDITION_TYPE changed_
std::shared_ptr< std::vector< double > > share_doubles(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
std::shared_ptr< std::vector< Integer > > share_integers() const
Returns a shared_ptr, sharing with the internal one.
MADARA_Export int read_file(const std::string &filename, void *&buffer, size_t &size, bool add_zero_char=false)
Reads a file into a provided void pointer.
std::shared_ptr< std::vector< unsigned char > > share_binary(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
This class stores variables and their values for use by any entity needing state information in a thr...
std::shared_ptr< std::vector< double > > take_doubles(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
Holds settings for checkpoints to load or save.
std::shared_ptr< T >(KnowledgeRecord::*)(void) const ConstMethodType
Provides knowledge logging services to files and terminals.
Optimized reference to a variable within the knowledge base.
Compiled, optimized KaRL logic.
std::vector< KnowledgeRecord > FunctionArguments
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > take_integers(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
A multi-threaded logger for logging to one or more destinations.
std::shared_ptr< std::string > take_string(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, while resetting this record to empty.
std::shared_ptr< std::vector< double > > take_doubles()
Returns a shared_ptr, while resetting this record to empty.
std::shared_ptr< std::string > take_string(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, while resetting this record to empty.
std::shared_ptr< std::vector< double > > take_doubles(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
KnowledgeMap & get_map_unsafe(void)
NOT THREAD SAFE!
std::shared_ptr< T > get_shared(K &&key, const KnowledgeReferenceSettings &settings)
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > take_integers(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > share_integers(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
FunctionMap functions_
map of function names to functions
Holds settings requirements for knowledge, usually in copying.
void set_log_level(int level)
Sets the log level.
Parses incoming expression strings into a parse tree and generates an expression tree from the parse ...
::std::map< std::string, KnowledgeRecord * > KnowledgeRecords
std::shared_ptr< std::vector< unsigned char > > take_binary()
Returns a shared_ptr, while resetting this record to empty.
::std::map< std::string, KnowledgeRecord > KnowledgeMap
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > share_integers(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
An abstract base class defines a simple abstract implementation of an expression tree node...
knowledge::KnowledgeRecords local_changed_map_
std::shared_ptr< std::vector< Integer > > take_integers()
Returns a shared_ptr, while resetting this record to empty.
std::shared_ptr< std::string > share_string(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
int get_log_level(void)
Gets the log level.
std::vector< VariableReference > VariableReferences
a vector of variable references
std::map< std::string, Function > FunctionMap
MADARA_Export bool exists(const char *originator, uint64_t clock, uint32_t update_number, OriginatorFragmentMap &map)
Checks if a fragment already exists within a fragment map.
knowledge::KnowledgeRecords changed_map_
logger::Logger * logger_
Logger for printing.
std::shared_ptr< std::vector< unsigned char > > take_binary(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
Provides functions and classes for the distributed knowledge base.
std::shared_ptr< T > get_shared(K &&key, const KnowledgeReferenceSettings &settings) const
std::shared_ptr< std::vector< unsigned char > > share_binary(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
std::shared_ptr< std::string > share_string(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
std::shared_ptr< std::vector< unsigned char > > take_binary(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
Settings for applying knowledge updates.
const KnowledgeMap & get_map_unsafe(void) const
NOT THREAD SAFE!
Provides an interface for external functions into the MADARA KaRL variable settings.
madara::expression::Interpreter * interpreter_
KaRL interpreter.
std::vector< std::string > PrefixVector
Typedef for vector of prefixes to use for a generic task.
Defines a terminal node of that references the current value stored in a variable.
std::shared_ptr< std::vector< double > > share_doubles(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.