CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
MemoryMaps.h
Go to the documentation of this file.
1
12
13#if !defined(_MEMORYMAPS_H_)
14#define _MEMORYMAPS_H_
15
16#include "MemoryManager.h"
17
18namespace cmlabs {
19
24#define ID_SYSPAGE 0
25#define ID_PAGEPOOL 1
26#define ID_EOLPAGE 2
27#define ID_QUEUEPAGE 3
28#define ID_COMPMAPPAGE 4
29#define ID_TYPEMAPPAGE 5
30#define ID_TOPICMAPPAGE 6
31//#define ID_NODEMAPPAGE 7
32#define ID_QUEUEMAPPAGE 7
33#define ID_PROCESSMAPPAGE 8
34#define ID_REQUESTMAPPAGE 9
35#define ID_CRANKMAPPAGE 10
36#define ID_CONTEXTMAPPAGE 11
37#define RESERVEDPAGECOUNT 12
39
42#define SIGNALQ_ID 0
43#define MSGQ_ID 1
44#define REQQ_ID 2
45#define CMDQ_ID 3
47
50 uint32 size; // total size of map structure in bytes
51 uint32 count; // number of entries
52 uint32 bitFieldSize; // number of bytes in the bitfield
53 // Bitfield
54 // Entries
55};
56
58struct TypeMapEntry {
59 uint16 id; // id, corresponds to the index in map
60 uint64 time; // timestamp when entered
61 char name[MAXKEYNAMELEN+1]; // name in text
62 uint32 key;
63};
64
67 uint32 size; // total size of map structure in bytes
68 uint32 count; // number of entries
69 uint32 bitFieldSize; // number of bytes in the bitfield
70 // Bitfield
71 // Entries
72};
73
75struct ContextMapEntry {
76 uint16 id; // id, corresponds to the index in map
77 uint64 time; // timestamp when entered
78 char name[MAXKEYNAMELEN+1]; // name in text
79 uint32 key;
80};
81
84 uint32 size; // total size of map structure in bytes
85 uint32 count; // number of entries
86 uint32 bitFieldSize; // number of bytes in the bitfield
87 // Bitfield
88 // Entries
89};
90
93 uint32 id; // id, corresponds to the index in map
94 uint64 time; // timestamp when entered
95 char name[MAXKEYNAMELEN+1]; // name in text
96 uint32 key;
97};
98
99//struct NodeMapHeader {
100// uint32 size; // total size of map structure in bytes
101// uint32 count; // number of entries
102// uint32 bitFieldSize; // number of bytes in the bitfield
103// // Bitfield
104// // Entries
105//};
106//
107//struct NodeMapEntry {
108// uint16 id; // id, corresponds to the index in map
109// uint64 time; // timestamp when entered
110// char name[MAXKEYNAMELEN+1]; // name in text
111// uint64 key; // 32bit IP4, 16bit port, 16bit unused
112//};
113
116 uint32 size; // total size of map structure in bytes
117 uint32 count; // number of entries
118 uint32 bitFieldSize; // number of bytes in the bitfield
119 // Bitfield
120 // Entries
121};
122
124struct CrankMapEntry {
125 uint16 id; // id, corresponds to the index in map
126 uint64 time; // timestamp when entered
127 char name[MAXKEYNAMELEN+1]; // name in text
128 char function[MAXKEYNAMELEN+1]; // name in text
129 char libraryFilename[MAXKEYNAMELEN+1]; // name in text
130 char script[MAXSCRIPTLEN+1]; // script in text
131 uint64 key; // 32bit IP4, 16bit port, 16bit unused
132};
133
136 uint32 size; // total size of map structure in bytes
137 uint32 count; // number of entries
138 uint32 bitFieldSize; // number of bytes in the bitfield
139 // Bitfield
140 // Entries
141};
142
145 uint16 id; // id, corresponds to the index in map
146 uint64 time; // timestamp when entered
147 char name[MAXKEYNAMELEN+1]; // name in text
148 uint32 key; // 32bit IP4, 16bit port, 16bit unused
149};
150
153#define PROC_ERROR 0
154#define PROC_INIT 1
155#define PROC_IDLE 2
156#define PROC_READY 3
157#define PROC_ACTIVE 4
159
162 uint32 size; // total size of map structure in bytes
163 uint32 count; // number of entries
164 uint32 bitFieldSize; // number of bytes in the bitfield
165 // Bitfield
166 // Entries
167};
168
171 uint32 id; // id, corresponds to the index in map
172 uint64 time; // timestamp when entered
173 uint64 lastseen; // timestamp when entered
174 uint8 status; // status of the process
175 char name[MAXKEYNAMELEN+1]; // name in text
176 uint32 key;
177 char commandline[MAXCOMMANDLINELEN+1]; // commandline in text
178 uint32 signalQID; // id of Signal queue
179 uint32 messageQID; // id of Message queue
180 uint32 timeQID; // id of Time queue
181 uint32 requestQID; // id of Request queue
182 uint32 commandQID; // id of Command queue
183};
184
187 uint32 size; // total size of map structure in bytes
188 uint32 count; // number of entries
189 uint32 bitFieldSize; // number of bytes in the bitfield
190 // Bitfield
191 // Entries
192};
193
195struct RequestMapEntry {
196 uint32 id; // id, corresponds to the index in map
197 uint64 time; // timestamp when entered
198 char name[MAXKEYNAMELEN+1]; // name in text
199 uint32 key;
200 uint8 status; // status of the process
201 uint32 from; // id of component making the request
202 uint32 to; // id of component processing the request
203 uint64 dataMessageID; // id of Data Message
204 uint64 dataMessageEOL; // eol of Data Message
205};
206
208struct GenericMapHeader {
209 uint32 size; // total size of map structure in bytes
210 uint32 count; // number of entries
211 uint32 bitFieldSize; // number of bytes in the bitfield
212 // Bitfield
213 // Entries
214};
215
216
220inline uint16 TypePageID(TypeMapEntry* e) {return ID_TYPEMAPPAGE;}
221inline uint16 TypePageID(TopicMapEntry* e) {return ID_TOPICMAPPAGE;}
222//inline uint16 TypePageID(NodeMapEntry* e) {return ID_NODEMAPPAGE;}
223inline uint16 TypePageID(QueueMapEntry* e) {return ID_QUEUEMAPPAGE;}
226inline uint16 TypePageID(CrankMapEntry* e) {return ID_CRANKMAPPAGE;}
229
233#define REQ_CREATED 1
234#define REQ_RECEIVED_LOCAL 2
235#define REQ_RECEIVED_REMOTE 3
236#define REQ_PROCESSING_LOCAL 4
237#define REQ_PROCESSING_REMOTE 5
238#define REQ_REPLY_READY 6
239#define REQ_FAILED 7
240#define REQ_FAILED_DATA 8
241#define REQ_FAILED_NODATA 9
242#define REQ_FAILED_DATA_EOL 10
243#define REQ_SUCCESS 11
244#define REQ_SUCCESS_DATA 12
245#define REQ_SUCCESS_NODATA 13
246#define REQ_SUCCESS_DATA_EOL 14
248
249
250
257public:
258 // TypeLevelMap
259 static bool CreateNewTypeLevel(uint16 id, const char* name, uint64 time = 0);
260 static bool GetTypeLevelName(uint16 id, char* name, uint32 maxSize);
261 static bool GetTypeLevelID(const char* name, uint16 &id);
262 static bool DeleteTypeLevel(const char* name);
263 static bool DeleteTypeLevel(uint16 id);
264 static uint64 GetTypeLevelCreateTime(uint16 id);
265
266 // ContextLevelMap
267 static bool CreateNewContextLevel(uint16 id, const char* name, uint64 time = 0);
268 static bool GetContextLevelName(uint16 id, char* name, uint32 maxSize);
269 static bool GetContextLevelID(const char* name, uint16 &id);
270 static bool DeleteContextLevel(const char* name);
271 static bool DeleteContextLevel(uint16 id);
272 static uint64 GetContextLevelCreateTime(uint16 id);
273
274 // TopicMap
275 static bool CreateNewTopic(uint8 id, const char* name);
276 static bool GetTopicName(uint32 id, char* name, uint32 maxSize);
277 static bool GetTopicID(const char* name, uint32 &id);
278 static bool DeleteTopic(const char* name);
279 static bool DeleteTopic(uint32 id);
280 static uint64 GetTopicCreateTime(uint32 id);
281
282 // NodeMap
283 //static bool CreateNewNode(uint8 id, const char* name, uint64 address);
284 //static uint64 GetNodeAddress(uint16 id);
285 //static bool GetNodeID(uint64 address, uint16 &id);
286 //static bool GetNodeName(uint16 id, char* name, uint32 maxSize);
287 //static bool GetNodeID(const char* name, uint16 &id);
288 //static bool DeleteNode(uint64 address);
289 //static bool DeleteNode(uint16 id);
290 //static bool DeleteNode(const char* name);
291 //static uint64 GetNodeCreateTime(uint16 id);
292
293 // CrankMap
294 static bool CreateNewCrank(uint16 id, const char* name, const char* function, const char* libraryFilename, uint64 time = 0);
295 static bool GetCrankName(uint16 id, char* name, uint32 maxSize);
296 static bool GetCrankFunction(uint16 id, char* function, uint32 maxSize);
297 static bool GetCrankLibraryFilename(uint16 id, char* libraryFilename, uint32 maxSize);
298 static bool GetCrankID(const char* name, uint16 &id);
299 static bool GetCrankScript(uint16 id, char* script, uint32 maxSize);
300 static bool SetCrankScript(uint16 id, const char* script);
301 static bool DeleteCrank(uint16 id);
302 static bool DeleteCrank(const char* name);
303 static uint64 GetCrankCreateTime(uint16 id);
304
306 //static bool CreateNewQueue(uint32 pageID, const char* name, uint32 &id);
307 //static bool GetQueueName(uint32 id, char* name, uint32 maxSize);
308 //static uint32 GetQueuePageID(uint32 id);
309 //static bool GetQueueID(const char* name, uint32 &id);
310 //static bool GetQueueID(uint32 pageID, uint32 &id);
311 //static bool DeleteQueue(uint32 id);
312 //static bool DeleteQueue(const char* name);
313 //static uint64 GetQueueCreateTime(uint32 id);
314
316 //static bool CreateNewProcess(const char* name, uint16 &id);
317 //static bool GetProcessName(uint16 id, char* name, uint32 maxSize);
318 //static bool GetProcessID(const char* name, uint16 &id);
319 //static bool GetProcessQueueID(uint16 id, uint8 queueType, uint32& qid);
320 //static uint8 GetProcessStatus(uint16 id, uint64& lastseen);
321 //static bool GetProcessCommandLine(uint16 id, char* cmdline, uint32 maxSize);
322 //static bool SetProcessQueueID(uint16 id, uint8 queueType, uint32 qid);
323 //static bool SetProcessStatus(uint16 id, uint8 status);
324 //static bool SetProcessCommandLine(uint16 id, const char* cmdline);
325 //static uint16 GetProcessIDFromOSID(uint32 osid);
326 //static uint32 GetProcessOSID(uint16 id);
327 //static bool SetProcessOSID(uint16 id, uint32 osid);
328 //static bool DeleteProcess(const char* name);
329 //static bool DeleteProcess(uint16 id);
330 //static uint64 GetProcessCreateTime(uint16 id);
331
333 //static RequestMapEntry* CreateAndLockNewRequest(uint32 from, uint32 to, uint32 &id);
334 //static RequestMapEntry* GetAndLockRequestEntry(uint32 id);
335 //static bool UnlockRequestMap();
336 //static bool DeleteRequest(uint32 id);
337 //static bool GetRequestCount(uint32& count);
338
339protected:
340// static ProcessMapEntry* GetAndLockProcessEntry(uint16 id);
341// static bool UnlockProcessMap();
342};
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
367template <typename T, typename ID, typename KEY>
368class GenericMemoryMap {
369public:
370 // Generic MemoryMap
371 static uint32 GetCount(char* data);
372 static T* CreateEntry(char* data, ID id, const char* name);
373 static T* GetEntry(char* data, ID id);
374 static bool DeleteEntry(char* data, ID id);
375 static uint64 GetEntryTime(char* data, ID id);
376 static const char* GetEntryName(char* data, ID id, uint32& size);
377 static ID GetEntryID(char* data, const char* name);
378};
379
380
381
382} // namespace cmlabs
383
384#include "PsyTime.h"
385#include "MemoryMaps.tpl.h"
386
387#endif // _MEMORYMAPS_H_
388
389
Central shared-memory manager for a Psyclone node: master segment, per-subsystem shared maps and the ...
#define ID_TYPEMAPPAGE
Type map.
Definition MemoryMaps.h:29
#define ID_CONTEXTMAPPAGE
Context map.
Definition MemoryMaps.h:36
#define ID_PROCESSMAPPAGE
Process map.
Definition MemoryMaps.h:33
#define ID_TOPICMAPPAGE
Topic map.
Definition MemoryMaps.h:30
#define ID_QUEUEMAPPAGE
Queue map.
Definition MemoryMaps.h:32
#define ID_REQUESTMAPPAGE
Request map.
Definition MemoryMaps.h:34
#define ID_CRANKMAPPAGE
Crank map.
Definition MemoryMaps.h:35
Template implementations of the GenericMemoryMap shared-map algorithms.
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
#define MAXKEYNAMELEN
Definition Utils.h:85
#define MAXCOMMANDLINELEN
Definition Utils.h:88
#define MAXSCRIPTLEN
Definition Utils.h:91
Static algorithms shared by all bitfield-indexed maps in the data-maps segment.
static uint32 GetCount(char *data)
static T * GetEntry(char *data, ID id)
static const char * GetEntryName(char *data, ID id, uint32 &size)
static T * CreateEntry(char *data, ID id, const char *name)
Reserve entry id.
static ID GetEntryID(char *data, const char *name)
static bool DeleteEntry(char *data, ID id)
Free the entry.
static uint64 GetEntryTime(char *data, ID id)
Legacy static facade over the page-based shared maps (types, contexts, topics, cranks).
Definition MemoryMaps.h:256
static bool GetCrankID(const char *name, uint16 &id)
static bool CreateNewTypeLevel(uint16 id, const char *name, uint64 time=0)
static bool GetCrankScript(uint16 id, char *script, uint32 maxSize)
static uint64 GetCrankCreateTime(uint16 id)
static bool CreateNewTopic(uint8 id, const char *name)
static bool DeleteTopic(const char *name)
static uint64 GetTypeLevelCreateTime(uint16 id)
static bool GetTypeLevelID(const char *name, uint16 &id)
static bool GetTopicName(uint32 id, char *name, uint32 maxSize)
static bool CreateNewContextLevel(uint16 id, const char *name, uint64 time=0)
static bool GetCrankFunction(uint16 id, char *function, uint32 maxSize)
static bool DeleteTypeLevel(const char *name)
static bool GetContextLevelID(const char *name, uint16 &id)
static bool GetContextLevelName(uint16 id, char *name, uint32 maxSize)
static bool DeleteCrank(uint16 id)
static bool GetTopicID(const char *name, uint32 &id)
static bool GetCrankLibraryFilename(uint16 id, char *libraryFilename, uint32 maxSize)
static uint64 GetContextLevelCreateTime(uint16 id)
static bool SetCrankScript(uint16 id, const char *script)
static bool DeleteContextLevel(const char *name)
static bool GetTypeLevelName(uint16 id, char *name, uint32 maxSize)
static uint64 GetTopicCreateTime(uint32 id)
static bool GetCrankName(uint16 id, char *name, uint32 maxSize)
static bool CreateNewCrank(uint16 id, const char *name, const char *function, const char *libraryFilename, uint64 time=0)
uint16 TypePageID(TypeMapEntry *e)
Definition MemoryMaps.h:220
Context-map entry: one registered psychological/system context name/id.
char name[MAXKEYNAMELEN+1]
uint64 time
uint32 key
Definition MemoryMaps.h:79
uint16 id
Legacy context-map header.
Definition MemoryMaps.h:66
Crank-map entry: one registered crank (user callback/script) with its function, library and inline sc...
char name[MAXKEYNAMELEN+1]
char function[MAXKEYNAMELEN+1]
uint64 time
uint64 key
Definition MemoryMaps.h:131
char script[MAXSCRIPTLEN+1]
uint16 id
char libraryFilename[MAXKEYNAMELEN+1]
Legacy crank-map header.
Definition MemoryMaps.h:115
Common header of every map inside the data-maps segment.
Legacy process-map entry with the ids of the process's five queues.
Definition MemoryMaps.h:170
uint64 time
Definition MemoryMaps.h:172
uint32 commandQID
Definition MemoryMaps.h:182
uint32 requestQID
Definition MemoryMaps.h:181
uint64 lastseen
Definition MemoryMaps.h:173
uint32 messageQID
Definition MemoryMaps.h:179
uint32 timeQID
Definition MemoryMaps.h:180
uint32 signalQID
Definition MemoryMaps.h:178
uint32 id
Definition MemoryMaps.h:171
uint32 key
Definition MemoryMaps.h:176
uint8 status
Definition MemoryMaps.h:174
char commandline[MAXCOMMANDLINELEN+1]
Definition MemoryMaps.h:177
char name[MAXKEYNAMELEN+1]
Definition MemoryMaps.h:175
Legacy process-map header.
Definition MemoryMaps.h:161
Legacy queue-map entry.
Definition MemoryMaps.h:144
uint32 key
Definition MemoryMaps.h:148
uint64 time
Definition MemoryMaps.h:146
uint16 id
Definition MemoryMaps.h:145
char name[MAXKEYNAMELEN+1]
Definition MemoryMaps.h:147
Legacy queue-map header.
Definition MemoryMaps.h:135
Request-map entry tracking one cross-component request/reply transaction.
uint8 status
REQ_* lifecycle status.
uint32 key
Definition MemoryMaps.h:199
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.
uint32 from
Id of the component making the request.
Legacy request-map header.
Definition MemoryMaps.h:186
Legacy topic-map entry.
Definition MemoryMaps.h:92
uint32 id
Definition MemoryMaps.h:93
uint32 key
Definition MemoryMaps.h:96
char name[MAXKEYNAMELEN+1]
Definition MemoryMaps.h:95
uint64 time
Definition MemoryMaps.h:94
Legacy topic-map header.
Definition MemoryMaps.h:83
Type-map entry: one registered message type name/id.
uint32 key
Definition MemoryMaps.h:62
uint64 time
uint16 id
char name[MAXKEYNAMELEN+1]
Legacy type-map header (bitfield + TypeMapEntry array).
Definition MemoryMaps.h:49