MADARA
3.1.8
|
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... | |
bool | clear (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Clears a variable. More... | |
void | clear (bool erase=false) |
Clears the context. More... | |
CompiledExpression | compile (const std::string &expression) |
Compiles a KaRL expression into an expression tree. More... | |
void | copy (const ThreadSafeContext &source, const KnowledgeRequirements &settings) |
Copies variables and values from source to this context. More... | |
void | copy (const ThreadSafeContext &source, const CopySet ©_set=CopySet(), bool clean_copy=false) |
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, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &), const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines an external 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, const std::string &expression, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines a MADARA KaRL function. More... | |
void | define_function (const std::string &name, const CompiledExpression &expression, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines a MADARA KaRL 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... | |
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... | |
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... | |
madara::knowledge::KnowledgeRecord | get (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns the value of a variable. More... | |
madara::knowledge::KnowledgeRecord | get (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns the value of a variable. More... | |
uint64_t | get_clock (void) const |
Atomically gets the Lamport clock. More... | |
uint64_t | get_clock (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically gets the Lamport clock of a variable. More... | |
const knowledge::KnowledgeRecords & | 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 knowledge::KnowledgeRecords & | get_modifieds (void) const |
Retrieves a list of modified variables. 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... | |
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... | |
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 (CheckpointSettings &checkpoint_settings, const KnowledgeUpdateSettings &update_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 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_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_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_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_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 | 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 | print (unsigned int level) const |
Atomically prints all variables and values in the context. 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... | |
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 (void) |
Reset all variables to be unmodified. More... | |
void | reset_modified (const std::string &key) |
Resets a variable to 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 std::string &filename) const |
Saves the context to a file as JSON. More... | |
int64_t | save_as_json (const CheckpointSettings &settings) const |
Saves the context to a file as JSON. 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_as_karl (const CheckpointSettings &settings) const |
Saves the context to a file as karl assignments, rather than binary. 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_checkpoint (const CheckpointSettings &settings) const |
Saves a checkpoint of a list of changes to a file. More... | |
int64_t | save_context (const std::string &filename, const std::string &id="") const |
Saves the context to a file. More... | |
int64_t | save_context (const CheckpointSettings &settings) 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, 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, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Atomically sets the value of a variable to an array. 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 VariableReference &variable, const T *value, uint32_t size, 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 (uint64_t clock) |
Atomically sets the lamport clock. 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... | |
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, 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... | |
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, const std::string &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, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
NON-Atomically sets the value of a variable to the specific value. 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... | |
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< std::vector< unsigned char > > | share_binary (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Returns a shared_ptr, sharing with the internal one. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
std::shared_ptr< std::string > | share_string (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Returns a shared_ptr, sharing with the internal one. More... | |
void | signal (bool lock=true) const |
Signals that this thread is done with the context. More... | |
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. More... | |
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. More... | |
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. More... | |
std::shared_ptr< std::vector< double > > | take_doubles (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Returns a shared_ptr, sharing with the internal one. More... | |
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. More... | |
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. More... | |
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. More... | |
std::shared_ptr< std::string > | take_string (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Returns a shared_ptr, while resetting this record to empty. 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... | |
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... | |
knowledge::KnowledgeMap | to_map (const std::string &prefix) const |
Creates a map with Knowledge Records that begin with the given prefix. 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... | |
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::const_iterator, KnowledgeMap::const_iterator > | get_prefix_range (const std::string &prefix) const |
std::pair< KnowledgeMap::iterator, KnowledgeMap::iterator > | get_prefix_range (const std::string &prefix) |
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 (const char *name, knowledge::KnowledgeRecord *record, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
method for marking a record modified and signaling changes More... | |
void | mark_to_checkpoint_unsafe (const std::string &key, madara::knowledge::KnowledgeRecord &record, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) |
Changes variable to modified at current clock for the purposes of checkpointing. More... | |
void | mark_to_send_unsafe (const std::string &key, madara::knowledge::KnowledgeRecord &record, 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... | |
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 std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
Atomically returns a reference to the 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_ |
knowledge::KnowledgeRecords | 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... | |
knowledge::KnowledgeRecords | 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_ |
Friends | |
class | expression::CompositeArrayReference |
class | expression::VariableNode |
class | KnowledgeBaseImpl |
class | rcw::BaseTracker |
This class stores variables and their values for use by any entity needing state information in a thread safe way.
Definition at line 82 of file ThreadSafeContext.h.
|
private |
Definition at line 181 of file ThreadSafeContext.h.
|
private |
Definition at line 167 of file ThreadSafeContext.h.
madara::knowledge::ThreadSafeContext::ThreadSafeContext | ( | ) |
Constructor.
Definition at line 22 of file ThreadSafeContext.cpp.
madara::knowledge::ThreadSafeContext::~ThreadSafeContext | ( | void | ) |
Destructor.
Definition at line 39 of file ThreadSafeContext.cpp.
|
inline |
Adds a file to the logger.
filename | the file to add to logger |
Definition at line 1082 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 985 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 1019 of file ThreadSafeContext.inl.
|
inline |
Attaches a logger to be used for printing.
logger | the logger the context should lose |
Definition at line 671 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 438 of file ThreadSafeContext.inl.
|
inline |
Clears the context.
erase | If true, completely erase keys. If false, reset knowledge |
Definition at line 741 of file ThreadSafeContext.inl.
madara::knowledge::CompiledExpression madara::knowledge::ThreadSafeContext::compile | ( | const std::string & | expression | ) |
Compiles a KaRL expression into an expression tree.
expression | expression to compile |
Definition at line 1079 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::copy | ( | const ThreadSafeContext & | source, |
const KnowledgeRequirements & | 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 |
settings | requirements that must be met |
Definition at line 1487 of file ThreadSafeContext.cpp.
void madara::knowledge::ThreadSafeContext::copy | ( | const ThreadSafeContext & | source, |
const CopySet & | copy_set = CopySet () , |
||
bool | clean_copy = false |
||
) |
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. |
Definition at line 1599 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 900 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 391 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 537 of file ThreadSafeContext.inl.
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 911 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, |
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 1018 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 1027 of file ThreadSafeContext.cpp.
|
inline |
Deletes the expression from the interpreter cache.
expression | the KaRL logic in the interpreter context |
Definition at line 427 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 1348 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 470 of file ThreadSafeContext.inl.
madara::knowledge::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 |
Definition at line 1095 of file ThreadSafeContext.cpp.
madara::knowledge::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 |
Definition at line 1104 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 501 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 135 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 851 of file ThreadSafeContext.cpp.
|
inline |
Atomically returns the 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 value of a variable.
variable | reference to a variable ( |
settings | the settings for referring to variables |
Definition at line 40 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 657 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 680 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 1000 of file ThreadSafeContext.inl.
|
inline |
Gets the log level.
Definition at line 1089 of file ThreadSafeContext.inl.
|
inline |
Gets the logger used for information printing.
Definition at line 664 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 1607 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 1621 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 1199 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 948 of file ThreadSafeContext.inl.
|
private |
Definition at line 1429 of file ThreadSafeContext.cpp.
|
private |
Definition at line 1405 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 277 of file ThreadSafeContext.cpp.
madara::knowledge::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 53 of file ThreadSafeContext.cpp.
madara::knowledge::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 79 of file ThreadSafeContext.cpp.
madara::knowledge::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 111 of file ThreadSafeContext.cpp.
|
inlineprivate |
Definition at line 170 of file ThreadSafeContext.h.
|
inlineprivate |
Definition at line 184 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 310 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 382 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 400 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 647 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 618 of file ThreadSafeContext.inl.
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 |
check that there is more than one state and that the rest of the file is sufficient to at least be a message header (what we use as a checkpoint header
What we read into the checkpoint_header will dictate our max_buffer. We want to make this checkpoint_header size into something reasonable.
create a new array and copy the remaining elements from buffer_remaining
Definition at line 2381 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 |
check that there is more than one state and that the rest of the file is sufficient to at least be a message header (what we use as a checkpoint header
What we read into the checkpoint_header will dictate our max_buffer. We want to make this checkpoint_header size into something reasonable.
create a new array and copy the remaining elements from buffer_remaining
Definition at line 2499 of file ThreadSafeContext.cpp.
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 |
check that there is more than one state and that the rest of the file is sufficient to at least be a message header (what we use as a checkpoint header
What we read into the checkpoint_header will dictate our max_buffer. We want to make this checkpoint_header size into something reasonable.
create a new array and copy the remaining elements from buffer_remaining
Definition at line 2617 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.
Definition at line 717 of file ThreadSafeContext.inl.
|
inlineprivate |
method for marking a record modified and signaling changes
name | variable name |
record | record to place in the changed_map |
settings | settings for applying modification and signalling |
Definition at line 855 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 890 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 879 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 832 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 821 of file ThreadSafeContext.inl.
|
inlineprivate |
Changes variable to modified at current clock for the purposes of checkpointing.
Skips all safety checks and variable expansions.
key | the key of the record you are marking |
record | record of the key in the context (should exist) |
settings | the settings for referring to variables |
Definition at line 843 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 799 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 788 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.
key | the key of the record you are marking |
record | record of the key in the context (should exist) |
settings | the settings for referring to variables |
Definition at line 809 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 773 of file ThreadSafeContext.cpp.
|
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 732 of file ThreadSafeContext.inl.
|
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 17 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 249 of file ThreadSafeContext.cpp.
|
inline |
Reset all checkpoint variables in the modified lists.
This essentially purges the diff and starts fresh
Definition at line 1060 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 1009 of file ThreadSafeContext.inl.
|
inline |
Resets a variable to unmodified.
Reset a variable to unmodified.
key | unique identifier of the variable |
Definition at line 1051 of file ThreadSafeContext.inl.
madara::knowledge::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 1053 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 163 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 149 of file ThreadSafeContext.inl.
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 2125 of file ThreadSafeContext.cpp.
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 2233 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 1888 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 1987 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 |
if the record is larger than the buffer we have remaining, then write the buffer to the file
If the record is larger than the buffer, then we must allocate a buffer large enough to write to it.
if the record is larger than the buffer we have remaining, then write the buffer to the file
If the record is larger than the buffer, then we must allocate a buffer large enough to write to it.
Definition at line 3227 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 |
id | unique identifier of the context holder |
If the record is larger than the buffer, then we must allocate a buffer large enough to write to it.
Definition at line 2832 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 |
if the record is larger than the buffer we have remaining, then write the buffer to the file
If the record is larger than the buffer, then we must allocate a buffer large enough to write to it.
Definition at line 1636 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 |
Definition at line 1748 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 956 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 174 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 185 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 199 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 211 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 766 of file ThreadSafeContext.cpp.
|
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 563 of file ThreadSafeContext.inl.
|
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 579 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 313 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 223 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 407 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 488 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.
|
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 324 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 335 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 368 of file ThreadSafeContext.inl.
|
inlineprivate |
Definition at line 349 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 303 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 197 of file ThreadSafeContext.cpp.
|
inline |
Sets the log level.
level | the maximum detail level to print |
Definition at line 1095 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 343 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 293 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 171 of file ThreadSafeContext.cpp.
|
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 252 of file ThreadSafeContext.inl.
|
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 268 of file ThreadSafeContext.inl.
|
inlineprivate |
Definition at line 231 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 380 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 283 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 144 of file ThreadSafeContext.cpp.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a binary file, returns NULL shared_ptr
Definition at line 348 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a binary file, returns NULL shared_ptr
Definition at line 361 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a doubles array, returns NULL shared_ptr
Definition at line 296 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a doubles array, returns NULL shared_ptr
Definition at line 309 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not an integer array, returns NULL shared_ptr
Definition at line 244 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not an integer array, returns NULL shared_ptr
Definition at line 257 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a string, returns NULL shared_ptr
Definition at line 199 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a string, returns NULL shared_ptr
Definition at line 210 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 1070 of file ThreadSafeContext.inl.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a binary file, returns NULL shared_ptr
Definition at line 374 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a binary file, returns NULL shared_ptr
Definition at line 387 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a doubles array, returns NULL shared_ptr
Definition at line 322 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not a doubles array, returns NULL shared_ptr
Definition at line 335 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not an integer array, returns NULL shared_ptr
Definition at line 270 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, sharing with the internal one.
If this record is not an integer array, returns NULL shared_ptr
Definition at line 283 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, while resetting this record to empty.
If this record is not a string, returns NULL shared_ptr
Definition at line 221 of file ThreadSafeContext.h.
|
inline |
Returns a shared_ptr, while resetting this record to empty.
If this record is not a string, returns NULL shared_ptr
Definition at line 232 of file ThreadSafeContext.h.
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 1147 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 1262 of file ThreadSafeContext.cpp.
madara::knowledge::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 1452 of file ThreadSafeContext.cpp.
madara::knowledge::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 1466 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 791 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 1118 of file ThreadSafeContext.cpp.
|
inline |
Unlocks the mutex on this context.
Unlock the mutex on this context.
Definition at line 724 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 651 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 723 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 768 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 52 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 80 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 93 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 121 of file ThreadSafeContext.inl.
|
friend |
Definition at line 86 of file ThreadSafeContext.h.
|
friend |
Definition at line 87 of file ThreadSafeContext.h.
|
friend |
Definition at line 85 of file ThreadSafeContext.h.
|
friend |
Definition at line 88 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1678 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1681 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1680 of file ThreadSafeContext.h.
|
private |
Definition at line 1679 of file ThreadSafeContext.h.
|
private |
map of function names to functions
Definition at line 1685 of file ThreadSafeContext.h.
|
private |
KaRL interpreter.
Definition at line 1688 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1682 of file ThreadSafeContext.h.
|
mutableprivate |
Logger for printing.
Definition at line 1691 of file ThreadSafeContext.h.
|
private |
Hash table containing variable names and values.
Definition at line 1676 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1677 of file ThreadSafeContext.h.