Robox Library for Cpp: BCC/31 module 1.0.0
RLibCpp BCC/31 protocol implementation
Public Member Functions | Protected Types | Protected Member Functions | List of all members
Connection::VariablesCache Class Reference

The class to handle variable caches. More...

#include <connection.h>

Public Member Functions

 VariablesCache (Connection *connection)
 The constructor.
 
 ~VariablesCache ()
 The destructor.
 
Globals::Results update (VariablesDict &varDict, bool useCoherentValues)
 Updates the variables' cache with the current dictionary values.
 
Globals::Results getCacheItem (Client &client, uint32_t cacheId, bool forceVarDictUpdate, bool useCoherentValues, bool checkFullVar, uint32_t startMsgOffset, uint32_t splitOffset, VariablesCacheItem *&vcache)
 Query a cached item given its ID.
 
uint32_t add (const String &name, const String &extraTag="")
 Adds a variable to the cache.
 
bool contains (uint32_t cacheId)
 Helper to check if cacheId is a valid identifier stored into the cache.
 
uint32_t find (const String &name, const String &extraTag="")
 Check if the variable of specified in name with extraTag is cached.
 
Globals::Results remove (uint32_t cacheId)
 Removes the variable specified by cacheId from the cache.
 
Message::DataTypes dataType (uint32_t cacheId)
 Get the data types for the specified cacheId stored into the cache.
 
uint32_t count ()
 Get the number of cached items.
 
void clear ()
 Clears the variables' cache removing all the cached variables.
 
void cleanup ()
 Clears each cached variable without removing the cache entry.
 
VariablesCacheItemitem (uint32_t cacheId)
 Returns the pointer to the cache item with cache id cacheId
 
bool needUpdate () const
 get the flag to indicate if the variable cache needs to be udpated
 

Protected Types

typedef std::map< uint32_t, VariablesCacheItem * > VariablesCacheItemHash
 

Protected Member Functions

uint32_t getCacheId (const String &name, const String &extraTag)
 Get the cache identifier from the name.
 
VariablesCacheItemHashvarCaches ()
 Get the cached variable dictionary (

See also
VariablesCacheItem

)

 
Connectionconnection () const
 Get the connection internal object.
 
void setNeedUpdate (bool value)
 Set/reset the flag for variable cache to be udpated on the next operation using the cache.
 

Detailed Description

The class to handle variable caches.

Member Typedef Documentation

◆ VariablesCacheItemHash

typedef std::map<uint32_t, VariablesCacheItem*> VariablesCacheItemHash
protected

Constructor & Destructor Documentation

◆ VariablesCache()

VariablesCache ( Connection * connection)

The constructor.

Parameters
connectionThe connection to use

◆ ~VariablesCache()

The destructor.

Member Function Documentation

◆ add()

uint32_t add ( const String & name,
const String & extraTag = "" )

Adds a variable to the cache.

Parameters
nameThe name of the variable to add to the cache
extraTagThe optional extra tag used in cache id calculation: you can set this to different values to force caching of distinct entries of the same variable
Returns
Returns the variable cache identifier or 0 if some error occurred

All successive operation onto the variable (Client.readVariable(ClientStruct::ReadVariableData &) , Client.writeVariable(ClientStruct::WriteVariableData &) etc) must refer to returned cache identifier

Variable naming convention must the same as RDE.

Using different extraTag values for the same name may be useful to maximize performance when accessing the same variable from Monitor, Client ( e.g. Client.readVariable(ClientStruct::ReadVariableData &), Client.writeVariable(ClientStruct::WriteVariableData &) , Monitor::read(MonitorStruct::ReadData &), etc) or Oscilloscope: in that cases, using different extraTag values (e.g. "MON", "CLIENT", "OSC" ) will force the caching of distinct entry , improving the overall performance

◆ cleanup()

void cleanup ( )

Clears each cached variable without removing the cache entry.

◆ clear()

void clear ( )

Clears the variables' cache removing all the cached variables.

◆ connection()

Connection * connection ( ) const
protected

Get the connection internal object.

Returns
The parameter value

◆ contains()

bool contains ( uint32_t cacheId)

Helper to check if cacheId is a valid identifier stored into the cache.

Parameters
cacheIdThe cache identifier to check
Returns
Returns true if the cacheId is a valid identifier stored into the cache

◆ count()

uint32_t count ( )

Get the number of cached items.

Returns
Returns the number of cached items

◆ dataType()

Message::DataTypes dataType ( uint32_t cacheId)

Get the data types for the specified cacheId stored into the cache.

Parameters
cacheIdThe cache identifier for which to get the data type
Returns
Returns the Message::DataTypes for the cached variable if the cacheId was found , or Message::DataTypes::dtUndef if not found

◆ find()

uint32_t find ( const String & name,
const String & extraTag = "" )

Check if the variable of specified in name with extraTag is cached.

Parameters
nameThe name of the variable to earch for
extraTagThe optional extra tag used in cache id calculation
See also
addToVarsCache(const String &, const String &)
Returns
Returns the variable cache identifier or 0 if some error occurred or variable not cached

The search is case insensitive: leading and traling whites char are trimmed.

◆ getCacheId()

uint32_t getCacheId ( const String & name,
const String & extraTag )
protected

Get the cache identifier from the name.

The id is calculated from the 'normalized' name i.e the name is trimmed and converted to upper case

Parameters
namethe name from which to get the cache id
extraTagThe extra tag used in cache id calculation: you can set this to different values to force caching of distinct entries of the same variable
Returns
The cache id

◆ getCacheItem()

Globals::Results getCacheItem ( Client & client,
uint32_t cacheId,
bool forceVarDictUpdate,
bool useCoherentValues,
bool checkFullVar,
uint32_t startMsgOffset,
uint32_t splitOffset,
VariablesCacheItem *& vcache )

Query a cached item given its ID.

Parameters
clientThe client to use for comunicate to the device.
cacheIdThe identifier of the variable into the cache
forceVarDictUpdateFlag to force the variable dictionary update
useCoherentValuesFlag to indicate that coherent operations are required, so no packet splitting will be performed
checkFullVarFlag to enable the variable full check when parsing
startMsgOffsetMessage offset to be used on new var
splitOffsetOffset to be applyed to the to the parsing variable logic to properly split the variable. Thats applies when a variable has to be fitted into a BCC message which contains other data (tipcally when using monitors)
vcacheThe cache object , or null if some error occurred
Returns
Return the operation result code.

◆ item()

VariablesCacheItem * item ( uint32_t cacheId)

Returns the pointer to the cache item with cache id cacheId

Parameters
cacheIdthe item cache id
Returns
Returns the pointer to the item, NULL if no item was found for cacheId

◆ needUpdate()

bool needUpdate ( ) const

get the flag to indicate if the variable cache needs to be udpated

Returns
The parameter value

◆ remove()

Globals::Results remove ( uint32_t cacheId)

Removes the variable specified by cacheId from the cache.

Parameters
cacheIdThe cache identifier to remove
Returns
Returns Globals::resSuccess if the cacheId was found and succesfully removed from cache

◆ setNeedUpdate()

void setNeedUpdate ( bool value)
protected

Set/reset the flag for variable cache to be udpated on the next operation using the cache.

Parameters
valueThe value to set

◆ update()

Globals::Results update ( VariablesDict & varDict,
bool useCoherentValues )

Updates the variables' cache with the current dictionary values.

Parameters
varDictthe variable dictionay to use
useCoherentValuesFlag to ensure coherent values operation
Returns
Return true if each cached variable was successfully updated

◆ varCaches()

QHash< uint32_t, VariablesCacheItem * > & varCaches ( )
protected

Get the cached variable dictionary (

See also
VariablesCacheItem

)

Returns
The parameter value