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
#include <QBasicTimer>
#include <QThread>
#include <QDebug>
#include <mutex>
#include "capi.h"
class IdleTimer : public QObject
{
Q_OBJECT
public:
static IdleTimer *singleton() {
static IdleTimer singleton;
return &singleton;
}
void init(int32_t *guiIdleRun)
{
this->guiIdleRun = guiIdleRun;
}
Q_INVOKABLE void start()
{
timer.start(0, this);
}
protected:
void timerEvent(QTimerEvent *event)
{
__sync_synchronize();
if (*guiIdleRun > 0) {
hookIdleTimer();
} else {
timer.stop();
}
}
private:
int32_t *guiIdleRun;
QBasicTimer timer;
};
void idleTimerInit(int32_t *guiIdleRun)
{
IdleTimer::singleton()->init(guiIdleRun);
}
void idleTimerStart()
{
QMetaObject::invokeMethod(IdleTimer::singleton(), "start", Qt::QueuedConnection);
}
// vim:ts=4:sw=4:et:ft=cpp