2011-10-25 07:51:19 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-28 08:44:43 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2011-10-25 07:51:19 +00:00
|
|
|
**
|
|
|
|
** This file is part of the QtCore module of the Qt Toolkit.
|
|
|
|
**
|
2014-08-21 13:51:22 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see http://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2011-10-25 07:51:19 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-21 13:51:22 +00:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2015-01-28 08:44:43 +00:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-10-25 07:51:19 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#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.
|
|
|
|
//
|
|
|
|
|
2011-12-21 10:34:07 +00:00
|
|
|
// #define QTIMERINFO_DEBUG
|
|
|
|
|
2011-12-21 10:33:33 +00:00
|
|
|
#include "qabstracteventdispatcher.h"
|
2011-10-25 07:51:19 +00:00
|
|
|
|
|
|
|
#include <sys/time.h> // struct timeval
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
// internal timer info
|
|
|
|
struct QTimerInfo {
|
|
|
|
int id; // - timer identifier
|
2011-12-21 10:33:56 +00:00
|
|
|
int interval; // - timer interval in milliseconds
|
2011-12-21 10:33:33 +00:00
|
|
|
Qt::TimerType timerType; // - timer type
|
2012-08-10 14:14:48 +00:00
|
|
|
timespec timeout; // - when to actually fire
|
2011-10-25 07:51:19 +00:00
|
|
|
QObject *obj; // - object to receive event
|
|
|
|
QTimerInfo **activateRef; // - ref from activateTimers
|
2011-12-21 10:34:07 +00:00
|
|
|
|
|
|
|
#ifdef QTIMERINFO_DEBUG
|
2012-01-05 12:56:01 +00:00
|
|
|
timeval expected; // when timer is expected to fire
|
2011-12-21 10:34:07 +00:00
|
|
|
float cumulativeError;
|
|
|
|
uint count;
|
|
|
|
#endif
|
2011-10-25 07:51:19 +00:00
|
|
|
};
|
|
|
|
|
2012-01-05 13:12:18 +00:00
|
|
|
class Q_CORE_EXPORT QTimerInfoList : public QList<QTimerInfo*>
|
2011-10-25 07:51:19 +00:00
|
|
|
{
|
|
|
|
#if ((_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC)) || defined(QT_BOOTSTRAPPED)
|
2012-08-10 14:14:48 +00:00
|
|
|
timespec previousTime;
|
2011-10-25 07:51:19 +00:00
|
|
|
clock_t previousTicks;
|
|
|
|
int ticksPerSecond;
|
|
|
|
int msPerTick;
|
|
|
|
|
2012-08-10 14:14:48 +00:00
|
|
|
bool timeChanged(timespec *delta);
|
|
|
|
void timerRepair(const timespec &);
|
2011-10-25 07:51:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// state variables used by activateTimers()
|
|
|
|
QTimerInfo *firstTimerInfo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
QTimerInfoList();
|
|
|
|
|
2012-08-10 14:14:48 +00:00
|
|
|
timespec currentTime;
|
|
|
|
timespec updateCurrentTime();
|
2011-10-25 07:51:19 +00:00
|
|
|
|
|
|
|
// must call updateCurrentTime() first!
|
|
|
|
void repairTimersIfNeeded();
|
|
|
|
|
2012-08-10 14:14:48 +00:00
|
|
|
bool timerWait(timespec &);
|
2011-10-25 07:51:19 +00:00
|
|
|
void timerInsert(QTimerInfo *);
|
|
|
|
|
Add a remainingTime() method to the public interface of the QTimer class
It is an extension coming from the use case when you, for instance, need to
implement a countdown timer in client codes, and manually maintain a dedicated
variable for counting down with the help of yet another Timer. There might be
other use cases as well. The returned value is meant to be in milliseconds, as
the method documentation says, since it is reasonable, and consistent with the
rest (ie. the interval accessor).
The elapsed time is already being tracked inside the event dispatcher, thus the
effort is only exposing that for all platforms supported according to the
desired timer identifier, and propagating up to the QTimer public API. It is
done by using the QTimerInfoList class in the glib and unix dispatchers, and the
WinTimeInfo struct for the windows dispatcher.
It might be a good idea to to establish a QWinTimerInfo
(qtimerinfo_win{_p.h,cpp}) in the future for resembling the interface for
windows with the glib/unix management so that it would be consistent. That would
mean abstracting out a base class (~interface) for the timer info classes.
Something like that QAbstractTimerInfo.
Test: Build test only on (Arch)Linux, Windows and Mac. I have also run the unit
tests and they passed as well.
Change-Id: Ie37b3aff909313ebc92e511e27d029abb070f110
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
2012-02-23 05:41:30 +00:00
|
|
|
int timerRemainingTime(int timerId);
|
|
|
|
|
2011-12-21 10:33:33 +00:00
|
|
|
void registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object);
|
2011-10-25 07:51:19 +00:00
|
|
|
bool unregisterTimer(int timerId);
|
|
|
|
bool unregisterTimers(QObject *object);
|
2011-12-21 10:33:33 +00:00
|
|
|
QList<QAbstractEventDispatcher::TimerInfo> registeredTimers(QObject *object) const;
|
2011-10-25 07:51:19 +00:00
|
|
|
|
|
|
|
int activateTimers();
|
|
|
|
};
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // QTIMERINFO_UNIX_P_H
|