CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::ComponentMemory Class Reference

Accessor for the shared component registry. More...

#include <ComponentMemory.h>

Public Member Functions

 ComponentMemory (MasterMemory *master)
 ~ComponentMemory ()
bool getMemoryUsage (uint64 &alloc, uint64 &usage)
 Report allocation/usage of the component segment.
bool open ()
 Attach to the existing component segment.
bool create (uint32 indexSize)
 Create the component segment (master only).
std::vector< ComponentInfoStruct > * getAllComponents ()
 Snapshot all components.
std::vector< ComponentInfoStruct > * getAllLocalComponents ()
 Snapshot components on this node.
std::vector< ComponentInfoStruct > * getAllLocalComponents (uint8 type)
 Snapshot local components of type.
std::vector< ComponentInfoStruct > * getAllModules ()
 Snapshot all module components.
std::vector< ComponentInfoStruct > * getAllCatalogs ()
 Snapshot all catalog components.
bool writeComponentsToMsg (DataMessage *msg)
 Serialize all component records into msg.
bool writeComponentNamesToMsg (DataMessage *msg)
 Write just the component names into msg.
bool syncComponents (DataMessage *msg)
 Merge component records received from a remote node.
bool confirmComponentID (uint32 id)
 Mark a provisionally reserved component id as ready (syncStatus 2).
bool cancelComponentID (uint32 id)
 Release a provisionally reserved component id.
uint8 lookupComponentID (const char *name, uint32 &id)
 Look up a component by name without filtering on readiness.
bool createComponent (uint32 id, uint8 type, uint8 policy, uint8 selfTrigger, const char *name, uint64 size, uint16 nodeID, uint16 procID, uint64 time, uint32 &existingID)
 Register a component record.
bool destroyComponent (uint32 cid)
 Remove a component record and free its space.
bool getComponentName (uint32 cid, char *name, uint32 maxNameLen)
 Copy the component name into name.
std::string getComponentNameString (uint32 cid)
uint8 getComponentType (uint32 cid)
bool getComponentID (const char *name, uint32 &cid)
 Look up a component id by name.
ComponentStats getComponentStats (uint32 cid)
bool setComponentStats (uint32 cid, ComponentStats &stats)
 Overwrite the component's stats.
AveragePerfStats getComponentPerfStats (uint32 cid)
bool setComponentPerfStats (uint32 cid, AveragePerfStats &perfStruct)
 Store new performance averages.
bool isComponentLocal (uint32 cid)
bool isComponentLocal (const char *name)
bool getComponentLocation (uint32 cid, uint16 &nodeID, uint16 &procID)
 Get the node/process the component runs in.
uint8 getComponentPolicy (uint32 cid)
bool updateComponentInformation (uint32 cid, uint8 type, uint8 policy, uint8 selfTrigger, uint16 nodeID, uint16 procID)
 Update type/policy/self-trigger/location in one call.
bool setComponentPolicy (uint32 cid, uint8 policy)
 Set the migration policy.
uint8 getComponentSelfTrigger (uint32 cid)
bool setComponentSelfTrigger (uint32 cid, uint8 selfTrigger)
 Set the self-trigger policy.
uint16 getComponentNodeID (uint32 cid)
uint16 getComponentProcessID (uint32 cid)
bool updateComponentLocation (uint32 cid, uint16 nodeID, uint16 procID)
 Record a new location (after migration).
bool addComponentStats (uint32 cid, uint8 status, uint64 usageCPUTicks, DataMessage *inputMsg, DataMessage *outputMsg, uint32 runCount, uint32 cycleCount)
 Fold a run's activity into the component's stats (counters, rings, CPU ticks).
bool canComponentMigrate (uint32 cid)
std::list< uint16 > * findProcessComponents (uint16 procID)
 List ids of components in process procID.
char * getComponentData (uint32 cid, uint64 &size)
 Copy a component's whole data area (for migration).
bool setComponentData (uint32 cid, const char *data, uint64 size, bool wasMigrated)
 Replace a component's data area (after migration).
bool hasParameter (uint32 cid, const char *name)
bool deleteParameter (uint32 cid, const char *name)
 Remove the parameter.
bool addLocalPerformanceStats (std::list< PerfStats > &perfStats)
 Append PerfStats for all local components.
std::string printFriendly ()
std::string toXML (bool stats=true)
Private data (named binary blobs owned by a component)

Blobs are stored inline in the component record with optional mimetype.

bool setPrivateData (uint32 cid, const char *name, const char *data, uint64 size, const char *mimetype=NULL)
 Create/replace blob name.
uint64 getPrivateDataSize (uint32 cid, const char *name)
std::string getPrivateDataMimetype (uint32 cid, const char *name)
bool getPrivateData (uint32 cid, const char *name, char *data, uint64 maxSize)
 Copy blob into caller buffer data (max maxSize).
char * getPrivateDataCopy (uint32 cid, const char *name, uint64 &size)
bool deletePrivateData (uint32 cid, const char *name)
 Delete blob name.
std::map< std::string, std::string > getPrivateDataKeysAndTypes (uint32 cid)
std::list< std::string > getPrivateDataKeys (uint32 cid)
Parameter creation

Overloads create string/integer/float parameters or collections thereof; values are copied into the component record.

min/max/interval of 0 mean unconstrained.

Returns
true on success (false if the parameter exists with a different type).
bool createParameter (uint32 cid, const char *name, const char *val, const char *defaultValue=NULL)
bool createParameter (uint32 cid, const char *name, const char *val, uint32 count, uint32 defaultIndex)
bool createParameter (uint32 cid, const char *name, std::vector< std::string > values, const char *defaultValue=NULL)
bool createParameter (uint32 cid, const char *name, int64 *val, uint32 count, uint32 defaultIndex)
bool createParameter (uint32 cid, const char *name, std::vector< std::string > values, int64 defaultValue)
bool createParameter (uint32 cid, const char *name, std::vector< int64 > values, int64 defaultValue=0)
bool createParameter (uint32 cid, const char *name, float64 *val, uint32 count, uint32 defaultIndex)
bool createParameter (uint32 cid, const char *name, std::vector< std::string > values, float64 defaultValue)
bool createParameter (uint32 cid, const char *name, std::vector< float64 > values, float64 defaultValue=0)
bool createParameter (uint32 cid, const char *name, int64 val, int64 min=0, int64 max=0, int64 interval=0)
bool createParameter (uint32 cid, const char *name, float64 val, float64 min=0, float64 max=0, float64 interval=0)
Parameter access

Typed getters convert where sensible; getters return 0/empty on missing parameters.

Setters clamp to min/max where configured.

Returns
true on success (bool forms).
uint8 getParameterDataType (uint32 cid, const char *name)
uint32 getParameterValueSize (uint32 cid, const char *name)
bool getParameter (uint32 cid, const char *name, char *val, uint32 maxSize)
bool getParameter (uint32 cid, const char *name, int64 &val)
bool getParameter (uint32 cid, const char *name, float64 &val)
std::string getParameterString (uint32 cid, const char *name, uint32 maxSize)
std::string getParameterString (uint32 cid, const char *name)
int64 getParameterInt (uint32 cid, const char *name)
float64 getParameterFloat (uint32 cid, const char *name)
bool getParameterAsBool (uint32 cid, const char *name)
bool setParameter (uint32 cid, const char *name, const char *val)
bool setParameter (uint32 cid, const char *name, int64 val)
bool setParameter (uint32 cid, const char *name, float64 val)
bool resetParameter (uint32 cid, const char *name)
 Restore the parameter's default value/index.
bool tweakParameter (uint32 cid, const char *name, int32 tweak)
 Step the value by tweak * interval (or collection index).

Static Public Member Functions

static bool UnitTest ()
 Self-test.

Detailed Description

Accessor for the shared component registry.

One instance per process (created by MemoryManager). The node master calls create(); other processes open(). Every method locks the segment's named cross-process mutex and re-attaches when the segment was resized elsewhere (serial check). String/char* out parameters are copied into caller buffers; returned containers (vectors/lists) are heap-allocated and owned by the caller. The master pointer is borrowed.

uint32 cid; uint32 existing;
componentMemory->createComponent(cid, type, policy, SELFTRIGGER_NONE,
"MyModule", 4096, nodeID, procID, now, existing);
componentMemory->createParameter(cid, "Threshold", (int64)10, 0, 100, 1);
int64 v = componentMemory->getParameterInt(cid, "Threshold");
#define SELFTRIGGER_NONE
Self-triggering forbidden.

Definition at line 262 of file ComponentMemory.h.

Constructor & Destructor Documentation

◆ ComponentMemory()

cmlabs::ComponentMemory::ComponentMemory ( MasterMemory * master)
Parameters
masterSegment bookkeeping interface (borrowed, not owned).

Definition at line 14 of file ComponentMemory.cpp.

◆ ~ComponentMemory()

cmlabs::ComponentMemory::~ComponentMemory ( )

Definition at line 23 of file ComponentMemory.cpp.

References cmlabs::utils::CloseSharedMemorySegment().

Member Function Documentation

◆ addComponentStats()

◆ addLocalPerformanceStats()

◆ cancelComponentID()

bool cmlabs::ComponentMemory::cancelComponentID ( uint32 id)

◆ canComponentMigrate()

bool cmlabs::ComponentMemory::canComponentMigrate ( uint32 cid)
Returns
true if the component's policy allows migration.

Definition at line 836 of file ComponentMemory.cpp.

References COMPONENT_CAN_MIGRATE, and getComponentPolicy().

◆ confirmComponentID()

bool cmlabs::ComponentMemory::confirmComponentID ( uint32 id)

Mark a provisionally reserved component id as ready (syncStatus 2).

Returns
true on success.

Definition at line 436 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, cmlabs::ComponentInfoStruct::syncStatus, and cmlabs::ComponentInfoStruct::type.

Referenced by syncComponents(), and UnitTest().

◆ create()

bool cmlabs::ComponentMemory::create ( uint32 indexSize)

Create the component segment (master only).

Parameters
indexSizeComponent-id capacity.
Returns
true on success.

Definition at line 206 of file ComponentMemory.cpp.

References COMPONENTMEMORYID, cmlabs::utils::CreateSharedMemorySegment(), cmlabs::GetTimeNow(), and cmlabs::utils::StringFormat().

◆ createComponent()

bool cmlabs::ComponentMemory::createComponent ( uint32 id,
uint8 type,
uint8 policy,
uint8 selfTrigger,
const char * name,
uint64 size,
uint16 nodeID,
uint16 procID,
uint64 time,
uint32 & existingID )

Register a component record.

Parameters
idRequested component id.
typeComponent type.
policyMigration policy.
selfTriggerSELFTRIGGER_* policy.
nameUnique component name.
sizeInitial record size in bytes.
nodeIDNode the component lives on.
procIDProcess the component lives in.
timeCreation timestamp (µs).
existingIDReceives the id of a pre-existing component with the same name, if any.
Returns
true on success.

Definition at line 546 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, cmlabs::ComponentInfoStruct::createdTime, GETCOMPDATA, getComponentID(), cmlabs::GetTimeNow(), LOG_MEMORY, LogPrint, MAXKEYNAMELEN, cmlabs::ComponentInfoStruct::name, cmlabs::ComponentInfoStruct::nodeID, cmlabs::ComponentInfoStruct::policy, cmlabs::ComponentInfoStruct::procID, cmlabs::ComponentInfoStruct::selfTrigger, cmlabs::ComponentInfoStruct::size, cmlabs::utils::strcpyavail(), stricmp, cmlabs::ComponentInfoStruct::syncStatus, and cmlabs::ComponentInfoStruct::type.

Referenced by syncComponents(), and UnitTest().

◆ createParameter() [1/11]

◆ createParameter() [2/11]

◆ createParameter() [3/11]

◆ createParameter() [4/11]

◆ createParameter() [5/11]

◆ createParameter() [6/11]

◆ createParameter() [7/11]

bool cmlabs::ComponentMemory::createParameter ( uint32 cid,
const char * name,
std::vector< float64 > values,
float64 defaultValue = 0 )

Definition at line 1800 of file ComponentMemory.cpp.

References createParameter().

◆ createParameter() [8/11]

bool cmlabs::ComponentMemory::createParameter ( uint32 cid,
const char * name,
std::vector< int64 > values,
int64 defaultValue = 0 )

Definition at line 1772 of file ComponentMemory.cpp.

References createParameter().

◆ createParameter() [9/11]

bool cmlabs::ComponentMemory::createParameter ( uint32 cid,
const char * name,
std::vector< std::string > values,
const char * defaultValue = NULL )

Definition at line 1740 of file ComponentMemory.cpp.

References createParameter().

◆ createParameter() [10/11]

bool cmlabs::ComponentMemory::createParameter ( uint32 cid,
const char * name,
std::vector< std::string > values,
float64 defaultValue )

Definition at line 1786 of file ComponentMemory.cpp.

References cmlabs::utils::Ascii2Float64(), and createParameter().

◆ createParameter() [11/11]

bool cmlabs::ComponentMemory::createParameter ( uint32 cid,
const char * name,
std::vector< std::string > values,
int64 defaultValue )

Definition at line 1758 of file ComponentMemory.cpp.

References cmlabs::utils::Ascii2Int64(), and createParameter().

◆ deleteParameter()

bool cmlabs::ComponentMemory::deleteParameter ( uint32 cid,
const char * name )

◆ deletePrivateData()

bool cmlabs::ComponentMemory::deletePrivateData ( uint32 cid,
const char * name )

◆ destroyComponent()

bool cmlabs::ComponentMemory::destroyComponent ( uint32 cid)

Remove a component record and free its space.

Returns
true on success.

Definition at line 688 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, GETCOMPOFFSETP, and cmlabs::ComponentInfoStruct::size.

Referenced by UnitTest().

◆ findProcessComponents()

std::list< uint16 > * cmlabs::ComponentMemory::findProcessComponents ( uint16 procID)

List ids of components in process procID.

Returns
Caller-owned list.

Definition at line 818 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, and GETCOMPDATA.

◆ getAllCatalogs()

std::vector< ComponentInfoStruct > * cmlabs::ComponentMemory::getAllCatalogs ( )

Snapshot all catalog components.

Returns
Caller-owned vector.

Definition at line 190 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, COMP_CATALOG, COMP_WHITEBOARD, and GETCOMPDATA.

◆ getAllComponents()

std::vector< ComponentInfoStruct > * cmlabs::ComponentMemory::getAllComponents ( )

Snapshot all components.

Returns
Caller-owned vector.

Definition at line 129 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, and GETCOMPDATA.

Referenced by printFriendly(), toXML(), writeComponentNamesToMsg(), and writeComponentsToMsg().

◆ getAllLocalComponents() [1/2]

std::vector< ComponentInfoStruct > * cmlabs::ComponentMemory::getAllLocalComponents ( )

Snapshot components on this node.

Returns
Caller-owned vector.

Definition at line 144 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, and GETCOMPDATA.

◆ getAllLocalComponents() [2/2]

std::vector< ComponentInfoStruct > * cmlabs::ComponentMemory::getAllLocalComponents ( uint8 type)

Snapshot local components of type.

Returns
Caller-owned vector.

Definition at line 159 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, and GETCOMPDATA.

◆ getAllModules()

std::vector< ComponentInfoStruct > * cmlabs::ComponentMemory::getAllModules ( )

Snapshot all module components.

Returns
Caller-owned vector.

Definition at line 174 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, COMP_EXTERNAL, COMP_INTERNAL, and GETCOMPDATA.

◆ getComponentData()

char * cmlabs::ComponentMemory::getComponentData ( uint32 cid,
uint64 & size )

Copy a component's whole data area (for migration).

Parameters
cidComponent id.
sizeReceives byte count.
Returns
Caller-owned heap buffer (free with free()/delete[] per implementation), or NULL.

Definition at line 758 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::size.

◆ getComponentID()

bool cmlabs::ComponentMemory::getComponentID ( const char * name,
uint32 & cid )

Look up a component id by name.

Returns
true if found.

Definition at line 1214 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and stricmp.

Referenced by createComponent(), isComponentLocal(), and UnitTest().

◆ getComponentLocation()

bool cmlabs::ComponentMemory::getComponentLocation ( uint32 cid,
uint16 & nodeID,
uint16 & procID )

Get the node/process the component runs in.

Returns
true if found.

Definition at line 952 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, cmlabs::ComponentInfoStruct::nodeID, and cmlabs::ComponentInfoStruct::procID.

Referenced by UnitTest().

◆ getComponentName()

bool cmlabs::ComponentMemory::getComponentName ( uint32 cid,
char * name,
uint32 maxNameLen )

Copy the component name into name.

Returns
true if found.

Definition at line 1079 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, cmlabs::ComponentInfoStruct::name, and cmlabs::utils::strcpyavail().

Referenced by UnitTest().

◆ getComponentNameString()

std::string cmlabs::ComponentMemory::getComponentNameString ( uint32 cid)
Returns
Component name, or empty string if unknown.

Definition at line 1057 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::name.

◆ getComponentNodeID()

uint16 cmlabs::ComponentMemory::getComponentNodeID ( uint32 cid)
Returns
Node id hosting the component.

Definition at line 977 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::nodeID.

Referenced by UnitTest().

◆ getComponentPerfStats()

AveragePerfStats cmlabs::ComponentMemory::getComponentPerfStats ( uint32 cid)
Returns
Copy of the windowed performance averages.

Definition at line 1146 of file ComponentMemory.cpp.

References GETCOMPDATA, open(), and cmlabs::ComponentInfoStruct::perfStats.

◆ getComponentPolicy()

uint8 cmlabs::ComponentMemory::getComponentPolicy ( uint32 cid)
Returns
Migration policy, 0 if unknown.

Definition at line 840 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::policy.

Referenced by canComponentMigrate().

◆ getComponentProcessID()

uint16 cmlabs::ComponentMemory::getComponentProcessID ( uint32 cid)
Returns
Process id hosting the component.

Definition at line 999 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::procID.

Referenced by UnitTest().

◆ getComponentSelfTrigger()

uint8 cmlabs::ComponentMemory::getComponentSelfTrigger ( uint32 cid)
Returns
SELFTRIGGER_* policy.

Definition at line 909 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::selfTrigger.

Referenced by UnitTest().

◆ getComponentStats()

ComponentStats cmlabs::ComponentMemory::getComponentStats ( uint32 cid)
Returns
Copy of the component's stats (zeroed if unknown).

Definition at line 1122 of file ComponentMemory.cpp.

References GETCOMPDATA, open(), and cmlabs::ComponentInfoStruct::stats.

Referenced by UnitTest().

◆ getComponentType()

uint8 cmlabs::ComponentMemory::getComponentType ( uint32 cid)
Returns
Component type, 0 if unknown.

Definition at line 1100 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::type.

Referenced by UnitTest().

◆ getMemoryUsage()

bool cmlabs::ComponentMemory::getMemoryUsage ( uint64 & alloc,
uint64 & usage )

Report allocation/usage of the component segment.

Returns
true on success.

Definition at line 35 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL.

◆ getParameter() [1/3]

◆ getParameter() [2/3]

bool cmlabs::ComponentMemory::getParameter ( uint32 cid,
const char * name,
float64 & val )

◆ getParameter() [3/3]

bool cmlabs::ComponentMemory::getParameter ( uint32 cid,
const char * name,
int64 & val )

◆ getParameterAsBool()

bool cmlabs::ComponentMemory::getParameterAsBool ( uint32 cid,
const char * name )

◆ getParameterDataType()

uint8 cmlabs::ComponentMemory::getParameterDataType ( uint32 cid,
const char * name )
Returns
PARAM_* type, 0 if absent.

Definition at line 2051 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, getParameter(), and cmlabs::ParamHeader::type.

◆ getParameterFloat()

float64 cmlabs::ComponentMemory::getParameterFloat ( uint32 cid,
const char * name )

Definition at line 2163 of file ComponentMemory.cpp.

References getParameter().

◆ getParameterInt()

int64 cmlabs::ComponentMemory::getParameterInt ( uint32 cid,
const char * name )

Definition at line 2156 of file ComponentMemory.cpp.

References getParameter().

◆ getParameterString() [1/2]

std::string cmlabs::ComponentMemory::getParameterString ( uint32 cid,
const char * name )

◆ getParameterString() [2/2]

std::string cmlabs::ComponentMemory::getParameterString ( uint32 cid,
const char * name,
uint32 maxSize )

Definition at line 2108 of file ComponentMemory.cpp.

References getParameter().

◆ getParameterValueSize()

uint32 cmlabs::ComponentMemory::getParameterValueSize ( uint32 cid,
const char * name )

◆ getPrivateData()

bool cmlabs::ComponentMemory::getPrivateData ( uint32 cid,
const char * name,
char * data,
uint64 maxSize )

Copy blob into caller buffer data (max maxSize).

Returns
true on success.

Definition at line 1467 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, getPrivateData(), and cmlabs::PrivateHeader::size.

Referenced by deletePrivateData(), getPrivateData(), getPrivateDataCopy(), getPrivateDataMimetype(), getPrivateDataSize(), setPrivateData(), and UnitTest().

◆ getPrivateDataCopy()

char * cmlabs::ComponentMemory::getPrivateDataCopy ( uint32 cid,
const char * name,
uint64 & size )
Returns
Caller-owned heap copy of the blob, or NULL.

Definition at line 1436 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, getPrivateData(), and cmlabs::PrivateHeader::size.

◆ getPrivateDataKeys()

std::list< std::string > cmlabs::ComponentMemory::getPrivateDataKeys ( uint32 cid)

◆ getPrivateDataKeysAndTypes()

std::map< std::string, std::string > cmlabs::ComponentMemory::getPrivateDataKeysAndTypes ( uint32 cid)

◆ getPrivateDataMimetype()

std::string cmlabs::ComponentMemory::getPrivateDataMimetype ( uint32 cid,
const char * name )
Returns
Blob mimetype, empty if absent.

Definition at line 1497 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, and getPrivateData().

◆ getPrivateDataSize()

uint64 cmlabs::ComponentMemory::getPrivateDataSize ( uint32 cid,
const char * name )
Returns
Blob size in bytes, 0 if absent.

Definition at line 1412 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, getPrivateData(), and cmlabs::PrivateHeader::size.

Referenced by UnitTest().

◆ hasParameter()

bool cmlabs::ComponentMemory::hasParameter ( uint32 cid,
const char * name )
Returns
true if the parameter exists.

Definition at line 2004 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, and getParameter().

◆ isComponentLocal() [1/2]

bool cmlabs::ComponentMemory::isComponentLocal ( const char * name)
Returns
true if the named component runs on this node.

Definition at line 1049 of file ComponentMemory.cpp.

References getComponentID(), and isComponentLocal().

◆ isComponentLocal() [2/2]

bool cmlabs::ComponentMemory::isComponentLocal ( uint32 cid)
Returns
true if the component runs on this node.

Definition at line 1022 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::nodeID.

Referenced by isComponentLocal().

◆ lookupComponentID()

uint8 cmlabs::ComponentMemory::lookupComponentID ( const char * name,
uint32 & id )

Look up a component by name without filtering on readiness.

Parameters
nameComponent name to look up.
idReceives the component id when found.
Returns
Sync status: 0 not there, 1 in-sync (reserved), 2 ready.

Definition at line 1234 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, cmlabs::ComponentInfoStruct::name, stricmp, and cmlabs::ComponentInfoStruct::syncStatus.

◆ open()

bool cmlabs::ComponentMemory::open ( )

◆ printFriendly()

std::string cmlabs::ComponentMemory::printFriendly ( )
Returns
Human-readable dump of the registry.

Definition at line 83 of file ComponentMemory.cpp.

References getAllComponents(), and cmlabs::utils::StringFormat().

◆ resetParameter()

bool cmlabs::ComponentMemory::resetParameter ( uint32 cid,
const char * name )

Restore the parameter's default value/index.

Returns
true on success.

Definition at line 2530 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, getParameter(), PARAM_FLOAT, PARAM_FLOAT_COLL, PARAM_INTEGER, PARAM_INTEGER_COLL, PARAM_STRING, PARAM_STRING_COLL, setParameter(), and cmlabs::ParamHeader::type.

◆ setComponentData()

bool cmlabs::ComponentMemory::setComponentData ( uint32 cid,
const char * data,
uint64 size,
bool wasMigrated )

Replace a component's data area (after migration).

Parameters
cidComponent id.
dataNew data area.
sizeByte count.
wasMigratedMarks a migration event.
Returns
true on success.

Definition at line 782 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, cmlabs::ComponentStats::migrationCount, cmlabs::ComponentInfoStruct::size, and cmlabs::ComponentInfoStruct::stats.

◆ setComponentPerfStats()

bool cmlabs::ComponentMemory::setComponentPerfStats ( uint32 cid,
AveragePerfStats & perfStruct )

Store new performance averages.

Returns
true on success.

Definition at line 1170 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::perfStats.

◆ setComponentPolicy()

bool cmlabs::ComponentMemory::setComponentPolicy ( uint32 cid,
uint8 policy )

Set the migration policy.

Returns
true on success.

Definition at line 888 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::policy.

◆ setComponentSelfTrigger()

bool cmlabs::ComponentMemory::setComponentSelfTrigger ( uint32 cid,
uint8 selfTrigger )

Set the self-trigger policy.

Returns
true on success.

Definition at line 930 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::selfTrigger.

◆ setComponentStats()

bool cmlabs::ComponentMemory::setComponentStats ( uint32 cid,
ComponentStats & stats )

Overwrite the component's stats.

Returns
true on success.

Definition at line 1192 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, and cmlabs::ComponentInfoStruct::stats.

◆ setParameter() [1/3]

bool cmlabs::ComponentMemory::setParameter ( uint32 cid,
const char * name,
const char * val )

◆ setParameter() [2/3]

bool cmlabs::ComponentMemory::setParameter ( uint32 cid,
const char * name,
float64 val )

◆ setParameter() [3/3]

bool cmlabs::ComponentMemory::setParameter ( uint32 cid,
const char * name,
int64 val )

◆ setPrivateData()

bool cmlabs::ComponentMemory::setPrivateData ( uint32 cid,
const char * name,
const char * data,
uint64 size,
const char * mimetype = NULL )

Create/replace blob name.

Data is copied.

Returns
true on success.

Definition at line 1329 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, cmlabs::ComponentInfoStruct::dataCount, cmlabs::ComponentInfoStruct::dataSize, deletePrivateData(), GETCOMPDATA, getPrivateData(), cmlabs::PrivateHeader::size, and stricmp.

Referenced by UnitTest().

◆ syncComponents()

bool cmlabs::ComponentMemory::syncComponents ( DataMessage * msg)

Merge component records received from a remote node.

Returns
true on success.

Definition at line 520 of file ComponentMemory.cpp.

References confirmComponentID(), createComponent(), cmlabs::DataMessage::getInt(), cmlabs::DataMessage::getString(), and cmlabs::DataMessage::getTime().

◆ toXML()

std::string cmlabs::ComponentMemory::toXML ( bool stats = true)
Returns
XML dump of all components (optionally with stats).

Definition at line 107 of file ComponentMemory.cpp.

References getAllComponents(), and cmlabs::utils::StringFormat().

◆ tweakParameter()

◆ UnitTest()

bool cmlabs::ComponentMemory::UnitTest ( )
static

Self-test.

Returns
true if all checks pass.

Definition at line 2670 of file ComponentMemory.cpp.

References addComponentStats(), COMP_INTERNAL, COMPONENT_CAN_MIGRATE, cmlabs::MemoryManager::componentMemory, COMPSTATUS_RUNNING, confirmComponentID(), cmlabs::DataMapsMemory::confirmTagID(), cmlabs::DataMapsMemory::confirmTypeLevelID(), cmlabs::MemoryManager::create(), createComponent(), cmlabs::DataMapsMemory::createNewTag(), cmlabs::DataMapsMemory::createNewTypeLevel(), createParameter(), cmlabs::ComponentStats::cycleCount, cmlabs::MemoryManager::dataMapsMemory, deleteParameter(), deletePrivateData(), destroyComponent(), cmlabs::unittest::detail(), DRAFTMSGSIZE, cmlabs::unittest::fail(), getComponentID(), getComponentLocation(), getComponentName(), getComponentNodeID(), getComponentProcessID(), getComponentSelfTrigger(), getComponentStats(), getComponentType(), cmlabs::DataMessage::getInt(), getParameter(), getParameterValueSize(), getPrivateData(), getPrivateDataSize(), cmlabs::DataMessage::getSize(), cmlabs::DataMapsMemory::getTagID(), cmlabs::DataMapsMemory::getTagName(), cmlabs::DataMapsMemory::getTypeLevelID(), cmlabs::DataMapsMemory::getTypeLevelName(), cmlabs::ComponentStats::msgInBytes, cmlabs::ComponentStats::msgInCount, cmlabs::ComponentStats::msgOutBytes, cmlabs::ComponentStats::msgOutCount, cmlabs::unittest::progress(), cmlabs::ComponentStats::recentInMsg, cmlabs::ComponentStats::runCount, SELFTRIGGER_ALLOW, SELFTRIGGER_WARN, cmlabs::DataMessage::setInt(), setPrivateData(), cmlabs::DataMessage::setString(), cmlabs::utils::strcpyavail(), tweakParameter(), updateComponentLocation(), and cmlabs::ComponentStats::usageCPUTicks.

Referenced by cmlabs::Register_ComponentMemory_Tests().

◆ updateComponentInformation()

bool cmlabs::ComponentMemory::updateComponentInformation ( uint32 cid,
uint8 type,
uint8 policy,
uint8 selfTrigger,
uint16 nodeID,
uint16 procID )

◆ updateComponentLocation()

bool cmlabs::ComponentMemory::updateComponentLocation ( uint32 cid,
uint16 nodeID,
uint16 procID )

Record a new location (after migration).

Returns
true on success.

Definition at line 736 of file ComponentMemory.cpp.

References CHECKCOMPONENTMEMORYSERIAL, GETCOMPDATA, cmlabs::ComponentInfoStruct::nodeID, and cmlabs::ComponentInfoStruct::procID.

Referenced by UnitTest().

◆ writeComponentNamesToMsg()

bool cmlabs::ComponentMemory::writeComponentNamesToMsg ( DataMessage * msg)

Write just the component names into msg.

Returns
true on success.

Definition at line 479 of file ComponentMemory.cpp.

References getAllComponents(), and cmlabs::DataMessage::setString().

◆ writeComponentsToMsg()

bool cmlabs::ComponentMemory::writeComponentsToMsg ( DataMessage * msg)

Serialize all component records into msg.

Returns
true on success.

Definition at line 497 of file ComponentMemory.cpp.

References getAllComponents().


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