18#if !defined(_DATAMAPSMEMORY_H_)
19#define _DATAMAPSMEMORY_H_
78 if (!msg)
return false;
79 msg->
setInt((int64)n,
"ID",
id);
86 if (!msg)
return false;
104 if (!msg)
return false;
105 msg->
setInt((int64)n,
"ID",
id);
112 if (!msg)
return false;
130 if (!msg)
return false;
131 msg->
setInt((int64)n,
"ID",
id);
138 if (!msg)
return false;
158 return utils::StringFormat(
"\t<crank id=\"%u\" name=\"%s\" status=\"%u\" time=\"%llu\" compid=\"%u\" function=\"%s\" library=\"%s\">\n\t\t%s\n\t</crank>\n",
161 return utils::StringFormat(
"\t<crank id=\"%u\" name=\"%s\" status=\"%u\" time=\"%llu\" compid=\"%u\" function=\"%s\" library=\"%s\" />\n",
166 if (!msg)
return false;
167 msg->
setInt((int64)n,
"ID",
id);
179 if (!msg)
return false;
191#define REQ_RECEIVED_LOCAL 2
192#define REQ_RECEIVED_REMOTE 3
193#define REQ_PROCESSING_LOCAL 4
194#define REQ_PROCESSING_REMOTE 5
195#define REQ_REPLY_READY 6
196#define REQ_FAILED_TO_SEND 7
198#define REQ_FAILED_DATA 9
199#define REQ_FAILED_NODATA 10
200#define REQ_FAILED_DATA_EOL 11
201#define REQ_SUCCESS 12
202#define REQ_SUCCESS_DATA 13
203#define REQ_SUCCESS_NODATA 14
204#define REQ_SUCCESS_DATA_EOL 15
222 return utils::StringFormat(
"\t<request id=\"%u\" name=\"%s\" status=\"%u\" time=\"%llu\" lastupdate=\"%llu\" from=\"%u\" to=\"%u\" remoteid=\"%u\" msgid=\"%llu\" msgeol=\"%llu\" />\n",
230#define CHECKDATAMAPSMEMORYSERIAL if (serial != master->getDataMapsShmemSerial()) {if (!open()) {mutex->leave();return 0;}}
253 bool create(uint32 typesMaxCount, uint32 contextsMaxCount, uint32 tagsMaxCount, uint32 cranksMaxCount, uint32 requestsMaxCount);
271 bool createNewTypeLevel(uint16
id,
const char* name, uint64 time, uint16& existingID);
305 bool createNewTag(uint32
id,
const char* name, uint64 time, uint32& existingID);
307 bool getTagName(uint32
id,
char* name, uint32 maxSize);
308 bool getTagID(
const char* name, uint32 &
id);
322 bool createNewCrank(uint16
id, uint32 compID,
const char* name,
const char* function,
const char* libraryFilename,
const char* language,
const char* script, uint64 time, uint16& existingID);
324 bool getCrankName(uint16
id,
char* name, uint32 maxSize);
328 bool getCrankID(
const char* name, uint16 &
id);
344 bool getRequestInfo(uint32
id, uint32& from, uint32& to, uint32& remoteID);
345 bool getRequestStatus(uint32
id, uint8& status, uint64& time, uint64& msgID, uint64& msgEOL);
347 bool setRequestStatus(uint32
id, uint8 status, uint64 msgID, uint64 msgEOL);
348 bool waitForRequestReply(uint32
id, uint32 timeout, uint8& status, uint64& time, uint64& msgID, uint64& msgEOL);
354 bool resize(uint16 port, uint32 serial, uint32 typesMaxCount, uint32 contextsMaxCount, uint32 tagsMaxCount, uint32 cranksMaxCount, uint32 requestsMaxCount);
378template <
typename T,
typename ID>
382 static T*
CreateEntry(
char* data, ID
id,
const char* name);
384 static T*
GetEntry(
char* data, ID
id);
389 static bool GetEntryName(
char* data, ID
id,
char* name, uint32 maxSize);
390 static ID
GetEntryID(
char* data,
const char* name,
bool force =
false);
391 static uint8
LookupEntryID(
char* data,
const char* name, ID&
id);
396 static std::string
ToXML(
char* data);
Central shared-memory manager for a Psyclone node: master segment, per-subsystem shared maps and the ...
Template implementations of the GenericMemoryMap shared-map algorithms.
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
bool getTypeLevelID(const char *name, uint16 &id)
bool syncContextLevels(DataMessage *msg)
bool waitForRequestReply(uint32 id, uint32 timeout, uint8 &status, uint64 &time, uint64 &msgID, uint64 &msgEOL)
bool confirmContextLevelID(uint16 id)
bool deleteCrank(uint16 id)
DataMapsMemory(MasterMemory *master)
bool createNewCrank(uint16 id, uint32 compID, const char *name, const char *function, const char *libraryFilename, const char *language, const char *script, uint64 time, uint16 &existingID)
bool getRequestStatus(uint32 id, uint8 &status, uint64 &time, uint64 &msgID, uint64 &msgEOL)
bool createNewTag(uint32 id, const char *name, uint64 time, uint32 &existingID)
bool getTagName(uint32 id, char *name, uint32 maxSize)
bool create(uint32 typesMaxCount, uint32 contextsMaxCount, uint32 tagsMaxCount, uint32 cranksMaxCount, uint32 requestsMaxCount)
Create the segment (master only) with the given per-map capacities.
bool writeTagsToMsg(DataMessage *msg)
bool getTagID(const char *name, uint32 &id)
bool deleteContextLevel(const char *name)
uint64 getTagCreateTime(uint32 id)
uint64 getTypeLevelCreateTime(uint16 id)
uint8 lookupTagID(const char *name, uint32 &id)
bool deleteRequest(uint32 id)
bool cancelCrankID(uint16 id)
bool getContextLevelName(uint16 id, char *name, uint32 maxSize)
bool maintenance()
Periodic cleanup (e.g.
bool confirmTypeLevelID(uint16 id)
uint8 lookupTypeLevelID(const char *name, uint16 &id)
bool writeContextLevelsToMsg(DataMessage *msg)
bool open()
Attach to the existing data-maps segment.
bool getRequestInfo(uint32 id, uint32 &from, uint32 &to, uint32 &remoteID)
bool createNewTypeLevel(uint16 id, const char *name, uint64 time, uint16 &existingID)
std::string printAllContexts()
bool getCrankFunction(uint16 id, char *function, uint32 maxSize)
std::string printAllTypes()
bool writeIDsToMsg(DataMessage *msg)
Write all map names/ids into msg for cluster sync.
bool syncCranks(DataMessage *msg)
bool cancelContextLevelID(uint16 id)
bool getCrankLanguage(uint16 id, char *language, uint32 maxSize)
bool confirmTagID(uint32 id)
bool setRequestStatus(uint32 id, uint8 status)
bool writeTypeLevelsToMsg(DataMessage *msg)
bool syncTags(DataMessage *msg)
bool getContextLevelID(const char *name, uint16 &id)
bool confirmCrankID(uint16 id)
uint32 getCrankCompID(uint16 id)
std::string printFriendlyHTML()
bool getMemoryUsage(uint64 &alloc, uint64 &usage)
Report allocation/usage.
uint64 getCrankCreateTime(uint16 id)
bool cancelTagID(uint32 id)
bool syncTypeLevels(DataMessage *msg)
bool deleteTag(const char *name)
bool cancelTypeLevelID(uint16 id)
bool createNewContextLevel(uint16 id, const char *name, uint64 time, uint16 &existingID)
uint8 lookupContextLevelID(const char *name, uint16 &id)
bool getCrankID(const char *name, uint16 &id)
bool getCrankName(uint16 id, char *name, uint32 maxSize)
bool getCrankLibraryFilename(uint16 id, char *libraryFilename, uint32 maxSize)
uint64 getContextLevelCreateTime(uint16 id)
bool writeCranksToMsg(DataMessage *msg)
uint8 lookupCrankID(const char *name, uint16 &id)
bool getCrankScript(uint16 id, char *script, uint32 maxSize)
bool createNewRequest(uint32 from, uint32 to, uint32 remoteID, uint32 &id)
bool getTypeLevelName(uint16 id, char *name, uint32 maxSize)
bool deleteTypeLevel(const char *name)
The central Psyclone data container: a self-contained binary message with typed, named user entries.
bool setTime(const char *key, uint64 value)
setTime(const char* key, uint64 value)
bool setString(const char *key, const char *value)
setString(const char* key, const char* value)
bool setInt(const char *key, int64 value)
setInt(const char* key, int64 value)
Static algorithms shared by all bitfield-indexed maps in the data-maps segment.
static bool GetEntryName(char *data, ID id, char *name, uint32 maxSize)
Copy the entry name.
static T * CreateEntry(char *data, ID id, const char *name)
Reserve entry id with name (status 1).
static bool ConfirmEntry(char *data, ID id)
Mark entry ready (status 2).
static bool WriteAllEntriesToMsg(char *data, DataMessage *msg)
Serialize all entries into msg.
static ID GetEntryID(char *data, const char *name, bool force=false)
Case-insensitive reverse lookup: find the id registered under name.
static std::string ToXML(char *data)
Serialize all occupied entries as XML by delegating to each entry's toXML(), wrapped in the outer ele...
static T * CreateFirstFreeEntry(char *data, ID &id, const char *name)
Reserve the first free id.
static bool DeleteEntry(char *data, ID id)
Free the entry and its bit.
static uint32 GetCount(char *data)
Number of entries currently registered in the map (from the header's count field).
static uint32 GetUsage(char *data)
Approximate bytes in use by entry payloads (count * sizeof(T)); excludes the header and bitfield.
static uint8 LookupEntryID(char *data, const char *name, ID &id)
Case-insensitive lookup returning the entry's sync status rather than filtering by it.
static std::string PrintAllEntries(char *data)
Human-readable text dump of all occupied entries, one per line ("id = name (time)"; unconfirmed entri...
static T * GetEntry(char *data, ID id)
Fetch the confirmed entry at index id.
static bool WriteAllIDsToMsg(const char *arrayname, char *data, DataMessage *msg)
Write just names into msg under arrayname.
static uint64 GetEntryTime(char *data, ID id)
Creation timestamp of entry id.
static bool CancelEntry(char *data, ID id)
Roll back a reserved entry.
static std::string PrintAllEntriesHTML(char *data)
Dump all occupied entries as HTML table rows (no surrounding table element); used by the node's monit...
Handle to the node's master shared-memory segment (MemoryMasterStruct).
Recursive mutual-exclusion lock, optionally named for cross-process use.
std::string StringFormat(const char *format,...)
printf into a std::string.
Context-map entry: one registered psychological/system context name/id.
bool writeToMsg(uint32 n, DataMessage *msg)
char name[MAXKEYNAMELEN+1]
static std::string GetOuterXMLName()
bool writeIDToMsg(const char *arrayname, uint32 n, DataMessage *msg)
Crank-map entry: one registered crank (user callback/script) with its function, library and inline sc...
char name[MAXKEYNAMELEN+1]
char function[MAXKEYNAMELEN+1]
char language[MAXKEYNAMELEN+1]
bool writeToMsg(uint32 n, DataMessage *msg)
static std::string GetOuterXMLName()
char script[MAXSCRIPTLEN+1]
bool writeIDToMsg(const char *arrayname, uint32 n, DataMessage *msg)
char libraryFilename[MAXKEYNAMELEN+1]
Root header of the data-maps segment; records capacity/size of each contained map.
uint32 typesBitFieldSize
Bytes in the type map's occupancy bitfield.
uint64 requestsSize
Total bytes of the request map.
uint64 size
Total segment size in bytes.
uint32 contextsBitFieldSize
Bytes in the context map's occupancy bitfield.
uint32 requestsMaxCount
Capacity of the request map (entries).
uint32 cid
Check/magic id validated on attach.
uint64 contextsSize
Total bytes of the context map.
uint32 typesMaxCount
Capacity of the type map (entries).
uint64 typesSize
Total bytes of the type map.
uint32 cranksMaxCount
Capacity of the crank map (entries).
uint32 requestsBitFieldSize
Bytes in the request map's occupancy bitfield.
uint64 createdTime
Creation timestamp (µs).
uint64 tagsSize
Total bytes of the tag map.
uint64 cranksSize
Total bytes of the crank map.
uint32 contextsMaxCount
Capacity of the context map (entries).
uint32 cranksBitFieldSize
Bytes in the crank map's occupancy bitfield.
uint32 tagsMaxCount
Capacity of the tag map (entries).
uint32 tagsBitFieldSize
Bytes in the tag map's occupancy bitfield.
Request-map entry tracking one cross-component request/reply transaction.
uint8 status
REQ_* lifecycle status.
uint32 remoteID
Id of the request at the origin node, if forwarded cross-node.
uint64 time
Creation timestamp (µs).
char name[MAXKEYNAMELEN+1]
Internal use only, for named events.
uint32 id
Request id; corresponds to the index in the map.
uint64 dataMessageEOL
End-of-life of the reply message; after this the payload is gone (REQ_*_DATA_EOL).
uint64 dataMessageID
TemporalMemory id of the reply DataMessage (0 = none yet).
uint32 to
Id of the component processing the request.
static std::string GetOuterXMLName()
uint32 from
Id of the component making the request.
uint64 lastUpdate
Timestamp of the last status change (µs); used to expire stale requests.
Tag-map entry: one registered tag name/id.
bool writeIDToMsg(const char *arrayname, uint32 n, DataMessage *msg)
static std::string GetOuterXMLName()
char name[MAXKEYNAMELEN+1]
bool writeToMsg(uint32 n, DataMessage *msg)
Type-map entry: one registered message type name/id.
bool writeToMsg(uint32 n, DataMessage *msg)
bool writeIDToMsg(const char *arrayname, uint32 n, DataMessage *msg)
char name[MAXKEYNAMELEN+1]
static std::string GetOuterXMLName()