16 this->master = master;
25 mutex->enter(5000, __FUNCTION__);
36 if (!mutex || !mutex->enter(5000, __FUNCTION__))
41 usage = header->usage;
48 if (!mutex || !mutex->enter(5000, __FUNCTION__))
54 for (uint32 n=0; n<=header->maxID; n++) {
58 stats.spaceID = info->
procID;
59 stats.nodeID = info->
nodeID;
60 stats.type = info->
type;
61 stats.status = info->
status;
63 stats.currentMemoryBytes = info->
size;
76 perfStats.push_back(stats);
86 return "No components registered";
87 else if (!list->size()) {
89 return "No components registered";
92 std::string str =
utils::StringFormat(
"Components count %u intcount %u indexSize %u maxID %u memsize %u memuse %u\n",
93 list->size(), header->count, header->indexSize, header->maxID, header->size, header->usage);
94 std::vector<ComponentInfoStruct>::iterator i = list->begin(), e = list->end();
96 str +=
utils::StringFormat(
"Comp %u: '%s' node %u proc %u type %u, %u params %u data %u runs %u msgIn %u msgOut\n",
97 (*i).id, (*i).name, (*i).nodeID, (*i).procID, (*i).type, (*i).paramCount, (*i).dataCount,
98 (*i).stats.runCount, (*i).stats.msgInCount, (*i).stats.msgOutCount);
110 return "<components count=\"0\" />\n";
111 else if (!list->size()) {
113 return "<components count=\"0\" />\n";
116 std::string str =
utils::StringFormat(
"<components count=\"%u\" indexsize=\"%u\" maxid=\"%u\" memsize=\"%u\" memuse=\"%u\">\n",
117 header->count, header->indexSize, header->maxID, header->size, header->usage);
118 std::vector<ComponentInfoStruct>::iterator i = list->begin(), e = list->end();
120 str += (*i).toXML(stats);
124 str +=
"</components>\n";
130 std::vector<ComponentInfoStruct>* list =
new std::vector<ComponentInfoStruct>;
131 if (!mutex || !mutex->enter(5000, __FUNCTION__))
136 for (uint32 n=0; n<=header->maxID; n++) {
138 list->push_back(*info);
145 std::vector<ComponentInfoStruct>* list =
new std::vector<ComponentInfoStruct>;
146 if (!mutex || !mutex->enter(5000, __FUNCTION__))
151 for (uint32 n=0; n<=header->maxID; n++) {
152 if ((info =
GETCOMPDATA(header, n)) && (info->nodeID == master->getNodeID()))
153 list->push_back(*info);
160 std::vector<ComponentInfoStruct>* list =
new std::vector<ComponentInfoStruct>;
161 if (!mutex || !mutex->enter(5000, __FUNCTION__))
166 for (uint32 n=0; n<=header->maxID; n++) {
167 if ((info =
GETCOMPDATA(header, n)) && (info->nodeID == master->getNodeID()) && (info->type == type))
168 list->push_back(*info);
175 std::vector<ComponentInfoStruct>* list =
new std::vector<ComponentInfoStruct>;
176 if (!mutex || !mutex->enter(5000, __FUNCTION__))
181 for (uint32 n=0; n<=header->maxID; n++) {
182 if ((info =
GETCOMPDATA(header, n)) && (info->nodeID == master->getNodeID())
184 list->push_back(*info);
191 std::vector<ComponentInfoStruct>* list =
new std::vector<ComponentInfoStruct>;
192 if (!mutex || !mutex->enter(5000, __FUNCTION__))
197 for (uint32 n=0; n<=header->maxID; n++) {
198 if ((info =
GETCOMPDATA(header, n)) && (info->nodeID == master->getNodeID())
200 list->push_back(*info);
207 serial = master->incrementComponentShmemSerial();
211 if (!mutex->enter(5000, __FUNCTION__))
228 memset(header, 0, (
size_t)memorySize);
229 header->size = memorySize;
232 header->indexSize = indexSize;
235 master->setComponentShmemSize(memorySize);
241 serial = master->getComponentShmemSerial();
242 uint64 size = master->getComponentShmemSize();
243 this->port = master->port;
245 bool createdMutex =
false;
249 if (!mutex->enter(5000, __FUNCTION__))
279bool ComponentMemory::resize(uint64 newMemorySize) {
281 if (newMemorySize > 100000000) {
285 else if (newMemorySize > 50000000) {
289 serial = master->incrementComponentShmemSerial();
291 if (!mutex || !mutex->enter(5000, __FUNCTION__))
305 memcpy(newHeader, header, (
size_t)header->usage);
306 newHeader->size = newMemorySize;
314 memorySize = newMemorySize;
315 master->setComponentShmemSize(memorySize);
321bool ComponentMemory::resizeIndex(uint32 newIndexSize) {
323 int32 difSize = (newIndexSize - header->indexSize) *
sizeof(uint64);
326 if ((uint32)difSize > header->size - header->usage)
327 if (!resize(memorySize * 2))
332 uint32 oldDataOffset =
sizeof(ComponentMemoryStruct) + (header->indexSize*
sizeof(uint64));
333 uint32 newDataOffset =
sizeof(ComponentMemoryStruct) + (newIndexSize*
sizeof(uint64));
334 memmove(((
char*)header) + newDataOffset, ((
char*)header) + oldDataOffset, (
size_t)(header->usage - oldDataOffset));
335 memset(((
char*)header) + oldDataOffset, 0, newDataOffset - oldDataOffset);
337 header->indexSize = newIndexSize;
338 header->usage += newDataOffset - oldDataOffset;
344bool ComponentMemory::growComponent(uint32
id, uint64 addSize) {
345 ComponentInfoStruct* info =
GETCOMPDATA(header,
id);
348 return resizeComponent(
id, info->size + addSize);
351bool ComponentMemory::resizeComponent(uint32
id, uint64 newSize) {
352 ComponentInfoStruct* info = NULL;
364 if (info->size > newSize)
366 difSize = newSize - info->size;
368 if (header->size - header->usage < difSize) {
369 if (!resize(memorySize * 2))
371 return resizeComponent(
id, newSize);
376 uint64* i = index + 1;
377 for (n=
id+1; n<=header->maxID; n++, i++) {
387 uint64 oldOffset = *i;
390 LogPrint(0,
LOG_MEMORY, 0,
"Couldn't shift component %u memory when inserting component %u...", nextID,
id);
397 uint64 nextStart = (header->indexSize *
sizeof(uint64)) + oldOffset;
398 uint64 sizeMove = header->usage - nextStart;
399 memmove(data+difSize, data, (
size_t)sizeMove);
401 for (n=nextID; n<=header->maxID; n++, i++) {
410 info = (ComponentInfoStruct*) data;
411 memset(info, 0,
sizeof(ComponentInfoStruct));
413 info->createdTime = info->lastUpdateTime =
GetTimeNow();
418 GETCOMPOFFSET(header,
id) = header->usage - (header->indexSize *
sizeof(uint64));
420 memset(info, 0,
sizeof(ComponentInfoStruct));
422 info->createdTime = info->lastUpdateTime =
GetTimeNow();
425 info->size = newSize;
426 header->usage += difSize;
441 if (!mutex || !mutex->enter(5000, __FUNCTION__))
444 if (
id >= header->indexSize) {
462 if (!mutex || !mutex->enter(5000, __FUNCTION__))
465 if (
id >= header->indexSize) {
487 else if (!list->size()) {
492 std::vector<ComponentInfoStruct>::iterator i = list->begin(), e = list->end();
494 msg->
setString((*i).id,
"component", (*i).name);
505 else if (!list->size()) {
511 std::vector<ComponentInfoStruct>::iterator i = list->begin(), e = list->end();
513 if (!(*i).writeToMsg(n, msg)) {
526 uint16 id, nodeID, procID;
527 uint8 type, policy, selfTrigger;
532 (
id = (uint16)msg->
getInt(n,
"ID")) &&
533 (type = (uint8)msg->
getInt(n,
"Type")) &&
534 (size = (uint64)msg->
getInt(n,
"Size")) &&
535 (nodeID = (uint16)msg->
getInt(n,
"NodeID")) &&
536 (procID = (uint16)msg->
getInt(n,
"ProcID")) &&
538 (time = msg->
getTime(n,
"CreatedTime"))) {
539 policy = (uint8)msg->
getInt(n,
"Policy");
540 selfTrigger = (uint8)msg->
getInt(n,
"SelfTrigger");
541 if (!
createComponent(
id, type, policy, selfTrigger, name, size, nodeID, procID, time, exID))
550bool ComponentMemory::createComponent(uint32
id, uint8 type, uint8 policy, uint8 selfTrigger,
const char* name, uint64 size, uint16 nodeID, uint16 procID, uint64 time, uint32& existingID) {
553 if (!mutex || !mutex->enter(5000, __FUNCTION__))
562 if (
id >= header->indexSize)
563 resizeIndex(header->indexSize +
id + 1024);
568 if (master->getNodeID() == nodeID)
571 LogPrint(0,
LOG_MEMORY, 1,
"Updating remote component %u (node %u proc %u)...",
id, nodeID, procID);
583 if (size > info->
size)
590 if (master->getNodeID() == nodeID)
591 LogPrint(0,
LOG_MEMORY, 2,
"Creating new local component %u (proc %u)...",
id, procID);
593 LogPrint(0,
LOG_MEMORY, 2,
"Registering remote component %u (node %u proc %u)...",
id, nodeID, procID);
612 if (
id > header->maxID)
627 DataMessage* outputMsg, uint32 runCount, uint32 cycleCount) {
628 if (!mutex || !mutex->enter(5000, __FUNCTION__))
632 if (cid >= header->indexSize) {
677 memcpy(outSlot, outputMsg->
data, outputMsg->
data->
size);
693 if (!mutex || !mutex->enter(5000, __FUNCTION__))
697 if (cid >= header->indexSize) {
708 uint64 size = info->
size;
712 if (cid < header->maxID) {
718 for (uint32 n=cid+1; n<=header->maxID; n++, i++) {
725 uint64 nextStart = (header->indexSize *
sizeof(uint64)) + *i;
726 memmove(info, ((
char*)info)+size, (
size_t)(header->usage - nextStart));
735 header->usage -= size;
743 if (!mutex || !mutex->enter(5000, __FUNCTION__))
747 if (cid >= header->indexSize) {
765 if (!mutex || !mutex->enter(5000, __FUNCTION__))
769 if (cid >= header->indexSize) {
781 char* data =
new char[(size_t)size];
782 memcpy(data, info, (
size_t)size);
789 if (!mutex || !mutex->enter(5000, __FUNCTION__))
793 if (cid >= header->indexSize)
794 resizeIndex(header->indexSize + 256);
796 if (!resizeComponent(cid, size)) {
807 uint64 oldsize = info->
size;
809 memcpy(info, data, (
size_t)size);
810 info->
size = oldsize;
812 if (cid > header->maxID)
825 if (!mutex || !mutex->enter(5000, __FUNCTION__))
830 uint16 localNodeID = master->getNodeID();
831 std::list<uint16>* comps =
new std::list<uint16>;
832 for (uint32 n=0; n<=header->maxID; n++) {
834 if ((info->nodeID == localNodeID) && (info->procID == procID))
835 comps->push_back(info->id);
847 if (!mutex || !mutex->enter(5000, __FUNCTION__))
851 if (cid >= header->indexSize) {
862 uint8 policy = info->
policy;
868 if (!mutex || !mutex->enter(5000, __FUNCTION__))
872 if (cid >= header->indexSize) {
895 if (!mutex || !mutex->enter(5000, __FUNCTION__))
905 if (!mutex || !mutex->enter(5000, __FUNCTION__))
915 if (!mutex || !mutex->enter(5000, __FUNCTION__))
919 if (cid >= header->indexSize) {
936 if (!mutex || !mutex->enter(5000, __FUNCTION__))
940 if (cid >= header->indexSize) {
957 if (!mutex || !mutex->enter(5000, __FUNCTION__))
961 if (cid >= header->indexSize) {
981 if (!mutex || !mutex->enter(5000, __FUNCTION__))
985 if (cid >= header->indexSize) {
1004 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1008 if (cid >= header->indexSize) {
1019 uint16 nodeID = info->
nodeID;
1026 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1030 if (cid >= header->indexSize) {
1041 uint16 procID = info->
procID;
1049 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1053 if (cid >= header->indexSize) {
1064 if (master->getNodeID() == info->
nodeID) {
1084 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1088 if (cid >= header->indexSize) {
1099 std::string str = info->
name;
1106 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1110 if (cid >= header->indexSize) {
1127 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1131 if (cid >= header->indexSize) {
1142 uint8 type = info->
type;
1152 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1154 if (serial != master->getComponentShmemSerial()) {
if (!
open()) {mutex->leave();
return stats;}}
1156 if (cid >= header->indexSize) {
1176 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1178 if (serial != master->getComponentShmemSerial()) {
if (!
open()) {mutex->leave();
return perfStats;}}
1180 if (cid >= header->indexSize) {
1197 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1201 if (cid >= header->indexSize) {
1219 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1223 if (cid >= header->indexSize) {
1241 if (!mutex || !mutex->enter(5000, __FUNCTION__) || !name || !strlen(name))
1246 for (uint32 n=0; n<=header->maxID; n++) {
1247 if ((info =
GETCOMPDATA(header, n)) && (info->syncStatus > 1)) {
1248 if (
stricmp(info->name, name) == 0) {
1261 if (!mutex || !mutex->enter(5000, __FUNCTION__) || !name || !strlen(name))
1267 for (uint32 n=0; n<=header->maxID; n++) {
1283char* ComponentMemory::makeRoomForPrivateData(uint32 cid, uint64 newSize) {
1288 if (!growComponent(cid, newSize))
1293 return ((
char*)info) +
sizeof(ComponentInfoStruct) + info->paramSize + info->dataSize;
1296char* ComponentMemory::makeRoomForParameter(uint32 cid, uint64 newSize) {
1297 ComponentInfoStruct* info =
GETCOMPDATA(header, cid);
1301 if (!growComponent(cid, newSize))
1308 char* paramSrc = (
char*)info +
sizeof(ComponentInfoStruct);
1309 char* dataSrc = paramSrc + info->paramSize;
1313 memmove(dataSrc+newSize, dataSrc, (
size_t)info->dataSize);
1315 memset(dataSrc, 0, (
size_t)newSize);
1321 ComponentInfoStruct* info =
GETCOMPDATA(header, cid);
1325 char* src = (
char*)info +
sizeof(ComponentInfoStruct);
1326 char* srcEnd = src + info->paramSize;
1329 while ( src < srcEnd ) {
1330 if (
stricmp(name, src +
sizeof(ParamHeader)) == 0)
1331 return (ParamHeader*)src;
1332 offset += *(uint32*)src;
1333 src += *(uint32*)src;
1339 ComponentInfoStruct* info =
GETCOMPDATA(header, cid);
1343 char* src = (
char*)info +
sizeof(ComponentInfoStruct) + info->paramSize;
1344 char* srcEnd = src + info->dataSize;
1346 while ( src < srcEnd ) {
1347 if (
stricmp(name, src +
sizeof(PrivateHeader)) == 0)
1348 return (PrivateHeader*)src;
1349 src += *(uint32*)src;
1357 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1361 if (cid >= header->indexSize) {
1366 std::string actualMimetype;
1368 uint32 nameLen = (uint32)strlen(name);
1371 if (
stricmp(mimetype,
"xml") == 0)
1372 actualMimetype =
"text/xml";
1373 else if (
stricmp(mimetype,
"json") == 0)
1374 actualMimetype =
"application/json";
1375 else if (
stricmp(mimetype,
"binary") == 0)
1376 actualMimetype =
"application/octet-stream";
1377 else if (
stricmp(mimetype,
"html") == 0)
1378 actualMimetype =
"text/html";
1379 else if (
stricmp(mimetype,
"bitmap") == 0)
1380 actualMimetype =
"image/bmp";
1381 else if (
stricmp(mimetype,
"text") == 0)
1382 actualMimetype =
"text/plain";
1384 actualMimetype = mimetype;
1385 mimeLen = (uint32)actualMimetype.length();
1387 uint64 totalSize =
sizeof(
PrivateHeader) + nameLen + 1 + mimeLen + 1 + size;
1392 if (priv->
size == totalSize) {
1394 memcpy(((
char*)priv) +
sizeof(
PrivateHeader) + nameLen + 1, actualMimetype.c_str(), (
size_t)mimeLen + 1);
1396 memset(((
char*)priv) +
sizeof(
PrivateHeader) + nameLen + 1, 0, 1);
1397 memcpy(((
char*)priv) +
sizeof(
PrivateHeader) + nameLen + 1 + mimeLen + 1, data, (
size_t)size);
1412 char* newData = makeRoomForPrivateData(cid, totalSize);
1413 if (newData == NULL) {
1419 *(uint64*) newData = totalSize;
1422 memcpy(newData +
sizeof(
PrivateHeader) + nameLen + 1, actualMimetype.c_str(), mimeLen + 1);
1424 memset(newData +
sizeof(
PrivateHeader) + nameLen + 1, 0, 1);
1425 memcpy(newData +
sizeof(
PrivateHeader) + nameLen+1 + mimeLen + 1, data, (
size_t)size);
1440 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1444 if (cid >= header->indexSize) {
1455 uint32 nameLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader)));
1456 uint32 mimeLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader) + nameLen+1));
1464 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1468 if (cid >= header->indexSize) {
1479 uint32 nameLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader)));
1480 uint32 mimeLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader) + nameLen + 1));
1482 uint64 offset =
sizeof(
PrivateHeader) + nameLen + mimeLen + 2;
1483 size = priv->
size - offset;
1488 char* data =
new char[(size_t)size];
1489 memcpy((
void*)data, ((
char*)priv) + offset, (
size_t)size);
1495 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1499 if (cid >= header->indexSize) {
1510 uint32 nameLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader)));
1511 uint32 mimeLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader) + nameLen + 1));
1513 uint64 offset =
sizeof(
PrivateHeader) + nameLen + mimeLen + 2;
1514 uint64 size = priv->
size - offset;
1515 if (size > maxSize) {
1519 memcpy((
void*)data, ((
char*)priv) + offset, (
size_t)size);
1525 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1529 if (cid >= header->indexSize) {
1540 uint32 nameLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader)));
1541 std::string type = ((
char*)priv +
sizeof(
PrivateHeader) + nameLen + 1);
1548 std::map<std::string, std::string> map;
1550 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1561 char* srcEnd = src + info->
dataSize;
1567 while (src < srcEnd) {
1569 nameLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader)));
1570 mimeLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader) + nameLen + 1));
1579 src += *(uint32*)src;
1587 std::list<std::string> list;
1589 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1600 char* srcEnd = src + info->
dataSize;
1605 while (src < srcEnd) {
1607 nameLen = (uint32)strlen(((
char*)priv +
sizeof(
PrivateHeader)));
1612 src += *(uint32*)src;
1624 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1628 if (cid >= header->indexSize) {
1640 uint64 delSize = priv->
size;
1641 uint64 moveSize = (uint32)(((
char*)info)+
COMPINFOUSAGE(info)-((
char*)priv)-priv->
size);
1642 memmove(((
char*)priv), ((
char*)priv)+priv->
size, (
size_t)moveSize);
1660 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1664 if (cid >= header->indexSize) {
1676 uint32 nameLen = (uint32)strlen(name);
1677 uint32 newSize = nameLen + 1 +
sizeof(
ParamHeader) + (uint32)strlen(val) + 1;
1678 if (defaultValue != NULL)
1679 newSize += (uint32)strlen(defaultValue) + 1;
1681 newSize += (uint32)strlen(val) + 1;
1683 char* newData = makeRoomForParameter(cid, newSize);
1684 if (newData == NULL) {
1691 param->
size = newSize;
1693 memcpy(newData +
sizeof(
ParamHeader), name, nameLen+1);
1697 newData += strlen(val) + 1;
1699 if (defaultValue != NULL)
1712 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1716 if (cid >= header->indexSize) {
1729 uint32 nameLen = (uint32)strlen(name);
1731 uint32 dataSize = 0;
1732 const char* pVal = val;
1733 for (n=0; n<count; n++) {
1734 len = (uint32)strlen(pVal) + 1;
1738 newSize += dataSize;
1740 char* newData = makeRoomForParameter(cid, newSize);
1741 if (newData == NULL) {
1748 param->
size = newSize;
1750 memcpy(newData +
sizeof(
ParamHeader), name, nameLen+1);
1753 dHeader->
index = defaultIndex;
1755 dHeader->
count = count;
1768 uint32 n, dlen, len = 0, dataSize = 0, defaultIndex = 0;
1769 uint32 count = (uint32)values.size();
1770 for (n=0; n<count; n++)
1771 dataSize += (uint32)values[n].size() + 1;
1772 char* val =
new char[dataSize];
1773 for (n=0; n<count; n++) {
1774 dlen = (uint32)values[n].size()+1;
1775 memcpy(val+len, values[n].c_str(), dlen);
1777 if (values[n] == defaultValue)
1786 uint32 n, defaultIndex = 0;
1787 uint32 count = (uint32)values.size();
1788 int64* val =
new int64[count];
1789 for (n=0; n<count; n++) {
1791 if (val[n] == defaultValue)
1800 uint32 n, defaultIndex = 0;
1801 uint32 count = (uint32)values.size();
1802 int64* val =
new int64[count];
1803 for (n = 0; n<count; n++) {
1805 if (val[n] == defaultValue)
1814 uint32 n, defaultIndex = 0;
1815 uint32 count = (uint32)values.size();
1816 float64* val =
new float64[count];
1817 for (n=0; n<count; n++) {
1819 if (val[n] == defaultValue)
1828 uint32 n, defaultIndex = 0;
1829 uint32 count = (uint32)values.size();
1830 float64* val =
new float64[count];
1831 for (n = 0; n<count; n++) {
1833 if (val[n] == defaultValue)
1842 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1846 if (cid >= header->indexSize) {
1858 uint32 nameLen = (uint32)strlen(name);
1861 char* newData = makeRoomForParameter(cid, newSize);
1862 if (newData == NULL) {
1869 pHeader->
size = newSize;
1871 memcpy(newData +
sizeof(
ParamHeader), name, nameLen+1);
1874 dHeader->
index = defaultIndex;
1876 dHeader->
count = count;
1889 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1893 if (cid >= header->indexSize) {
1905 uint32 nameLen = (uint32)strlen(name);
1908 char* newData = makeRoomForParameter(cid, newSize);
1909 if (newData == NULL) {
1916 pHeader->
size = newSize;
1918 memcpy(newData +
sizeof(
ParamHeader), name, nameLen+1);
1921 dHeader->
index = defaultIndex;
1923 dHeader->
count = count;
1936 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1940 if (cid >= header->indexSize) {
1952 uint32 nameLen = (uint32)strlen(name);
1955 char* newData = makeRoomForParameter(cid, newSize);
1956 if (newData == NULL) {
1963 pHeader->
size = newSize;
1965 memcpy(newData +
sizeof(
ParamHeader), name, nameLen+1);
1984 if (!mutex || !mutex->enter(5000, __FUNCTION__))
1988 if (cid >= header->indexSize) {
2000 uint32 nameLen = (uint32)strlen(name);
2003 char* newData = makeRoomForParameter(cid, newSize);
2004 if (newData == NULL) {
2011 pHeader->
size = newSize;
2013 memcpy(newData +
sizeof(
ParamHeader), name, nameLen+1);
2032 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2036 if (cid >= header->indexSize) {
2053 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2057 if (cid >= header->indexSize) {
2069 uint32 delSize = param->
size;
2073 uint32 moveSize = (uint32)(((
char*)info) +
COMPINFOUSAGE(info) - ((
char*)param) - param->
size);
2074 memmove(((
char*)param), ((
char*)param)+param->
size, moveSize);
2082 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2086 if (cid >= header->indexSize) {
2097 uint8 type = param->
type;
2103 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2107 if (cid >= header->indexSize) {
2121 size =
sizeof(int64);
2123 size =
sizeof(float64);
2125 size = ((uint32)strlen(pSrc) + 1);
2129 for (uint32 n=0; n<cHeader->
index; n++)
2130 pSrc += strlen(pSrc) + 1;
2131 size = (uint32)strlen(pSrc) + 1;
2139 char* val =
new char[maxSize];
2142 std::string valString = val;
2149 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2153 if (cid >= header->indexSize) {
2164 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2174 for (uint32 n = 0; n<cHeader->
index; n++)
2175 pSrc += strlen(pSrc) + 1;
2201 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2205 if (cid >= header->indexSize) {
2219 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2222 if (
stricmp(pSrc,
"Yes") == 0) {
2234 for (uint32 n = 0; n<cHeader->
index; n++)
2235 pSrc += strlen(pSrc) + 1;
2236 if (
stricmp(pSrc,
"yes") == 0) {
2246 ival = *(int64*)(pSrc);
2253 ival = *(int64*)pSrc;
2258 fval = *(float64*)(pSrc);
2265 fval = *(float64*)pSrc;
2277 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2281 if (cid >= header->indexSize) {
2292 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2295 if (maxSize < strlen(pSrc) + 1) {
2306 for (uint32 n=0; n<cHeader->
index; n++)
2307 pSrc += strlen(pSrc) + 1;
2308 if (maxSize < strlen(pSrc) + 1) {
2323 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2327 if (cid >= header->indexSize) {
2338 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2341 val = *(int64*)(pSrc);
2348 val = *(int64*) pSrc;
2359 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2363 if (cid >= header->indexSize) {
2374 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2377 val = *(float64*)(pSrc);
2384 val = *(float64*) pSrc;
2396 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2400 if (cid >= header->indexSize) {
2412 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2414 oldSize = (uint32)strlen(pSrc);
2415 if (strlen(val) == oldSize) {
2422 uint32 defaultSize = (uint32)strlen(pSrc + oldSize + 1) + 1;
2423 char* defaultValue =
new char[defaultSize];
2427 delete [] defaultValue;
2433 delete [] defaultValue;
2438 delete [] defaultValue;
2447 while (index < cHeader->count) {
2448 if (
stricmp(val, pSrc) == 0) {
2450 cHeader->
index = index;
2455 pSrc += strlen(pSrc) + 1;
2463 long long n = strtoll(val, &e, 10);
2464 bool ok = (e && e != val && !*e) &&
setParameter(cid, name, (int64)n);
2470 double f = strtod(val, &e);
2471 bool ok = (e && e != val && !*e) &&
setParameter(cid, name, (float64)f);
2482 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2486 if (cid >= header->indexSize) {
2497 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2509 while (index < cHeader->count) {
2510 if (*(int64*)pSrc == val) {
2512 cHeader->
index = index;
2517 pSrc +=
sizeof(int64);
2529 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2533 if (cid >= header->indexSize) {
2544 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2556 while (index < cHeader->count) {
2557 if (*(float64*)pSrc == val) {
2559 cHeader->
index = index;
2564 pSrc +=
sizeof(float64);
2577 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2581 if (cid >= header->indexSize) {
2592 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2617 std::string def = pSrc + strlen(pSrc) + 1;
2640 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2644 uint64 base = header->indexSize *
sizeof(uint64);
2647 for (uint32 n = 0; n <= header->maxID && n < header->indexSize && err.empty(); n++) {
2651 if (off != expect) err =
utils::StringFormat(
"component %u at offset %llu, expected %llu (gap or overlap)", n, (
unsigned long long)off, (
unsigned long long)expect);
2656 expect = off + (info ? info->
size : 0);
2659 if (err.empty() && base + expect != header->usage) err =
utils::StringFormat(
"records end at %llu, usage %llu", (
unsigned long long)(base + expect), (
unsigned long long)header->usage);
2660 if (err.empty() && count != header->count) err =
utils::StringFormat(
"%u records, count %u", count, header->count);
2674 default:
return "unknown";
2686 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2689 if (cid >= header->indexSize) {
2704 char* end = src + ph->
size;
2707 p.
name = std::string(nm, strnlen(nm, end - nm));
2709 char* v = (
char*)nm + p.
name.size() + 1;
2711 p.
value = std::string(v, strnlen(v, end - v));
2712 char* d = v + p.
value.size() + 1;
2713 if (d < end) p.
defaultValue = std::string(d, strnlen(d, end - d));
2741 for (uint32 n = 0; n < c->
count; n++) {
2743 if (e +
sizeof(int64) > end)
break;
2748 if (e +
sizeof(float64) > end)
break;
2750 e +=
sizeof(float64);
2753 if (e >= end)
break;
2754 size_t l = strnlen(e, end - e);
2755 p.
options.push_back(std::string(e, l));
2770 if (!mutex || !mutex->enter(5000, __FUNCTION__))
2774 if (cid >= header->indexSize) {
2785 char* pSrc = ((
char*)pHeader) +
sizeof(
ParamHeader) + strlen(((
char*)pHeader) +
sizeof(
ParamHeader)) + 1;
2789 if ( (cHeader->
index + tweak >= 0) && (cHeader->
index + tweak < cHeader->count) ) {
2790 cHeader->
index += tweak;
2805 int64 testInt = iHeader->
val + (tweak * iHeader->
interval);
2806 if ( (iHeader->
minVal == iHeader->
maxVal) || ((testInt >= iHeader->
minVal) && (testInt <= iHeader->maxVal)) ) {
2807 iHeader->
val = testInt;
2818 float64 testFloat = fHeader->
val + (tweak * fHeader->
interval);
2819 if ( (fHeader->
minVal == fHeader->
maxVal) || ( (testFloat >= fHeader->
minVal) && (testFloat <= fHeader->maxVal)) ) {
2820 fHeader->
val = testFloat;
2853 if (!manager->
create(0)) {
unittest::fail(
"MemoryManager init() failed");
delete(manager);
return false; }
2855 std::map<uint32, std::string> live;
2856 std::string step, err;
2858 auto check = [&](
const char* what) ->
bool {
2861 for (
auto& c : live) {
2867 if (!cm->
getPrivateData(c.first,
"P", b,
sizeof(b)) || std::string(b) !=
"P-" + c.second) { err =
utils::StringFormat(
"component %u private data '%s'", c.first, b);
return false; }
2871 auto make = [&](uint32 id, uint64 size) ->
bool {
2873 std::string pd =
"P-" + n;
2883 if (!make(1, 1024) || !check(
"create 1"))
break;
2884 if (!make(21, 1024) || !make(22, 1024) || !check(
"create 21, 22"))
break;
2885 if (!make(7, 256) || !check(
"insert 7 below 21"))
break;
2886 if (!make(3, 0) || !check(
"insert 3 (size 0) below 7"))
break;
2888 std::string s =
"x";
2890 for (
int g = 0; g < 40 && grew; g++) { s +=
" and more"; grew = cm->
setParameter(21,
"Label", s.c_str()) || cm->
createParameter(21,
"Label", s.c_str()); }
2891 if (!grew || !check(
"grow a parameter of 21"))
break;
2892 std::string big(3000,
'Z');
2893 if (!cm->
setPrivateData(3,
"Big", big.c_str(), big.size(),
"text/plain") || !check(
"grow private data of 3"))
break;
2897 if (!check(
"destroy 1"))
break;
2900 if (!check(
"destroy 7"))
break;
2902 for (uint32 k = 10; k < 16; k++)
if (!make(k, 512)) { err =
utils::StringFormat(
"create %u", k);
break; }
2903 if (err.size() || !check(
"create 10..15 below 21"))
break;
2904 if (!cm->
setPrivateData(11,
"P",
"P-Comp11", 9,
"text/plain") || !cm->
setPrivateData(11,
"Grow", big.c_str(), 2000,
"text/plain") || !check(
"grow 11"))
break;
2907 if (!check(
"destroy 12"))
break;
2908 if (!make(1, 1024) || !make(20, 256) || !check(
"recreate 1, create 20"))
break;
2909 if (!cm->
deleteParameter(21,
"Label") || !check(
"delete a parameter of 21"))
break;
2910 for (
auto it = live.begin(); it != live.end();) { uint32
id = it->first; it = live.erase(it);
if (!cm->
destroyComponent(
id)) { err =
utils::StringFormat(
"destroy %u",
id);
break; } }
2911 if (err.size() || !check(
"destroy all"))
break;
2914 if (!ok)
unittest::fail(
"layout broken after '%s': %s", step.c_str(), err.c_str());
2926 if (!manager->
create(0)) {
2934 uint32 cid = 1, existingID;
2935 char* name =
new char[1024];
2944 char* str =
new char[1024];
2950 if (strcmp(name, str) != 0) {
2951 unittest::fail(
"Component name mismatch ('%s' != '%s')", name, str);
2964 unittest::fail(
"Component id mismatch ('%u' != '%u')", cid, cid2);
2989 char* test =
new char[1024];
2996 if (strcmp(
"Test", test) != 0) {
3020 if (strcmp(
"Test2", test) != 0) {
3021 unittest::fail(
"Component get private data comparison 2 failed");
3042 unittest::fail(
"Component create duplicate name failed to fail");
3072 if (strcmp(
"Test", test) != 0) {
3073 unittest::fail(
"Component get string parameter comparison 2 failed");
3117 unittest::fail(
"Component get non-existing param failed to fail");
3167 unittest::fail(
"Component tweak integer param 2 failed to fail");
3173 int64 i64[] = {1,2,3,4,5};
3187 unittest::fail(
"Component tweak integer coll param result failed");
3205 unittest::fail(
"Component tweak integer coll param result 2 failed");
3211 unittest::fail(
"Component tweak integer coll param failed to fail");
3235 if (strcmp(test,
"Test3") != 0) {
3236 unittest::fail(
"Component tweak string coll param result failed");
3253 if (strcmp(test,
"Test5") != 0) {
3254 unittest::fail(
"Component tweak string coll param result 2 failed");
3260 unittest::fail(
"Component tweak string coll param failed to fail");
3277 std::vector<std::string> names = {
"low",
"mid",
"high" };
3278 std::vector<int64> sizes = { 8, 16, 32 };
3279 bool made = cm->
createParameter(cid,
"PInt", (int64)55, 0, 110, 5) && cm->
createParameter(cid,
"PFloat", 0.25, -1.0, 1.0, 0.05) &&
3281 std::vector<ParamInfo> info;
3283 std::map<std::string, ParamInfo> by;
3284 for (
ParamInfo& pi : info) by[pi.name] = pi;
3285 if (by[
"PInt"].type !=
PARAM_INTEGER || by[
"PInt"].value !=
"55" || by[
"PInt"].minVal !=
"0" || by[
"PInt"].maxVal !=
"110" || by[
"PInt"].step !=
"5"
3286 || by[
"PFloat"].type !=
PARAM_FLOAT || by[
"PFloat"].value !=
"0.25" || by[
"PFloat"].minVal !=
"-1" || by[
"PFloat"].step !=
"0.05"
3287 || by[
"PStr"].value !=
"abc" || by[
"PStr"].defaultValue !=
"abc"
3288 || by[
"PColl"].type !=
PARAM_STRING_COLL || by[
"PColl"].options.size() != 3 || by[
"PColl"].value !=
"mid" || by[
"PColl"].index != 1
3289 || by[
"PIColl"].type !=
PARAM_INTEGER_COLL || by[
"PIColl"].options.size() != 3 || by[
"PIColl"].value !=
"16") {
3290 unittest::fail(
"parameter info: wrong listing (PInt %s [%s:%s:%s], PFloat %s, PColl %s/%u, PIColl %s)", by[
"PInt"].value.c_str(), by[
"PInt"].minVal.c_str(),
3291 by[
"PInt"].maxVal.c_str(), by[
"PInt"].step.c_str(), by[
"PFloat"].value.c_str(), by[
"PColl"].value.c_str(), (
unsigned)by[
"PColl"].options.size(), by[
"PIColl"].value.c_str());
3292 delete(manager);
return false;
3299 unittest::fail(
"parameter info: setting from text failed");
delete(manager);
return false;
3303 unittest::fail(
"parameter info: reset failed");
delete(manager);
return false;
3320 unittest::fail(
"Loc: create failed");
delete(manager);
return false;
3323 uint16 nID = 99, pID = 99;
3325 unittest::fail(
"Loc: getComponentLocation got node=%u proc=%u (want 3/4)", nID, pID);
delete(manager);
return false;
3328 unittest::fail(
"Loc: node/proc id accessors mismatch");
delete(manager);
return false;
3331 unittest::fail(
"Loc: selfTrigger mismatch");
delete(manager);
return false;
3334 unittest::fail(
"Loc: type mismatch");
delete(manager);
return false;
3337 unittest::fail(
"Loc: updateComponentLocation failed");
delete(manager);
return false;
3340 unittest::fail(
"Loc: location not updated");
delete(manager);
return false;
3345 unittest::fail(
"Loc: out-of-range id returned success");
delete(manager);
return false;
3348 unittest::fail(
"Loc: id 0 returned a self-trigger");
delete(manager);
return false;
3351 unittest::fail(
"Loc: out-of-range getComponentName returned success");
delete(manager);
return false;
3360 const int NCOMP = 6;
3361 const uint32 baseID = 10;
3362 char cname[64], buf[4096], expect[64];
3365 for (
int k = 0; k < NCOMP; k++) {
3366 snprintf(cname,
sizeof(cname),
"Comp%d", k);
3368 unittest::fail(
"Multi: create %s failed", cname);
delete(manager);
return false;
3371 snprintf(buf,
sizeof(buf),
"DATA-%d", k);
3373 unittest::fail(
"Multi: setPrivateData %s failed", cname);
delete(manager);
return false;
3377 for (
int k = 0; k < NCOMP; k++) {
3378 snprintf(cname,
sizeof(cname),
"Comp%d", k);
3379 snprintf(expect,
sizeof(expect),
"DATA-%d", k);
3381 unittest::fail(
"Multi: name check Comp%d got '%s'", k, str);
delete(manager);
return false;
3384 unittest::fail(
"Multi: data check Comp%d got '%s' want '%s'", k, buf, expect);
delete(manager);
return false;
3389 memset(buf,
'Z',
sizeof(buf));
3390 snprintf(buf,
sizeof(buf),
"BIGDATA-1");
3392 unittest::fail(
"Multi: grow Comp1 private data failed");
delete(manager);
return false;
3395 for (
int k = 0; k < NCOMP; k++) {
3396 snprintf(cname,
sizeof(cname),
"Comp%d", k);
3398 unittest::fail(
"Multi: post-grow name check Comp%d got '%s'", k, str);
delete(manager);
return false;
3400 if (k == 1) snprintf(expect,
sizeof(expect),
"BIGDATA-1");
3401 else snprintf(expect,
sizeof(expect),
"DATA-%d", k);
3403 unittest::fail(
"Multi: post-grow data check Comp%d got '%s' want '%s'", k, buf, expect);
delete(manager);
return false;
3409 unittest::fail(
"Multi: destroy middle component failed");
delete(manager);
return false;
3412 unittest::fail(
"Multi: destroyed Comp2 still present");
delete(manager);
return false;
3415 for (
int k = 0; k < NCOMP; k++) {
3416 if (k == 2)
continue;
3417 snprintf(cname,
sizeof(cname),
"Comp%d", k);
3419 unittest::fail(
"Multi: post-destroy name check Comp%d got '%s'", k, str);
delete(manager);
return false;
3421 if (k == 1) snprintf(expect,
sizeof(expect),
"BIGDATA-1");
3422 else snprintf(expect,
sizeof(expect),
"DATA-%d", k);
3424 unittest::fail(
"Multi: post-destroy data check Comp%d got '%s' want '%s'", k, buf, expect);
delete(manager);
return false;
3428 for (
int k = 0; k < NCOMP; k++)
3438 unittest::fail(
"Stats: create failed");
delete(manager);
return false;
3451 unittest::fail(
"Stats: counters wrong (in=%llu out=%llu run=%llu cyc=%llu cpu=%llu)",
3453 delete(manager);
return false;
3457 for (
int k = 1; k <= 12; k++) {
3459 m.
setInt(
"Seq", (int64)k);
3467 bool seen[13];
for (
int k = 0; k < 13; k++) seen[k] =
false;
3469 for (
int n = 0; n < 10; n++) {
3476 int64 seq = m.
getInt(
"Seq", ok);
3477 if (ok && seq >= 1 && seq <= 12)
3480 if (present != 10) {
3481 unittest::fail(
"Stats: ring holds %d messages (want 10)", present);
delete(manager);
return false;
3483 if (seen[1] || seen[2]) {
3484 unittest::fail(
"Stats: ring did not evict oldest (Seq 1/2 still present)");
delete(manager);
return false;
3486 for (
int k = 3; k <= 12; k++) {
3488 unittest::fail(
"Stats: ring missing recent message Seq %d", k);
delete(manager);
return false;
3498 uint32 nexisting, gotID;
3504 unittest::fail(
"Name: lookup 'Beta' got %u (want 31)", gotID);
delete(manager);
return false;
3507 unittest::fail(
"Name: lookup 'Alpha' got %u (want 30)", gotID);
delete(manager);
return false;
3510 unittest::fail(
"Name: lookup of missing name returned success");
delete(manager);
return false;
3519 uint16 tidt, existingID16;
3552 if (strcmp(test,
"Type2")) {
3595 if (strcmp(test,
"Tag2")) {
3606 uint32 n1 = 61, n2 = 62, ex = 0;
3611 unittest::fail(
"parameter info: neighbour setup failed");
delete(manager);
return false; }
3612 std::string grown =
"hello";
3613 for (
int g = 0; g < 40; g++) {
3614 grown +=
" and some more text";
3617 unittest::fail(
"parameter info: growing a parameter of one component damaged the next (step %d, name '%s')", g, cm->
getComponentNameString(n2).c_str());
delete(manager);
return false; }
3619 char blob[32] = { 0 };
3620 if (!cm->
getPrivateData(n1,
"Blob", blob, 32) || strcmp(blob,
"0123456789")) {
unittest::fail(
"parameter info: private data damaged by parameter growth ('%s')", blob);
delete(manager);
return false; }
3634 "Component memory layout: create above/below, grow, destroy in the middle, recreate; integrity after every step",
"memory");
3636 "Component memory: components, private data, parameters, type levels, tags",
"memory");
#define PARAM_STRING_COLL
#define PARAM_INTEGER_COLL
Shared-memory component registry: identity, location, parameters, private data and statistics for eve...
#define COMPSTATUS_STARTING
Component is starting up.
#define CHECKCOMPONENTMEMORYSERIALRETURN(a)
#define SELFTRIGGER_ALLOW
Explicitly allowed.
#define COMPONENT_CAN_MIGRATE
Migration-policy flag: component may be moved to another process/node.
#define GETCOMPOFFSET(header, id)
Offset value for component id (0 = not present).
#define SELFTRIGGER_WARN
Allowed but logged as a warning.
#define GETCOMPDATA(header, id)
Record pointer for component id, or NULL.
#define COMPINFOUSAGE(info)
Total bytes used by a component record including its parameter and private-data areas.
#define COMPSTATUS_RUNNING
Component is executing a run.
#define GETCOMPOFFSETP(header, id)
Pointer to the offset slot for component id.
#define CHECKCOMPONENTMEMORYSERIAL
Re-open the component segment if the master's resize serial no longer matches ours; bails out of the ...
#define COMPONENT_PAUSED
Policy flag (16 Nov 2026): the component is stopped - its crank is told to finish (PsyAPI::shouldCont...
#define DRAFTMSGSIZE
Fixed byte size of the per-message draft slots used in the recent-message rings of ComponentStats / P...
#define COMPONENTMEMORYID
#define COMP_WHITEBOARD
Whiteboard: publish/subscribe message store with retention.
#define COMP_EXTERNAL
External module running outside the node process.
#define COMP_INTERNAL
Internal module (same id as COMP_MODULE).
#define COMP_CATALOG
Catalog: keyed/queryable data store.
Small, dependency-free unit test harness used by all CMSDK object tests.
Accessor for the shared component registry.
bool setParameter(uint32 cid, const char *name, const char *val)
bool writeComponentsToMsg(DataMessage *msg)
Serialize all component records into msg.
bool create(uint32 indexSize)
Create the component segment (master only).
uint16 getComponentNodeID(uint32 cid)
bool getComponentName(uint32 cid, char *name, uint32 maxNameLen)
Copy the component name into name.
bool getParameterInfo(uint32 cid, std::vector< ParamInfo > &out)
Every parameter of component cid, in creation order, with type, value, default, range,...
bool open()
Attach to the existing component segment.
bool getParameterAsBool(uint32 cid, const char *name)
bool syncComponents(DataMessage *msg)
Merge component records received from a remote node.
std::string getComponentNameString(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.
std::string printFriendly()
bool deletePrivateData(uint32 cid, const char *name)
Delete blob name.
bool updateComponentLocation(uint32 cid, uint16 nodeID, uint16 procID)
Record a new location (after migration).
std::vector< ComponentInfoStruct > * getAllModules()
Snapshot all module components.
uint8 getParameterDataType(uint32 cid, const char *name)
bool deleteParameter(uint32 cid, const char *name)
Remove the parameter.
bool setComponentStats(uint32 cid, ComponentStats &stats)
Overwrite the component's stats.
bool cancelComponentID(uint32 id)
Release a provisionally reserved component id.
bool getComponentID(const char *name, uint32 &cid)
Look up a component id by name.
AveragePerfStats getComponentPerfStats(uint32 cid)
uint16 getComponentProcessID(uint32 cid)
bool setComponentData(uint32 cid, const char *data, uint64 size, bool wasMigrated)
Replace a component's data area (after migration).
bool addLocalPerformanceStats(std::list< PerfStats > &perfStats)
Append PerfStats for all local components.
bool tweakParameter(uint32 cid, const char *name, int32 tweak)
Step the value by tweak * interval (or collection index).
char * getPrivateDataCopy(uint32 cid, const char *name, uint64 &size)
ComponentMemory(MasterMemory *master)
static const char * ParamTypeName(uint8 type)
std::list< std::string > getPrivateDataKeys(uint32 cid)
uint8 lookupComponentID(const char *name, uint32 &id)
Look up a component by name without filtering on readiness.
bool destroyComponent(uint32 cid)
Remove a component record and free its space.
float64 getParameterFloat(uint32 cid, const char *name)
uint32 getParameterValueSize(uint32 cid, const char *name)
uint8 getComponentPolicy(uint32 cid)
bool confirmComponentID(uint32 id)
Mark a provisionally reserved component id as ready (syncStatus 2).
bool getPrivateData(uint32 cid, const char *name, char *data, uint64 maxSize)
Copy blob into caller buffer data (max maxSize).
bool canComponentMigrate(uint32 cid)
std::string getPrivateDataMimetype(uint32 cid, const char *name)
bool getComponentLocation(uint32 cid, uint16 &nodeID, uint16 &procID)
Get the node/process the component runs in.
std::list< uint16 > * findProcessComponents(uint16 procID)
List ids of components in process procID.
std::vector< ComponentInfoStruct > * getAllComponents()
Snapshot all components.
uint64 getPrivateDataSize(uint32 cid, const char *name)
std::vector< ComponentInfoStruct > * getAllCatalogs()
Snapshot all catalog components.
bool setComponentPerfStats(uint32 cid, AveragePerfStats &perfStruct)
Store new performance averages.
char * getComponentData(uint32 cid, uint64 &size)
Copy a component's whole data area (for migration).
std::string checkIntegrity()
Check the segment layout: every present component's record lies inside the used area,...
static bool UnitTest()
Self-test.
bool hasParameter(uint32 cid, const char *name)
std::map< std::string, std::string > getPrivateDataKeysAndTypes(uint32 cid)
bool setComponentPaused(uint32 cid, bool paused)
Set or clear COMPONENT_PAUSED (stop / start).
uint8 getComponentSelfTrigger(uint32 cid)
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 isComponentLocal(uint32 cid)
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 setComponentPolicy(uint32 cid, uint8 policy)
bool getParameter(uint32 cid, const char *name, char *val, uint32 maxSize)
bool resetParameter(uint32 cid, const char *name)
Restore the parameter's default value/index.
std::vector< ComponentInfoStruct > * getAllLocalComponents()
Snapshot components on this node.
uint8 getComponentType(uint32 cid)
ComponentStats getComponentStats(uint32 cid)
bool isComponentPaused(uint32 cid)
Set the migration policy.
bool setPrivateData(uint32 cid, const char *name, const char *data, uint64 size, const char *mimetype=NULL)
Create/replace blob name.
std::string toXML(bool stats=true)
int64 getParameterInt(uint32 cid, const char *name)
std::string getParameterString(uint32 cid, const char *name, uint32 maxSize)
bool createParameter(uint32 cid, const char *name, const char *val, const char *defaultValue=NULL)
bool writeComponentNamesToMsg(DataMessage *msg)
Write just the component names into msg.
bool setComponentSelfTrigger(uint32 cid, uint8 selfTrigger)
Set the self-trigger policy.
bool getMemoryUsage(uint64 &alloc, uint64 &usage)
Report allocation/usage of the component segment.
bool getTypeLevelID(const char *name, uint16 &id)
bool createNewTag(uint32 id, const char *name, uint64 time, uint32 &existingID)
bool getTagName(uint32 id, char *name, uint32 maxSize)
bool getTagID(const char *name, uint32 &id)
bool confirmTypeLevelID(uint16 id)
bool createNewTypeLevel(uint16 id, const char *name, uint64 time, uint16 &existingID)
bool confirmTagID(uint32 id)
bool getTypeLevelName(uint16 id, char *name, uint32 maxSize)
The central Psyclone data container: a self-contained binary message with typed, named user entries.
bool setString(const char *key, const char *value)
setString(const char* key, const char* value)
bool getInt(const char *key, int64 &value)
getInt(const char* key, int64& value)
bool setInt(const char *key, int64 value)
setInt(const char* key, int64 value)
DataMessageHeader * data
Pointer to the message's flat memory block (header + user entries).
uint32 getSize()
getSize() Get message size Many types of data of any size can be put into a message as user entries; ...
uint64 getTime(const char *key)
getTime(const char* key)
const char * getString(const char *key)
getString(const char* key)
Handle to the node's master shared-memory segment (MemoryMasterStruct).
Top-level facade of the shared-memory subsystem for one process.
ComponentMemory * componentMemory
Accessor for the component registry.
bool create(uint16 sysID, uint32 slotCount=100000, uint16 binCount=2, uint32 minBlockSize=1024, uint32 maxBlockSize=64 *1024, uint64 initSize=50000000L, uint64 maxSize=1000000000L, bool force=false)
Create all shared segments for a new node instance (master process only).
DataMapsMemory * dataMapsMemory
Accessor for the type/context/tag/crank/request maps.
static UnitTestRunner & instance()
Access the singleton (created on first use).
void registerTest(const char *name, UnitTestFunc func, const char *description="", const char *category="", bool inDefaultRun=true, uint32 timeoutSec=0)
Register a test with the runner.
Recursive mutual-exclusion lock, optionally named for cross-process use.
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
char * OpenSharedMemorySegment(const char *name, uint64 size)
Open and map an existing named shared memory segment.
bool UnlinkSharedMemorySegment(char *data)
Remove a segment's name now, whoever created it; every existing mapping stays valid.
char * CreateSharedMemorySegment(const char *name, uint64 size, bool force=false)
Create a named shared memory segment and map it into this process.
bool CloseSharedMemorySegment(char *data, uint64 size)
Unmap a segment previously created/opened here.
bool DisownSharedMemorySegment(char *data)
Give up this process's ownership of a segment's name, so closing it here only unmaps.
uint32 strcpyavail(char *dst, const char *src, uint32 maxlen, bool copyAvailable)
Bounded strcpy that always NUL-terminates.
void fail(const char *fmt,...)
Set an explanatory reason shown on the FAIL line.
void detail(const char *fmt,...)
Verbose-only indented diagnostic line (shown only when verbose=1).
void progress(int percent, const char *action)
Report progress with a short description of the current action.
std::string BytifySize(double val)
Format a byte count with binary units, e.g.
std::string StringFormat(const char *format,...)
printf into a std::string.
int64 Ascii2Int64(const char *ascii, uint32 start=0, uint32 end=0)
Parse a signed 64-bit decimal integer from a substring.
float64 Ascii2Float64(const char *ascii, uint32 start=0, uint32 end=0)
Parse a 64-bit float from a substring (decimal point, not locale dependent).
static bool ComponentMemoryLayoutUnitTest()
void Register_ComponentMemory_Tests()
static std::string ParamFloatText(float64 v)
Sliding-window averages derived from successive PerfStats snapshots.
One component's registry record in shared memory.
uint16 nodeID
Node the component currently runs on.
uint8 policy
Migration policy (COMPONENT_CAN_MIGRATE flag).
uint64 size
Total record size in bytes including parameter and data areas.
uint8 type
Component type (Whiteboard, Catalog, Module, ...).
uint8 selfTrigger
SELFTRIGGER_* policy.
char name[MAXKEYNAMELEN]
Component name (unique per system).
uint64 createdTime
Creation timestamp (µs).
uint16 procID
Process (space) the component currently runs in.
uint32 id
Component id (index into the segment's offset table).
AveragePerfStats perfStats
uint8 status
COMPSTATUS_* run status.
uint8 syncStatus
Cluster sync status (0: not there, 1: in-sync, 2: ready).
Root header of the component-memory segment.
uint32 cid
Check/magic id validated on attach.
Legacy per-component throughput counters (DataMessageHeader-based rings).
uint64 usageCPUTicks
Cumulative CPU ticks consumed.
uint32 migrationCount
Times this component has migrated.
uint64 msgInBytes
Total bytes received.
uint64 msgInCount
Total messages received.
uint64 cycleCount
Total processing cycles.
uint64 time
Timestamp of the last update (µs).
uint64 currentRunStartTime
Timestamp the current/last run started (µs).
uint64 runCount
Total runs.
uint64 msgOutBytes
Total bytes posted.
DataMessageHeader recentInMsg[10]
uint64 firstRunStartTime
Timestamp of the first run (µs).
DataMessageHeader recentOutMsg[10]
uint64 msgOutCount
Total messages posted.
One parameter as listed by ComponentMemory::getParameterInfo(): a copy, safe to keep after the call.
std::string value
Current value as text.
std::vector< std::string > options
Collections: every entry as text, in order.
uint32 defaultIndex
Collections: the selected and the default entry.
uint8 type
PARAM_* data type.
std::string step
Integer/float: tweak step (interval), empty when 0.
std::string maxVal
Integer/float: inclusive range, both empty when unbounded (min == max).
std::string defaultValue
Value restored by resetParameter().
Raw per-component performance counters sampled inside shared memory.