Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtimerinfo_unix_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QTIMERINFO_UNIX_P_H
6#define QTIMERINFO_UNIX_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/private/qglobal_p.h>
20
22
23#include <sys/time.h> // struct timespec
24#include <chrono>
25
26QT_BEGIN_NAMESPACE
27
28// internal timer info
29struct QTimerInfo
30{
31 using Duration = QAbstractEventDispatcher::Duration;
32 using TimePoint = std::chrono::time_point<std::chrono::steady_clock, Duration>;
33 QTimerInfo(Qt::TimerId timerId, Duration interval, Qt::TimerType type, QObject *obj)
34 : interval(interval), id(timerId), timerType(type), obj(obj)
35 {
36 }
37
38 TimePoint timeout = {}; // - when to actually fire
39 Duration interval = Duration{-1}; // - timer interval
40 Qt::TimerId id = Qt::TimerId::Invalid; // - timer identifier
41 Qt::TimerType timerType; // - timer type
42 QObject *obj = nullptr; // - object to receive event
43 QTimerInfo **activateRef = nullptr; // - ref from activateTimers
44};
45
46class Q_CORE_EXPORT QTimerInfoList
47{
48public:
49 using Duration = QAbstractEventDispatcher::Duration;
50 using TimerInfo = QAbstractEventDispatcher::TimerInfoV2;
51 QTimerInfoList();
52
53 mutable std::chrono::steady_clock::time_point currentTime;
54
55 std::optional<Duration> timerWait();
56 void timerInsert(QTimerInfo *);
57
58 Duration remainingDuration(Qt::TimerId timerId) const;
59
60 void registerTimer(Qt::TimerId timerId, Duration interval,
61 Qt::TimerType timerType, QObject *object);
62 bool unregisterTimer(Qt::TimerId timerId);
63 bool unregisterTimers(QObject *object);
64 QList<TimerInfo> registeredTimers(QObject *object) const;
65
66 int activateTimers();
67 bool hasPendingTimers();
68
69 void clearTimers()
70 {
71 qDeleteAll(timers);
72 timers.clear();
73 }
74
75 bool isEmpty() const { return timers.empty(); }
76
77 qsizetype size() const { return timers.size(); }
78
79 auto findTimerById(Qt::TimerId timerId) const
80 {
81 auto matchesId = [timerId](const auto &t) { return t->id == timerId; };
82 return std::find_if(timers.cbegin(), timers.cend(), matchesId);
83 }
84
85private:
86 std::chrono::steady_clock::time_point updateCurrentTime() const;
87
88 // state variables used by activateTimers()
89 QTimerInfo *firstTimerInfo = nullptr;
90 QList<QTimerInfo *> timers;
91};
92
93QT_END_NAMESPACE
94
95#endif // QTIMERINFO_UNIX_P_H