]> vaikene.ee Git - evaf/blob - src/libs/Common/eventqueue.h
a4b834be5efef4ee253f50244cb1c983e0d428b4
[evaf] / src / libs / Common / eventqueue.h
1 /**
2 * @file Common/eventqueue.h
3 * @brief Event queue interface implementation
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #ifndef __COMMON_EVENTQUEUE_H
21 #define __COMMON_EVENTQUEUE_H
22
23 #include "ieventqueue.h"
24
25 #include <QObject>
26 #include <QString>
27 #include <QHash>
28 #include <QVector>
29
30
31 namespace eVaf {
32 namespace Common {
33 namespace Internal {
34
35 /**
36 * iEventQueue interface implementation
37 */
38 class EventQueue : public iEventQueue
39 {
40 Q_OBJECT
41
42 public:
43
44 EventQueue();
45
46 virtual ~EventQueue();
47
48 /// Qt event handler
49 virtual bool event(QEvent * e);
50
51 /*
52 iEventQueue interface
53 */
54
55 virtual uint registerEvent(QString const & name);
56
57 virtual uint queryEvent(QString const & name) const;
58
59 virtual void unregisterEvent(uint id);
60
61 virtual uint subscribeEvent(uint id, QObject * obj);
62
63 virtual void unsubscribeEvent(uint id, QObject * obj);
64
65 virtual void broadcastEvent(Event * event);
66
67
68 private: // Members
69
70 /// ID of the next event
71 uint mNextEventId;
72
73 /// List of registered events
74 typedef QHash<uint, QString> Events;
75 Events mEvents;
76
77 /// List of subscribers
78 typedef QHash<uint, QVector<QObject *> > Subscribers;
79 Subscribers mSubscribers;
80
81
82 private slots:
83
84 /// One of the subscribers is destroyed
85 /// We need to remove it from the list of subscribers.
86 void subscriberDestroyed(QObject * obj = 0);
87
88 };
89
90 } // namespace evaf::Common::Internal
91 } // namespace eVaf::Common
92 } // namespace eVaf
93
94 #endif // eventqueue.h