CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
MessagePlayer.h
Go to the documentation of this file.
1
12
13#if !defined(_MESSAGEPLAYER_H_)
14#define _MESSAGEPLAYER_H_
15
16#include "DataMessage.h"
17
18namespace cmlabs {
19
31 uint32 cid;
32 uint64 serial;
33 uint64 msgTime;
34 uint32 size;
35 char msgTriggerName[128];
37#if defined ARCH_32
38 DataMessage* dummy;
39#endif
41 bool reset() {
42 memset(this, 0, sizeof(ReplayIndexEntry));
44 return true;
45 }
46
47 bool isValid() {
48 return (cid == DATAMESSAGEINFOID);
49 }
50};
51
52
66public:
71
77 bool initRead(const char* root, uint32 interval, bool rotate = false);
82 bool initRead(const char* root, bool rotate = false);
88 bool initWrite(const char* root, uint32 maxCount, uint64 maxSize);
89
91 bool setSubTypeList(std::map<uint16, std::string>& subtypes);
93 bool setSubContextList(std::map<uint16, std::string>& subcontexts);
95 bool setComponentNameList(std::map<uint32, std::string>& names);
97 bool writeMetadata();
99 bool readMetadata();
101 bool setSystemIDs(DataMessage* msg);
103 bool knowsTypeOf(DataMessage* msg);
104
109 bool exportToCSVFile(const char* filename, const char* separator = NULL);
113 std::string exportToCSV(const char* separator = NULL);
114
120 bool addMessage(const char* name, DataMessage* msg);
126 DataMessage* waitForNextMessage(uint32 ms, const char* &triggerName);
131 DataMessage* waitForNextMessage(uint32 ms, uint32 &msToNext);
137 DataMessage* waitForNextMessage(uint32 ms, const char* &triggerName, uint32 &msToNext);
143 std::string getCurrentTriggerName();
144
146 bool flushToDisk();
150 std::string printAllString(const char* format = NULL);
151
152private:
153 bool writeBuffer();
154 bool readBuffer();
155
156 uint32 interval;
157 uint32 maxCount;
158 uint64 maxSize;
159 uint32 indexSize;
160 bool rotate;
161 std::string root;
162 char* indexData;
163 char currentTriggerName[MAXKEYNAMELEN + 1];
164 std::string indexFile;
165 uint32 indexFileSize;
166
167 std::string metadataFile;
168 std::string metadataTextFile;
169 std::string csvFile;
170
171 std::map<uint16, std::string> subtypeList;
172 std::map<uint16, std::string> subcontextList;
173 std::map<uint32, std::string> componentNameList;
174
175 uint32 curStart;
176 uint32 curWrite;
177 uint32 curIndex;
178 uint32 curCount;
179 uint64 curSize;
180 uint64 lastWriteTime;
181 uint64 lastReceiveTime;
182 uint64 lastReadTime;
183 uint64 serial;
184 uint64 nextMsgTime;
185};
186
187} // namespace cmlabs
188
189#endif //_MESSAGEPLAYER_H_
190
The binary DataMessage container — the central data-exchange object of Psyclone/CMSDK.
#define DATAMESSAGEINFOID
Definition ObjectIDs.h:69
#define MAXKEYNAMELEN
Definition Utils.h:85
The central Psyclone data container: a self-contained binary message with typed, named user entries.
std::string printAllString(const char *format=NULL)
Render a human-readable dump of all recorded messages.
bool addMessage(const char *name, DataMessage *msg)
Append a message to the recording (write mode).
std::string exportToCSV(const char *separator=NULL)
Export the whole recording as a CSV string.
bool readMetadata()
Load the metadata files of an opened recording.
DataMessage * waitForNextMessage(uint32 ms, const char *&triggerName)
Wait for and return the next message in the recording (read mode), honouring the replay timing.
bool flushToDisk()
Force buffered messages and the index out to disk (write mode).
bool setComponentNameList(std::map< uint32, std::string > &names)
Provide readable names for component ids, used in metadata/CSV export.
bool setSubTypeList(std::map< uint16, std::string > &subtypes)
Provide readable names for type level ids, used in metadata/CSV export.
bool writeMetadata()
Write the metadata (name lists etc.) files alongside the recording.
bool setSystemIDs(DataMessage *msg)
Stamp system-identifying header fields onto msg for recording.
~MessagePlayer()
Destructor; releases buffers (does not delete messages already handed out).
bool knowsTypeOf(DataMessage *msg)
true when every level of the message's type has a name in the current id list (a recorder refreshes t...
bool initRead(const char *root, uint32 interval, bool rotate=false)
Open a recording for replay with a fixed playback interval.
MessagePlayer()
Create an uninitialised player; call initRead() or initWrite() before use.
bool initWrite(const char *root, uint32 maxCount, uint64 maxSize)
Open a recording for writing.
std::string getCurrentTriggerName()
bool exportToCSVFile(const char *filename, const char *separator=NULL)
Export the whole recording to a CSV file.
bool setSubContextList(std::map< uint16, std::string > &subcontexts)
Provide readable names for context level ids, used in metadata/CSV export.
Fixed-size on-disk index record describing one recorded message.
char msgTriggerName[128]
Name of the trigger that produced the message.
bool reset()
Zero the entry and stamp it with DATAMESSAGEINFOID.
DataMessage * msg
In-memory pointer to the loaded message; not valid on disk.
bool isValid()
uint64 serial
Sequence number of the message within the recording.
uint64 msgTime
Original message time in microseconds (drives replay timing).
uint32 size
Binary size of the recorded message block in bytes.
uint32 cid
Object id, DATAMESSAGEINFOID when valid.