author | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
commit | 6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4 (patch) (side-by-side diff) | |
tree | 6ebc93c6432f4ed9d00ef1448b6a047ef522a79a /library/alarmserver.cpp | |
parent | d10cddb3c9ce75bc90b14add14bc133737fe35aa (diff) | |
download | opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.zip opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.gz opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.bz2 |
Qtopia1-6 merge
still to test
bic changes to be resolved
more changes to be made?
-rw-r--r-- | library/alarmserver.cpp | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp index a1a7142..1ee05c6 100644 --- a/library/alarmserver.cpp +++ b/library/alarmserver.cpp @@ -1,20 +1,20 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ @@ -181,32 +181,34 @@ static bool triggerAtd( bool writeHWClock = FALSE ) void TimerReceiverObject::deleteTimer() { if ( !atfilename.isEmpty() ) { unlink( atfilename ); atfilename = QString::null; triggerAtd( FALSE ); } } void TimerReceiverObject::resetTimer() { const int maxsecs = 2147000; int total_written; QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime); QDateTime now = QDateTime::currentDateTime(); + if ( nearest < now ) + nearest = now; int secs = TimeConversion::secsTo( now, nearest ); if ( secs > maxsecs ) { // too far for millisecond timing secs = maxsecs; } // System timer (needed so that we wake from deep sleep), // from the Epoch in seconds. // int at_secs = TimeConversion::toUTC(nearest); // qDebug("reset timer to %d seconds from Epoch",at_secs); QString fn = atdir + QString::number(at_secs) + "." + QString::number(getpid()); if ( fn != atfilename ) { QFile atfile(fn+".new"); if ( atfile.open(IO_WriteOnly|IO_Raw) ) { @@ -232,59 +234,76 @@ void TimerReceiverObject::resetTimer() } } // Qt timers (does the actual alarm) // from now in milliseconds // qDebug("AlarmServer waiting %d seconds",secs); startTimer( 1000 * secs + 500 ); } void TimerReceiverObject::timerEvent( QTimerEvent * ) { bool needSave = FALSE; killTimers(); if (nearestTimerEvent) { if ( nearestTimerEvent->UTCtime <= TimeConversion::toUTC(QDateTime::currentDateTime()) ) { +#ifndef QT_NO_COP QCopEnvelope e( nearestTimerEvent->channel, nearestTimerEvent->message ); e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime ) << nearestTimerEvent->data; +#endif timerEventList.remove( nearestTimerEvent ); needSave = TRUE; } setNearestTimerEvent(); } else { resetTimer(); } if ( needSave ) saveState(); } /*! \class AlarmServer alarmserver.h - \brief The AlarmServer class provides alarms to be scheduled. + \brief The AlarmServer class allows alarms to be scheduled and unscheduled. + + Applications can schedule alarms with addAlarm() and can + unschedule alarms with deleteAlarm(). When the time for an alarm + to go off is reached the specified \link qcop.html QCop\endlink + message is sent on the specified channel (optionally with + additional data). + + Scheduling an alarm using this class is important (rather just using + a QTimer) since the machine may be asleep and needs to get woken up using + the Linux kernel which implements this at the kernel level to minimize + battery usage while asleep. - Applications which wish to be informed when a certain time instant - passes use the functions of AlarmServer to request so. + \ingroup qtopiaemb + \sa QCopEnvelope */ /*! - Schedules an alarm for \a when. Soon after this time, - \a message will be sent to \a channel, with \a data as - a parameter. \a message must be of the form "someMessage(int)". + Schedules an alarm to go off at (or soon after) time \a when. When + the alarm goes off, the \link qcop.html QCop\endlink \a message will + be sent to \a channel, with \a data as a parameter. + + If this function is called with exactly the same data as a previous + call the subsequent call is ignored, so there is only ever one alarm + with a given set of parameters. \sa deleteAlarm() */ void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, const QCString& message, int data) { if ( qApp->type() == QApplication::GuiServer ) { bool needSave = FALSE; // Here we are the server so either it has been directly called from // within the server or it has been sent to us from a client via QCop if (!timerEventReceiver) timerEventReceiver = new TimerReceiverObject; timerEventItem *newTimerEventItem = new timerEventItem; newTimerEventItem->UTCtime = TimeConversion::toUTC( when ); newTimerEventItem->channel = channel; @@ -299,45 +318,51 @@ void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, timerEventList.append( newTimerEventItem ); needSave = TRUE; // quicker than using setNearestTimerEvent() if ( nearestTimerEvent ) { if (newTimerEventItem->UTCtime < nearestTimerEvent->UTCtime) { nearestTimerEvent = newTimerEventItem; timerEventReceiver->killTimers(); timerEventReceiver->resetTimer(); } } else { nearestTimerEvent = newTimerEventItem; timerEventReceiver->resetTimer(); } if ( needSave ) saveState(); } else { +#ifndef QT_NO_COP QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" ); e << when << channel << message << data; +#endif } } /*! - Deletes previously scheduled alarms which match \a when, \a channel, \a message, - and \a data. + Deletes previously scheduled alarms which match \a when, \a channel, + \a message, and \a data. - Passing null values for \a when, \a channel, or \a message indicates "any". - Passing -1 for \a data indicates "any". + Passing null values for \a when, \a channel, or for the \link + qcop.html QCop\endlink \a message, acts as a wildcard meaning "any". + Similarly, passing -1 for \a data indicates "any". + + If there is no matching alarm, nothing happens. + + \sa addAlarm() - \sa deleteAlarm() */ void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data) { if ( qApp->type() == QApplication::GuiServer) { bool needSave = FALSE; if ( timerEventReceiver != NULL ) { timerEventReceiver->killTimers(); // iterate over the list of events QListIterator<timerEventItem> it( timerEventList ); time_t deleteTime = TimeConversion::toUTC( when ); for ( ; *it; ++it ) { // if its a match, delete it if ( ( (*it)->UTCtime == deleteTime || when.isNull() ) && ( channel.isNull() || (*it)->channel == channel ) && ( message.isNull() || (*it)->message == message ) @@ -346,31 +371,33 @@ void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QC // if it's first, then we need to update the timer if ( (*it) == nearestTimerEvent ) { timerEventList.remove(*it); setNearestTimerEvent(); } else { timerEventList.remove(*it); } needSave = TRUE; } } if ( nearestTimerEvent ) timerEventReceiver->resetTimer(); } if ( needSave ) saveState(); } else { +#ifndef QT_NO_COP QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" ); e << when << channel << message << data; +#endif } } /*! Writes the system clock to the hardware clock. */ void Global::writeHWClock() { if ( !triggerAtd( TRUE ) ) { // atd not running? set it ourselves system("/sbin/hwclock --systohc"); // ##### UTC? } } |