2 * @file Common/ieventqueue.h
3 * @brief Event queue interface
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
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.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #ifndef __COMMON_IEVENTQUEUE_H
21 #define __COMMON_IEVENTQUEUE_H
23 #include "libcommon.h"
34 * The eVaf event queue interface
35 * @code#include <Common/iEventQueue>@endcode
37 * This interface is used to work with eVaf events. Functions in this interface register new events,
38 * subscribe to existing events and broadcast events to the rest of the application.
39 * Events are implemented using the Qt event loop.
41 class COMMON_EXPORT iEventQueue
: public QObject
47 /// Interface constructor
48 iEventQueue() : QObject() {}
50 /// Empty virtual destructor
51 virtual ~iEventQueue() {}
54 * Returns the instance of the iEventQueue interface
55 * @return The iEventQueue interface
57 static iEventQueue
* instance();
61 * @param name Name of the event
62 * @return Unique ID of the event
64 * This function registers an event and returns a unique ID for the event. The event ID value
65 * is always greater than zero.
67 * If an event with the given name already exists, then returns the event ID for the existing
70 virtual uint
registerEvent(QString
const & name
) = 0;
73 * Queries for an existing event
74 * @param name Name of the event
75 * @return The ID of the event or 0 if not found
77 * This function returns the ID of the event or zero if no such event is found.
79 virtual uint
queryEvent(QString
const & name
) const = 0;
82 * Unregisters an event
83 * @param id The ID of the event
85 * This function removes an event. It also unsubscribes all the subscribers from this event.
87 virtual void unregisterEvent(uint id
) = 0;
90 * Subscribes to an event
91 * @param id The ID of the event (can be zero)
92 * @param obj The subscriber object
93 * @return The ID of the event; or zero if failed to subscribe
95 * This function subscribes to an event identified by the ID value. Every object that wants to
96 * receive specific events, needs to subscribe to them.
98 * The id parameter can be zero and the following example code is correct even when the event
99 * called "my-event" does not exist. The value of myEventId will be set to zero if the event
102 * int myEventId = iEventQueue::instance()->subscribeEvent(iEventQueue::instance()->queryEvent("my-event"), this);
105 virtual uint
subscribeEvent(uint id
, QObject
* obj
) = 0;
108 * Unsubscribes from an event
109 * @param id The ID of the event (can be zero)
110 * @param obj The subscriber object
112 * This function removes the subscriber object from the list of subscribers for the given event identified
113 * by the event ID value. After this function call the subscriber does no more receive these events.
115 virtual void unsubscribeEvent(uint id
, QObject
* obj
) = 0;
118 * Sends the event to all the subscribers
119 * @param event The event object
121 * This function sends the event to all the subscribers. The event object is destroyed when the event loop
122 * is finished for this event.
124 * The event object shall be allocated in the heap.
126 virtual void broadcastEvent(Event
* event
) = 0;
130 } // namespace eVaf::Common
133 #endif // ieventqueue.h