CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
MessageIndex.h
Go to the documentation of this file.
1
12
13#if !defined(_MESSAGEINDEX_H_)
14#define _MESSAGEINDEX_H_
15
16#include "DataMessage.h"
17#include "PsyTime.h"
18#include "Subscriptions.h"
19
20namespace cmlabs {
21
22
34public:
36 static bool UnitTest();
37
42
46 bool setDefaultTTL(uint64 defaultTTL);
47
54 bool addIndexKey(const char* key, uint8 type);
60 bool removeIndexKey(const char* key, uint8 type);
61
67 bool setFileStorage(const char* dir, uint32 buffertime, const char* indexfilename = "index.db");
68
73 bool addMessage(DataMessage* msg);
74
82 char* queryMessages(RetrieveSpec* spec, uint32 &size, uint32 &count);
83
85 uint32 getCount();
86
90 bool doMaintenance();
91
92private:
93
94 bool addMessageToTime(DataMessage* msg);
95 bool addMessageToString(DataMessage* msg);
96 bool addMessageToInteger(DataMessage* msg);
97 bool addMessageToFloat(DataMessage* msg);
98
99 template <typename T>
100 bool deleteIndexKey(const char* key, std::map<std::string, std::multimap<T, DataMessage*> > &maps);
101
102 template <typename T>
103 bool removeMessage(DataMessage* msg, std::multimap<T, DataMessage*> &map, T &val);
104
105 template <typename T>
106 char* queryMessages(uint32 from, uint32 to, PsyType &type, uint32 maxcount, uint64 maxage, uint32 &size, uint32 &count, std::multimap<T, DataMessage*> &map);
107 template <typename T>
108 char* queryMessages(T start, uint32 from, uint32 to, PsyType &type, uint32 maxcount, uint64 maxage, uint32 &size, uint32 &count, std::multimap<T, DataMessage*> &map);
109 template <typename T>
110 char* queryMessages(T start, T end, uint32 from, uint32 to, PsyType &type, uint32 maxcount, uint64 maxage, uint32 &size, uint32 &count, std::multimap<T, DataMessage*> &map);
111
112 typedef std::pair <uint64, DataMessage*> Time_Pair;
113 typedef std::pair <std::string, DataMessage*> String_Pair;
114 typedef std::pair <int64, DataMessage*> Int_Pair;
115 typedef std::pair <float64, DataMessage*> Float_Pair;
116 typedef std::pair <PsyType, DataMessage*> Type_Pair;
117
118 std::map<std::string, std::multimap<uint64, DataMessage*> > timeMaps;
119 std::map<std::string, std::multimap<std::string, DataMessage*> > stringMaps;
120 std::map<std::string, std::multimap<int64, DataMessage*> > integerMaps;
121 std::map<std::string, std::multimap<float64, DataMessage*> > floatMaps;
122
123 std::multimap<PsyType, DataMessage*>* typeMap;
124 std::multimap<uint64, DataMessage*>* timeMap;
125 std::multimap<uint64, DataMessage*> eolMap;
126 uint64 lastMaintenance;
127
128 std::string dir;
129 std::string indexfilename;
130 int32 buffertime;
131 int32 maintenanceInterval;
132
133 uint64 defaultTTL;
134};
135
136
137} // namespace cmlabs
138
139#endif // _MESSAGEINDEX_H_
The binary DataMessage container — the central data-exchange object of Psyclone/CMSDK.
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
Subscription, trigger, retrieval, query, post and signal specifications — the declarative wiring of a...
The central Psyclone data container: a self-contained binary message with typed, named user entries.
bool setFileStorage(const char *dir, uint32 buffertime, const char *indexfilename="index.db")
Enable file-backed storage of indexed messages.
char * queryMessages(RetrieveSpec *spec, uint32 &size, uint32 &count)
Execute a retrieval query and return matching messages as one flat buffer.
static bool UnitTest()
Run the built-in self test.
bool addIndexKey(const char *key, uint8 type)
Start indexing messages by the value of a named user entry.
~MessageIndex()
Destroys the index and deletes all messages it still holds.
bool addMessage(DataMessage *msg)
Add a message to the index; the index TAKES OWNERSHIP of msg and will delete it on expiry.
bool doMaintenance()
Perform periodic housekeeping: evict expired messages (per TTL/EOL) and flush file storage buffers.
bool removeIndexKey(const char *key, uint8 type)
Remove a previously added index key (the index over that entry is dropped; the messages themselves re...
MessageIndex()
Create an empty index with no extra index keys and no file storage.
bool setDefaultTTL(uint64 defaultTTL)
Set the TTL applied to messages that carry none of their own.
Hierarchical message type identifier — the key used for publish/subscribe matching in Psyclone.
Definition Types.h:123
Specification of a whiteboard retrieval attached to a TriggerSpec.