diff options
author | Leela Prasanna Kumar Chintagunta <leelaprasannakumar.chintagunta@nokia.com> | 2011-04-05 14:15:39 +0530 |
---|---|---|
committer | Leela Prasanna Kumar Chintagunta <leelaprasannakumar.chintagunta@nokia.com> | 2011-04-05 14:15:39 +0530 |
commit | 38f5055a3c48f916f307590a79d60a75f6a27260 (patch) | |
tree | be9dad7b998518f6b48e11ba7e99427d691ac0de | |
parent | 48b3b8cb356329c37bf102562ee9ac7eb1265d5b (diff) |
Heartbeat timer for symbian
-rw-r--r-- | src/systeminfo/qsystemalignedtimer_symbian.cpp | 212 | ||||
-rw-r--r-- | src/systeminfo/qsystemalignedtimer_symbian_p.h | 106 | ||||
-rw-r--r-- | src/systeminfo/symbian/HeartBeatTimer_s60.cpp | 164 | ||||
-rw-r--r-- | src/systeminfo/symbian/HeartBeatTimer_s60.h | 88 | ||||
-rw-r--r-- | src/systeminfo/systeminfo.pro | 20 |
5 files changed, 585 insertions, 5 deletions
diff --git a/src/systeminfo/qsystemalignedtimer_symbian.cpp b/src/systeminfo/qsystemalignedtimer_symbian.cpp new file mode 100644 index 0000000000..0369a5f793 --- /dev/null +++ b/src/systeminfo/qsystemalignedtimer_symbian.cpp @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsystemalignedtimer_symbian_p.h" +#include "trace.h" + + +QTM_BEGIN_NAMESPACE + +QSystemAlignedTimerPrivate::QSystemAlignedTimerPrivate(QObject *parent) : + QObject(parent), + m_lastError(QSystemAlignedTimer::NoError), + m_minimumInterval(0), + m_maximumInterval(0), + m_running(false), + m_singleShot(false), m_singleShotReceiver(0),m_singleShotMember(0),m_heartbeattimer(0) +{ + TRACES(qDebug() << "QSystemAlignedTimerPrivate--Constructor Start"); + m_heartbeattimer = CHeartbeatTimer::NewL(); + m_heartbeattimer->addObserver(this); + TRACES(qDebug() << "QSystemAlignedTimerPrivate--Constructor End"); +} + +QSystemAlignedTimerPrivate::~QSystemAlignedTimerPrivate() +{ + TRACES(qDebug() << "QSystemAlignedTimerPrivate::~QSystemAlignedTimerPrivate-Start"); + + if (m_heartbeattimer ) { + m_heartbeattimer->removeObserver(this); + delete m_heartbeattimer; + m_heartbeattimer = 0; + } + + TRACES(qDebug() << "QSystemAlignedTimerPrivate::~QSystemAlignedTimerPrivate-End"); +} + +void QSystemAlignedTimerPrivate::wokeUp() +{ + TRACES(qDebug() << "QSystemAlignedTimerPrivate::wokeUp-Start"); + + if (m_singleShot) { + //if singleshot stop the timer + TRACES(qDebug() << "QSystemAlignedTimerPrivate::wokeUp-Timer is single shot"); + stop(); + return; + } + + //If not singleshot resetting the timer + m_heartbeattimer->ResetTimer(); +} + +int QSystemAlignedTimerPrivate::minimumInterval() const +{ + return m_minimumInterval; +} + +void QSystemAlignedTimerPrivate::setMinimumInterval(int seconds) +{ + m_minimumInterval = seconds; +} + +int QSystemAlignedTimerPrivate::maximumInterval() const +{ + return m_maximumInterval; +} + +void QSystemAlignedTimerPrivate::setMaximumInterval(int seconds) +{ + m_maximumInterval = seconds; +} + +void QSystemAlignedTimerPrivate::setSingleShot(bool singleShot) +{ + m_singleShot = singleShot; + m_heartbeattimer->setsingleShot(singleShot); +} + +bool QSystemAlignedTimerPrivate::isSingleShot() const +{ + return m_singleShot; +} + +void QSystemAlignedTimerPrivate::singleShot(int minimumTime, int maximumTime, QObject *receiver, const char *member) +{ + TRACES(qDebug() << "QSystemAlignedTimerPrivate::singleShot--Static"); + QSystemAlignedTimerPrivate *alignedTimer = NULL; + alignedTimer = new QSystemAlignedTimerPrivate(); + + if (alignedTimer){ + TRACES(qDebug() << "QSystemAlignedTimerPrivate::singleShot--Issuing request,Wait for SingleShot() callback"); + alignedTimer->m_singleShotReceiver = receiver; + alignedTimer->m_singleShotMember = member; + alignedTimer->start(minimumTime, maximumTime); + } +} + +QSystemAlignedTimer::AlignedTimerError QSystemAlignedTimerPrivate::lastError() const +{ + return m_lastError; +} + +// public slots + +void QSystemAlignedTimerPrivate::start(int minimumTime, int maximumTime) +{ + m_minimumInterval = minimumTime; + m_maximumInterval = maximumTime; + + start(); +} + +void QSystemAlignedTimerPrivate::start() +{ + if (m_running) { + TRACES(qDebug() << "QSystemAlignedTimerPrivate::start()-Already Started, return"); + return; + } + + if ( m_minimumInterval < 0 || m_maximumInterval < 0 ) { + m_lastError = QSystemAlignedTimer::InvalidArgument; + emit error(m_lastError); + return; + } + + //Arguments are valid, Go ahead to start the timer + TTimeIntervalMicroSeconds window = (m_maximumInterval - m_minimumInterval)* 1000 * 1000; + TTimeIntervalMicroSeconds interval = m_maximumInterval * 1000 * 1000; + TRACES(qDebug() << "QSystemAlignedTimerPrivate::start()-Issuing request"); + TRACES(qDebug() << "winodow:"<< window.Int64()); + TRACES(qDebug() << "Interval:"<< interval.Int64()); + m_heartbeattimer->StartTimer( window, interval ); + + m_running = true; + m_lastError = QSystemAlignedTimer::NoError; +} + +void QSystemAlignedTimerPrivate::stop() +{ + if (!m_running) { + return; + } + TRACES(qDebug() << "QSystemAlignedTimerPrivate::stop()-Issuing stop request"); + //Do heartbeattimer here + m_heartbeattimer->StopTimer(); + + m_running = false; + m_lastError = QSystemAlignedTimer::NoError; +} + +void QSystemAlignedTimerPrivate::NotifyheartbeatReceived() +{ + TRACES(qDebug() << "QSystemAlignedTimerPrivate::NotiftyheartbeatReceived()"); + //Check if there are any single shot members. + //Issuing or (Not to issue) of timer is taken care by CHeartbeatTimer + if (m_singleShotMember != NULL && m_singleShotMember !=NULL ) + { + TRACES(qDebug() << "Single shot members exist"); + QMetaObject::invokeMethod(m_singleShotReceiver, m_singleShotMember); + this->deleteLater(); + } + else + { + emit timeout(); + } +} + +bool QSystemAlignedTimerPrivate::isActive () const +{ + return m_running; +} + +#include "moc_qsystemalignedtimer_symbian_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/systeminfo/qsystemalignedtimer_symbian_p.h b/src/systeminfo/qsystemalignedtimer_symbian_p.h new file mode 100644 index 0000000000..2be17882cc --- /dev/null +++ b/src/systeminfo/qsystemalignedtimer_symbian_p.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSYSTEMALIGNEDTIMER_SYMBIAN_P_H +#define QSYSTEMALIGNEDTIMER_SYMBIAN_P_H + +#include "qsystemalignedtimer.h" +#include "heartbeattimer_s60.h" + +#include <QObject> + +QT_BEGIN_HEADER +QTM_BEGIN_NAMESPACE + +class QSystemAlignedTimerPrivate : public QObject, public MHeartBeatObserver +{ + Q_OBJECT + +public: + explicit QSystemAlignedTimerPrivate(QObject *parent = 0); + ~QSystemAlignedTimerPrivate(); + +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); + QSystemAlignedTimer::AlignedTimerError lastError() const; + + bool isActive() const; + QSystemAlignedTimer::AlignedTimerError m_lastError; + +protected: + //From MHeartBeatObserver + void NotifyheartbeatReceived(); + +Q_SIGNALS: + void timeout(); + void error(QSystemAlignedTimer::AlignedTimerError error); + +private: + int m_minimumInterval; + int m_maximumInterval; + bool m_running; + bool m_singleShot; + QObject *m_singleShotReceiver; + const char *m_singleShotMember; + CHeartbeatTimer *m_heartbeattimer; + +public Q_SLOTS: + void start(int minimumTime, int maximumTime); + void start(); + void stop(); +}; + +QTM_END_NAMESPACE + +QT_END_HEADER + +#endif // QSYSTEMALIGNEDTIMER_SYMBIAN_P_H diff --git a/src/systeminfo/symbian/HeartBeatTimer_s60.cpp b/src/systeminfo/symbian/HeartBeatTimer_s60.cpp new file mode 100644 index 0000000000..98451b1358 --- /dev/null +++ b/src/systeminfo/symbian/HeartBeatTimer_s60.cpp @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "HeartBeatTimer_s60.h" + + +CHeartbeatTimer* CHeartbeatTimer::NewL() + { + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer::NewL-Start"); + CHeartbeatTimer* self = new (ELeave) CHeartbeatTimer( CActive::EPriorityStandard ); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer::NewL-End"); + return self; + } + +void CHeartbeatTimer::ConstructL() + { + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer::CreateL-Start"); + CFlexTimer::ConstructL(); + CActiveScheduler::Add(this); + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer::CreateL-End"); + } + +CHeartbeatTimer::CHeartbeatTimer(TInt aPriority):CFlexTimer(aPriority), + m_singleShot(false),m_interval(0) + + { + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer"); + } + + +CHeartbeatTimer::~CHeartbeatTimer() + { + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer::~CHeartbeatTimer-Start"); + TRACES(qDebug() << "CFlextTimer Cancel"); + CFlexTimer::Cancel(); + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer::~CHeartbeatTimer-End"); + } + +void CHeartbeatTimer::addObserver(MHeartBeatObserver *observer) + { + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer::addObserver"); + m_observers.append(observer); + } + +void CHeartbeatTimer::removeObserver(MHeartBeatObserver *observer) + { + TRACES(qDebug() << "CHeartbeatTimer::CHeartbeatTimer::removeObserver"); + m_observers.removeOne(observer); + } + +void CHeartbeatTimer::RunL() + { + TRACES(qDebug() << "CHeartbeatTimer::RunL()-Start"); + + if (iStatus != KErrNone) { TRACES(qDebug() << "CHeartbeatTimer::RunL() Error:" << iStatus.Int());} + + if (iStatus == KErrNone) + { + TRACES(qDebug() << "CHeartbeatTimer::RunL()->TimerExpired"); + foreach (MHeartBeatObserver *observer, m_observers) + { + observer->NotifyheartbeatReceived(); + } + if (m_singleShot == false) CFlexTimer::After(m_interval); //Refresh timer if not singleshot + } + + if (iStatus == KErrCancel ) { + TRACES(qDebug() << "CHeartbeatTimer::RunL->TimerCancelled"); + //Take some action ??? + } + + TRACES(qDebug() << "CHeartbeatTimer::RunL()-End"); +} + +void CHeartbeatTimer::StartTimer( TTimeIntervalMicroSeconds aWindow, TTimeIntervalMicroSeconds aInterval) + { + TRACES(qDebug() << "CHeartbeatTimer::StartTimer-Start"); + m_interval = aInterval; + if (IsActive()) { + TRACES(qDebug() << "CHeartbeatTimer::Timer is already running"); + return; + } + + //Issue request + TInt configerr = KErrNone; + configerr = CFlexTimer::Configure(aWindow); + if (configerr != KErrNone) TRACES(qDebug() << "CHeartbeatTimer::Configerror:"<<configerr); + TRACES(qDebug() << "Configure done"); + CFlexTimer::After(aInterval); + TRACES(qDebug() << "Issued after call"); + TRACES(qDebug() << "iStatus:" << iStatus.Int()); + TRACES(qDebug() << "CHeartbeatTimer::StartTimer-End"); + } + + void CHeartbeatTimer::setsingleShot(bool asingleShot) + { + m_singleShot = asingleShot; + } + +void CHeartbeatTimer::StopTimer() + { + TRACES(qDebug() << "CHeartbeatTimer::StopTimer-Start"); + if (!IsActive()) { + TRACES(qDebug() << "CHeartbeatTimer::Timer is currently inactive"); + return; + } + TRACES(qDebug() << "iStatus:" << iStatus.Int()); + CFlexTimer::Cancel(); + TRACES(qDebug() << "CHeartbeatTimer::StopTimer-End"); + } + +void CHeartbeatTimer::ResetTimer() + { + TRACES(qDebug() << "CHeartbeatTimer::ResetTimer-Start"); + if (!IsActive()) { + TRACES(qDebug() << "CHeartbeatTimer::Timer is currently inactive"); + return; + } + TRACES(qDebug() << "iStatus:" << iStatus.Int()); + CFlexTimer::Cancel(); + CFlexTimer::After(m_interval); + TRACES(qDebug() << "CHeartbeatTimer::StopTimer-End"); + } diff --git a/src/systeminfo/symbian/HeartBeatTimer_s60.h b/src/systeminfo/symbian/HeartBeatTimer_s60.h new file mode 100644 index 0000000000..0caeed5201 --- /dev/null +++ b/src/systeminfo/symbian/HeartBeatTimer_s60.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HEARTBEATTIMER_S60_H +#define HEARTBEATTIMER_S60_H + +#include <e32base.h> +#include <e32std.h> +#include <e32property.h> +#include <QList> +#include "trace.h" +#include <flextimer.h> +#include <QObject> + +class MHeartBeatObserver +{ +public: + virtual void NotifyheartbeatReceived() = 0; +}; + +class CHeartbeatTimer : public CFlexTimer +{ +public: + static CHeartbeatTimer* NewL(); + ~CHeartbeatTimer(); + + void addObserver(MHeartBeatObserver *observer); + void removeObserver(MHeartBeatObserver *observer); + void StartTimer( TTimeIntervalMicroSeconds aWindow, TTimeIntervalMicroSeconds aInterval); + void setsingleShot(bool asingleShot); + void StopTimer(); + void ResetTimer(); + +protected: //from CActive + virtual void RunL(); + +private: + void ConstructL(); + CHeartbeatTimer(TInt aPriority); + +private: + bool m_singleShot; + TTimeIntervalMicroSeconds m_interval; + QList<MHeartBeatObserver *> m_observers; + /*The callback function which is called at the completion of flextimer server requests*/ + //TCallBack m_callback; +}; + + +#endif //HEARTBEATTIMER_S60_H diff --git a/src/systeminfo/systeminfo.pro b/src/systeminfo/systeminfo.pro index 46118d0059..ccc4d406ea 100644 --- a/src/systeminfo/systeminfo.pro +++ b/src/systeminfo/systeminfo.pro @@ -230,6 +230,19 @@ unix:!simulator { } else { LIBS += -lptiengine \ } + + contains(symbianflextimer_enabled,yes) { + message("SymbianFlexTimer enabled") + SOURCES += qsystemalignedtimer_symbian.cpp \ + heartbeattimer_s60.cpp + HEADERS += qsystemalignedtimer_symbian_p.h \ + heartbeattimer_s60.h + DEFINES += ALIGNEDTIMER_SYMBIAN + LIBS += -lflextimerclient + } else { + SOURCES += qsystemalignedtimer_stub.cpp + HEADERS += qsystemalignedtimer_stub_p.h + } INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE DEPENDPATH += symbian @@ -241,8 +254,7 @@ unix:!simulator { storagestatus_s60.cpp \ pubandsubkey_s60.cpp \ batterystatus_s60.cpp \ - networkinfo_s60.cpp \ - qsystemalignedtimer_stub.cpp + networkinfo_s60.cpp HEADERS += qsysteminfo_s60_p.h \ telephonyinfo_s60.h \ @@ -251,8 +263,7 @@ unix:!simulator { storagestatus_s60.h \ pubandsubkey_s60.h \ batterystatus_s60.h \ - networkinfo_s60.h \ - qsystemalignedtimer_stub_p.h + networkinfo_s60.h LIBS += -lprofileengine \ -letel3rdparty \ @@ -266,7 +277,6 @@ unix:!simulator { -lcone \ -lws32 \ -lcentralrepository \ - -lprofileengine \ -lbluetooth \ -lgdi \ -lecom \ |