45template <
typename T,
typename ID>
49 fprintf(stderr,
"CreateEntry %u no data provided\n",
id);
54 if (
id >= header->
maxID) {
55 fprintf(stderr,
"CreateEntry bit location %u out of range\n",
id);
70 if (entry && (strcmp(name, entry->name) == 0)) {
83 if (offset > header->
size) {
84 fprintf(stderr,
"CreateEntry offset error in Memory Map\n");
87 entry = (T*) (data+offset);
88 if ((entry->id ==
id) || (entry->time == 0)) {
98 fprintf(stderr,
"CreateEntry entry error in Memory Map\n");
116template <
typename T,
typename ID>
131 fprintf(stderr,
"No more bit locations available\n");
141 if (offset > header->
size) {
142 fprintf(stderr,
"Offset error in Memory Map\n");
145 entry = (T*) (data+offset);
146 if ((entry->id ==
id) || (entry->time == 0)) {
156 fprintf(stderr,
"Entry error in Memory Map\n");
170template <
typename T,
typename ID>
179 if (offset > header->
size)
181 entry = (T*) (data+offset);
182 if ((entry->id !=
id) || (entry->time == 0))
195template <
typename T,
typename ID>
212template <
typename T,
typename ID>
221 if (offset > header->
size)
223 entry = (T*) (data+offset);
224 if ((entry->id ==
id) && (entry->time != 0) && (entry->status > 1))
236template <
typename T,
typename ID>
245 if (offset > header->
size)
247 entry = (T*) (data+offset);
248 if ((entry->id ==
id) && entry->time && (entry->status >= 1)) {
264template <
typename T,
typename ID>
273 if (offset > header->
size)
275 entry = (T*) (data+offset);
276 if ((entry->id ==
id) && entry->time && (entry->status <= 1)) {
281 else if ((entry->id == 0) || (entry->status == 0))
291template <
typename T,
typename ID>
310template <
typename T,
typename ID>
318 while ((uint32)((
char*)entry - data) < header->
size) {
319 if (
stricmp(name, entry->name) == 0) {
320 if ((entry->status > 1) || force)
338template <
typename T,
typename ID>
347 while ((uint32)((
char*)entry - data) < header->
size) {
348 if (
stricmp(name, entry->name) == 0) {
350 return entry->status;
360template <
typename T,
typename ID>
369 while ((uint32)((
char*)entry - data) < header->
size) {
371 if (entry->status > 1)
383template <
typename T,
typename ID>
392 while ((uint32)((
char*)entry - data) < header->
size) {
394 if (entry->status > 1)
406template <
typename T,
typename ID>
416 while ((uint32)((
char*)entry - data) < header->
size) {
418 str += entry->toXML();
423 std::string outerName = T::GetOuterXMLName();
427 return utils::StringFormat(
"<%s count=\"%u\">\n%s</%s>\n", outerName.c_str(), count, str.c_str(), outerName.c_str());
433template <
typename T,
typename ID>
442 while ((uint32)((
char*)entry - data) < header->
size) {
444 if (!entry->writeIDToMsg(arrayname, n, msg))
457template <
typename T,
typename ID>
466 while ((uint32)((
char*)entry - data) < header->
size) {
468 if (!entry->writeToMsg(n, msg))
479template <
typename T,
typename ID>
488template <
typename T,
typename ID>
Cross-platform utility toolbox for CMSDK: threading, synchronization, shared memory,...
The central Psyclone data container: a self-contained binary message with typed, named user entries.
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...
std::string PrintTimeString(uint64 t, bool local=true, bool us=true, bool ms=true)
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
bool GetFirstFreeBitLoc(const char *bitfield, uint32 bytesize, uint32 &loc)
Find the first 0 (free) bit.
bool GetBit(uint32 loc, const char *bitfield, uint32 bytesize, bit &val)
Read bit loc.
bool SetBit(uint32 loc, bit value, char *bitfield, uint32 bytesize)
Set bit loc to value.
uint32 strcpyavail(char *dst, const char *src, uint32 maxlen, bool copyAvailable)
Bounded strcpy that always NUL-terminates.
std::string StringFormat(const char *format,...)
printf into a std::string.