MADARA  3.1.8
madara::knowledge::ThreadSafeContext Class Reference

This class stores variables and their values for use by any entity needing state information in a thread safe way. More...

#include <ThreadSafeContext.h>

Collaboration diagram for madara::knowledge::ThreadSafeContext:

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 &copy_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::KnowledgeRecordsget_local_modified (void) const
 Retrieves a list of modified local variables. More...
 
int get_log_level (void)
 Gets the log level. More...
 
logger::Loggerget_logger (void) const
 Gets the logger used for information printing. More...
 
KnowledgeMapget_map_unsafe (void)
 NOT THREAD SAFE! More...
 
const KnowledgeMapget_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::KnowledgeRecordsget_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...
 
KnowledgeRecordget_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...
 
Functionretrieve_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::KnowledgeRecordwith (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Atomically returns a reference to the variable. More...
 
madara::knowledge::KnowledgeRecordwith (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Atomically returns the value of a variable. More...
 
const madara::knowledge::KnowledgeRecordwith (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Atomically returns a reference to the variable. More...
 
const madara::knowledge::KnowledgeRecordwith (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::Interpreterinterpreter_
 KaRL interpreter. More...
 
knowledge::KnowledgeRecords local_changed_map_
 
logger::Loggerlogger_
 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
 

Detailed Description

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.

Member Typedef Documentation

template<typename T >
using madara::knowledge::ThreadSafeContext::ConstMethodType = std::shared_ptr<T> (KnowledgeRecord::*) (void) const
private

Definition at line 181 of file ThreadSafeContext.h.

template<typename T >
using madara::knowledge::ThreadSafeContext::MethodType = std::shared_ptr<T> (KnowledgeRecord::*) (void)
private

Definition at line 167 of file ThreadSafeContext.h.

Constructor & Destructor Documentation

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.

Member Function Documentation

void madara::knowledge::ThreadSafeContext::add_logger ( const std::string &  filename)
inline

Adds a file to the logger.

Parameters
filenamethe file to add to logger

Definition at line 1082 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::add_modifieds ( const VariableReferences modifieds) const
inline

Adds a list of VariableReferences to the current modified list.

Parameters
modifiedsa list of variables to add to modified list

Definition at line 985 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::apply_modified ( void  )
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.

void madara::knowledge::ThreadSafeContext::attach_logger ( logger::Logger logger) const
inline

Attaches a logger to be used for printing.

Parameters
loggerthe logger the context should lose

Definition at line 671 of file ThreadSafeContext.inl.

bool madara::knowledge::ThreadSafeContext::clear ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inline

Clears a variable.

This is much safer than

See also
delete_variable. It clears the memory used in the variable and marks it as UNCREATED, meaning that it is effectively deleted, will not show up in
print statements or
save_checkpoint.
Parameters
keyunique identifier of the variable
settingssettings for referring to variables
Returns
true if variable exists

Definition at line 438 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::clear ( bool  erase = false)
inline

Clears the context.

Parameters
eraseIf 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.

Parameters
expressionexpression to compile
Returns
compiled, optimized expression tree

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

Parameters
sourcethe source context to copy from
settingsrequirements 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).

Parameters
sourcethe source context to copy from
copy_seta map of variables that should be copied. If empty, then everything is copied. If not empty, only the supplied variables will be copied.
clean_copyif true, clear the destination context (this) before copying.

Definition at line 1599 of file ThreadSafeContext.cpp.

std::string madara::knowledge::ThreadSafeContext::debug_modifieds ( void  ) const
inline

Retrieves a stringified list of all modified variables that are ready to send over transport on next send_modifieds call.

Returns
stringified list of the modified knowledge records

Definition at line 900 of file ThreadSafeContext.inl.

madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::dec ( const std::string &  key,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically decrements the value of the variable.

Parameters
keyunique identifier of the variable
settingssettings for applying the update
Returns
new value of variable

Definition at line 391 of file ThreadSafeContext.inl.

madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::dec ( const VariableReference variable,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically decrements the value of the variable.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingssettings for applying the update
Returns
new value of variable

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.

Parameters
namename of the function
funcexternal function to call with this name
settingssettings 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.

Parameters
namename of the function
funcexternal function to call with this name
settingssettings 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.

Parameters
namename of the function
expressionKaRL function body
settingssettings 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.

Parameters
namename of the function
expressionKaRL function body
settingssettings for referring to variables

Definition at line 1027 of file ThreadSafeContext.cpp.

bool madara::knowledge::ThreadSafeContext::delete_expression ( const std::string &  expression)
inline

Deletes the expression from the interpreter cache.

Parameters
expressionthe KaRL logic in the interpreter context
Returns
true if variable exists

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.

Parameters
prefixstring which starts all variables to delete
settingssettings for referring to variables

Definition at line 1348 of file ThreadSafeContext.cpp.

bool madara::knowledge::ThreadSafeContext::delete_variable ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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

See also
saved_modifieds listing, 3) a compiled expression in KaRL that uses the variable. There are very, very few reasons to ever use this function. Actually, there is one: you will never, ever, ever use this variable again. That's it. Otherwise, use
clear with the default argument
Parameters
keyunique identifier of the variable
settingssettings for referring to variables
Returns
true if variable exists

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.

Parameters
expressionA compiled expressio to run.
settingssettings for applying the update
Returns
result of the evaluation

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.

Parameters
rootRoot of an expression tree
settingssettings for applying the update
Returns
result of the evaluation

Definition at line 1104 of file ThreadSafeContext.cpp.

bool madara::knowledge::ThreadSafeContext::exists ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
inline

Atomically checks to see if a variable already exists.

Parameters
keyunique identifier of the variable
settingssettings for referring to variables
Returns
true if variable exists

Definition at line 501 of file ThreadSafeContext.inl.

bool madara::knowledge::ThreadSafeContext::exists ( const VariableReference variable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings (false) 
) const
inline

Checks if a knowledge variable exists in the context.

Parameters
variableknowledge variable reference
settingssettings for referring to knowledge variables
Returns
true if location has been set

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".

Parameters
statementstatement to expand. Useful for printing.
Returns
variable expanded statement

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.

madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::get ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
inline

Atomically returns the value of a variable.

Parameters
keyunique identifier of the variable
settingsthe settings for referring to variables
Returns
the madara::knowledge::KnowledgeRecord::Integer value for the variable

Definition at line 27 of file ThreadSafeContext.inl.

madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::get ( const VariableReference variable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
inline

Atomically returns the value of a variable.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingsthe settings for referring to variables
Returns
the madara::knowledge::KnowledgeRecord::Integer value for the variable

Definition at line 40 of file ThreadSafeContext.inl.

uint64_t madara::knowledge::ThreadSafeContext::get_clock ( void  ) const
inline

Atomically gets the Lamport clock.

get the lamport clock (updates with lamport clocks lower than our current clock get discarded)

Returns
current global clock

Definition at line 657 of file ThreadSafeContext.inl.

uint64_t madara::knowledge::ThreadSafeContext::get_clock ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
inline

Atomically gets the Lamport clock of a variable.

get the lamport clock for a particular variable

Parameters
keyunique identifier of the variable
settingssettings for reading the variable
Returns
current variable clock

Definition at line 680 of file ThreadSafeContext.inl.

const madara::knowledge::KnowledgeRecords & madara::knowledge::ThreadSafeContext::get_local_modified ( void  ) const
inline

Retrieves a list of modified local variables.

Return list of variables that have been modified.

Useful for building a comprehensive checkpoint.

Returns
the modified knowledge records

Definition at line 1000 of file ThreadSafeContext.inl.

int madara::knowledge::ThreadSafeContext::get_log_level ( void  )
inline

Gets the log level.

Returns
the maximum detail level to print

Definition at line 1089 of file ThreadSafeContext.inl.

madara::logger::Logger & madara::knowledge::ThreadSafeContext::get_logger ( void  ) const
inline

Gets the logger used for information printing.

Returns
the context's logger

Definition at line 664 of file ThreadSafeContext.inl.

KnowledgeMap& madara::knowledge::ThreadSafeContext::get_map_unsafe ( void  )
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.

Returns
a reference to this context's KnowledgeMap

Definition at line 1607 of file ThreadSafeContext.h.

const KnowledgeMap& madara::knowledge::ThreadSafeContext::get_map_unsafe ( void  ) const
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.

Returns
a reference to this context's KnowledgeMap

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.

Parameters
prefixstring that the key must start with
suffixstring that the key must end with
matchesall VariableReferences matching the prefix and suffix

Definition at line 1199 of file ThreadSafeContext.cpp.

const madara::knowledge::KnowledgeRecords & madara::knowledge::ThreadSafeContext::get_modifieds ( void  ) const
inline

Retrieves a list of modified variables.

Return list of variables that have been modified.

Useful for building a disseminatable knowledge update.

Returns
the modified knowledge records

Definition at line 948 of file ThreadSafeContext.inl.

std::pair< madara::knowledge::KnowledgeMap::const_iterator, madara::knowledge::KnowledgeMap::const_iterator > madara::knowledge::ThreadSafeContext::get_prefix_range ( const std::string &  prefix) const
private

Definition at line 1429 of file ThreadSafeContext.cpp.

std::pair< madara::knowledge::KnowledgeMap::iterator, madara::knowledge::KnowledgeMap::iterator > madara::knowledge::ThreadSafeContext::get_prefix_range ( const std::string &  prefix)
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.

Parameters
keyunique identifier of the
settingssettings for referring to a knowledge variable
Returns
quality associated with the variable
quality of the 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

Parameters
keyunique identifier of the variable. Allows variable expansion.
settingsthe settings for referring to variables
Returns
the knowledge record for the variable

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.

Parameters
keyunique identifier of the variable
settingssettings for referring to knowledge variables
Returns
reference to the variable in the context

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.

Parameters
keyunique identifier of the variable
settingssettings for referring to knowledge variables
Returns
reference to the variable in the context. If variable doesn't exist, then a null reference is returned.

Definition at line 111 of file ThreadSafeContext.cpp.

template<typename T , MethodType< T > Get, typename K >
std::shared_ptr<T> madara::knowledge::ThreadSafeContext::get_shared ( K &&  key,
const KnowledgeReferenceSettings settings 
)
inlineprivate

Definition at line 170 of file ThreadSafeContext.h.

template<typename T , ConstMethodType< T > Get, typename K >
std::shared_ptr<T> madara::knowledge::ThreadSafeContext::get_shared ( K &&  key,
const KnowledgeReferenceSettings settings 
) const
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.

Parameters
keyunique identifier of the variable
settingssettings for referring to a knowledge variable
Returns
write quality associated with the variable
quality of the variable

Definition at line 310 of file ThreadSafeContext.cpp.

madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::inc ( const std::string &  key,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically increments the value of the variable.

Parameters
keyunique identifier of the variable
settingssettings for applying the update
Returns
new value of variable

Definition at line 382 of file ThreadSafeContext.inl.

madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::inc ( const VariableReference variable,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically increments the value of the variable.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingssettings for applying the update
Returns
new value of variable

Definition at line 400 of file ThreadSafeContext.inl.

uint64_t madara::knowledge::ThreadSafeContext::inc_clock ( const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings ())
inline

Atomically increments the Lamport clock and returns the new clock time (intended for sending knowledge updates).

increment the process lamport clock

Parameters
settingssettings for applying the update
Returns
new clock time

Definition at line 647 of file ThreadSafeContext.inl.

uint64_t madara::knowledge::ThreadSafeContext::inc_clock ( const std::string &  key,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
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)

Parameters
keyunique identifier of the variable
settingssettings for applying the update
Returns
new clock time for variable

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.

Parameters
filenamename of the file to open
idunique identifier of the context holder (will be changed by the function)
settingssettings for applying the update
Returns
-1 if file open failed
-2 if file read failed
>0 if successful (number of bytes written)

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.

Parameters
filenamename of the file to open
metaa file header that will contain metadata such as originator, timestamp, lamport clock, etc.
settingssettings for applying the update
Returns
-1 if file open failed
-2 if file read failed
>0 if successful (number of bytes written)

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.

Parameters
checkpoint_settingscheckpoint settings to load
update_settingssettings for applying the updates
Returns
-1 if file open failed
-2 if file read failed
>0 if successful (number of bytes written)

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.

void madara::knowledge::ThreadSafeContext::lock ( void  ) const
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.

void madara::knowledge::ThreadSafeContext::mark_and_signal ( const char *  name,
knowledge::KnowledgeRecord record,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inlineprivate

method for marking a record modified and signaling changes

Parameters
namevariable name
recordrecord to place in the changed_map
settingssettings for applying modification and signalling

Definition at line 855 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::mark_modified ( const VariableReference variable,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inline

Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for globals and locals respectively)

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingsthe settings for referring to variables

Definition at line 890 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::mark_modified ( const std::string &  key,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Changes global variables to modified at current clock for the purposes of sending or checkpointing knowledge (globals and locals respectively)

Parameters
keythe key of the record you are changing
settingsthe settings for referring to variables

Definition at line 879 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::mark_to_checkpoint ( const VariableReference variable,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inline

Changes variable reference to modified at current clock for the purposes of checkpointing (even if it is a global).

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingsthe settings for referring to variables

Definition at line 832 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::mark_to_checkpoint ( const std::string &  key,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Changes variable to modified at current clock for the purposes of checkpointing (even if it is a global).

Parameters
keythe key of the record you are marking
settingsthe settings for referring to variables

Definition at line 821 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::mark_to_checkpoint_unsafe ( const std::string &  key,
madara::knowledge::KnowledgeRecord record,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inlineprivate

Changes variable to modified at current clock for the purposes of checkpointing.

Skips all safety checks and variable expansions.

Parameters
keythe key of the record you are marking
recordrecord of the key in the context (should exist)
settingsthe settings for referring to variables

Definition at line 843 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::mark_to_send ( const VariableReference variable,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
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.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingsthe settings for referring to variables

Definition at line 799 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::mark_to_send ( const std::string &  key,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
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.

Parameters
keythe key of the record you are marking
settingsthe settings for referring to variables

Definition at line 788 of file ThreadSafeContext.inl.

void madara::knowledge::ThreadSafeContext::mark_to_send_unsafe ( const std::string &  key,
madara::knowledge::KnowledgeRecord record,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
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.

Parameters
keythe key of the record you are marking
recordrecord of the key in the context (should exist)
settingsthe 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.

Parameters
levellog level.
See also
LogMacros.h

Definition at line 773 of file ThreadSafeContext.cpp.

void madara::knowledge::ThreadSafeContext::print ( const std::string &  statement,
unsigned int  level 
) const
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.

Parameters
statementtemplated statement to print from
levellog level.
See also
LogMacros.h

input = "MyVar{.id} = {MyVar{.id}}\n";

Definition at line 732 of file ThreadSafeContext.inl.

int madara::knowledge::ThreadSafeContext::read_file ( const std::string &  key,
const std::string &  filename,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically reads a file into a variable.

Parameters
keyunique identifier of the variable
filenamefile to read
settingssettings for applying the update
Returns
0 if the value was set. -1 if unsuccessful

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.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
filenamefile to read
settingssettings for applying the update
Returns
0 if the value was set. -1 if unsuccessful

Definition at line 249 of file ThreadSafeContext.cpp.

void madara::knowledge::ThreadSafeContext::reset_checkpoint ( void  ) const
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.

void madara::knowledge::ThreadSafeContext::reset_modified ( void  )
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.

void madara::knowledge::ThreadSafeContext::reset_modified ( const std::string &  key)
inline

Resets a variable to unmodified.

Reset a variable to unmodified.

Parameters
keyunique 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.

Parameters
namename of the function to retrieve
settingssettings for referring to variables
Returns
the mapped external function

Definition at line 1053 of file ThreadSafeContext.cpp.

madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::retrieve_index ( const std::string &  key,
size_t  index,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inline

Retrieves a value at a specified index within a knowledge array.

Parameters
keyknowledge location
indexindex within the array
settingssettings for referring to knowledge variables
Returns
value at knowledge location

Definition at line 163 of file ThreadSafeContext.inl.

madara::knowledge::KnowledgeRecord madara::knowledge::ThreadSafeContext::retrieve_index ( const VariableReference variable,
size_t  index,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inline

Retrieves a value at a specified index within a knowledge array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
indexindex within the array
settingssettings for referring to knowledge variables
Returns
value at knowledge location

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.

Parameters
filenamename of the file to save to
Returns
total bytes written

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.

Parameters
settingsthe settings to save
Returns
total bytes written

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.

Parameters
filenamename of the file to save to
Returns
total bytes written

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.

Parameters
settingsthe settings to save
Returns
total bytes written

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.

Parameters
filenamename of the file to open
idunique identifier of the context holder
Returns
-1 if file open failed
-2 if file write failed
>0 if successful (number of bytes written)

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.

Parameters
settingscheckpoint settings to load
idunique identifier of the context holder
Returns
-1 if file open failed
-2 if file write failed
>0 if successful (number of bytes written)

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.

Parameters
filenamename of the file to open
idunique identifier of the context holder
Returns
-1 if file open failed
-2 if file write failed
>0 if successful (number of bytes written)

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.

Parameters
settingsthe settings to save
Returns
-1 if file open failed
-2 if file write failed
>0 if successful (number of bytes written)

Definition at line 1748 of file ThreadSafeContext.cpp.

madara::knowledge::VariableReferences madara::knowledge::ThreadSafeContext::save_modifieds ( void  ) const
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

See also
add_modifieds to remodify
Returns
a vector of VariableReferences to the current modified list

Definition at line 956 of file ThreadSafeContext.inl.

template<typename T >
int madara::knowledge::ThreadSafeContext::set ( const std::string &  key,
T &&  value,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of a variable to the specific record.

Note, this does not copy meta information (e.g. quality, clock).

Parameters
keyunique identifier of the variable
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 174 of file ThreadSafeContext.inl.

template<typename T >
int madara::knowledge::ThreadSafeContext::set ( const VariableReference variable,
T &&  value,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of a variable to an array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 185 of file ThreadSafeContext.inl.

template<typename T >
int madara::knowledge::ThreadSafeContext::set ( const std::string &  key,
const T *  value,
uint32_t  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of a variable to an array.

Parameters
keyunique identifier of the variable
valuean array
sizenumber of elements in the array
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 199 of file ThreadSafeContext.inl.

template<typename T >
int madara::knowledge::ThreadSafeContext::set ( const VariableReference variable,
const T *  value,
uint32_t  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of a variable to an array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuean array of type T
sizenumber of elements in the array
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

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.

uint64_t madara::knowledge::ThreadSafeContext::set_clock ( uint64_t  clock)
inline

Atomically sets the lamport clock.

set the lamport clock (updates with lamport clocks lower than our current clock get discarded)

Parameters
clocknew global clock
Returns
new clock time

Definition at line 563 of file ThreadSafeContext.inl.

uint64_t madara::knowledge::ThreadSafeContext::set_clock ( const std::string &  key,
uint64_t  clock,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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)

Parameters
keyunique identifier of the variable
clocknew variable clock
settingssettings for applying the update
Returns
new clock time for variable

Definition at line 579 of file ThreadSafeContext.inl.

int madara::knowledge::ThreadSafeContext::set_file ( const std::string &  key,
const unsigned char *  value,
size_t  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of a variable to an arbitrary string.

Parameters
keyunique identifier of the variable
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

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.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

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.

Parameters
keyunique identifier of the variable
valuenew value of the variable
qualityquality to set the variable at (type of priority)
clockclock value of the update
settingssettings for applying the update
Returns
1 if the value was changed. 0 if not changed. -1 if null key

Always updates clock to highest value

Returns
1 if the value was changed. 0 if not changed. -1 if null key, -2 if quality not high enough

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.

Parameters
keyunique identifier of the variable
valuenew value of the variable
qualityquality to set the variable at (type of priority)
clockclock value of the update
settingssettings for applying the update
Returns
1 if the value was changed. 0 if not changed. -1 if null key

Always updates clock to highest value

Returns
1 if the value was changed. 0 if not changed. -1 if null key, -2 if quality not high enough

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.

Parameters
keyunique identifier of the variable
valuenew value of the variable
qualityquality to set the variable at (type of priority)
clockclock value of the update
settingssettings for applying the update
Returns
1 if the value was changed. 0 if not changed. -1 if null key

Always updates clock to highest value

Returns
1 if the value was changed. 0 if not changed. -1 if null key, -2 if quality not high enough

Definition at line 569 of file ThreadSafeContext.cpp.

template<typename T >
int madara::knowledge::ThreadSafeContext::set_index ( const std::string &  key,
size_t  index,
T &&  value,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of an array index to a value.

Parameters
keyunique identifier of the variable
indexindex within array
valuenew value of the array index
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 324 of file ThreadSafeContext.inl.

template<typename T >
int madara::knowledge::ThreadSafeContext::set_index ( const VariableReference variable,
size_t  index,
T &&  value,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of an array index to a value.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
indexindex within array
valuenew value of the array index
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 335 of file ThreadSafeContext.inl.

template<typename T >
int madara::knowledge::ThreadSafeContext::set_index_unsafe ( const VariableReference variable,
size_t  index,
T &&  value,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

NON-Atomically sets the value of an array index to a value.

THIS IS NOT A THREAD-SAFE FUNCTION.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
indexindex within array
valuenew value of the array index
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 368 of file ThreadSafeContext.inl.

template<typename T >
int madara::knowledge::ThreadSafeContext::set_index_unsafe_impl ( const VariableReference variable,
size_t  index,
T &&  value,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inlineprivate

Definition at line 349 of file ThreadSafeContext.inl.

int madara::knowledge::ThreadSafeContext::set_jpeg ( const std::string &  key,
const unsigned char *  value,
size_t  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of a variable to a JPEG image.

Parameters
keyunique identifier of the variable
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

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.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 197 of file ThreadSafeContext.cpp.

void madara::knowledge::ThreadSafeContext::set_log_level ( int  level)
inline

Sets the log level.

Parameters
levelthe 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.

Parameters
keyunique identifier of the variable
qualityquality of this process
force_updateforce an update to variable, even if lower
settingssettings for referring to a knowledge variable
Returns
write quality associated with the variable
quality of the variable after this call

Definition at line 343 of file ThreadSafeContext.cpp.

int madara::knowledge::ThreadSafeContext::set_text ( const std::string &  key,
const char *  value,
size_t  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of a variable to an XML string.

Parameters
keyunique identifier of the variable
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

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.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 171 of file ThreadSafeContext.cpp.

template<typename T >
int madara::knowledge::ThreadSafeContext::set_unsafe ( const VariableReference variable,
T &&  value,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
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).

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 252 of file ThreadSafeContext.inl.

template<typename T >
int madara::knowledge::ThreadSafeContext::set_unsafe ( const VariableReference variable,
const T *  array,
size_t  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
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).

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
arraynew array value of the variable
sizesize of array pointed to by array
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 268 of file ThreadSafeContext.inl.

template<typename... Args>
int madara::knowledge::ThreadSafeContext::set_unsafe_impl ( const VariableReference variable,
const KnowledgeUpdateSettings settings,
Args &&...  args 
)
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.

Parameters
keyunique identifier of the variable
qualitywrite quality of this process
settingssettings for referring to a knowledge variable

Definition at line 380 of file ThreadSafeContext.cpp.

int madara::knowledge::ThreadSafeContext::set_xml ( const std::string &  key,
const char *  value,
size_t  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)
inline

Atomically sets the value of a variable to an XML string.

Parameters
keyunique identifier of the variable
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

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.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 144 of file ThreadSafeContext.cpp.

std::shared_ptr<std::vector<unsigned char> > madara::knowledge::ThreadSafeContext::share_binary ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
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.

std::shared_ptr<std::vector<unsigned char> > madara::knowledge::ThreadSafeContext::share_binary ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
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.

std::shared_ptr<std::vector<double> > madara::knowledge::ThreadSafeContext::share_doubles ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
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.

std::shared_ptr<std::vector<double> > madara::knowledge::ThreadSafeContext::share_doubles ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
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.

std::shared_ptr<std::vector<KnowledgeRecord::Integer> > madara::knowledge::ThreadSafeContext::share_integers ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
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.

std::shared_ptr<std::vector<KnowledgeRecord::Integer> > madara::knowledge::ThreadSafeContext::share_integers ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
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.

std::shared_ptr<std::string> madara::knowledge::ThreadSafeContext::share_string ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
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.

std::shared_ptr<std::string> madara::knowledge::ThreadSafeContext::share_string ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
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.

void madara::knowledge::ThreadSafeContext::signal ( bool  lock = true) const
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.

std::shared_ptr<std::vector<unsigned char> > madara::knowledge::ThreadSafeContext::take_binary ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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.

std::shared_ptr<std::vector<unsigned char> > madara::knowledge::ThreadSafeContext::take_binary ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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.

std::shared_ptr<std::vector<double> > madara::knowledge::ThreadSafeContext::take_doubles ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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.

std::shared_ptr<std::vector<double> > madara::knowledge::ThreadSafeContext::take_doubles ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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.

std::shared_ptr<std::vector<KnowledgeRecord::Integer> > madara::knowledge::ThreadSafeContext::take_integers ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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.

std::shared_ptr<std::vector<KnowledgeRecord::Integer> > madara::knowledge::ThreadSafeContext::take_integers ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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.

std::shared_ptr<std::string> madara::knowledge::ThreadSafeContext::take_string ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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.

std::shared_ptr<std::string> madara::knowledge::ThreadSafeContext::take_string ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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*"

Parameters
subjectAn expression that matches the variable names that are of interest. Wildcards may only be at the end.
targetThe map that will be filled with variable names and the Knowledge Records that correspond to
Returns
entries in the resulting map

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

See also
containers::FlexMap).
Parameters
prefixText that must be present at the front of the key
delimiterText that signifies a logical boundary in hierarchy If empty, no check is performed.
suffixText that must be present at the end of the key. If empty, no check is performed.
next_keysThe immediate keys in the hierarchy after prefix
resultThe map that will be filled with full variable names and the Knowledge Records that correspond to
just_keysif true, do not fill result, only next_keys
Returns
entries in the resulting map

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

Parameters
prefixPrefix string to match with
Returns
A new map with just entries starting with prefix

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.

Parameters
prefixPrefix string to match with
Returns
A new map with just entries starting with prefix

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.

Parameters
targetwhere to store the resulting string operation.
array_delimiterfor any arrays, the characters in between data elements.
record_delimiterthe characters to place between individual key/value pairs
key_val_delimiterthe 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.

Parameters
subjectThe 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".
startAn inclusive start index
endAn inclusive end index
targetThe vector that will be filled with Knowledge Record instances within the subject range.
Returns
entries in the resulting vector

Definition at line 1118 of file ThreadSafeContext.cpp.

void madara::knowledge::ThreadSafeContext::unlock ( void  ) const
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.

Parameters
keyunique identifier of the variable
rhsnew value of the variable
settingssettings for applying the update
Returns
1 if the value was changed. 0 if not changed. -1 if null key

Always updates clock to highest value

Returns
1 if the value was changed. 0 if not changed. -1 if null key, -2 if quality not high enough

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.

Parameters
targetthe target reference in the knowledge base
rhsnew value of the variable
settingssettings for applying the update
Returns
1 if the value was changed. 0 if not changed. -1 if null key

Always updates clock to highest value

Returns
1 if the value was changed. 0 if not changed. -1 if null key, -2 if quality not high enough

Definition at line 723 of file ThreadSafeContext.cpp.

void madara::knowledge::ThreadSafeContext::wait_for_change ( bool  extra_release = false)
inline

Wait for a change to happen to the context.

Make the current thread of execution wait for a change on the context.

Parameters
extra_releaseperform extra release of lock for nested locks

Definition at line 768 of file ThreadSafeContext.inl.

madara::knowledge::KnowledgeRecord * madara::knowledge::ThreadSafeContext::with ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inlineprivate

Atomically returns a reference to the variable.

Parameters
keyunique identifier of the variable
settingsthe settings for referring to variables
Returns
pointer to record, nullptr if none exists

Definition at line 52 of file ThreadSafeContext.inl.

madara::knowledge::KnowledgeRecord * madara::knowledge::ThreadSafeContext::with ( const VariableReference variable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inlineprivate

Atomically returns the value of a variable.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingsthe settings for referring to variables
Returns
pointer to record, nullptr if none exists

Definition at line 80 of file ThreadSafeContext.inl.

const madara::knowledge::KnowledgeRecord * madara::knowledge::ThreadSafeContext::with ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
inlineprivate

Atomically returns a reference to the variable.

Parameters
keyunique identifier of the variable
settingsthe settings for referring to variables
Returns
the madara::knowledge::KnowledgeRecord::Integer value for the variable

Definition at line 93 of file ThreadSafeContext.inl.

const madara::knowledge::KnowledgeRecord * madara::knowledge::ThreadSafeContext::with ( const VariableReference variable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
inlineprivate

Atomically returns the value of a variable.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingsthe settings for referring to variables
Returns
the madara::knowledge::KnowledgeRecord::Integer value for the variable

Definition at line 121 of file ThreadSafeContext.inl.

Friends And Related Function Documentation

Definition at line 86 of file ThreadSafeContext.h.

friend class expression::VariableNode
friend

Definition at line 87 of file ThreadSafeContext.h.

friend class KnowledgeBaseImpl
friend

Definition at line 85 of file ThreadSafeContext.h.

friend class rcw::BaseTracker
friend

Definition at line 88 of file ThreadSafeContext.h.

Member Data Documentation

MADARA_CONDITION_TYPE madara::knowledge::ThreadSafeContext::changed_
mutableprivate

Definition at line 1678 of file ThreadSafeContext.h.

knowledge::KnowledgeRecords madara::knowledge::ThreadSafeContext::changed_map_
mutableprivate

Definition at line 1681 of file ThreadSafeContext.h.

uint64_t madara::knowledge::ThreadSafeContext::clock_
mutableprivate

Definition at line 1680 of file ThreadSafeContext.h.

std::vector< std::string> madara::knowledge::ThreadSafeContext::expansion_splitters_
private

Definition at line 1679 of file ThreadSafeContext.h.

FunctionMap madara::knowledge::ThreadSafeContext::functions_
private

map of function names to functions

Definition at line 1685 of file ThreadSafeContext.h.

madara::expression::Interpreter* madara::knowledge::ThreadSafeContext::interpreter_
private

KaRL interpreter.

Definition at line 1688 of file ThreadSafeContext.h.

knowledge::KnowledgeRecords madara::knowledge::ThreadSafeContext::local_changed_map_
mutableprivate

Definition at line 1682 of file ThreadSafeContext.h.

logger::Logger* madara::knowledge::ThreadSafeContext::logger_
mutableprivate

Logger for printing.

Definition at line 1691 of file ThreadSafeContext.h.

madara::knowledge::KnowledgeMap madara::knowledge::ThreadSafeContext::map_
private

Hash table containing variable names and values.

Definition at line 1676 of file ThreadSafeContext.h.

MADARA_LOCK_TYPE madara::knowledge::ThreadSafeContext::mutex_
mutableprivate

Definition at line 1677 of file ThreadSafeContext.h.


The documentation for this class was generated from the following files: