98#if !defined(_DATAMESSAGE_H_)
99#define _DATAMESSAGE_H_
109#define CURRENTDATAMESSAGEVERSION 10
230 std::string
toJSON(std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
236 std::string
toXML(std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
317 DataMessage(
PsyType type, uint32 from, uint32 to, uint64 ttl = 0, uint16 priority = 0);
328 DataMessage(
PsyType type, uint32 from, uint32 to, uint32 tag, uint64 time, uint64 ttl = 0, uint16 priority = 0);
485 uint64
getTime(
const char* key);
504 const char*
getString(
const char* key, uint32 &size);
514 bool getInt(
const char* key, int64& value);
525 bool getDouble(
const char* key,
double& value);
536 bool getFloat(
const char* key, float64& value);
546 const char*
getData(
const char* key, uint32& size);
580 uint64
getTime(
const char* key,
bool& success);
591 const char*
getString(
const char* key,
bool& success);
602 const char*
getString(
const char* key, uint32 &size,
bool& success);
614 int64
getInt(
const char* key,
bool& success);
626 double getDouble(
const char* key,
bool& success);
637 float64
getFloat(
const char* key,
bool& success);
648 const char*
getData(
const char* key, uint32& size,
bool& success);
661 char*
getDataCopy(
const char* key, uint32& size,
bool& success);
684 int64
getInt(
const char* key);
722 bool setTime(
const char* key, uint64 value);
733 bool setString(
const char* key,
const char* value);
743 bool setInt(
const char* key, int64 value);
753 bool setDouble(
const char* key,
double value);
764 bool setFloat(
const char* key, float64 value);
776 bool setData(
const char* key,
const char* value, uint32 size);
796 return data->userSize;
805 return data->userCount;
854 bool hasKey(
const char* key);
927 uint64
getTime(int64 i,
const char* key);
941 int64
getAsInt(int64 i,
const char* key);
948 uint64
getAsTime(int64 i,
const char* key);
962 const char*
getString(int64 i,
const char* key);
970 const char*
getString(int64 i,
const char* key, uint32 &size);
978 bool getInt(int64 i,
const char* key, int64& value);
986 bool getDouble(int64 i,
const char* key,
double& value);
994 bool getFloat(int64 i,
const char* key, float64& value);
1002 int64
getInt(int64 i,
const char* key,
bool& success);
1009 double getDouble(int64 i,
const char* key,
bool& success);
1016 float64
getFloat(int64 i,
const char* key,
bool& success);
1023 int64
getInt(int64 i,
const char* key);
1029 double getDouble(int64 i,
const char* key);
1035 float64
getFloat(int64 i,
const char* key);
1043 const char*
getData(int64 i,
const char* key, uint32& size);
1051 char*
getDataCopy(int64 i,
const char* key, uint32& size);
1068 bool setTime(int64 i,
const char* key, uint64 value);
1076 bool setString(int64 i,
const char* key,
const char* value);
1084 bool setInt(int64 i,
const char* key, int64 value);
1092 bool setDouble(int64 i,
const char* key,
double value);
1100 bool setFloat(int64 i,
const char* key, float64 value);
1108 bool setData(int64 i,
const char* key,
const char* value, uint32 size);
1146 std::map<int64, int64>
getIntArray(
const char* key);
1197 bool setTimeArray(
const char* key, std::map<int64, uint64>& map);
1205 bool setStringArray(
const char* key, std::map<int64, std::string>& map);
1213 bool setIntArray(
const char* key, std::map<int64, int64>& map);
1221 bool setDoubleArray(
const char* key, std::map<int64, double>& map);
1229 bool setFloatArray(
const char* key, std::map<int64, float64>& map);
1273 uint64
getTime(
const char* idx,
const char* key);
1282 std::string
getAsString(
const char* idx,
const char* key);
1291 int64
getAsInt(
const char* idx,
const char* key);
1300 uint64
getAsTime(
const char* idx,
const char* key);
1309 float64
getAsFloat(
const char* idx,
const char* key);
1317 const char*
getString(
const char* idx,
const char* key);
1326 const char*
getString(
const char* idx,
const char* key, uint32 &size);
1336 bool getInt(
const char* idx,
const char* key, int64& value);
1346 bool getDouble(
const char* idx,
const char* key,
double& value);
1356 bool getFloat(
const char* idx,
const char* key, float64& value);
1364 int64
getInt(
const char* idx,
const char* key,
bool& success);
1373 double getDouble(
const char* idx,
const char* key,
bool& success);
1382 float64
getFloat(
const char* idx,
const char* key,
bool& success);
1390 int64
getInt(
const char* idx,
const char* key);
1399 double getDouble(
const char* idx,
const char* key);
1407 float64
getFloat(
const char* idx,
const char* key);
1416 const char*
getData(
const char* idx,
const char* key, uint32& size);
1426 char*
getDataCopy(
const char* idx,
const char* key, uint32& size);
1443 bool setTime(
const char* idx,
const char* key, uint64 value);
1452 bool setString(
const char* idx,
const char* key,
const char* value);
1461 bool setInt(
const char* idx,
const char* key, int64 value);
1471 bool setDouble(
const char* idx,
const char* key,
double value);
1481 bool setFloat(
const char* idx,
const char* key, float64 value);
1491 bool setData(
const char* idx,
const char* key,
const char* value, uint32 size);
1508 std::map<std::string, uint64>
getTimeMap(
const char* key);
1516 std::map<std::string, std::string>
getAsStringMap(
const char* key);
1524 std::map<std::string, int64>
getAsIntMap(
const char* key);
1532 std::map<std::string, float64>
getAsFloatMap(
const char* key);
1539 std::map<std::string, std::string>
getStringMap(
const char* key);
1546 std::map<std::string, int64>
getIntMap(
const char* key);
1554 std::map<std::string, double>
getDoubleMap(
const char* key);
1561 std::map<std::string, float64>
getFloatMap(
const char* key);
1576 bool setTimeMap(
const char* key, std::map<std::string, uint64>& map);
1584 bool setStringMap(
const char* key, std::map<std::string, std::string>& map);
1592 bool setIntMap(
const char* key, std::map<std::string, int64>& map);
1601 bool setDoubleMap(
const char* key, std::map<std::string, double>& map);
1610 bool setFloatMap(
const char* key, std::map<std::string, float64>& map);
1627 std::string
toJSON(std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
1634 std::string
toXML(std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
1646 std::string
toCSV(
const char* separator = NULL,
const char* preample = NULL, std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
1655 static std::string
GetCSVHeader(
const char* separator = NULL,
const char* preample = NULL);
1698 return data->origin;
1707 return data->destination;
1717 data->origin = addr;
1728 data->destination = addr;
1753 bool setMultiple(uint32 from, uint32 to, uint32 tag, uint64 ttl, uint8 policy, uint64 sendtime) {
1755 if (from)
data->from = from;
1756 if (to)
data->to = to;
1757 if (tag)
data->tag = tag;
1758 if (ttl)
data->ttl = ttl;
1759 if (policy)
data->policy = policy;
1760 if (sendtime)
data->sendtime = sendtime;
1797 return data->reference;
1807 data->reference = ref;
1818 return data->systemid;
1828 data->systemid = id;
1951 return data->contextchange;
1969 data->contextchange = context;
2044 int64 ttl = eol -
data->time;
2046 data->ttl = (uint64)ttl;
2065 return data->priority;
2084 data->priority = priority;
2100 return data->policy;
2116 data->policy = policy;
2131 return data->sendtime;
2147 data->sendtime = time;
2162 return data->recvtime;
2178 data->recvtime = time;
2225 return data->status;
2241 data->status = status;
2255 return data->serial;
2271 data->serial = serial;
2298 bool addTimeUsage(uint32 cycleCPUTime, uint32 cycleWallTime, uint32 chainCPUTime = 0, uint32 chainWallTime = 0, uint32 chainCount = 0);
2312 return data->cyclecputime;
2328 data->cyclecputime = t;
2346 return data->cyclewalltime;
2362 data->cyclewalltime = t;
2381 return data->chaincputime;
2397 data->chaincputime = t;
2415 return data->chainwalltime;
2431 data->chainwalltime = t;
2448 return data->chaincount;
2464 data->chaincount= count;
2522 bool setRawData(
const char* key,
const char* value, uint32 size, uint32 datatype);
2537 char* srcEnd = (
char*)
data +
data->size;
2538 while (src < srcEnd) {
2564 if (src == NULL)
return NULL;
2580 if (src == NULL)
return true;
2603 char* srcEnd = (
char*)
data +
data->size;
2604 while (src < srcEnd) {
Object type ids used to tag and verify every binary structure in CMSDK memory.
#define GetObjID(data)
Extract the cid field from a binary object block: the uint32 at byte offset 4 (after the leading size...
Core fixed-width scalar typedefs and the PsyType / PsyContext hierarchical identifiers.
static struct PsyType NOTYPE
The empty/unset message type (isValid() == false).
static struct PsyContext NOCONTEXT
The empty/unset context (isValid() == false).
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.
bool setOrigin(uint16 addr)
setOrigin(uint16 addr) Set origin to address addr and return new origin
bool setTime(const char *key, uint64 value)
setTime(const char* key, uint64 value)
std::map< int64, float64 > getAsFloatArray(const char *key)
getAsFloatArray(const char* key)
uint16 getOrigin()
getOrigin() Get the NodeID of the node the message originated on
bool setFloatArray(const char *key, std::map< int64, float64 > &map)
setFloatArray(const char* key, std::map<int64, float64>& map) Sets the whole float array named key in...
bool setChainCount(uint32 count)
setChainCount(uint32 count)
static bool UnitTest()
Run the built-in self test for the DataMessage implementation.
DataMessage()
DataMessage() Creates an empty DataMessage.
bool getDouble(const char *key, double &value)
getDouble(const char* key, double& value)
~DataMessage()
~DataMessage() Message destructor
std::string toXML(std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
toXML()
bool setTTL(uint64 ttl)
setTTL(uint64 ttl)
bool deleteEntry(const char *key)
deleteEntry(const char* key)
uint32 getSystemID()
getSystemID() Get and return message system id
bool setEOL(uint64 eol)
setEOL(uint64 eol)
static DataMessage * FindClosestMessage(uint64 t, std::map< uint64, DataMessage * > &messages)
FindClosestMessage(uint64 t, std::map<uint64, DataMessage*> &messages) In a map of time -> DataMessag...
bool setPriority(uint16 priority)
setPriority(uint16 priority)
bool setFloat(const char *key, float64 value)
setFloat(const char* key, float64 value)
std::map< int64, int64 > getIntArray(const char *key)
getIntArray(const char* key)
bool setMemID(uint64 id)
setMemID(uint64 id) Set memory ID to id
bool setChainWallTime(uint32 t)
setChainWallTime(uint32 t)
bool addTimeUsage(uint32 cycleCPUTime, uint32 cycleWallTime, uint32 chainCPUTime=0, uint32 chainWallTime=0, uint32 chainCount=0)
addTimeUsage()
std::map< std::string, double > getDoubleMap(const char *key)
returns the user double entry with this key
uint32 getFrom()
getFrom() Get the sender id
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)
bool isSingleValue(const char *key)
isSingleValue(const char* key)
bool hasData(const char *key)
Check if key variable exists and is a data entry.
uint32 getMapCount(const char *key)
getMapCount(const char* key) Returns the number of elements in map with name '<key>'
std::map< std::string, uint64 > getTimeMap(const char *key)
returns the user time entry with this key
std::map< std::string, int64 > getIntMap(const char *key)
returns the user integer entry with this key
bool setChainCPUTime(uint32 t)
setChainCPUTime(uint32 t)
bool setTag(uint32 tag)
setTag(uint32 tag)
std::string _lastFindKey
Internal: last key looked up (single-entry lookup cache; mutable so const-style getters can update it...
uint16 getDestination()
getDestination() Get the NodeID of the destination node
bool setDestination(uint16 addr)
setDestination(uint16 addr) Set destination to address addr and return new destination
PsyContext getContextChange()
getContextChange()
uint32 getArraySize(const char *key)
getArraySize(const char* key) Returns the number of elements in array with name '<key>'
char * getDataCopy(const char *key, uint32 &size)
getDataCopy(const char* key, uint32& size)
uint16 getCycleWallTime()
getCycleWallTime()
bool setDoubleMap(const char *key, std::map< std::string, double > &map)
sets the user double entry with this key to the value provided
std::string getAsString(const char *key)
getAsString(const char* key)
DataMessageHeader * data
Pointer to the message's flat memory block (header + user entries).
bool setStatus(uint16 status)
setStatus(uint16 status)
std::string toJSON(std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
toJSON()
std::map< int64, float64 > getFloatArray(const char *key)
getFloatArray(const char* key)
std::string toCSV(const char *separator=NULL, const char *preample=NULL, std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
toCSV()
PsyType getType()
getType()
bool hasFloat(const char *key)
Check if key variable exists and is a float.
bool setIntMap(const char *key, std::map< std::string, int64 > &map)
sets the user integer entry with this key
char * findKey(const char *key)
findKey(const char* key) Internal function: linear scan of the entry list for an entry whose key matc...
char * findEntry(const char *key)
findEntry(const char* key)
const char * getData(const char *key, uint32 &size)
getData(const char* key, uint32& size)
uint16 getChainCPUTime()
getChainCPUTime()
uint16 getStatus()
getStatus()
bool getAsBool(const char *key)
getAsBool(const char* key)
uint32 getUserCount()
getUserCount()
uint32 getSize()
getSize() Get message size Many types of data of any size can be put into a message as user entries; ...
uint64 getReference()
getReference() Get and return message reference id
static bool ConvertDataFromOlderMessageFormat(const char *data, char **newData)
Convert a binary block in the legacy (pre-version-10, DATAMESSAGEOLDID) format to the current DataMes...
uint32 copyUserEntriesFromMessage(DataMessage *msg)
copyUserEntriesFromMessage(DataMessage* msg) Copies all user data from a message into this message,...
std::string getUserEntriesAsJSON(bool asText)
getUserEntriesAsJSON(bool asText) Returns the JSON representation of the full message including all u...
char * _lastFindKeyResult
Internal: cached location of the last key's entry inside the block; NULL if not found.
bool setAttachedMessage(const char *key, DataMessage *msg)
setAttachedMessage(const char* key, DataMessage* msg)
bool setTimeArray(const char *key, std::map< int64, uint64 > &map)
setTimeArray(const char* key, std::map<int64, uint64>& map) Sets the whole time array named key in on...
bool setRecvTime(uint64 time)
setRecvTime(uint64 time)
std::map< std::string, std::string > getStringMap(const char *key)
returns the user string entry with this key
std::map< int64, std::string > getStringArray(const char *key)
getStringArray(const char* key)
bool setAttachedMessageArray(const char *key, std::map< int64, DataMessage * > &map)
setAttachedMessageArray(const char* key, std::map<int64, DataMessage*>& map) Sets the whole array of ...
bool removeEntry(const char *key)
removeEntry(const char* key)
bool hasTime(const char *key)
Check if key variable exists and is a time.
std::map< int64, std::string > getAsStringArray(const char *key)
getAsStringArray(const char* key)
bool setIntArray(const char *key, std::map< int64, int64 > &map)
setIntArray(const char* key, std::map<int64, int64>& map) Sets the whole integer array named key in o...
bool setFrom(uint32 from)
setFrom(uint32 from)
std::map< std::string, DataMessage * > getAttachedMessageMap(const char *key)
returns a copy of the user message entry with this key
bool setTo(uint32 to)
setTo(uint32 to)
bool setTimeMap(const char *key, std::map< std::string, uint64 > &map)
sets the user time entry with this key
bool setCreatedTime(uint64 t)
setCreatedTime(uint64 t)
uint32 getContentSize(const char *key)
getContentSize(const char* key)
void invalidateFindKeyCache()
Internal: clears the single-entry key-lookup cache.
uint32 getArrayCount(const char *key)
getArrayCount(const char* key) Returns the number of elements in array with name '<key>'
bool setReference(uint64 ref)
setReference(uint64 ref) Set message reference
std::map< std::string, int64 > getAsIntMap(const char *key)
returns the user entry as an integer map regardless of what type it is
bool setFloatMap(const char *key, std::map< std::string, float64 > &map)
sets the user float entry with this key to the value provided
uint64 getAsTime(const char *key)
getAsTime(const char* key)
uint16 getPriority()
getPriority()
bool isMapContent(const char *key)
isMapContent(const char* key)
bool hasKey(const char *key)
Check if key variable exists.
uint64 getTime(const char *key)
getTime(const char* key)
bool setSystemID(uint32 id)
setSystemID(uint32 id) Set message system id
bool setType(PsyType &type)
setType(PsyType &type)
bool getFloat(const char *key, float64 &value)
getFloat(const char* key, float64& value)
bool setRawData(const char *key, const char *value, uint32 size, uint32 datatype)
Internal: low-level entry writer used by all typed set...() overloads.
bool setDouble(const char *key, double value)
setDouble(const char* key, double value)
std::map< std::string, std::string > getAsStringMap(const char *key)
returns the user entry as a string regardless of what type it is
int64 getAsInt(const char *key)
getAsInt(const char* key)
uint16 getChainWallTime()
getChainWallTime()
bool setDoubleArray(const char *key, std::map< int64, double > &map)
setDoubleArray(const char* key, std::map<int64, double>& map) Sets the whole double array named key i...
bool setStringMap(const char *key, std::map< std::string, std::string > &map)
sets the user string entry with this key
bool isArrayContent(const char *key)
isArrayContent(const char* key)
DataMessage * getAttachedMessageCopy(const char *key)
getAttachedMessageCopy(const char* key)
uint64 getMemID()
getMemID() Get and return memory ID
bool isValid()
isValid() Checks that the message memory block exists and carries the current-format object id (DATAM...
uint64 getSerial()
getSerial()
bool setPolicy(uint8 policy)
setPolicy(uint8 policy)
uint8 getPolicy()
getPolicy()
uint64 getCreatedTime()
getCreatedTime()
bool hasMessage(const char *key)
Check if key variable exists and is a message.
char * getRawData()
getRawData() Retrieve a pointer to the raw binary block of the message (header + entries).
uint32 getTag()
getTag() Retrieve and return message tag id Tags can be used to segment data temporally,...
const char * swapMessageData(const char *data)
swapMessageData(const char* data)
std::map< int64, uint64 > getTimeArray(const char *key)
uint32 getMapSize(const char *key)
getMapSize(const char* key) Returns the number of elements in map with name '<key>'
std::map< int64, double > getDoubleArray(const char *key)
getDoubleArray(const char* key)
bool setData(const char *key, const char *value, uint32 size)
setData(const char* key, const char* value, uint32 size)
bool hasString(const char *key)
Check if key variable exists and is a string.
std::map< int64, DataMessage * > getAttachedMessageArray(const char *key)
getAttachedMessageArray(const char* key)
const char * getString(const char *key)
getString(const char* key)
char * findSpace(uint32 space)
findSpace(uint32 space)
static std::string GetCSVHeader(const char *separator=NULL, const char *preample=NULL)
toCSVHeader()
bool fillInDraftUserDataFrom(const char *data, uint32 maxDraftSize)
fillInDraftUserDataFrom(const char* data, uint32 maxDraftSize)
KeyType getKeyType(const char *key)
getKeyType(const char* key)
uint32 getContentType(const char *key)
getContentType(const char* key)
bool setSerial(uint64 serial)
setSerial(uint64 serial)
bool setCycleWallTime(uint32 t)
setCycleWallTime(uint32 t)
uint32 getChainCount()
getChainCount()
bool setStringArray(const char *key, std::map< int64, std::string > &map)
setStringArray(const char* key, std::map<int64, std::string>& map) Sets the whole string array named ...
uint64 getRecvTime()
getRecvTime()
uint16 getCycleCPUTime()
getCycleCPUTime()
uint64 getSendTime()
getSendTime()
DataMessage * copy()
copy() Creates a full deep copy of the message and returns it.
bool hasInteger(const char *key)
Check if key variable exists and is an integer.
std::map< int64, int64 > getAsIntArray(const char *key)
getAsIntArray(const char* key)
bool setAttachedMessageMap(const char *key, std::map< std::string, DataMessage * > &map)
sets the user message entry with this key to the provided message
bool setMultiple(uint32 from, uint32 to, uint32 tag, uint64 ttl, uint8 policy, uint64 sendtime)
setMultiple(uint32 from, uint32 to, uint32 tag, uint64 ttl, uint8 policy, uint64 sendtime) Set multip...
bool setContextChange(PsyContext &context)
setContextChange(PsyContext& context)
uint32 getUserSize()
getUserSize()
bool setSendTime(uint64 time)
setSendTime(uint64 time)
std::string getUserEntriesAsString()
getUserEntriesAsString() Returns the textual representation of the full message including all user en...
float64 getAsFloat(const char *key)
getAsFloat(const char* key)
std::map< std::string, float64 > getFloatMap(const char *key)
returns the user float entry with this key
bool setCycleCPUTime(uint32 t)
setCycleCPUTime(uint32 t)
std::map< std::string, float64 > getAsFloatMap(const char *key)
returns the user entry as a float map regardless of what type it is
Hierarchical execution-context identifier.
Hierarchical message type identifier — the key used for publish/subscribe matching in Psyclone.