MADARA
3.2.3
|
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, jobject callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
Defines a named java function. 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 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... | |
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... | |
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 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... | |
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 |
std::shared_ptr< std::vector< unsigned char > > | share_binary (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< std::vector< double > > | share_doubles (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< std::vector< double > > | share_doubles (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > | share_integers (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > | share_integers (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< std::string > | share_string (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const |
std::shared_ptr< 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... | |
std::shared_ptr< std::vector< unsigned char > > | take_binary (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
std::shared_ptr< std::vector< unsigned char > > | take_binary (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
std::shared_ptr< std::vector< double > > | take_doubles (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
std::shared_ptr< std::vector< double > > | take_doubles (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > | take_integers (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > | take_integers (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
std::shared_ptr< std::string > | take_string (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
std::shared_ptr< std::string > | take_string (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) |
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... | |
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::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 (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... | |
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_ |
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_ |
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 75 of file ThreadSafeContext.h.
|
private |
Definition at line 174 of file ThreadSafeContext.h.
|
private |
Definition at line 160 of file ThreadSafeContext.h.
madara::knowledge::ThreadSafeContext::ThreadSafeContext | ( | ) |
Constructor.
Definition at line 23 of file ThreadSafeContext.cpp.
madara::knowledge::ThreadSafeContext::~ThreadSafeContext | ( | void | ) |
Destructor.
Definition at line 40 of file ThreadSafeContext.cpp.
|
inline |
Adds a file to the logger.
filename | the file to add to logger |
Definition at line 1118 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 1023 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 1055 of file ThreadSafeContext.inl.
|
inline |
Attaches a logger to be used for printing.
logger | the logger the context should lose |
Definition at line 699 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 436 of file ThreadSafeContext.inl.
|
inline |
Clears the context.
erase | If true, completely erase keys. If false, reset knowledge |
Definition at line 775 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 |
expression::KarlException | failure during compile/evaluate |
Definition at line 1101 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 1507 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 1619 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 940 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 389 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 564 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 933 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, |
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 986 of file ThreadSafeContext.cpp.
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 1013 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 1040 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 1049 of file ThreadSafeContext.cpp.
|
inline |
Deletes the expression from the interpreter cache.
expression | the KaRL logic in the interpreter context |
Definition at line 425 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 1369 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 468 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 499 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 515 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 |
expression::KarlException | failure during compile/evaluate |
Definition at line 1117 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 |
expression::KarlException | failure during compile/evaluate |
Definition at line 1126 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 528 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 130 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 875 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 28 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 41 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 685 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 708 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 1036 of file ThreadSafeContext.inl.
|
inline |
Gets the log level.
Definition at line 1125 of file ThreadSafeContext.inl.
|
inline |
Gets the logger used for information printing.
Definition at line 692 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 1661 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 1675 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 1221 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 988 of file ThreadSafeContext.inl.
|
private |
Definition at line 1450 of file ThreadSafeContext.cpp.
|
private |
Definition at line 1426 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 284 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 54 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 80 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 112 of file ThreadSafeContext.cpp.
|
inlineprivate |
Definition at line 163 of file ThreadSafeContext.h.
|
inlineprivate |
Definition at line 177 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 317 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 380 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 398 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 675 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 646 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 |
Definition at line 2149 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 |
Definition at line 2161 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 2225 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 745 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 895 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 930 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 919 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 870 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 859 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 882 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 834 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 823 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 846 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 797 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 766 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 18 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 254 of file ThreadSafeContext.cpp.
|
inline |
Reset all checkpoint variables in the modified lists.
This essentially purges the diff and starts fresh
Definition at line 1096 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 1045 of file ThreadSafeContext.inl.
|
inline |
Resets a variable to unmodified.
Reset a variable to unmodified.
key | unique identifier of the variable |
Definition at line 1087 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 1075 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 157 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 142 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 1981 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 1992 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 1823 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 1834 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 |
Definition at line 2853 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 |
If the record is larger than the buffer, then we must allocate a buffer large enough to write to it.
Definition at line 2447 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 |
Definition at line 1656 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 1668 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 996 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 168 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 179 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 194 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 206 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 790 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 591 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 607 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 310 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 226 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 414 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 500 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 586 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 321 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 332 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 366 of file ThreadSafeContext.inl.
|
inlineprivate |
Definition at line 346 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 300 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 198 of file ThreadSafeContext.cpp.
|
inline |
Sets the log level.
level | the maximum detail level to print |
Definition at line 1131 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 350 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 290 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 170 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 249 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 265 of file ThreadSafeContext.inl.
|
inlineprivate |
Definition at line 226 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 387 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 280 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 347 of file ThreadSafeContext.h.
|
inline |
Definition at line 360 of file ThreadSafeContext.h.
|
inline |
Definition at line 293 of file ThreadSafeContext.h.
|
inline |
Definition at line 306 of file ThreadSafeContext.h.
|
inline |
Definition at line 239 of file ThreadSafeContext.h.
|
inline |
Definition at line 252 of file ThreadSafeContext.h.
|
inline |
Definition at line 192 of file ThreadSafeContext.h.
|
inline |
Definition at line 203 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 1106 of file ThreadSafeContext.inl.
|
inline |
Definition at line 374 of file ThreadSafeContext.h.
|
inline |
Definition at line 388 of file ThreadSafeContext.h.
|
inline |
Definition at line 320 of file ThreadSafeContext.h.
|
inline |
Definition at line 334 of file ThreadSafeContext.h.
|
inline |
Definition at line 266 of file ThreadSafeContext.h.
|
inline |
Definition at line 280 of file ThreadSafeContext.h.
|
inline |
Definition at line 215 of file ThreadSafeContext.h.
|
inline |
Definition at line 227 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 1169 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 1283 of file ThreadSafeContext.cpp.
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 1473 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 1487 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 815 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 1140 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 751 of file ThreadSafeContext.inl.
|
inline |
Unlocks the mutex on this context.
Unlock the mutex on this context.
Definition at line 758 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 673 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 748 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 803 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 53 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 81 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 91 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 119 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.
|
friend |
Definition at line 81 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1726 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1729 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1728 of file ThreadSafeContext.h.
|
private |
Definition at line 1727 of file ThreadSafeContext.h.
|
private |
map of function names to functions
Definition at line 1733 of file ThreadSafeContext.h.
|
private |
KaRL interpreter.
Definition at line 1736 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1730 of file ThreadSafeContext.h.
|
mutableprivate |
Logger for printing.
Definition at line 1739 of file ThreadSafeContext.h.
|
private |
Hash table containing variable names and values.
Definition at line 1724 of file ThreadSafeContext.h.
|
mutableprivate |
Definition at line 1725 of file ThreadSafeContext.h.