MADARA
3.4.1
|
This class stores variables and their values for use by any entity needing state information in a thread safe way. More...
#include <ThreadSafeContext.h>
Public Member Functions | |
ThreadSafeContext () | |
Constructor. More... | |
~ThreadSafeContext (void) | |
Destructor. More... | |
void | add_logger (const std::string &filename) |
Adds a file to the logger. More... | |
void | add_modifieds (const VariableReferences &modifieds) const |
Adds a list of VariableReferences to the current modified list. More... | |
void | apply_modified (void) |
Changes all global variables to modified at current clock. More... | |
void | attach_logger (logger::Logger &logger) const |
Attaches a logger to be used for printing. More... | |
std::unique_ptr< BaseStreamer > | attach_streamer (std::unique_ptr< BaseStreamer > streamer) |
Attach a streaming provider object, inherited from BaseStreamer, such as CheckpointStreamer. More... | |
template<typename Callable > | |
auto | cinvoke (const std::string &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >())) |
template<typename Callable > | |
auto | cinvoke (const VariableReference &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >())) |
void | clear (bool erase=false) |
Clears the context. More... | |
bool | clear (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Clears a variable. More... | |
bool | clear (const VariableReference &variable) |
Clears a variable. More... | |
CompiledExpression | compile (const std::string &expression) |
Compiles a KaRL expression into an expression tree. More... | |
void | copy (const ThreadSafeContext &source, const CopySet ©_set=CopySet(), bool clean_copy=false, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Copies variables and values from source to this context. More... | |
void | copy (const ThreadSafeContext &source, const KnowledgeRequirements &reqs, const KnowledgeUpdateSettings &settings) |
Copies variables and values from source to this context. More... | |
std::string | debug_modifieds (void) const |
Retrieves a stringified list of all modified variables that are ready to send over transport on next send_modifieds call. More... | |
madara::knowledge::KnowledgeRecord | dec (const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically decrements the value of the variable. More... | |
madara::knowledge::KnowledgeRecord | dec (const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically decrements the value of the variable. More... | |
void | define_function (const std::string &name, boost::python::object callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines a named python function. More... | |
void | define_function (const std::string &name, const CompiledExpression &expression, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines a MADARA KaRL function. More... | |
void | define_function (const std::string &name, const std::string &expression, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines a MADARA KaRL function. More... | |
void | define_function (const std::string &name, jobject callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines a named java function. More... | |
void | define_function (const std::string &name, knowledge::KnowledgeRecord(*func)(const char *, FunctionArguments &, Variables &), const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines a named function that can distinguish the name it was called with in MADARA. More... | |
void | define_function (const std::string &name, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &), const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines an external function. More... | |
bool | delete_expression (const std::string &expression) |
Deletes the expression from the interpreter cache. More... | |
void | delete_prefix (const std::string &prefix, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Deletes keys starting with the given prefix. More... | |
bool | delete_variable (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Deletes the key. More... | |
bool | delete_variable (const VariableReference &var, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Deletes the variable. More... | |
void | delete_variables (KnowledgeMap::iterator begin, KnowledgeMap::iterator end, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Deletes variables. More... | |
knowledge::KnowledgeRecord | evaluate (CompiledExpression expression, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Evaluate a compiled expression. More... | |
knowledge::KnowledgeRecord | evaluate (expression::ComponentNode *root, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Evaluate a component node-rooted tree. More... | |
KnowledgeRecord | evaluate_file (CheckpointSettings &checkpoint_settings, const KnowledgeUpdateSettings &update_settings=KnowledgeUpdateSettings(true, true, true, false)) |
Loads and evaluates a karl script from a file. More... | |
bool | exists (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically checks to see if a variable already exists. More... | |
bool | exists (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false)) const |
Checks if a knowledge variable exists in the context. More... | |
std::string | expand_statement (const std::string &statement) const |
Expands a string with variable expansion. More... | |
std::string | file_to_string (CheckpointSettings &checkpoint_settings) |
Loads and returns a karl script from a file with encode/decode. More... | |
template<typename Func > | |
void | for_each (Func &&func) const |
Call given Callable on each element in this context. More... | |
madara::knowledge::KnowledgeRecord | get (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns the current value of a variable. More... | |
madara::knowledge::KnowledgeRecord | get (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns the current value of a variable. More... | |
madara::knowledge::KnowledgeRecord | get_actual (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns the underlying value of a variable, including history. More... | |
madara::knowledge::KnowledgeRecord | get_actual (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns the underlying value of a variable, including history. More... | |
uint64_t | get_clock (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically gets the Lamport clock of a variable. More... | |
uint64_t | get_clock (void) const |
Atomically gets the Lamport clock. More... | |
const VariableReferenceMap & | get_local_modified (void) const |
Retrieves a list of modified local variables. More... | |
int | get_log_level (void) |
Gets the log level. More... | |
logger::Logger & | get_logger (void) const |
Gets the logger used for information printing. More... | |
KnowledgeMap & | get_map_unsafe (void) |
NOT THREAD SAFE! More... | |
const KnowledgeMap & | get_map_unsafe (void) const |
NOT THREAD SAFE! More... | |
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. More... | |
const VariableReferenceMap & | get_modifieds (void) const |
Retrieves a list of modified variables. More... | |
KnowledgeMap | get_modifieds_current (const std::map< std::string, bool > &send_list, bool reset=true) |
Retrieves the current modifieds map. More... | |
uint32_t | get_quality (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Atomically gets quality of a variable. More... | |
KnowledgeRecord * | get_record (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Retrieves a knowledge record from the key. More... | |
VariableReference | get_ref (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Atomically returns a reference to the variable. More... | |
VariableReference | get_ref (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns a reference to the variable. More... | |
uint32_t | get_write_quality (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Atomically gets write quality of this process for a variable. More... | |
madara::knowledge::KnowledgeRecord | inc (const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically increments the value of the variable. More... | |
madara::knowledge::KnowledgeRecord | inc (const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically increments the value of the variable. More... | |
uint64_t | inc_clock (const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically increments the Lamport clock and returns the new clock time (intended for sending knowledge updates). More... | |
uint64_t | inc_clock (const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically increments the Lamport clock of a variable and returns the new clock time (intended for sending knowledge updates). More... | |
template<typename Callable > | |
auto | invoke (const std::string &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >())) |
template<typename Callable > | |
auto | invoke (const std::string &key, Callable &&callable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >())) |
template<typename Callable > | |
auto | invoke (const VariableReference &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >())) |
template<typename Callable > | |
auto | invoke (const VariableReference &key, Callable &&callable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >())) |
int64_t | load_context (CheckpointSettings &checkpoint_settings, const KnowledgeUpdateSettings &update_settings=KnowledgeUpdateSettings(true, true, true, false)) |
Loads the context from a file. More... | |
int64_t | load_context (const std::string &filename, FileHeader &meta, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true, true, true, false)) |
Loads the context from a file. More... | |
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. More... | |
void | lock (void) const |
Locks the mutex on this context. More... | |
void | mark_modified (const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Changes global variables to modified at current clock for the purposes of sending or checkpointing knowledge (globals and locals respectively) More... | |
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 globals and locals respectively) More... | |
void | mark_to_checkpoint (const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Changes variable to modified at current clock for the purposes of checkpointing (even if it is a global). More... | |
void | mark_to_checkpoint (const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Changes variable reference to modified at current clock for the purposes of checkpointing (even if it is a global). More... | |
void | mark_to_send (const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Changes variable to modified at current clock, and queues it to send, even if it is a local that would not ordinarily be sent. More... | |
void | mark_to_send (const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Changes variable reference to modified at current clock, and queues it to send, even if it is a local that would not ordinarily be sent. More... | |
void | print (const std::string &statement, unsigned int level) const |
Atomically Print a statement, similar to printf (variable expansions allowed) e.g., input = "MyVar{.id} = {MyVar{.id}}\n";. More... | |
void | print (unsigned int level) const |
Atomically prints all variables and values in the context. More... | |
int | read_file (const std::string &key, const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically reads a file into a variable. More... | |
int | read_file (const VariableReference &variable, const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically reads a file into a variable. More... | |
void | reset_checkpoint (void) const |
Reset all checkpoint variables in the modified lists. More... | |
void | reset_modified (const std::string &key) |
Resets a variable to unmodified. More... | |
void | reset_modified (void) |
Reset all variables to be unmodified. More... | |
Function * | retrieve_function (const std::string &name, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Retrieves an external function. More... | |
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. More... | |
KnowledgeRecord | retrieve_index (const VariableReference &variable, size_t index, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Retrieves a value at a specified index within a knowledge array. More... | |
int64_t | save_as_json (const CheckpointSettings &settings) const |
Saves the context to a file as JSON. More... | |
int64_t | save_as_json (const std::string &filename) const |
Saves the context to a file as JSON. More... | |
int64_t | save_as_karl (const CheckpointSettings &settings) const |
Saves the context to a file as karl assignments, rather than binary. More... | |
int64_t | save_as_karl (const std::string &filename) const |
Saves the context to a file as karl assignments, rather than binary. More... | |
int64_t | save_checkpoint (const CheckpointSettings &settings) const |
Saves a checkpoint of a list of changes to a file. More... | |
int64_t | save_checkpoint (const std::string &filename, const std::string &id="") const |
Saves a checkpoint of a list of changes to a file. More... | |
int64_t | save_context (const CheckpointSettings &settings) const |
Saves the context to a file. More... | |
int64_t | save_context (const std::string &filename, const std::string &id="") const |
Saves the context to a file. More... | |
VariableReferences | save_modifieds (void) const |
Saves the list of modified records to use later for resending. More... | |
template<typename T > | |
int | set (const std::string &key, const T *value, uint32_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to an array. More... | |
template<typename T > | |
int | set (const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to the specific record. More... | |
template<typename T > | |
int | set (const VariableReference &variable, const T *value, uint32_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to an array. More... | |
template<typename T > | |
int | set (const VariableReference &variable, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to an array. More... | |
void | set_changed (void) |
Force a change to be registered, waking up anyone waiting on entry. More... | |
uint64_t | set_clock (const std::string &key, uint64_t clock, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Atomically sets the Lamport clock of a variable and returns the new clock time (intended for sending knowledge updates). More... | |
uint64_t | set_clock (uint64_t clock) |
Atomically sets the lamport clock. More... | |
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. More... | |
int | set_file (const VariableReference &variable, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to an arbitrary string. More... | |
int | set_if_unequal (const std::string &key, const std::string &value, uint32_t quality, uint64_t clock, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets if the variable value will be different. More... | |
int | set_if_unequal (const std::string &key, double value, uint32_t quality, uint64_t clock, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets if the variable value will be different. More... | |
int | set_if_unequal (const std::string &key, madara::knowledge::KnowledgeRecord::Integer value, uint32_t quality, uint64_t clock, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets if the variable value will be different. More... | |
template<typename T > | |
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. More... | |
template<typename T > | |
int | set_index (const VariableReference &variable, size_t index, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of an array index to a value. More... | |
template<typename T > | |
int | set_index_unsafe (const VariableReference &variable, size_t index, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
NON-Atomically sets the value of an array index to a value. More... | |
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. More... | |
int | set_jpeg (const VariableReference &variable, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to a JPEG image. More... | |
void | set_log_level (int level) |
Sets the log level. More... | |
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. More... | |
int | set_text (const std::string &key, const char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to an XML string. More... | |
int | set_text (const VariableReference &variable, const char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to a text file's contents. More... | |
template<typename T > | |
int | set_unsafe (const VariableReference &variable, const T *array, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
NON-Atomically sets the value of a variable to the specific array. More... | |
template<typename T > | |
int | set_unsafe (const VariableReference &variable, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
NON-Atomically sets the value of a variable to the specific value. More... | |
void | set_write_quality (const std::string &key, uint32_t quality, const KnowledgeReferenceSettings &settings) |
Atomically sets write quality of this process for a variable. More... | |
int | set_xml (const std::string &key, const char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to an XML string. More... | |
int | set_xml (const VariableReference &variable, const char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to an XML string. More... | |
std::shared_ptr< const std::vector< unsigned char > > | share_binary (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< const std::vector< unsigned char > > | share_binary (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< const std::vector< double > > | share_doubles (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< const std::vector< double > > | share_doubles (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< const std::vector< KnowledgeRecord::Integer > > | share_integers (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< const std::vector< KnowledgeRecord::Integer > > | share_integers (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< const std::string > | share_string (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< const std::string > | share_string (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
void | signal (bool lock=true) const |
Signals that this thread is done with the context. More... | |
knowledge::KnowledgeMap | to_map (const std::string &prefix) const |
Creates a map with Knowledge Records that begin with the given prefix. More... | |
size_t | to_map (const std::string &prefix, const std::string &delimiter, const std::string &suffix, std::vector< std::string > &next_keys, std::map< std::string, knowledge::KnowledgeRecord > &result, bool just_keys) |
Fills a variable map with list of keys according to a matching prefix, suffix, and delimiter hierarchy. More... | |
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. More... | |
knowledge::KnowledgeMap | to_map_stripped (const std::string &prefix) const |
Creates a map with Knowledge Records that begin with the given prefix. More... | |
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 function. More... | |
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 integer values. More... | |
bool | try_lock (void) const |
Locks the mutex on this context. More... | |
void | unlock (void) const |
Unlocks the mutex on this context. More... | |
int | update_record_from_external (const std::string &key, const knowledge::KnowledgeRecord &rhs, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true)) |
Atomically sets if the variable value meets update conditions. More... | |
int | update_record_from_external (const VariableReference &target, const knowledge::KnowledgeRecord &new_value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true)) |
Atomically sets if the variable value meets update conditions. More... | |
void | wait_for_change (bool extra_release=false) |
Wait for a change to happen to the context. More... | |
Private Types | |
template<typename T > | |
using | ConstMethodType = std::shared_ptr< T >(KnowledgeRecord::*)(void) const |
template<typename T > | |
using | MethodType = std::shared_ptr< T >(KnowledgeRecord::*)(void) |
Private Member Functions | |
std::pair< KnowledgeMap::iterator, KnowledgeMap::iterator > | get_prefix_range (const std::string &prefix) |
std::pair< KnowledgeMap::const_iterator, KnowledgeMap::const_iterator > | get_prefix_range (const std::string &prefix) const |
template<typename T , MethodType< T > Get, typename K > | |
std::shared_ptr< T > | get_shared (K &&key, const KnowledgeReferenceSettings &settings) |
template<typename T , ConstMethodType< T > Get, typename K > | |
std::shared_ptr< T > | get_shared (K &&key, const KnowledgeReferenceSettings &settings) const |
void | mark_and_signal (VariableReference ref, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
method for marking a record modified and signaling changes More... | |
void | mark_to_checkpoint_unsafe (VariableReference ref, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Changes variable to modified at current clock for the purposes of checkpointing. More... | |
void | mark_to_send_unsafe (VariableReference ref, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Changes variable to modified at current clock, and queues it to send, even if it is a local that would not ordinarily be sent. More... | |
template<typename T > | |
int | set_index_unsafe_impl (const VariableReference &variable, size_t index, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
template<typename... Args> | |
int | set_unsafe_impl (const VariableReference &variable, const KnowledgeUpdateSettings &settings, Args &&... args) |
madara::knowledge::KnowledgeRecord * | with (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Atomically returns a reference to the variable. More... | |
const madara::knowledge::KnowledgeRecord * | with (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns a reference to the variable. More... | |
madara::knowledge::KnowledgeRecord * | with (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Atomically returns the value of a variable. More... | |
const madara::knowledge::KnowledgeRecord * | with (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns the value of a variable. More... | |
Private Attributes | |
MADARA_CONDITION_TYPE | changed_ |
VariableReferenceMap | changed_map_ |
uint64_t | clock_ |
std::vector< std::string > | expansion_splitters_ |
FunctionMap | functions_ |
map of function names to functions More... | |
madara::expression::Interpreter * | interpreter_ |
KaRL interpreter. More... | |
VariableReferenceMap | local_changed_map_ |
logger::Logger * | logger_ |
Logger for printing. More... | |
madara::knowledge::KnowledgeMap | map_ |
Hash table containing variable names and values. More... | |
MADARA_LOCK_TYPE | mutex_ |
std::unique_ptr< BaseStreamer > | streamer_ = nullptr |
Streaming provider for saving all updates. More... | |
Friends | |
class | expression::CompositeArrayReference |
class | expression::VariableNode |
class | KnowledgeBaseImpl |
This class stores variables and their values for use by any entity needing state information in a thread safe way.
Definition at line 75 of file ThreadSafeContext.h.
|
private |
Definition at line 198 of file ThreadSafeContext.h.
|
private |
Definition at line 183 of file ThreadSafeContext.h.
madara::knowledge::ThreadSafeContext::ThreadSafeContext | ( | ) |
Constructor.
Definition at line 31 of file ThreadSafeContext.cpp.
madara::knowledge::ThreadSafeContext::~ThreadSafeContext | ( | void | ) |
Destructor.
Definition at line 49 of file ThreadSafeContext.cpp.
|
inline |
Adds a file to the logger.
filename | the file to add to logger |
Definition at line 1220 of file ThreadSafeContext.inl.
|
inline |
Adds a list of VariableReferences to the current modified list.
modifieds | a list of variables to add to modified list |
Definition at line 1132 of file ThreadSafeContext.inl.
|
inline |
Changes all global variables to modified at current clock.
Changes all global variables to modified at current time.
Definition at line 1161 of file ThreadSafeContext.inl.
|
inline |
Attaches a logger to be used for printing.
logger | the logger the context should lose |
Definition at line 770 of file ThreadSafeContext.inl.
|
inline |
Attach a streaming provider object, inherited from BaseStreamer, such as CheckpointStreamer.
Once attached, all updates to records in this ThreadSafeContext will be provided to the streamer. May pass nullptr to stop streaming.
streamer | the new streamer to attach |
Definition at line 1537 of file ThreadSafeContext.h.
|
inline |
Definition at line 1632 of file ThreadSafeContext.h.
|
inline |
Definition at line 1641 of file ThreadSafeContext.h.
|
inline |
Clears the context.
erase | If true, completely erase keys. If false, reset knowledge |
Definition at line 838 of file ThreadSafeContext.inl.
|
inline |
Clears a variable.
This is much safer than
key | unique identifier of the variable |
settings | settings for referring to variables |
Definition at line 506 of file ThreadSafeContext.inl.
|
inline |
Clears a variable.
This is much safer than
variable | reference to a variable ( |
Definition at line 535 of file ThreadSafeContext.inl.
CompiledExpression madara::knowledge::ThreadSafeContext::compile | ( | const std::string & | expression | ) |
Compiles a KaRL expression into an expression tree.
expression | expression to compile |
exceptions::KarlException | failure during compile/evaluate |
Definition at line 1057 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::copy | ( | const ThreadSafeContext & | source, |
const CopySet & | copy_set = CopySet() , |
||
bool | clean_copy = false , |
||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Copies variables and values from source to this context.
PERFORMANCE NOTES: worst case depends on size of copy_set. If empty, performance is always O (n), where n is number of variables in the source context. If copy_set is not empty, then performance is O (m log n) where m is the number of variables in copy_set and n is number of variables in the source context.
Note that this is a deep copy due to the fact that source and destination are expected to have their own thread management (ref-counted variables can be problematic if shallow copy).
source | the source context to copy from |
copy_set | a map of variables that should be copied. If empty, then everything is copied. If not empty, only the supplied variables will be copied. |
clean_copy | if true, clear the destination context (this) before copying. |
settings | settings for appplying updates to context |
Definition at line 1556 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::copy | ( | const ThreadSafeContext & | source, |
const KnowledgeRequirements & | reqs, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
Copies variables and values from source to this context.
PERFORMANCE NOTES: predicates with prefixes can limit copying to O(log n). predices with suffixes and no prefix force O(n) copy cost since all records could fit requirements
source | the source context to copy from |
reqs | requirements that must be met |
settings | settings for appplying updates to context |
Definition at line 1434 of file ThreadSafeContext.cpp.
|
inline |
Retrieves a stringified list of all modified variables that are ready to send over transport on next send_modifieds call.
Definition at line 991 of file ThreadSafeContext.inl.
|
inline |
Atomically decrements the value of the variable.
key | unique identifier of the variable |
settings | settings for applying the update |
Definition at line 464 of file ThreadSafeContext.inl.
|
inline |
Atomically decrements the value of the variable.
variable | reference to a variable ( |
settings | settings for applying the update |
Definition at line 645 of file ThreadSafeContext.inl.
void madara::knowledge::ThreadSafeContext::define_function | ( | const std::string & | name, |
boost::python::object | callable, | ||
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Defines a named python function.
name | name of the function |
callable | external python function to call with this name |
settings | settings for referring to variables |
Definition at line 976 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::define_function | ( | const std::string & | name, |
const CompiledExpression & | expression, | ||
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Defines a MADARA KaRL function.
name | name of the function |
expression | KaRL function body |
settings | settings for referring to variables |
Definition at line 1008 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::define_function | ( | const std::string & | name, |
const std::string & | expression, | ||
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Defines a MADARA KaRL function.
name | name of the function |
expression | KaRL function body |
settings | settings for referring to variables |
Definition at line 1001 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::define_function | ( | const std::string & | name, |
jobject | callable, | ||
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Defines a named java function.
name | name of the function |
callable | external java object to call with this name |
settings | settings for referring to variables |
Definition at line 951 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::define_function | ( | const std::string & | name, |
knowledge::KnowledgeRecord(*)(const char *, FunctionArguments &, Variables &) | func, | ||
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Defines a named function that can distinguish the name it was called with in MADARA.
name | name of the function |
func | external function to call with this name |
settings | settings for referring to variables |
void madara::knowledge::ThreadSafeContext::define_function | ( | const std::string & | name, |
knowledge::KnowledgeRecord(*)(FunctionArguments &, Variables &) | func, | ||
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Defines an external function.
name | name of the function |
func | external function to call with this name |
settings | settings for referring to variables |
Definition at line 901 of file ThreadSafeContext.cpp.
|
inline |
Deletes the expression from the interpreter cache.
expression | the KaRL logic in the interpreter context |
Definition at line 497 of file ThreadSafeContext.inl.
void madara::knowledge::ThreadSafeContext::delete_prefix | ( | const std::string & | prefix, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Deletes keys starting with the given prefix.
prefix | string which starts all variables to delete |
settings | settings for referring to variables |
Definition at line 1300 of file ThreadSafeContext.cpp.
|
inline |
Deletes the key.
Note that this is extremely unsafe. You can cause illegal operations in the knowledge base by using this method and trying to access this variable again with 1) a VariableReference, 2) a
key | unique identifier of the variable |
settings | settings for referring to variables |
Definition at line 556 of file ThreadSafeContext.inl.
|
inline |
Deletes the variable.
Note that this is extremely unsafe. You can cause illegal operations in the knowledge base by using this method and trying to access this variable again with 1) a VariableReference, 2) a
var | VariableReference to variable. Do not use object this after calling this method! |
settings | settings for referring to variables |
Definition at line 585 of file ThreadSafeContext.inl.
|
inline |
Deletes variables.
Note that this is extremely unsafe. You can cause illegal operations in the knowledge base by using this method and trying to access this variable again with 1) a VariableReference, 2) a
begin | iterator to variables inside the map |
end | iterator to variables inside the map |
settings | settings for referring to variables |
Definition at line 599 of file ThreadSafeContext.inl.
KnowledgeRecord madara::knowledge::ThreadSafeContext::evaluate | ( | CompiledExpression | expression, |
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Evaluate a compiled expression.
Please note that if you update any variables here, they will not be sent through any transports until you call through the KnowledgeBase.
expression | A compiled expressio to run. |
settings | settings for applying the update |
exceptions::KarlException | failure during compile/evaluate |
Definition at line 1072 of file ThreadSafeContext.cpp.
KnowledgeRecord madara::knowledge::ThreadSafeContext::evaluate | ( | expression::ComponentNode * | root, |
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Evaluate a component node-rooted tree.
Please note that if you update any variables here, they will not be sent through any transports until you call through the KnowledgeBase.
root | Root of an expression tree |
settings | settings for applying the update |
exceptions::KarlException | failure during compile/evaluate |
Definition at line 1079 of file ThreadSafeContext.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::evaluate_file | ( | CheckpointSettings & | checkpoint_settings, |
const KnowledgeUpdateSettings & | update_settings = KnowledgeUpdateSettings( true, true, true, false) |
||
) |
Loads and evaluates a karl script from a file.
checkpoint_settings | checkpoint settings to load |
update_settings | settings for applying the updates |
exceptions::MemoryException | not enough buffer to encode |
Definition at line 2174 of file ThreadSafeContext.cpp.
|
inline |
Atomically checks to see if a variable already exists.
key | unique identifier of the variable |
settings | settings for referring to variables |
Definition at line 611 of file ThreadSafeContext.inl.
|
inline |
Checks if a knowledge variable exists in the context.
variable | knowledge variable reference |
settings | settings for referring to knowledge variables |
Definition at line 237 of file ThreadSafeContext.inl.
std::string madara::knowledge::ThreadSafeContext::expand_statement | ( | const std::string & | statement | ) | const |
Expands a string with variable expansion.
Expand a string with variable expansions.
For instance, if .id == 5, and a statement of "MyVar{.id} = {.id} * 30" then then expanded statement would be "MyVar5 = 5 * 30".
statement | statement to expand. Useful for printing. |
This is a generic form of the function found in VariableNode, which is optimized to never change keys.
Definition at line 844 of file ThreadSafeContext.cpp.
std::string madara::knowledge::ThreadSafeContext::file_to_string | ( | CheckpointSettings & | checkpoint_settings | ) |
Loads and returns a karl script from a file with encode/decode.
checkpoint_settings | checkpoint settings to load |
exceptions::MemoryException | not enough buffer to encode |
Definition at line 2194 of file ThreadSafeContext.cpp.
|
inline |
Call given Callable on each element in this context.
Note that the context will be locked for the entire duration of this iteration. The Callable must accept one argument, a const std::pair<const std::string, KnowledgeRecord>&
, and it's return value is ignored.
Func | a callable type as described above |
func | the callable object; either function pointer or functor |
Definition at line 1659 of file ThreadSafeContext.h.
|
inline |
Atomically returns the current value of a variable.
key | unique identifier of the variable |
settings | the settings for referring to variables |
Definition at line 27 of file ThreadSafeContext.inl.
|
inline |
Atomically returns the current value of a variable.
variable | reference to a variable ( |
settings | the settings for referring to variables |
Definition at line 63 of file ThreadSafeContext.inl.
|
inline |
Atomically returns the underlying value of a variable, including history.
If record has no history, equivalent to get.
key | unique identifier of the variable |
settings | the settings for referring to variables |
Definition at line 99 of file ThreadSafeContext.inl.
|
inline |
Atomically returns the underlying value of a variable, including history.
If record has no history, equivalent to get.
variable | reference to a variable ( |
settings | the settings for referring to variables |
Definition at line 118 of file ThreadSafeContext.inl.
|
inline |
Atomically gets the Lamport clock of a variable.
get the lamport clock for a particular variable
key | unique identifier of the variable |
settings | settings for reading the variable |
Definition at line 777 of file ThreadSafeContext.inl.
|
inline |
Atomically gets the Lamport clock.
get the lamport clock (updates with lamport clocks lower than our current clock get discarded)
Definition at line 758 of file ThreadSafeContext.inl.
|
inline |
Retrieves a list of modified local variables.
Return list of variables that have been modified.
Useful for building a comprehensive checkpoint.
Definition at line 1144 of file ThreadSafeContext.inl.
|
inline |
Gets the log level.
Definition at line 1225 of file ThreadSafeContext.inl.
|
inline |
Gets the logger used for information printing.
Definition at line 764 of file ThreadSafeContext.inl.
|
inline |
NOT THREAD SAFE!
Retrieves a reference to the underlying KnowledgeMap. This is not thread-safe. Only call this if you already hold this Context's lock. Reading the map is then generally safe, but writting to it will bypass important mechanisms such as modification tracking. Make sure you know what you're doing, and consider whether other methods fit your needs.
Definition at line 1559 of file ThreadSafeContext.h.
|
inline |
NOT THREAD SAFE!
Retrieves a reference to the underlying KnowledgeMap. This is not thread-safe. Only call this if you already hold this Context's lock. Reading the map is then generally safe.
Ensure you know what you're doing, and consider whether other methods fit your needs.
Definition at line 1576 of file ThreadSafeContext.h.
void madara::knowledge::ThreadSafeContext::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.
prefix | string that the key must start with |
suffix | string that the key must end with |
matches | all VariableReferences matching the prefix and suffix |
Definition at line 1162 of file ThreadSafeContext.cpp.
|
inline |
Retrieves a list of modified variables.
Return list of variables that have been modified.
Useful for building a disseminatable knowledge update.
Definition at line 1037 of file ThreadSafeContext.inl.
|
inline |
Retrieves the current modifieds map.
send_list | map of variables that limit what will be sent |
reset | reset modifieds atomically |
Definition at line 1044 of file ThreadSafeContext.inl.
|
private |
Definition at line 1361 of file ThreadSafeContext.cpp.
|
private |
Definition at line 1383 of file ThreadSafeContext.cpp.
uint32_t madara::knowledge::ThreadSafeContext::get_quality | ( | const std::string & | key, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Atomically gets quality of a variable.
get quality of last update to a variable.
key | unique identifier of the |
settings | settings for referring to a knowledge variable |
Definition at line 275 of file ThreadSafeContext.cpp.
KnowledgeRecord * madara::knowledge::ThreadSafeContext::get_record | ( | const std::string & | key, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Retrieves a knowledge record from the key.
This function is useful for performance reasons and also for using a knowledge::KnowledgeRecord that can be one of multiple types
key | unique identifier of the variable. Allows variable expansion. |
settings | the settings for referring to variables |
This function is useful for performance reasons and also for using a knowledge::KnowledgeRecord that can be one of multiple types
Definition at line 61 of file ThreadSafeContext.cpp.
VariableReference madara::knowledge::ThreadSafeContext::get_ref | ( | const std::string & | key, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Atomically returns a reference to the variable.
Variable references are efficient mechanisms for reference variables individually–similar to speedups seen from CompiledExpression.
key | unique identifier of the variable |
settings | settings for referring to knowledge variables |
Definition at line 84 of file ThreadSafeContext.cpp.
VariableReference madara::knowledge::ThreadSafeContext::get_ref | ( | const std::string & | key, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) | const |
Atomically returns a reference to the variable.
key | unique identifier of the variable |
settings | settings for referring to knowledge variables |
Definition at line 115 of file ThreadSafeContext.cpp.
|
inlineprivate |
Definition at line 186 of file ThreadSafeContext.h.
|
inlineprivate |
Definition at line 201 of file ThreadSafeContext.h.
uint32_t madara::knowledge::ThreadSafeContext::get_write_quality | ( | const std::string & | key, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Atomically gets write quality of this process for a variable.
get quality of last update to a variable.
key | unique identifier of the variable |
settings | settings for referring to a knowledge variable |
Definition at line 306 of file ThreadSafeContext.cpp.
|
inline |
Atomically increments the value of the variable.
key | unique identifier of the variable |
settings | settings for applying the update |
Definition at line 457 of file ThreadSafeContext.inl.
|
inline |
Atomically increments the value of the variable.
variable | reference to a variable ( |
settings | settings for applying the update |
Definition at line 471 of file ThreadSafeContext.inl.
|
inline |
Atomically increments the Lamport clock and returns the new clock time (intended for sending knowledge updates).
increment the process lamport clock
settings | settings for applying the update |
Definition at line 749 of file ThreadSafeContext.inl.
|
inline |
Atomically increments the Lamport clock of a variable and returns the new clock time (intended for sending knowledge updates).
set the lamport clock for a particular variable (updates with lamport clocks lower than our current clock get discarded)
key | unique identifier of the variable |
settings | settings for applying the update |
Definition at line 722 of file ThreadSafeContext.inl.
|
inline |
Definition at line 1604 of file ThreadSafeContext.h.
|
inline |
Definition at line 1582 of file ThreadSafeContext.h.
|
inline |
Definition at line 1620 of file ThreadSafeContext.h.
|
inline |
Definition at line 1593 of file ThreadSafeContext.h.
int64_t madara::knowledge::ThreadSafeContext::load_context | ( | CheckpointSettings & | checkpoint_settings, |
const KnowledgeUpdateSettings & | update_settings = KnowledgeUpdateSettings( true, true, true, false) |
||
) |
Loads the context from a file.
checkpoint_settings | checkpoint settings to load |
update_settings | settings for applying the updates |
exceptions::MemoryException | not enough buffer to encode |
Definition at line 2261 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::load_context | ( | const std::string & | filename, |
FileHeader & | meta, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings( true, true, true, false) |
||
) |
Loads the context from a file.
filename | name of the file to open |
meta | a file header that will contain metadata such as originator, timestamp, lamport clock, etc. |
settings | settings for applying the update |
exceptions::MemoryException | not enough buffer to encode |
Definition at line 2114 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::load_context | ( | const std::string & | filename, |
std::string & | id, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings( true, true, true, false) |
||
) |
Loads the context from a file.
filename | name of the file to open |
id | unique identifier of the context holder (will be changed by the function) |
settings | settings for applying the update |
Definition at line 2104 of file ThreadSafeContext.cpp.
|
inline |
Locks the mutex on this context.
Lock the mutex on this context.
Warning: this will cause all operations to block until the unlock call is made.
Use ContextGuard instead of calling this directly.
Warning: this will cause all operations to block until the unlock call is made.
Definition at line 812 of file ThreadSafeContext.inl.
|
inlineprivate |
method for marking a record modified and signaling changes
ref | a reference to a variable in the knowledge base |
settings | settings for applying modification and signalling |
Definition at line 937 of file ThreadSafeContext.inl.
|
inline |
Changes global variables to modified at current clock for the purposes of sending or checkpointing knowledge (globals and locals respectively)
key | the key of the record you are changing |
settings | the settings for referring to variables |
Definition at line 970 of file ThreadSafeContext.inl.
|
inline |
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for globals and locals respectively)
variable | reference to a variable ( |
settings | the settings for referring to variables |
Definition at line 978 of file ThreadSafeContext.inl.
|
inline |
Changes variable to modified at current clock for the purposes of checkpointing (even if it is a global).
key | the key of the record you are marking |
settings | the settings for referring to variables |
Definition at line 909 of file ThreadSafeContext.inl.
|
inline |
Changes variable reference to modified at current clock for the purposes of checkpointing (even if it is a global).
variable | reference to a variable ( |
settings | the settings for referring to variables |
Definition at line 917 of file ThreadSafeContext.inl.
|
inlineprivate |
Changes variable to modified at current clock for the purposes of checkpointing.
Skips all safety checks and variable expansions.
ref | a reference to a variable in the knowledge base |
settings | the settings for referring to variables |
Definition at line 927 of file ThreadSafeContext.inl.
|
inline |
Changes variable to modified at current clock, and queues it to send, even if it is a local that would not ordinarily be sent.
key | the key of the record you are marking |
settings | the settings for referring to variables |
Definition at line 881 of file ThreadSafeContext.inl.
|
inline |
Changes variable reference to modified at current clock, and queues it to send, even if it is a local that would not ordinarily be sent.
variable | reference to a variable ( |
settings | the settings for referring to variables |
Definition at line 889 of file ThreadSafeContext.inl.
|
inlineprivate |
Changes variable to modified at current clock, and queues it to send, even if it is a local that would not ordinarily be sent.
Skips all safety checks and variable expansions.
ref | a reference to a variable in the knowledge base |
settings | the settings for referring to variables |
Definition at line 899 of file ThreadSafeContext.inl.
|
inline |
Atomically Print a statement, similar to printf (variable expansions allowed) e.g., input = "MyVar{.id} = {MyVar{.id}}\n";.
Print a statement, similar to printf (variable expressions allowed) e.g.
statement | templated statement to print from |
level | log level. |
input = "MyVar{.id} = {MyVar{.id}}\n";
Definition at line 830 of file ThreadSafeContext.inl.
void madara::knowledge::ThreadSafeContext::print | ( | unsigned int | level | ) | const |
Atomically prints all variables and values in the context.
level | log level. |
Definition at line 775 of file ThreadSafeContext.cpp.
|
inline |
Atomically reads a file into a variable.
key | unique identifier of the variable |
filename | file to read |
settings | settings for applying the update |
Definition at line 20 of file ThreadSafeContext.inl.
int madara::knowledge::ThreadSafeContext::read_file | ( | const VariableReference & | variable, |
const std::string & | filename, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Atomically reads a file into a variable.
variable | reference to a variable ( |
filename | file to read |
settings | settings for applying the update |
Definition at line 247 of file ThreadSafeContext.cpp.
|
inline |
Reset all checkpoint variables in the modified lists.
This essentially purges the diff and starts fresh
Definition at line 1201 of file ThreadSafeContext.inl.
|
inline |
Resets a variable to unmodified.
Reset a variable to unmodified.
key | unique identifier of the variable |
Definition at line 1194 of file ThreadSafeContext.inl.
|
inline |
Reset all variables to be unmodified.
Reset all variables to unmodified.
This will clear all global knowledge updates. Use with caution.
Definition at line 1153 of file ThreadSafeContext.inl.
Function * madara::knowledge::ThreadSafeContext::retrieve_function | ( | const std::string & | name, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings() |
||
) |
Retrieves an external function.
name | name of the function to retrieve |
settings | settings for referring to variables |
Definition at line 1034 of file ThreadSafeContext.cpp.
|
inline |
Retrieves a value at a specified index within a knowledge array.
key | knowledge location |
index | index within the array |
settings | settings for referring to knowledge variables |
Definition at line 279 of file ThreadSafeContext.inl.
|
inline |
Retrieves a value at a specified index within a knowledge array.
variable | reference to a variable ( |
index | index within the array |
settings | settings for referring to knowledge variables |
Definition at line 257 of file ThreadSafeContext.inl.
int64_t madara::knowledge::ThreadSafeContext::save_as_json | ( | const CheckpointSettings & | settings | ) | const |
Saves the context to a file as JSON.
settings | the settings to save |
Definition at line 1952 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::save_as_json | ( | const std::string & | filename | ) | const |
Saves the context to a file as JSON.
filename | name of the file to save to |
Definition at line 1944 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::save_as_karl | ( | const CheckpointSettings & | settings | ) | const |
Saves the context to a file as karl assignments, rather than binary.
settings | the settings to save |
Definition at line 1780 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::save_as_karl | ( | const std::string & | filename | ) | const |
Saves the context to a file as karl assignments, rather than binary.
filename | name of the file to save to |
Definition at line 1772 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::save_checkpoint | ( | const CheckpointSettings & | settings | ) | const |
Saves a checkpoint of a list of changes to a file.
settings | checkpoint settings to load |
exceptions::MemoryException | not enough buffer to encode |
Definition at line 2755 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::save_checkpoint | ( | const std::string & | filename, |
const std::string & | id = "" |
||
) | const |
Saves a checkpoint of a list of changes to a file.
filename | name of the file to open |
id | unique identifier of the context holder |
exceptions::MemoryException | not enough buffer to encode |
Definition at line 2808 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::save_context | ( | const CheckpointSettings & | settings | ) | const |
Saves the context to a file.
settings | the settings to save |
exceptions::MemoryException | not enough buffer to encode |
Definition at line 1603 of file ThreadSafeContext.cpp.
int64_t madara::knowledge::ThreadSafeContext::save_context | ( | const std::string & | filename, |
const std::string & | id = "" |
||
) | const |
Saves the context to a file.
filename | name of the file to open |
id | unique identifier of the context holder |
exceptions::MemoryException | not enough buffer to encode |
Definition at line 1593 of file ThreadSafeContext.cpp.
|
inline |
Saves the list of modified records to use later for resending.
This does not clear the modified list. This feature is useful if you want to remember what has been modified and then resend later, e.g., if you believe packets may be dropped and want to resend information. Use this function in conjunction with
Definition at line 1106 of file ThreadSafeContext.inl.
|
inline |
Atomically sets the value of a variable to an array.
key | unique identifier of the variable |
value | an array |
size | number of elements in the array |
settings | settings for applying the update |
Definition at line 308 of file ThreadSafeContext.inl.
|
inline |
Atomically sets the value of a variable to the specific record.
Note, this does not copy meta information (e.g. quality, clock).
key | unique identifier of the variable |
value | new value of the variable |
settings | settings for applying the update |
Definition at line 288 of file ThreadSafeContext.inl.
|
inline |
Atomically sets the value of a variable to an array.
variable | reference to a variable ( |
value | an array of type T |
size | number of elements in the array |
settings | settings for applying the update |
Definition at line 317 of file ThreadSafeContext.inl.
|
inline |
Atomically sets the value of a variable to an array.
variable | reference to a variable ( |
value | new value of the variable |
settings | settings for applying the update |
Definition at line 296 of file ThreadSafeContext.inl.
void madara::knowledge::ThreadSafeContext::set_changed | ( | void | ) |
Force a change to be registered, waking up anyone waiting on entry.
Indicate that a status change has occurred.
This could be a message from the transport to let the knowledge engine know that new agents are available to send knowledge to.
Definition at line 769 of file ThreadSafeContext.cpp.
|
inline |
Atomically sets the Lamport clock of a variable and returns the new clock time (intended for sending knowledge updates).
set the lamport clock (updates with lamport clocks lower than our current clock get discarded)
key | unique identifier of the variable |
clock | new variable clock |
settings | settings for applying the update |
Definition at line 685 of file ThreadSafeContext.inl.
|
inline |
Atomically sets the lamport clock.
set the lamport clock (updates with lamport clocks lower than our current clock get discarded)
clock | new global clock |
Definition at line 671 of file ThreadSafeContext.inl.
|
inline |
Atomically sets the value of a variable to an arbitrary string.
key | unique identifier of the variable |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
Definition at line 396 of file ThreadSafeContext.inl.
int madara::knowledge::ThreadSafeContext::set_file | ( | const VariableReference & | variable, |
const unsigned char * | value, | ||
size_t | size, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Atomically sets the value of a variable to an arbitrary string.
variable | reference to a variable ( |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
Definition at line 220 of file ThreadSafeContext.cpp.
int madara::knowledge::ThreadSafeContext::set_if_unequal | ( | const std::string & | key, |
const std::string & | value, | ||
uint32_t | quality, | ||
uint64_t | clock, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Atomically sets if the variable value will be different.
Set if the variable value will be different.
key | unique identifier of the variable |
value | new value of the variable |
quality | quality to set the variable at (type of priority) |
clock | clock value of the update |
settings | settings for applying the update |
Always updates clock to highest value
Definition at line 569 of file ThreadSafeContext.cpp.
int madara::knowledge::ThreadSafeContext::set_if_unequal | ( | const std::string & | key, |
double | value, | ||
uint32_t | quality, | ||
uint64_t | clock, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Atomically sets if the variable value will be different.
Set if the variable value will be different.
key | unique identifier of the variable |
value | new value of the variable |
quality | quality to set the variable at (type of priority) |
clock | clock value of the update |
settings | settings for applying the update |
Always updates clock to highest value
Definition at line 484 of file ThreadSafeContext.cpp.
int madara::knowledge::ThreadSafeContext::set_if_unequal | ( | const std::string & | key, |
madara::knowledge::KnowledgeRecord::Integer | value, | ||
uint32_t | quality, | ||
uint64_t | clock, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Atomically sets if the variable value will be different.
Set if the variable value will be different.
key | unique identifier of the variable |
value | new value of the variable |
quality | quality to set the variable at (type of priority) |
clock | clock value of the update |
settings | settings for applying the update |
Always updates clock to highest value
Definition at line 397 of file ThreadSafeContext.cpp.
|
inline |
Atomically sets the value of an array index to a value.
key | unique identifier of the variable |
index | index within array |
value | new value of the array index |
settings | settings for applying the update |
Definition at line 405 of file ThreadSafeContext.inl.
|
inline |
Atomically sets the value of an array index to a value.
variable | reference to a variable ( |
index | index within array |
value | new value of the array index |
settings | settings for applying the update |
Definition at line 413 of file ThreadSafeContext.inl.
|
inline |
NON-Atomically sets the value of an array index to a value.
THIS IS NOT A THREAD-SAFE FUNCTION.
variable | reference to a variable ( |
index | index within array |
value | new value of the array index |
settings | settings for applying the update |
Definition at line 444 of file ThreadSafeContext.inl.
|
inlineprivate |
Definition at line 424 of file ThreadSafeContext.inl.
|
inline |
Atomically sets the value of a variable to a JPEG image.
key | unique identifier of the variable |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
Definition at line 388 of file ThreadSafeContext.inl.
int madara::knowledge::ThreadSafeContext::set_jpeg | ( | const VariableReference & | variable, |
const unsigned char * | value, | ||
size_t | size, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Atomically sets the value of a variable to a JPEG image.
variable | reference to a variable ( |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
Definition at line 193 of file ThreadSafeContext.cpp.
|
inline |
Sets the log level.
level | the maximum detail level to print |
Definition at line 1230 of file ThreadSafeContext.inl.
uint32_t madara::knowledge::ThreadSafeContext::set_quality | ( | const std::string & | key, |
uint32_t | quality, | ||
bool | force_update, | ||
const KnowledgeReferenceSettings & | settings | ||
) |
Atomically sets quality of this process for a variable.
Set quality of last update to a variable.
key | unique identifier of the variable |
quality | quality of this process |
force_update | force an update to variable, even if lower |
settings | settings for referring to a knowledge variable |
Definition at line 337 of file ThreadSafeContext.cpp.
|
inline |
Atomically sets the value of a variable to an XML string.
key | unique identifier of the variable |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
Definition at line 381 of file ThreadSafeContext.inl.
int madara::knowledge::ThreadSafeContext::set_text | ( | const VariableReference & | variable, |
const char * | value, | ||
size_t | size, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Atomically sets the value of a variable to a text file's contents.
variable | reference to a variable ( |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
Definition at line 167 of file ThreadSafeContext.cpp.
|
inline |
NON-Atomically sets the value of a variable to the specific array.
THIS IS NOT A THREAD-SAFE FUNCTION. Note, this does not copy meta information (e.g. quality, clock).
variable | reference to a variable ( |
array | new array value of the variable |
size | size of array pointed to by array |
settings | settings for applying the update |
Definition at line 363 of file ThreadSafeContext.inl.
|
inline |
NON-Atomically sets the value of a variable to the specific value.
THIS IS NOT A THREAD-SAFE FUNCTION. Note, this does not copy meta information (e.g. quality, clock).
variable | reference to a variable ( |
value | new value of the variable |
settings | settings for applying the update |
Definition at line 350 of file ThreadSafeContext.inl.
|
inlineprivate |
Definition at line 330 of file ThreadSafeContext.inl.
void madara::knowledge::ThreadSafeContext::set_write_quality | ( | const std::string & | key, |
uint32_t | quality, | ||
const KnowledgeReferenceSettings & | settings | ||
) |
Atomically sets write quality of this process for a variable.
Set quality of this process writing to a variable.
key | unique identifier of the variable |
quality | write quality of this process |
settings | settings for referring to a knowledge variable |
Definition at line 372 of file ThreadSafeContext.cpp.
|
inline |
Atomically sets the value of a variable to an XML string.
key | unique identifier of the variable |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
Definition at line 374 of file ThreadSafeContext.inl.
int madara::knowledge::ThreadSafeContext::set_xml | ( | const VariableReference & | variable, |
const char * | value, | ||
size_t | size, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings() |
||
) |
Atomically sets the value of a variable to an XML string.
variable | reference to a variable ( |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
Definition at line 141 of file ThreadSafeContext.cpp.
|
inline |
Definition at line 289 of file ThreadSafeContext.h.
|
inline |
Definition at line 301 of file ThreadSafeContext.h.
|
inline |
Definition at line 265 of file ThreadSafeContext.h.
|
inline |
Definition at line 277 of file ThreadSafeContext.h.
|
inline |
Definition at line 241 of file ThreadSafeContext.h.
|
inline |
Definition at line 253 of file ThreadSafeContext.h.
|
inline |
Definition at line 217 of file ThreadSafeContext.h.
|
inline |
Definition at line 229 of file ThreadSafeContext.h.
|
inline |
Signals that this thread is done with the context.
Signal the condition that it can wake up someone else on changed data.
Anyone waiting on the underlying condition is awoken.
Definition at line 1209 of file ThreadSafeContext.inl.
KnowledgeMap madara::knowledge::ThreadSafeContext::to_map | ( | const std::string & | prefix | ) | const |
Creates a map with Knowledge Records that begin with the given prefix.
Runs in O(log n + m) time, where n is the size of the KnowledgeBase, and m is the number of matching records
prefix | Prefix string to match with |
Definition at line 1404 of file ThreadSafeContext.cpp.
size_t madara::knowledge::ThreadSafeContext::to_map | ( | const std::string & | prefix, |
const std::string & | delimiter, | ||
const std::string & | suffix, | ||
std::vector< std::string > & | next_keys, | ||
std::map< std::string, knowledge::KnowledgeRecord > & | result, | ||
bool | just_keys | ||
) |
Fills a variable map with list of keys according to a matching prefix, suffix, and delimiter hierarchy.
This is useful for understanding the logical hierarchy of your variables (and also a key utility of containers like
prefix | Text that must be present at the front of the key |
delimiter | Text that signifies a logical boundary in hierarchy If empty, no check is performed. |
suffix | Text that must be present at the end of the key. If empty, no check is performed. |
next_keys | The immediate keys in the hierarchy after prefix |
result | The map that will be filled with full variable names and the Knowledge Records that correspond to |
just_keys | if true, do not fill result, only next_keys |
Definition at line 1219 of file ThreadSafeContext.cpp.
size_t madara::knowledge::ThreadSafeContext::to_map | ( | const std::string & | subject, |
std::map< std::string, knowledge::KnowledgeRecord > & | target | ||
) |
Fills a variable map with Knowledge Records that match an expression.
At the moment, this expression must be of the form "subject*"
subject | An expression that matches the variable names that are of interest. Wildcards may only be at the end. |
target | The map that will be filled with variable names and the Knowledge Records that correspond to |
Definition at line 1115 of file ThreadSafeContext.cpp.
KnowledgeMap madara::knowledge::ThreadSafeContext::to_map_stripped | ( | const std::string & | prefix | ) | const |
Creates a map with Knowledge Records that begin with the given prefix.
Runs in O(log n + m) time, where n is the size of the KnowledgeBase, and m is the number of matching records
All key names have the "prefix" portion stripped off their front in the returned map.
prefix | Prefix string to match with |
Definition at line 1416 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::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 function.
This is an optimized version that allows the specification of a target string to avoid string copying (which can be expensive with longer strings across multiple function boundaries). This function differs from knowledge::KnowledgeRecord to_string in that it is intended to save the database in a format that can be easily parseable. Consequently, strings are delineated in this function by being included in single quotes. Arrays are delineated with array indices [].
This is not appropriate for saving the context if it has binary data inside of it, as only the size of the data entry would be saved.
target | where to store the resulting string operation. |
array_delimiter | for any arrays, the characters in between data elements. |
record_delimiter | the characters to place between individual key/value pairs |
key_val_delimiter | the characters to place between keys and values. |
Definition at line 789 of file ThreadSafeContext.cpp.
size_t madara::knowledge::ThreadSafeContext::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 integer values.
subject | The common subject of the variable names. For instance, if we are looking for a range of vars like "var0", "var1", "var2", then the common subject would be "var". |
start | An inclusive start index |
end | An inclusive end index |
target | The vector that will be filled with Knowledge Record instances within the subject range. |
Definition at line 1091 of file ThreadSafeContext.cpp.
|
inline |
Locks the mutex on this context.
Warning: this will cause all operations to block until the unlock call is made.
Returns immediately without blocking. Returns true if lock was successful, false otherwise.
Definition at line 817 of file ThreadSafeContext.inl.
|
inline |
Unlocks the mutex on this context.
Unlock the mutex on this context.
Definition at line 823 of file ThreadSafeContext.inl.
int madara::knowledge::ThreadSafeContext::update_record_from_external | ( | const std::string & | key, |
const knowledge::KnowledgeRecord & | rhs, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings(true) |
||
) |
Atomically sets if the variable value meets update conditions.
Set if the variable value will be different.
Appropriate conditions include clock being >= old clock, quality >= old quality, etc.
key | unique identifier of the variable |
rhs | new value of the variable |
settings | settings for applying the update |
Always updates clock to highest value
Definition at line 655 of file ThreadSafeContext.cpp.
int madara::knowledge::ThreadSafeContext::update_record_from_external | ( | const VariableReference & | target, |
const knowledge::KnowledgeRecord & | rhs, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings(true) |
||
) |
Atomically sets if the variable value meets update conditions.
Set if the variable value will be different.
Appropriate conditions include clock being >= old clock, quality >= old quality, etc.
target | the target reference in the knowledge base |
rhs | new value of the variable |
settings | settings for applying the update |
Always updates clock to highest value
Definition at line 730 of file ThreadSafeContext.cpp.
|
inline |
Wait for a change to happen to the context.
Make the current thread of execution wait for a change on the context.
extra_release | perform extra release of lock for nested locks |
Definition at line 863 of file ThreadSafeContext.inl.
|
inlineprivate |
Atomically returns a reference to the variable.
key | unique identifier of the variable |
settings | the settings for referring to variables |
Definition at line 138 of file ThreadSafeContext.inl.
|
inlineprivate |
Atomically returns a reference to the variable.
key | unique identifier of the variable |
settings | the settings for referring to variables |
Definition at line 183 of file ThreadSafeContext.inl.
|
inlineprivate |
Atomically returns the value of a variable.
variable | reference to a variable ( |
settings | the settings for referring to variables |
Definition at line 164 of file ThreadSafeContext.inl.
|
inlineprivate |
Atomically returns the value of a variable.
variable | reference to a variable ( |
settings | the settings for referring to variables |
Definition at line 217 of file ThreadSafeContext.inl.
|
friend |
Definition at line 79 of file ThreadSafeContext.h.
|
friend |
Definition at line 80 of file ThreadSafeContext.h.
|
friend |
Definition at line 78 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1713 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1716 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1715 of file ThreadSafeContext.h.
|
private |
Definition at line 1714 of file ThreadSafeContext.h.
|
private |
map of function names to functions
Definition at line 1720 of file ThreadSafeContext.h.
|
private |
KaRL interpreter.
Definition at line 1723 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1717 of file ThreadSafeContext.h.
|
mutableprivate |
Logger for printing.
Definition at line 1726 of file ThreadSafeContext.h.
|
private |
Hash table containing variable names and values.
Definition at line 1711 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1712 of file ThreadSafeContext.h.
|
private |
Streaming provider for saving all updates.
Definition at line 1729 of file ThreadSafeContext.h.