summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKranthi Kuntala <kranthi.kumar-kuntala@nokia.com>2012-02-22 11:17:36 +0200
committerKranthi Kuntala <kranthi.kumar-kuntala@nokia.com>2012-02-27 10:37:49 +0100
commit9be8d51e49adfc01c64cf594a0408bd8c9a30525 (patch)
tree44a57eb5ca68fbf14926f48432bfd37fb7e2377a /src
parentd7738e7ab35eb50802936afcbe5e6eeefdb26b60 (diff)
AlignedTimer addon module
Change-Id: I28d4cdc2b0a24294940e2fc12361927e03d30e72 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/alignedtimer/alignedtimer.pro36
-rw-r--r--src/alignedtimer/qalignedtimer.cpp271
-rw-r--r--src/alignedtimer/qalignedtimer.h104
-rw-r--r--src/alignedtimer/qalignedtimer_stub.cpp122
-rw-r--r--src/alignedtimer/qalignedtimer_stub_p.h87
-rw-r--r--src/alignedtimer/qalignedtimer_systemhb.cpp231
-rw-r--r--src/alignedtimer/qalignedtimer_systemhb_p.h105
-rw-r--r--src/alignedtimer/qalignedtimerglobal.h63
-rw-r--r--src/src.pro3
9 files changed, 1022 insertions, 0 deletions
diff --git a/src/alignedtimer/alignedtimer.pro b/src/alignedtimer/alignedtimer.pro
new file mode 100644
index 0000000..70c5bba
--- /dev/null
+++ b/src/alignedtimer/alignedtimer.pro
@@ -0,0 +1,36 @@
+load(qt_module)
+
+TARGET = QtAlignedTimer
+QPRO_PWD = $PWD
+CONFIG += module
+MODULE_PRI = ../../modules/qt_alignedtimer.pri
+
+QT = core
+
+DEFINES += QT_BUILD_ALIGNEDTIMER_LIB QT_MAKEDLL
+
+load(qt_module_config)
+VERSION = $$QT.alignedtimer.VERSION
+
+
+PUBLIC_HEADERS += \
+ qalignedtimer.h \
+ qalignedtimerglobal.h
+
+
+SOURCES += \
+ qalignedtimer.cpp
+
+ # alignedtimer for systemhb
+ contains(systemhb_enabled, yes): {
+ SOURCES += qalignedtimer_systemhb.cpp
+ HEADERS += qalignedtimer_systemhb_p.h
+ PKGCONFIG += libsystemhb
+ DEFINES += ALIGNEDTIMER_SYSTEMHB
+ LIBS += -lsystemhb
+ } else {
+ SOURCES += qalignedtimer_stub.cpp
+ HEADERS += qalignedtimer_stub_p.h
+ }
+
+HEADERS += qtalignedtimerversion.h $$PUBLIC_HEADERS $$PRIVATE_HEADERS
diff --git a/src/alignedtimer/qalignedtimer.cpp b/src/alignedtimer/qalignedtimer.cpp
new file mode 100644
index 0000000..e329e86
--- /dev/null
+++ b/src/alignedtimer/qalignedtimer.cpp
@@ -0,0 +1,271 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the alignedtimer module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qalignedtimer.h"
+#include <QDebug>
+#if defined(ALIGNEDTIMER_SYSTEMHB)
+#include "qalignedtimer_systemhb_p.h"
+#else
+#include "qalignedtimer_stub_p.h"
+#endif
+QT_BEGIN_NAMESPACE
+
+Q_GLOBAL_STATIC(QAlignedTimerPrivate, alignedTimerPrivate)
+
+/*!
+ \class QAlignedTimer
+ \ingroup events
+ \brief The QAlignedTimer class provides a service for applications to synchronize their activity.
+
+ QAlignedTimer is a fuzzy timer that allows applications that must do periodic activity like
+ after being in sleep mode a certain period, to synchronize their activities in the same window of time.
+
+ For example send network "alive" messages at the same time (i.e. turn the wireless radio on at the same time).
+
+ The service is not only for network-aware applications, it is for use by any applications
+ that need to periodic wake-ups.
+
+ The recommended use case is when app uses single-shot timer only: set mintime 0 for the first call
+ 'to jump to the train' and mintime > 0 after 1st wakeup.
+ \sa QBasicTimer, QTimer, QTimerEvent, QObject::timerEvent(), Timers,
+*/
+
+/*!
+ \fn void QAlignedTimer::timeout()
+
+ This signal is emitted when the timer times out.
+*/
+
+/*!
+ \enum QAlignedTimer::AlignedTimerError
+ This enum describes the last known AlignedTimerError
+
+ \value NoError No error.
+ \value AlignedTimerNotSupported The aligned timer is not support on this platform
+ \value InvalidArgument Interval arguments are invalid.
+ \value TimerFailed General timer failure.
+ \value InternalError Internal error.
+*/
+
+/*!
+ Constructs a QAlignedTimer object with the given \a parent.
+*/
+QAlignedTimer::QAlignedTimer(QObject *parent)
+ : QObject(parent)
+{
+ d = new QAlignedTimerPrivate(this);
+ connect(d, SIGNAL(timeout()), this, SIGNAL(timeout()));
+ connect(d, SIGNAL(error(QAlignedTimer::AlignedTimerError)), this, SIGNAL(error(QAlignedTimer::AlignedTimerError)));
+}
+
+/*!
+ Destructs the QAlignedTimer
+*/
+QAlignedTimer::~QAlignedTimer()
+{
+}
+
+/*!
+ Starts the timer with the minimal interval of \a minimumTime, and maximum interval \a maximumTime in seconds.
+
+ This is not a guaranteed interval, and the timeout signal may be fired at any time,
+ depending on other clients attached to this timer.
+
+ In the case of minimalInterval of 0, it means 'wake me up when someone else is woken up'.
+
+*/
+void QAlignedTimer::start(int minimumTime, int maximumTime)
+{
+ if (minimumTime > maximumTime || maximumTime <= 0) {
+ d->m_lastError = QAlignedTimer::InvalidArgument;
+ qWarning()<<Q_FUNC_INFO <<"invalid arguments minimumTime and maximumTime";
+ return;
+ }
+ d->start(minimumTime, maximumTime);
+}
+
+/*!
+ Starts the alignedtimer if the minimumtime is greater than zero
+ and maximumtime is greater than the minimumtime
+*/
+void QAlignedTimer::start()
+{
+ int minimumTime = minimumInterval();
+ int maximumTime = maximumInterval();
+ if ((minimumTime > maximumTime) || (maximumTime <= 0)) {
+ d->m_lastError = QAlignedTimer::InvalidArgument;
+ qWarning() <<Q_FUNC_INFO <<"invalid arguments minimumTime and maximumTime";
+ return;
+ }
+ d->start();
+}
+
+/*!
+ This should be called when the application wakes up via other means than QAlignedTimer timeout.
+
+ Other applications that are in their wakeup window *may* be woken up. Single-shot timer is canceled,
+ and reoccuring timer interval will restart.
+
+*/
+void QAlignedTimer::wokeUp()
+{
+ d->wokeUp();
+}
+
+/*!
+ Stops this timer request.
+*/
+void QAlignedTimer::stop()
+{
+ d->stop();
+}
+
+/*!
+ Set the timeout minimum interval to \a seconds in seconds that must be waited before timeout
+ signal is emitted.
+
+ Time in seconds that MUST be waited before timeout.
+ Value 0 means 'wake me up when someboy else is woken'.
+
+ mintime value 0 should be used with special care, as it may cause too frequent wakeups.
+ It is recommended that the first wait (if possible) uses minimum value of 0 to
+ "jump to the train" and minimum value > 0 after 1st wakeup
+*/
+void QAlignedTimer::setMinimumInterval(int seconds)
+{
+ d->setMinimumInterval(seconds);
+}
+
+/*!
+ \property QAlignedTimer::minimumInterval
+ \brief The timers's minimumInterval.
+
+ Returns this current timer minimum interval.
+*/
+int QAlignedTimer::minimumInterval() const
+{
+ return d->minimumInterval();
+}
+
+/*!
+ Set the timeout maximum interval to \a seconds the wait must end.
+
+ Time in seconds when the wait MUST end. It is wise to have maxtime-mintime
+ quite big so all users of this service get synced.
+ For example if you preferred wait is 120 seconds, use minval 110 and maxval 130.
+
+ max interval must be greater than min interval.
+*/
+void QAlignedTimer::setMaximumInterval(int seconds)
+{
+ d->setMaximumInterval(seconds);
+}
+
+/*!
+ \property QAlignedTimer::maximumInterval
+ \brief The timer's maximumInterval.
+
+ Returns this current timer maximum interval.
+*/
+int QAlignedTimer::maximumInterval() const
+{
+ return d->maximumInterval();
+}
+
+/*!
+ Sets this timer to be a single shot \a singleShot is true, otherwise false.
+*/
+void QAlignedTimer::setSingleShot(bool singleShot)
+{
+ d->setSingleShot(singleShot);
+}
+
+/*!
+ This static function starts a timer to call a slot after a \a minimumTime
+ interval has elapsed, and ensures that it will be called before the
+ \a maximumTime has elapsed.
+
+ These values are specified in seconds.
+
+ The receiver is the \a receiver object and the \a member is the slot.
+*/
+void QAlignedTimer::singleShot(int minimumTime, int maximumTime, QObject *receiver, const char *member)
+{
+ if (minimumTime > maximumTime || maximumTime <= 0)
+ return;
+ QAlignedTimerPrivate::singleShot(minimumTime, maximumTime, receiver, member);
+}
+
+/*!
+ \property QAlignedTimer::singleShot
+ Whether the timer is single shot.
+*/
+
+/*!
+ Returns true if this timer is a single shot, otherwise false.
+*/
+bool QAlignedTimer::isSingleShot() const
+{
+ return d->isSingleShot();
+}
+
+/*!
+ Returns the last AlignedTimerError.
+*/
+QAlignedTimer::AlignedTimerError QAlignedTimer::lastError() const
+{
+ return d->lastError();
+}
+
+/*!
+ \property QAlignedTimer::active
+ Returns true if the timer is running; otherwise false.
+*/
+
+/*!
+ Returns true if the timer is running; otherwise false.
+*/
+bool QAlignedTimer::isActive () const
+{
+ return d->isActive();
+}
+
+QT_END_NAMESPACE
diff --git a/src/alignedtimer/qalignedtimer.h b/src/alignedtimer/qalignedtimer.h
new file mode 100644
index 0000000..1c94e08
--- /dev/null
+++ b/src/alignedtimer/qalignedtimer.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the alignedtimer module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QALIGNEDTIMER_H
+#define QALIGNEDTIMER_H
+
+#include <QObject>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class QAlignedTimerPrivate;
+
+class Q_CORE_EXPORT QAlignedTimer : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int minimumInterval READ minimumInterval WRITE setMinimumInterval)
+ Q_PROPERTY(int maximumInterval READ maximumInterval WRITE setMaximumInterval)
+ Q_PROPERTY(bool singleShot READ isSingleShot WRITE setSingleShot)
+ Q_PROPERTY(bool active READ isActive)
+
+public:
+ explicit QAlignedTimer(QObject *parent = 0);
+ ~QAlignedTimer();
+
+ enum AlignedTimerError {
+ NoError = 0,
+ AlignedTimerNotSupported,
+ InvalidArgument,
+ TimerFailed,
+ InternalError
+ };
+
+ Q_INVOKABLE void wokeUp();
+
+ int minimumInterval() const;
+ void setMinimumInterval(int seconds);
+
+ int maximumInterval() const;
+ void setMaximumInterval(int seconds);
+
+ void setSingleShot(bool single);
+ bool isSingleShot() const;
+
+ Q_INVOKABLE static void singleShot(int minimumTime, int maximumTime, QObject *receiver, const char *member);
+
+ AlignedTimerError lastError() const;
+ bool isActive () const;
+
+public Q_SLOTS:
+ void start(int minimumTime, int maximumTime);
+ void start();
+ void stop();
+
+Q_SIGNALS:
+ void timeout();
+
+private:
+ QAlignedTimerPrivate *d;
+};
+
+QT_END_NAMESPACE
+QT_END_HEADER
+
+#endif // QALIGNEDTIMER_H
diff --git a/src/alignedtimer/qalignedtimer_stub.cpp b/src/alignedtimer/qalignedtimer_stub.cpp
new file mode 100644
index 0000000..46ef949
--- /dev/null
+++ b/src/alignedtimer/qalignedtimer_stub.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the alignedtimer module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qalignedtimer.h"
+#include "qalignedtimer_stub_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QAlignedTimerPrivate::QAlignedTimerPrivate(QObject *parent)
+ : QObject(parent)
+{
+}
+
+QAlignedTimerPrivate::~QAlignedTimerPrivate()
+{
+}
+
+void QAlignedTimerPrivate::wokeUp()
+{
+}
+
+int QAlignedTimerPrivate::minimumInterval() const
+{
+ return -1;
+}
+
+void QAlignedTimerPrivate::setMinimumInterval(int seconds)
+{
+ Q_UNUSED(seconds);
+}
+
+int QAlignedTimerPrivate::maximumInterval() const
+{
+ return -1;
+}
+
+void QAlignedTimerPrivate::setMaximumInterval(int seconds)
+{
+ Q_UNUSED(seconds);
+}
+
+void QAlignedTimerPrivate::setSingleShot(bool singleShot)
+{
+ Q_UNUSED(singleShot);
+}
+
+bool QAlignedTimerPrivate::isSingleShot() const
+{
+ return false;
+}
+
+void QAlignedTimerPrivate::singleShot(int minimumTime, int maximumTime, QObject *receiver, const char *member)
+{
+ Q_UNUSED(minimumTime);
+ Q_UNUSED(maximumTime);
+ Q_UNUSED(receiver);
+ Q_UNUSED(member);
+}
+
+QAlignedTimer::AlignedTimerError QAlignedTimerPrivate::lastError() const
+{
+ return QAlignedTimer::AlignedTimerNotSupported;
+}
+
+void QAlignedTimerPrivate::start(int minimumTime, int maximumTime)
+{
+ Q_UNUSED(minimumTime);
+ Q_UNUSED(maximumTime);
+}
+
+void QAlignedTimerPrivate::start()
+{
+}
+
+void QAlignedTimerPrivate::stop()
+{
+}
+
+bool QAlignedTimerPrivate::isActive () const
+{
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/alignedtimer/qalignedtimer_stub_p.h b/src/alignedtimer/qalignedtimer_stub_p.h
new file mode 100644
index 0000000..dc62c05
--- /dev/null
+++ b/src/alignedtimer/qalignedtimer_stub_p.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the alignedtimer module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QALIGNEDTIMER_STUB_P_H
+#define QALIGNEDTIMER_STUB_P_H
+
+#include "qalignedtimer.h"
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class QAlignedTimerPrivate : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QAlignedTimerPrivate(QObject *parent = 0);
+ ~QAlignedTimerPrivate();
+
+public:
+ void wokeUp();
+
+ int minimumInterval() const;
+ void setMinimumInterval(int seconds);
+
+ int maximumInterval() const;
+ void setMaximumInterval(int seconds);
+
+ bool isSingleShot() const;
+ void setSingleShot(bool singleShot);
+
+ static void singleShot(int minimumTime, int maximumTime, QObject *receiver, const char *member);
+ QAlignedTimer::AlignedTimerError lastError() const;
+ bool isActive() const;
+ QAlignedTimer::AlignedTimerError m_lastError;
+
+Q_SIGNALS:
+ void timeout();
+
+public Q_SLOTS:
+ void start(int minimumTime, int maximumTime);
+ void start();
+ void stop();
+};
+
+QT_END_NAMESPACE
+QT_END_HEADER
+
+#endif // QALIGNEDTIMER_STUB_P_H
diff --git a/src/alignedtimer/qalignedtimer_systemhb.cpp b/src/alignedtimer/qalignedtimer_systemhb.cpp
new file mode 100644
index 0000000..001a77d
--- /dev/null
+++ b/src/alignedtimer/qalignedtimer_systemhb.cpp
@@ -0,0 +1,231 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the alignedtimer module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qalignedtimer.h"
+#include "qalignedtimer_systemhb_p.h"
+#include <QDebug>
+
+#include <errno.h>
+#include <stdio.h>
+
+QT_BEGIN_NAMESPACE
+
+QAlignedTimerPrivate::QAlignedTimerPrivate(QObject *parent)
+ : QObject(parent)
+ , m_lastError(QAlignedTimer::NoError)
+ , m_minimumInterval(0)
+ , m_maximumInterval(0)
+ , m_running(false)
+ , m_singleShot(false)
+ , m_systemhbdHandler(0)
+ , m_notifier(0)
+{
+ m_systemhbdHandler = systemhb_open(0);
+
+ if (!m_systemhbdHandler) {
+ m_lastError = QAlignedTimer::InternalError;
+ qWarning() <<Q_FUNC_INFO <<"systemhb_open error" << m_systemhbdHandler<< errno <<strerror(errno);
+ return;
+ }
+
+ int sockfd = systemhb_get_fd(m_systemhbdHandler);
+ if (!(sockfd > -1)) {
+ m_lastError = QAlignedTimer::InternalError;
+ qWarning() <<Q_FUNC_INFO <<"socket failure"<<strerror(errno);
+ return;
+ }
+
+ m_notifier = new QSocketNotifier(sockfd, QSocketNotifier::Read);
+ if (!QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(heartbeatReceived(int)))) {
+ delete m_notifier, m_notifier = 0;
+ m_lastError = QAlignedTimer::TimerFailed;
+ qWarning()<<Q_FUNC_INFO <<"timer failed";
+ return;
+ }
+ m_notifier->setEnabled(false);
+}
+
+QAlignedTimerPrivate::~QAlignedTimerPrivate()
+{
+ if (m_systemhbdHandler)
+ (void)systemhb_close(m_systemhbdHandler);
+
+ if (m_notifier)
+ delete m_notifier;
+}
+
+void QAlignedTimerPrivate::wokeUp()
+{
+ if (!m_running)
+ return;
+
+ if (!(m_systemhbdHandler && m_notifier)) {
+ m_lastError = QAlignedTimer::InternalError;
+ qWarning()<<Q_FUNC_INFO <<"internal error occured";
+ return;
+ }
+
+ m_notifier->setEnabled(false);
+
+ (void)systemhb_I_woke_up(m_systemhbdHandler);
+
+ m_running = false;
+ m_lastError = QAlignedTimer::NoError;
+
+ if (!m_singleShot)
+ start();
+}
+
+int QAlignedTimerPrivate::minimumInterval() const
+{
+ return m_minimumInterval;
+}
+
+void QAlignedTimerPrivate::setMinimumInterval(int seconds)
+{
+ m_minimumInterval = seconds;
+}
+
+int QAlignedTimerPrivate::maximumInterval() const
+{
+ return m_maximumInterval;
+}
+
+void QAlignedTimerPrivate::setMaximumInterval(int seconds)
+{
+ m_maximumInterval = seconds;
+}
+
+void QAlignedTimerPrivate::setSingleShot(bool singleShot)
+{
+ m_singleShot = singleShot;
+}
+
+bool QAlignedTimerPrivate::isSingleShot() const
+{
+ return m_singleShot;
+}
+
+void QAlignedTimerPrivate::singleShot(int minimumTime, int maximumTime, QObject *receiver, const char *member)
+{
+ if (receiver && member) {
+ QAlignedTimerPrivate *alignedTimer = new QAlignedTimerPrivate(receiver);
+
+ alignedTimer->m_singleShot = true;
+
+ connect(alignedTimer, SIGNAL(timeout()), receiver, member);
+ alignedTimer->start(minimumTime, maximumTime);
+ }
+}
+
+QAlignedTimer::AlignedTimerError QAlignedTimerPrivate::lastError() const
+{
+ return m_lastError;
+}
+
+void QAlignedTimerPrivate::start(int minimumTime, int maximumTime)
+{
+ m_minimumInterval = minimumTime;
+ m_maximumInterval = maximumTime;
+
+ start();
+}
+
+void QAlignedTimerPrivate::start()
+{
+ if (m_running)
+ return;
+
+ if (!(m_systemhbdHandler && m_notifier)) {
+ m_lastError = QAlignedTimer::InternalError;
+ qWarning()<<Q_FUNC_INFO <<"internal error occured";
+ return;
+ }
+
+ int mustWait = 0;
+ time_t unixTime = systemhb_wait(m_systemhbdHandler, m_minimumInterval, m_maximumInterval, mustWait);
+
+ if (unixTime == (time_t)-1) {
+ m_lastError = QAlignedTimer::TimerFailed;
+ qWarning()<<Q_FUNC_INFO <<"Timer failed";
+ return;
+ }
+
+ m_notifier->setEnabled(true);
+ m_running = true;
+ m_lastError = QAlignedTimer::NoError;
+}
+
+void QAlignedTimerPrivate::stop()
+{
+ if (!m_running)
+ return;
+
+ if (!(m_systemhbdHandler && m_notifier)) {
+ m_lastError = QAlignedTimer::InternalError;
+ qWarning() <<Q_FUNC_INFO<< "systemhb_internal error";
+ return;
+ }
+
+ m_notifier->setEnabled(false);
+
+ (void)systemhb_discard_wakeups(m_systemhbdHandler);
+
+ m_running = false;
+ m_lastError = QAlignedTimer::NoError;
+}
+
+void QAlignedTimerPrivate::heartbeatReceived(int sock) {
+ Q_UNUSED(sock);
+
+ stop();
+ emit timeout();
+
+ if (!m_singleShot)
+ start();
+}
+
+bool QAlignedTimerPrivate::isActive() const
+{
+ return m_running;
+}
+
+QT_END_NAMESPACE
diff --git a/src/alignedtimer/qalignedtimer_systemhb_p.h b/src/alignedtimer/qalignedtimer_systemhb_p.h
new file mode 100644
index 0000000..f5f83e1
--- /dev/null
+++ b/src/alignedtimer/qalignedtimer_systemhb_p.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the alignedtimer module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QALIGNEDTIMER_SYSTEMHB_P_H
+#define QALIGNEDTIMER_SYSTEMHB_P_H
+
+#include "qalignedtimer.h"
+
+#include <QSocketNotifier>
+
+extern "C" {
+#include <systemhb/libsystemhb.h>
+}
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class QAlignedTimerPrivate : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QAlignedTimerPrivate(QObject *parent = 0);
+ ~QAlignedTimerPrivate();
+
+public:
+ void wokeUp();
+
+ int minimumInterval() const;
+ void setMinimumInterval(int seconds);
+
+ int maximumInterval() const;
+ void setMaximumInterval(int seconds);
+
+ bool isSingleShot() const;
+ void setSingleShot(bool singleShot);
+
+ static void singleShot(int minimumTime, int maximumTime, QObject *receiver, const char *member);
+ QAlignedTimer::AlignedTimerError lastError() const;
+
+ bool isActive() const;
+ QAlignedTimer::AlignedTimerError m_lastError;
+
+Q_SIGNALS:
+ void timeout();
+
+private:
+ int m_minimumInterval;
+ int m_maximumInterval;
+ bool m_running;
+ bool m_singleShot;
+ systemhb_t m_systemhbdHandler;
+ QSocketNotifier *m_notifier;
+
+public Q_SLOTS:
+ void start(int minimumTime, int maximumTime);
+ void start();
+ void stop();
+
+private Q_SLOTS:
+ void heartbeatReceived(int sock);
+};
+
+QT_END_NAMESPACE
+QT_END_HEADER
+
+#endif // QALIGNEDTIMER_SYSTEMHB_P_H
diff --git a/src/alignedtimer/qalignedtimerglobal.h b/src/alignedtimer/qalignedtimerglobal.h
new file mode 100644
index 0000000..22dbb0c
--- /dev/null
+++ b/src/alignedtimer/qalignedtimerglobal.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the alignedtimer module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTALIGNEDTIMERGLOBAL_H
+#define QTALIGNEDTIMERGLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(QT_NAMESPACE)
+# define QTALIGNEDTIMER_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::QtAlignedTimer::name
+# define QTALIGNEDTIMER_BEGIN_NAMESPACE namespace QT_NAMESPACE { namespace QtAlignedTimer {
+# define QTALIGNEDTIMER_END_NAMESPACE } }
+# define QTALIGNEDTIMER_USE_NAMESPACE using namespace QT_NAMESPACE; using namespace QtAlignedTimer;
+#else
+# define QTALIGNEDTIMER_PREPEND_NAMESPACE(name) ::QtAlignedTimer::name
+# define QTALIGNEDTIMER_BEGIN_NAMESPACE namespace QtAlignedTimer {
+# define QTALIGNEDTIMER_END_NAMESPACE }
+# define QTALIGNEDTIMER_USE_NAMESPACE using namespace QtAlignedTimer;
+#endif
+
+#define QTALIGNEDTIMER_VERSION_NAME "org.qt-project.Qt.alignedtimer.api.version"
+#define QTALIGNEDTIMER_IMPLEMENTATION_VERSION_NAME "org.qt-project.Qt.alignedtimer.implementation.version"
+#define QTALIGNEDTIMER_VERSION 1
+
+#endif
diff --git a/src/src.pro b/src/src.pro
new file mode 100644
index 0000000..2c0adbb
--- /dev/null
+++ b/src/src.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = alignedtimer