forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_queue.cpp
62 lines (52 loc) · 1.31 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
58
59
60
61
62
#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)
{
if (DBG_IsEnabled(DBG_INFO_L2) && event.what() && event.resource())
{
DBG_Printf(DBG_INFO_L2, "enqueue event %s for %s/%s\n", event.what(), event.resource(), qPrintable(event.id()));
}
eventQueue.push_back(event);
if (!eventTimer->isActive())
{
eventTimer->start();
}
}