1 // Copyright (c) 2016 The SigViewer Development Team
2 // Licensed under the GNU General Public License (GPL)
3 // https://www.gnu.org/licenses/gpl
4 
5 
6 #ifndef EVENT_MANAGER_IMPL_H
7 #define EVENT_MANAGER_IMPL_H
8 
9 #include "file_handling/event_manager.h"
10 #include "file_handling/file_signal_reader.h"
11 #include "event_table_file_reader.h"
12 
13 #include <QSharedPointer>
14 #include <QMap>
15 #include <QMutex>
16 
17 namespace sigviewer
18 {
19 
20 class EventManagerImpl : public EventManager
21 {
22 public:
23     EventManagerImpl (FileSignalReader const& reader);
24 
25     virtual ~EventManagerImpl ();
26 
27     //-------------------------------------------------------------------------
28     /// see base class
29     virtual QSharedPointer<SignalEvent const> getEvent (EventID id) const;
30 
31     //-------------------------------------------------------------------------
32     /// see base class
33     virtual QSharedPointer<SignalEvent> getAndLockEventForEditing (EventID id);
34 
35     //-------------------------------------------------------------------------
36     /// see base class
37     virtual void updateAndUnlockEvent (EventID id);
38 
39     //-------------------------------------------------------------------------
40     /// see base class
41     virtual QSharedPointer<SignalEvent const> createEvent (ChannelID channel_id,
42                                                            unsigned pos,
43                                                            unsigned length,
44                                                            EventType type,
45                                                            int stream_id,
46                                                            EventID id = UNDEFINED_EVENT_ID);
47 
48     //-------------------------------------------------------------------------
49     /// see base class
50     virtual void removeEvent (EventID id);
51 
52     //-------------------------------------------------------------------------
53     /// see base class
54     virtual std::set<EventID> getEventsAt (unsigned pos, ChannelID channel_id) const;
55 
56     //-------------------------------------------------------------------------
57     /// see base class
58     virtual double getSampleRate () const;
59 
60     //-------------------------------------------------------------------------
61     virtual unsigned getMaxEventPosition () const;
62 
63     //-------------------------------------------------------------------------
64     /// see base class
65     virtual QString getNameOfEventType (EventType type) const;
66 
67     //-------------------------------------------------------------------------
68     /// see base class
69     virtual QString getNameOfEvent (EventID event) const;
70 
71     //-------------------------------------------------------------------------
72     /// see base class
73     virtual QList<EventID> getAllEvents () const;
74 
75     //-------------------------------------------------------------------------
76     /// see base class
77     virtual unsigned getNumberOfEvents () const;
78 
79     //-------------------------------------------------------------------------
80     /// see base class
81     virtual std::set<EventType> getEventTypes (QString group_id = "") const;
82 
83     //-------------------------------------------------------------------------
84     virtual std::set<QString> getEventTypeGroupIDs () const;
85 
86     //-------------------------------------------------------------------------
87     /// see base class
88     virtual QList<EventID> getEvents (EventType type) const;
89 
90     //-------------------------------------------------------------------------
91     virtual EventID getNextEventOfSameType (EventID id) const;
92 
93     //-------------------------------------------------------------------------
94     virtual EventID getPreviousEventOfSameType (EventID id) const;
95 
96     //-------------------------------------------------------------------------
97     virtual QString getFileType () const;
98 
99     //-------------------------------------------------------------------------
100     virtual void setEventName (EventType event_type_id, QString const& name);
101 
102 
103 private:
104     EventTableFileReader event_table_reader_;
105 
106     unsigned const max_event_position_;
107     double sample_rate_;
108     QMutex* caller_mutex_;
109 
110     typedef QMap<EventID, QSharedPointer<SignalEvent> > EventMap;
111     typedef QMap<EventID, QSharedPointer<QMutex> > MutexMap;
112     typedef QMultiMap<uint32, EventID> PositionMap;
113 
114     EventMap event_map_;
115     MutexMap mutex_map_;
116     EventID next_free_id_;
117     PositionMap position_event_map_;
118     QMap<EventID, uint32> temp_event_position_map_;
119     QString file_type_;
120 };
121 
122 }
123 
124 #endif
125