CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
ComponentData.h
Go to the documentation of this file.
1
12
13#if !defined(_COMPONENTDATA_H_)
14#define _COMPONENTDATA_H_
15
16#include "MemoryManager.h"
17#include "DataMessage.h"
18
19namespace cmlabs {
20
21#define PARAM_STRING 1
22#define PARAM_INTEGER 2
23#define PARAM_FLOAT 3
24#define PARAM_STRING_COLL 4
25#define PARAM_INTEGER_COLL 5
26#define PARAM_FLOAT_COLL 6
27#define PARAM_TYPE_COLL 3
28
32 uint32 size; // total size of map structure in bytes
33 uint32 count; // number of entries
34 uint32 bitFieldSize; // number of bytes in the bitfield
35 // Bitfield
36 // Entries
37};
38
42 uint32 id; // id corresponds to the index in map
43 uint16 nodeID; // id of node component is running on currently
44 uint16 procID; // id of process component is running in currently
45 uint32 pageID; // Memory Page ID
46 uint64 time; // timestamp when entered
47 char name[MAXKEYNAMELEN+1]; // name in text
48};
49
64
68 // Admin
69 uint32 size;
70 uint32 cid;
71 uint16 nodeID; // id of node component is running on currently
72 uint16 procID; // id of process component is running in currently
73 uint32 pageID;
74 // Basic data
78 char name[MAXKEYNAMELEN]; // name in text
79 // Statistics
81 // Parameters
82 uint16 paramCount;
83 uint32 paramSize;
84 // Private Data
85 uint16 dataCount;
86 uint32 dataSize;
87};
88
92 uint32 size;
93 uint8 type;
94};
95
96// -- integer --
99 int64 val;
101 int64 minVal;
102 int64 maxVal;
103 int64 interval;
104};
105
106// -- float --
109 float64 val;
110 float64 defaultVal;
111 float64 minVal;
112 float64 maxVal;
113 float64 interval;
114};
115
116// -- string --
117//struct PARAMSTRINGHEADER {
118// char* val;
119// char* defaultVal;
120//};
121
122// -- integer collection --
126 uint32 index;
128 uint32 count;
129};
130
138public:
140 ComponentData(char* data);
142
143 static bool UnitTest();
144
145 static ComponentData* CreateComponent(uint32 id, const char* name, uint32 size, uint16 nodeID, uint16 procID);
146 static bool RecordRemoteComponent(uint32 id, const char* name, uint16 nodeID, uint64 time);
147 static bool ReserveComponentID(uint32 id, const char* name);
148 static bool DestroyComponent(uint32 cid);
149 static ComponentData* GetComponentData(uint32 cid);
150 static bool GetComponentName(uint32 cid, char* name, uint32 maxNameLen);
151 static bool GetComponentID(const char* name, uint32 &cid);
152 static ComponentStats GetComponentStats(uint32 cid);
153 static bool SetComponentStats(uint32 cid, ComponentStats& stats);
154 static bool IsComponentLocal(uint32 cid);
155 static bool IsComponentLocal(const char* name);
156 static uint16 GetComponentNodeID(uint32 cid);
157 static uint16 GetComponentProcessID(uint32 cid);
158 static char* GetAndRemoveComponent(uint32 cid, uint32& dataSize);
159 static bool AddExistingComponent(uint32 cid, uint16 nodeID, uint16 procID, char* oldData, uint32 dataSize);
160 static bool UpdateRemoteComponent(uint32 cid, uint16 nodeID, uint16 procID, const char* name);
161 static bool AddComponentStats(uint32 cid, uint64 userCPU, uint64 kernelCPU,
162 DataMessage* inputMsg, DataMessage* outputMsg, uint32 runCount);
163
164
165 bool disconnect();
166 bool destroyComponent();
167 bool resize(uint32 increase);
168 uint32 getAvailableDataSize();
169
170 // Private Data
171 bool setPrivateData(const char* name, const char* data, uint32 size);
172 uint32 getPrivateDataSize(const char* name);
173 bool getPrivateDataCopy(const char* name, char* data, uint32 maxSize);
174 bool replacePrivateData(const char* name, const char* data, uint32 size);
175 bool replacePrivateData(const char* name, const char* data, uint32 size, uint32 offset);
176 bool deletePrivateData(const char* name);
177
178 // Parameters
179 bool createParameter(const char* name, const char* val, const char* defaultValue = NULL);
180 bool createParameter(const char* name, const char* val, uint32 count, uint32 defaultIndex);
181 bool createParameter(const char* name, std::vector<std::string> values, const char* defaultValue = NULL);
182 bool createParameter(const char* name, int64* val, uint32 count, uint32 defaultIndex);
183 bool createParameter(const char* name, std::vector<std::string> values, int64 defaultValue = 0);
184 bool createParameter(const char* name, float64* val, uint32 count, uint32 defaultIndex);
185 bool createParameter(const char* name, std::vector<std::string> values, float64 defaultValue = 0);
186 bool createParameter(const char* name, int64 val, int64 min = 0, int64 max = 0, int64 interval = 0);
187 bool createParameter(const char* name, float64 val, float64 min = 0, float64 max = 0, float64 interval = 0);
188
189 bool hasParameter(const char* name);
190 bool deleteParameter(const char* name);
191
192 uint8 getParameterDataType(const char* name);
193 uint32 getParameterValueSize(const char* name);
194 bool getParameter(const char* name, char* val, uint32 maxSize);
195 bool getParameter(const char* name, int64& val);
196 bool getParameter(const char* name, float64& val);
197
198 bool setParameter(const char* name, const char* val);
199 bool setParameter(const char* name, int64 val);
200 bool setParameter(const char* name, float64 val);
201
202 bool resetParameter(const char* name);
203 bool tweakParameter(const char* name, int32 tweak);
204
205private:
206 static ComponentMapEntry* GetAndLockComponentEntry(uint32 id);
207 static bool UnlockComponentMap();
208
209 static bool InsertComponentPageID(uint32 cid, uint32 pageID, uint16 nodeID, uint16 procID, const char* name);
210 static bool GetComponentPageID(uint32 cid, uint32& pageID);
211 static bool GetNextAvailableComponentID(uint32& cid);
212 static bool FreeComponentID(uint32 cid);
213
214 char* makeRoomForPrivateData(uint32 newSize);
215 char* makeRoomForParameter(uint32 newSize);
216 struct COMPONENTDATAHEADER* header;
217};
218
219} // namespace cmlabs
220
221#endif //_COMPONENTDATA_H_
222
The binary DataMessage container — the central data-exchange object of Psyclone/CMSDK.
Central shared-memory manager for a Psyclone node: master segment, per-subsystem shared maps and the ...
#define MAXKEYNAMELEN
Definition Utils.h:85
static bool AddComponentStats(uint32 cid, uint64 userCPU, uint64 kernelCPU, DataMessage *inputMsg, DataMessage *outputMsg, uint32 runCount)
static bool SetComponentStats(uint32 cid, ComponentStats &stats)
static uint16 GetComponentNodeID(uint32 cid)
static ComponentData * CreateComponent(uint32 id, const char *name, uint32 size, uint16 nodeID, uint16 procID)
static bool IsComponentLocal(uint32 cid)
bool hasParameter(const char *name)
static bool UpdateRemoteComponent(uint32 cid, uint16 nodeID, uint16 procID, const char *name)
ComponentData(char *data)
Wrap an existing raw component record.
bool tweakParameter(const char *name, int32 tweak)
static uint16 GetComponentProcessID(uint32 cid)
static bool GetComponentID(const char *name, uint32 &cid)
static bool ReserveComponentID(uint32 id, const char *name)
bool createParameter(const char *name, const char *val, const char *defaultValue=NULL)
static bool IsComponentLocal(const char *name)
static bool GetComponentName(uint32 cid, char *name, uint32 maxNameLen)
bool getPrivateDataCopy(const char *name, char *data, uint32 maxSize)
uint32 getParameterValueSize(const char *name)
static bool RecordRemoteComponent(uint32 id, const char *name, uint16 nodeID, uint64 time)
bool setPrivateData(const char *name, const char *data, uint32 size)
static bool AddExistingComponent(uint32 cid, uint16 nodeID, uint16 procID, char *oldData, uint32 dataSize)
static ComponentStats GetComponentStats(uint32 cid)
bool deleteParameter(const char *name)
bool replacePrivateData(const char *name, const char *data, uint32 size)
bool deletePrivateData(const char *name)
static char * GetAndRemoveComponent(uint32 cid, uint32 &dataSize)
static bool DestroyComponent(uint32 cid)
bool resetParameter(const char *name)
bool getParameter(const char *name, char *val, uint32 maxSize)
static bool UnitTest()
Self-test.
bool resize(uint32 increase)
uint8 getParameterDataType(const char *name)
static ComponentData * GetComponentData(uint32 cid)
bool setParameter(const char *name, const char *val)
uint32 getPrivateDataSize(const char *name)
The central Psyclone data container: a self-contained binary message with typed, named user entries.
Fixed header of a legacy component data record; followed by parameter and private-data areas.
char name[MAXKEYNAMELEN]
One component's location record in the legacy component map.
uint16 nodeID
uint16 procID
uint64 time
uint32 pageID
char name[MAXKEYNAMELEN+1]
uint32 id
Header of the legacy shared component map (bitfield + ComponentMapEntry array).
Legacy per-component throughput counters (DataMessageHeader-based rings).
uint64 msgInBytes
Total bytes received.
uint64 msgInCount
Total messages received.
uint64 time
Timestamp of the last update (µs).
uint64 runCount
Total runs.
uint64 msgOutBytes
Total bytes posted.
DataMessageHeader recentInMsg[10]
DataMessageHeader recentOutMsg[10]
uint64 msgOutCount
Total messages posted.
The current (version 10) DataMessage wire/shared-memory header.
Legacy value block of a collection parameter; followed by the packed values.
Legacy value block of a float parameter.
Legacy size/type prefix of one parameter entry.
Legacy value block of an integer parameter.