1 #if !defined(_COMPONENTMEMORY_H_) 2 #define _COMPONENTMEMORY_H_ 4 #include "MemoryManager.h" 6 #include "Subscriptions.h" 11 #define COMPSTATUS_IDLE 1 12 #define COMPSTATUS_STARTING 2 13 #define COMPSTATUS_RUNNING 3 14 #define COMPSTATUS_FINISHED 4 16 #define NOTINUSE 65535 18 #define GETCOMPOFFSETP(header,id) (uint64*)(((char*)header) + sizeof(ComponentMemoryStruct) + (id*sizeof(uint64))) 19 #define GETCOMPOFFSET(header,id) *GETCOMPOFFSETP(header,id) 20 #define GETCOMPDATA(header,id) (ComponentInfoStruct*)(GETCOMPOFFSET(header,id) ? ((char*)header) + (header->indexSize * sizeof(uint64)) + GETCOMPOFFSET(header,id) : NULL) 33 #define PARAM_STRING 1 34 #define PARAM_INTEGER 2 36 #define PARAM_STRING_COLL 4 37 #define PARAM_INTEGER_COLL 5 38 #define PARAM_FLOAT_COLL 6 39 #define PARAM_TYPE_COLL 7 41 #define COMPONENT_CAN_MIGRATE 1 47 char recentInMsg[10*DRAFTMSGSIZE];
50 char recentOutMsg[10*DRAFTMSGSIZE];
51 uint64 firstRunStartTime;
52 uint64 currentRunStartTime;
55 uint32 migrationCount;
58 std::string xmlIn, xmlOut;
60 const char* oldData = NULL;
62 char* msgData = recentInMsg;
63 for (n = 0; n < 10; n++) {
67 xmlIn += msg->
toXML();
69 msgData += DRAFTMSGSIZE;
71 msgData = recentOutMsg;
72 for (n = 0; n < 10; n++) {
73 if (((DataMessageHeader*)msgData)->time) {
76 xmlOut += msg->
toXML();
78 msgData += DRAFTMSGSIZE;
83 return utils::StringFormat(
"<componentstats runcount=\"%llu\" msgincount=\"%llu\" msginbytes=\"%llu\" msgoutcount=\"%llu\" msgoutbytes=\"%llu\" time=\"%llu\">\n<inmsg>\n%s</inmsg>\n<outmsg>\n%s</outmsg>\n</componentstats>\n",
84 runCount, msgInCount, msgInBytes, msgOutCount, msgOutBytes, time, xmlIn.c_str(), xmlOut.c_str());
88 #define SELFTRIGGER_NONE 0 89 #define SELFTRIGGER_WARN 1 90 #define SELFTRIGGER_ALLOW 2 106 uint64 lastUpdateTime;
107 char name[MAXKEYNAMELEN];
118 std::string toXML(
bool printStats =
true) {
120 return utils::StringFormat(
"<component id=\"%u\" status=\"%u\" name=\"%s\" node=\"%u\" proc=\"%u\" type=\"%u\" policy=\"%u\" paramcount=\"%u\" paramsize=\"%u\" datacount=\"%u\" datasize=\"%llu\" createdtime=\"%llu\" migratedtime=\"%llu\" lastupdatetime=\"%llu\" selftrigger=\"%u\">\n%s%s</component>\n",
121 id, syncStatus, name, nodeID, procID, type, policy, paramCount, paramSize, dataCount, dataSize, createdTime, migratedTime, lastUpdateTime, selfTrigger, stats.toXML().c_str(), perfStats.toXML().c_str());
123 return utils::StringFormat(
"<component id=\"%u\" status=\"%u\" name=\"%s\" node=\"%u\" proc=\"%u\" type=\"%u\" policy=\"%u\" paramcount=\"%u\" paramsize=\"%u\" datacount=\"%u\" datasize=\"%llu\" createdtime=\"%llu\" migratedtime=\"%llu\" lastupdatetime=\"%llu\" selftrigger=\"%u\" />\n",
124 id, syncStatus, name, nodeID, procID, type, policy, paramCount, paramSize, dataCount, dataSize, createdTime, migratedTime, lastUpdateTime, selfTrigger);
127 if (!msg)
return false;
128 msg->
setInt((int64)n,
"ID",
id);
129 msg->
setInt((int64)n,
"Status", status);
130 msg->
setInt((int64)n,
"Type", type);
131 msg->
setInt((int64)n,
"Policy", policy);
132 msg->
setInt((int64)n,
"SelfTrigger", selfTrigger);
133 msg->
setInt((int64)n,
"Size", size);
134 msg->
setInt((int64)n,
"NodeID", nodeID);
135 msg->
setInt((int64)n,
"ProcID", procID);
137 msg->
setTime((int64)n,
"CreatedTime", createdTime);
142 #define COMPINFOUSAGE(info) (sizeof(ComponentInfoStruct) + info->paramSize + info->dataSize) 180 #define CHECKCOMPONENTMEMORYSERIAL if (serial != master->getComponentShmemSerial()) {if (!open()) {mutex->leave();return 0;}} 181 #define CHECKCOMPONENTMEMORYSERIALRETURN(a) if (serial != master->getComponentShmemSerial()) {if (!open()) {mutex->leave();return a;}} 186 static bool UnitTest();
191 bool getMemoryUsage(uint64& alloc, uint64& usage);
194 bool create(uint32 indexSize);
196 std::vector<ComponentInfoStruct>* getAllComponents();
197 std::vector<ComponentInfoStruct>* getAllLocalComponents();
198 std::vector<ComponentInfoStruct>* getAllLocalComponents(uint8 type);
199 std::vector<ComponentInfoStruct>* getAllModules();
200 std::vector<ComponentInfoStruct>* getAllCatalogs();
206 bool confirmComponentID(uint32
id);
207 bool cancelComponentID(uint32
id);
208 uint8 lookupComponentID(
const char* name, uint32 &
id);
209 bool createComponent(uint32
id, uint8 type, uint8 policy, uint8 selfTrigger,
const char* name, uint64 size, uint16 nodeID, uint16 procID, uint64 time, uint32& existingID);
212 bool destroyComponent(uint32 cid);
213 bool getComponentName(uint32 cid,
char* name, uint32 maxNameLen);
214 std::string getComponentNameString(uint32 cid);
215 uint8 getComponentType(uint32 cid);
216 bool getComponentID(
const char* name, uint32 &cid);
222 bool isComponentLocal(uint32 cid);
223 bool isComponentLocal(
const char* name);
224 bool getComponentLocation(uint32 cid, uint16& nodeID, uint16& procID);
225 uint8 getComponentPolicy(uint32 cid);
226 bool updateComponentInformation(uint32 cid, uint8 type, uint8 policy, uint8 selfTrigger, uint16 nodeID, uint16 procID);
227 bool setComponentPolicy(uint32 cid, uint8 policy);
228 uint8 getComponentSelfTrigger(uint32 cid);
229 bool setComponentSelfTrigger(uint32 cid, uint8 selfTrigger);
230 uint16 getComponentNodeID(uint32 cid);
231 uint16 getComponentProcessID(uint32 cid);
232 bool updateComponentLocation(uint32 cid, uint16 nodeID, uint16 procID);
236 bool addComponentStats(uint32 cid, uint8 status, uint64 usageCPUTicks,
239 bool canComponentMigrate(uint32 cid);
240 std::list<uint16>* findProcessComponents(uint16 procID);
242 char* getComponentData(uint32 cid, uint64& size);
243 bool setComponentData(uint32 cid,
const char* data, uint64 size,
bool wasMigrated);
246 bool setPrivateData(uint32 cid,
const char* name,
const char* data, uint64 size,
const char* mimetype = NULL);
247 uint64 getPrivateDataSize(uint32 cid,
const char* name);
248 std::string getPrivateDataMimetype(uint32 cid,
const char* name);
249 bool getPrivateData(uint32 cid,
const char* name,
char* data, uint64 maxSize);
250 char* getPrivateDataCopy(uint32 cid,
const char* name, uint64 &size);
251 bool deletePrivateData(uint32 cid,
const char* name);
252 std::map<std::string, std::string> getPrivateDataKeysAndTypes(uint32 cid);
253 std::list<std::string> getPrivateDataKeys(uint32 cid);
256 bool createParameter(uint32 cid,
const char* name,
const char* val,
const char* defaultValue = NULL);
257 bool createParameter(uint32 cid,
const char* name,
const char* val, uint32 count, uint32 defaultIndex);
258 bool createParameter(uint32 cid,
const char* name, std::vector<std::string> values,
const char* defaultValue = NULL);
259 bool createParameter(uint32 cid,
const char* name, int64* val, uint32 count, uint32 defaultIndex);
260 bool createParameter(uint32 cid,
const char* name, std::vector<std::string> values, int64 defaultValue);
261 bool createParameter(uint32 cid,
const char* name, std::vector<int64> values, int64 defaultValue = 0);
262 bool createParameter(uint32 cid,
const char* name, float64* val, uint32 count, uint32 defaultIndex);
263 bool createParameter(uint32 cid,
const char* name, std::vector<std::string> values, float64 defaultValue);
264 bool createParameter(uint32 cid,
const char* name, std::vector<float64> values, float64 defaultValue = 0);
265 bool createParameter(uint32 cid,
const char* name, int64 val, int64 min = 0, int64 max = 0, int64 interval = 0);
266 bool createParameter(uint32 cid,
const char* name, float64 val, float64 min = 0, float64 max = 0, float64 interval = 0);
268 bool hasParameter(uint32 cid,
const char* name);
269 bool deleteParameter(uint32 cid,
const char* name);
271 uint8 getParameterDataType(uint32 cid,
const char* name);
272 uint32 getParameterValueSize(uint32 cid,
const char* name);
273 bool getParameter(uint32 cid,
const char* name,
char* val, uint32 maxSize);
274 bool getParameter(uint32 cid,
const char* name, int64& val);
275 bool getParameter(uint32 cid,
const char* name, float64& val);
276 std::string getParameterString(uint32 cid,
const char* name, uint32 maxSize);
277 std::string getParameterString(uint32 cid,
const char* name);
278 int64 getParameterInt(uint32 cid,
const char* name);
279 float64 getParameterFloat(uint32 cid,
const char* name);
280 bool getParameterAsBool(uint32 cid,
const char* name);
282 bool setParameter(uint32 cid,
const char* name,
const char* val);
283 bool setParameter(uint32 cid,
const char* name, int64 val);
284 bool setParameter(uint32 cid,
const char* name, float64 val);
286 bool resetParameter(uint32 cid,
const char* name);
287 bool tweakParameter(uint32 cid,
const char* name, int32 tweak);
289 bool addLocalPerformanceStats(std::list<PerfStats> &perfStats);
290 std::string printFriendly();
291 std::string toXML(
bool stats =
true);
294 bool resize(uint64 newMemorySize);
295 bool resizeIndex(uint32 newIndexSize);
296 bool resizeComponent(uint32
id, uint64 newSize);
297 bool growComponent(uint32
id, uint64 addSize);
298 bool getSurroundingComponents(uint32 cid, uint32& prevID, uint32& nextID);
300 char* makeRoomForPrivateData(uint32 cid, uint64 newSize);
301 char* makeRoomForParameter(uint32 cid, uint64 newSize);
303 ParamHeader* getParameter(uint32 cid,
const char* name);
316 #endif //_COMPONENTMEMORY_H_ Definition: MemoryManager.h:169
bool setTime(const char *key, uint64 value)
Definition: DataMessage.cpp:1782
Definition: ComponentMemory.h:22
bool setString(const char *key, const char *value)
Definition: DataMessage.cpp:1776
Definition: ComponentMemory.h:184
Definition: ComponentData.h:34
std::string toXML(std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
Definition: DataMessage.cpp:775
bool setInt(const char *key, int64 value)
Definition: DataMessage.cpp:1786
Definition: MemoryManager.h:76
const char * swapMessageData(const char *data)
Definition: DataMessage.cpp:1399
Definition: DataMessage.h:95
Definition: ComponentMemory.h:93