v2.0.0
Loading...
Searching...
No Matches
eventsharedmemmanager.h
Go to the documentation of this file.
1//=============================================================================================================
35
36#ifndef EVENTSHAREDMEMMANAGER_EVENTS_H
37#define EVENTSHAREDMEMMANAGER_EVENTS_H
38
39//=============================================================================================================
40// STD INCLUDES
41//=============================================================================================================
42
43#include <string>
44#include <memory>
45#include <chrono>
46#include <thread>
47#include <mutex>
48#include <atomic>
49
50//=============================================================================================================
51// Qt INCLUDES
52//=============================================================================================================
53
54#include <QSharedMemory>
55
56//=============================================================================================================
57// MNECPP INCLUDES
58//=============================================================================================================
59
60#include "event.h"
61#include "eventgroup.h"
62
63namespace EVENTSLIB {
64
65//=============================================================================================================
66// EVENTSLIB FORWARD DECLARATIONS
67//=============================================================================================================
68
70class EventManager;
71
72namespace EVENTSINTERNAL {
73
74//=========================================================================================================
79
80//=========================================================================================================
84const std::string EventUpdateTypeString[3] = {"Null Event", "New Event", "Delete Event"};
85
93{
94public:
95 //=========================================================================================================
100
101 //=========================================================================================================
108 EventUpdate(int sample, int creator, enum EventUpdateType t);
109
110 //=========================================================================================================
115 long long getCreationTime() const;
116
117 //=========================================================================================================
122 int getSample() const;
123
124 //=========================================================================================================
129 int getCreatorId() const;
130
131 //=========================================================================================================
136 enum EventUpdateType getType() const;
137
138 //=========================================================================================================
143 void setType(enum EventUpdateType t);
144
145 //=========================================================================================================
150 std::string eventTypeToText();
151
152protected:
155 long long m_CreationTime;
157};
158
165{
166public:
167 //=========================================================================================================
172 explicit EventSharedMemManager(EVENTSLIB::EventManager* parent = nullptr);
173
174 //=========================================================================================================
179
180 //=========================================================================================================
186
187 //=========================================================================================================
192 bool isInit() const;
193
194 //=========================================================================================================
198 void stop();
199
200 //=========================================================================================================
205 void addEvent(int sample);
206
207 //=========================================================================================================
212 void deleteEvent(int sample);
213
214 //=========================================================================================================
219 static long long getTimeNow();
220
221 //=========================================================================================================
226 void processEvent(const EventUpdate& ne);
227
228private:
229 //=========================================================================================================
234 void attachToSharedSegment(QSharedMemory::AccessMode mode);
235
236 //=========================================================================================================
243 bool createSharedSegment(int bufferSize, QSharedMemory::AccessMode mode);
244
245 //=========================================================================================================
249 void launchSharedMemoryWatcherThread();
250
251 //=========================================================================================================
256 void attachToOrCreateSharedSegment(QSharedMemory::AccessMode mode);
257
258 //=========================================================================================================
262 void stopSharedMemoryWatcherThread();
263
264 //=========================================================================================================
268 void detachFromSharedMemory();
269
270 //=========================================================================================================
275 inline static int generateId();
276
277 //=========================================================================================================
282 void processNewEvent(const EventUpdate& n);
283
284 //=========================================================================================================
289 void processDeleteEvent(const EventUpdate& n);
290
291 //=========================================================================================================
295 void printLocalBuffer();
296
297 //=========================================================================================================
302 void copyNewUpdateToSharedMemory(EventUpdate& newUpdate);
303
304 //=========================================================================================================
308 void initializeSharedMemory();
309
310 //=========================================================================================================
314 void copySharedMemoryToLocalBuffer();
315
316 //=========================================================================================================
320 void processLocalBuffer();
321
322 //=========================================================================================================
326 void bufferWatcher();
327
328 //=========================================================================================================
332 void createGroupIfNeeded();
333
334 static int m_iLastUpdateIndex;
335 EVENTSLIB::EventManager* m_pEventManager;
336 QSharedMemory m_SharedMemory;
337 std::atomic_bool m_IsInit;
338 std::string m_sGroupName;
339 bool m_bGroupCreated;
340 idNum m_GroupId;
341 int m_SharedMemorySize;
342 int m_fTimerCheckBuffer;
343 std::thread m_BufferWatcherThread;
344 std::atomic_bool m_BufferWatcherThreadRunning;
345 std::atomic_bool m_WritingToSharedMemory;
346 long long m_lastCheckTime;
347 EventUpdate* m_LocalBuffer;
348 EventUpdate* m_SharedBuffer;
349 int m_Id;
350 enum EVENTSLIB::SharedMemoryMode m_Mode;
351};
352
353//=========================================================================================================
358inline int EventSharedMemManager::generateId()
359{
360 auto t = static_cast<int>(EventSharedMemManager::getTimeNow());
361 return abs(t);
362}
363
364} //namespace EVENTSINTERNAL
365}//namespace EVENTSLIB
366#endif // EVENTSHAREDMEMMANAGER_EVENTS_H
367
EventGroup declaration.
unsigned int idNum
Definition eventgroup.h:51
Event declaration.
Event annotation management (creation, grouping, shared-memory transport).
Definition event.h:56
const std::string EventUpdateTypeString[3]
Central registry that creates, stores, queries, and groups Event objects across one or more data file...
Serializable delta record describing a single event creation, deletion, or modification for shared-me...
EventSharedMemManager(EVENTSLIB::EventManager *parent=nullptr)