summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qtimerinfo_unix_p.h
blob: 293e9c4d4e787542fde319af44b2e3df5806540f (plain)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
// Copyright (C) 2016 The Qt Company Ltd.// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only#ifndef QTIMERINFO_UNIX_P_H#define QTIMERINFO_UNIX_P_H//// W A R N I N G// -------------//// This file is not part of the Qt API. It exists purely as an// implementation detail. This header file may change from version to// version without notice, or even be removed.//// We mean it.//#include <QtCore/private/qglobal_p.h>#include"qabstracteventdispatcher.h"#include <sys/time.h>// struct timespec#include <chrono> QT_BEGIN_NAMESPACE // internal timer infostruct QTimerInfo {using Duration =QAbstractEventDispatcher::Duration;using TimePoint =std::chrono::time_point<std::chrono::steady_clock, Duration>;QTimerInfo(Qt::TimerId timerId, Duration interval,Qt::TimerType type, QObject *obj):interval(interval),id(timerId),timerType(type),obj(obj){} TimePoint timeout = {};// - when to actually fire Duration interval = Duration{-1};// - timer intervalQt::TimerId id =Qt::TimerId::Invalid;// - timer identifierQt::TimerType timerType;// - timer type QObject *obj =nullptr;// - object to receive event QTimerInfo **activateRef =nullptr;// - ref from activateTimers};class Q_CORE_EXPORT QTimerInfoList {public:using Duration =QAbstractEventDispatcher::Duration;using TimerInfo =QAbstractEventDispatcher::TimerInfoV2;QTimerInfoList();mutable std::chrono::steady_clock::time_point currentTime;std::optional<Duration>timerWait();voidtimerInsert(QTimerInfo *); Duration remainingDuration(Qt::TimerId timerId)const;voidregisterTimer(Qt::TimerId timerId, Duration interval,Qt::TimerType timerType, QObject *object);boolunregisterTimer(Qt::TimerId timerId);boolunregisterTimers(QObject *object); QList<TimerInfo>registeredTimers(QObject *object)const;intactivateTimers();boolhasPendingTimers();voidclearTimers(){qDeleteAll(timers); timers.clear();}boolisEmpty()const{return timers.empty(); } qsizetype size()const{return timers.size(); }autofindTimerById(Qt::TimerId timerId)const{auto matchesId = [timerId](constauto&t) {return t->id == timerId; };returnstd::find_if(timers.cbegin(), timers.cend(), matchesId);}private:std::chrono::steady_clock::time_point updateCurrentTime()const;// state variables used by activateTimers() QTimerInfo *firstTimerInfo =nullptr; QList<QTimerInfo *> timers;}; QT_END_NAMESPACE #endif// QTIMERINFO_UNIX_P_H
close