forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_queue.cpp
57 lines (48 loc) · 1.11 KB
/
event_queue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <QVariantMap>
#include "de_web_plugin_private.h"
#include "json.h"
/*! Inits the event queue.
*/
void DeRestPluginPrivate::initEventQueue()
{
eventTimer = new QTimer(this);
eventTimer->setSingleShot(true);
eventTimer->setInterval(1);
connect(eventTimer, SIGNAL(timeout()), this, SLOT(eventQueueTimerFired()));
}
/*! Handles one event and fires again if more are in the queue.
*/
void DeRestPluginPrivate::eventQueueTimerFired()
{
DBG_Assert(!eventQueue.empty());
Event &e = eventQueue.front();
if (e.resource() == RSensors)
{
handleSensorEvent(e);
}
else if (e.resource() == RLights)
{
handleLightEvent(e);
}
else if (e.resource() == RGroups)
{
handleGroupEvent(e);
}
handleRuleEvent(e);
eventQueue.pop_front();
if (!eventQueue.empty())
{
eventTimer->start();
}
}
/*! Puts an event into the queue.
\param event - the event
*/
void DeRestPluginPrivate::enqueueEvent(const Event &event)
{
eventQueue.push_back(event);
if (!eventTimer->isActive())
{
eventTimer->start();
}
}