00001 #include "ut_abs_timer_qt_pure.hpp" 00002 00003 #include "common/assertions.h" 00004 00005 #include <limits.h> 00006 00007 #include <QtDebug> 00008 00009 QAbsTimer::QAbsTimer(QObject *parent) : 00010 QObject(parent) 00011 { 00012 iTimerAo.setSingleShot(true); 00013 connect(&iTimerAo, SIGNAL(timeout()), 00014 this, SLOT(handleTimeout())); 00015 } 00016 00017 QAbsTimer::~QAbsTimer() 00018 { 00019 } 00020 00021 bool QAbsTimer::isActive() const 00022 { 00023 return iTimerAo.isActive(); 00024 } 00025 00026 void QAbsTimer::start(const QDateTime& aExpTime) 00027 { 00028 iExpTime = aExpTime; 00029 startOrSignal(); 00030 } 00031 00032 void QAbsTimer::startOrSignal() 00033 { 00034 QDateTime now = QDateTime::currentDateTimeUtc(); 00035 if (now >= iExpTime) { 00036 emit timeout(); 00037 } else { 00038 qint64 diff = now.msecsTo(iExpTime); 00039 assert(diff > 0); 00040 00041 //qDebug() << "timer expiration msecs from now" << diff; 00042 int diffInt = qBound((qint64)0, diff, (qint64)INT_MAX); 00043 //qDebug() << "timer expiration msecs from now" << diffInt; 00044 00045 // The argument is also in msec, but the problem is that the int 00046 // type is narrower, and hence we must make sure that it is not 00047 // too large. 00048 iTimerAo.start(diffInt); 00049 } 00050 } 00051 00052 void QAbsTimer::stop() 00053 { 00054 iTimerAo.stop(); 00055 } 00056 00057 void QAbsTimer::handleTimeout() 00058 { 00059 startOrSignal(); 00060 } 00061 00062 /** 00063 00064 Copyright 2010 Helsinki Institute for Information Technology (HIIT) 00065 and the authors. All rights reserved. 00066 00067 Authors: Tero Hasu <tero.hasu@hut.fi> 00068 00069 Permission is hereby granted, free of charge, to any person 00070 obtaining a copy of this software and associated documentation files 00071 (the "Software"), to deal in the Software without restriction, 00072 including without limitation the rights to use, copy, modify, merge, 00073 publish, distribute, sublicense, and/or sell copies of the Software, 00074 and to permit persons to whom the Software is furnished to do so, 00075 subject to the following conditions: 00076 00077 The above copyright notice and this permission notice shall be 00078 included in all copies or substantial portions of the Software. 00079 00080 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00081 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00082 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00083 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00084 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00085 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00086 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00087 SOFTWARE. 00088 00089 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1