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);
102
107 bool exportToCSVFile(const char* filename, const char* separator = NULL);
111 std::string exportToCSV(const char* separator = NULL);
112
118 bool addMessage(const char* name, DataMessage* msg);
124 DataMessage* waitForNextMessage(uint32 ms, const char* &triggerName);
129 DataMessage* waitForNextMessage(uint32 ms, uint32 &msToNext);
135 DataMessage* waitForNextMessage(uint32 ms, const char* &triggerName, uint32 &msToNext);
141 std::string getCurrentTriggerName();
142
144 bool flushToDisk();
148 std::string printAllString(const char* format = NULL);
149
150private:
151 bool writeBuffer();
152 bool readBuffer();
153
154 uint32 interval;
155 uint32 maxCount;
156 uint64 maxSize;
157 uint32 indexSize;
158 bool rotate;
159 std::string root;
160 char* indexData;
161 char currentTriggerName[MAXKEYNAMELEN + 1];
162 std::string indexFile;
163 uint32 indexFileSize;
164
165 std::string metadataFile;
166 std::string metadataTextFile;
167 std::string csvFile;
168
169 std::map<uint16, std::string> subtypeList;
170 std::map<uint16, std::string> subcontextList;
171 std::map<uint32, std::string> componentNameList;
172
173 uint32 curStart;
174 uint32 curWrite;
175 uint32 curIndex;
176 uint32 curCount;
177 uint64 curSize;
178 uint64 lastWriteTime;
179 uint64 lastReceiveTime;
180 uint64 lastReadTime;
181 uint64 serial;
182 uint64 nextMsgTime;
183};
184
185} // namespace cmlabs
186
187#endif //_MESSAGEPLAYER_H_
188
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 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.