-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,7 +1,7 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
@@ -194,6 +194,8 @@ void TimerReceiverObject::resetTimer() | |||
194 | int total_written; | 194 | int total_written; |
195 | QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime); | 195 | QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime); |
196 | QDateTime now = QDateTime::currentDateTime(); | 196 | QDateTime now = QDateTime::currentDateTime(); |
197 | if ( nearest < now ) | ||
198 | nearest = now; | ||
197 | int secs = TimeConversion::secsTo( now, nearest ); | 199 | int secs = TimeConversion::secsTo( now, nearest ); |
198 | if ( secs > maxsecs ) { | 200 | if ( secs > maxsecs ) { |
199 | // too far for millisecond timing | 201 | // too far for millisecond timing |
@@ -245,10 +247,12 @@ void TimerReceiverObject::timerEvent( QTimerEvent * ) | |||
245 | if (nearestTimerEvent) { | 247 | if (nearestTimerEvent) { |
246 | if ( nearestTimerEvent->UTCtime | 248 | if ( nearestTimerEvent->UTCtime |
247 | <= TimeConversion::toUTC(QDateTime::currentDateTime()) ) { | 249 | <= TimeConversion::toUTC(QDateTime::currentDateTime()) ) { |
250 | #ifndef QT_NO_COP | ||
248 | QCopEnvelope e( nearestTimerEvent->channel, | 251 | QCopEnvelope e( nearestTimerEvent->channel, |
249 | nearestTimerEvent->message ); | 252 | nearestTimerEvent->message ); |
250 | e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime ) | 253 | e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime ) |
251 | << nearestTimerEvent->data; | 254 | << nearestTimerEvent->data; |
255 | #endif | ||
252 | timerEventList.remove( nearestTimerEvent ); | 256 | timerEventList.remove( nearestTimerEvent ); |
253 | needSave = TRUE; | 257 | needSave = TRUE; |
254 | } | 258 | } |
@@ -262,16 +266,31 @@ void TimerReceiverObject::timerEvent( QTimerEvent * ) | |||
262 | 266 | ||
263 | /*! | 267 | /*! |
264 | \class AlarmServer alarmserver.h | 268 | \class AlarmServer alarmserver.h |
265 | \brief The AlarmServer class provides alarms to be scheduled. | 269 | \brief The AlarmServer class allows alarms to be scheduled and unscheduled. |
270 | |||
271 | Applications can schedule alarms with addAlarm() and can | ||
272 | unschedule alarms with deleteAlarm(). When the time for an alarm | ||
273 | to go off is reached the specified \link qcop.html QCop\endlink | ||
274 | message is sent on the specified channel (optionally with | ||
275 | additional data). | ||
276 | |||
277 | Scheduling an alarm using this class is important (rather just using | ||
278 | a QTimer) since the machine may be asleep and needs to get woken up using | ||
279 | the Linux kernel which implements this at the kernel level to minimize | ||
280 | battery usage while asleep. | ||
266 | 281 | ||
267 | Applications which wish to be informed when a certain time instant | 282 | \ingroup qtopiaemb |
268 | passes use the functions of AlarmServer to request so. | 283 | \sa QCopEnvelope |
269 | */ | 284 | */ |
270 | 285 | ||
271 | /*! | 286 | /*! |
272 | Schedules an alarm for \a when. Soon after this time, | 287 | Schedules an alarm to go off at (or soon after) time \a when. When |
273 | \a message will be sent to \a channel, with \a data as | 288 | the alarm goes off, the \link qcop.html QCop\endlink \a message will |
274 | a parameter. \a message must be of the form "someMessage(int)". | 289 | be sent to \a channel, with \a data as a parameter. |
290 | |||
291 | If this function is called with exactly the same data as a previous | ||
292 | call the subsequent call is ignored, so there is only ever one alarm | ||
293 | with a given set of parameters. | ||
275 | 294 | ||
276 | \sa deleteAlarm() | 295 | \sa deleteAlarm() |
277 | */ | 296 | */ |
@@ -312,19 +331,25 @@ void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, | |||
312 | if ( needSave ) | 331 | if ( needSave ) |
313 | saveState(); | 332 | saveState(); |
314 | } else { | 333 | } else { |
334 | #ifndef QT_NO_COP | ||
315 | QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" ); | 335 | QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" ); |
316 | e << when << channel << message << data; | 336 | e << when << channel << message << data; |
337 | #endif | ||
317 | } | 338 | } |
318 | } | 339 | } |
319 | 340 | ||
320 | /*! | 341 | /*! |
321 | Deletes previously scheduled alarms which match \a when, \a channel, \a message, | 342 | Deletes previously scheduled alarms which match \a when, \a channel, |
322 | and \a data. | 343 | \a message, and \a data. |
323 | 344 | ||
324 | Passing null values for \a when, \a channel, or \a message indicates "any". | 345 | Passing null values for \a when, \a channel, or for the \link |
325 | Passing -1 for \a data indicates "any". | 346 | qcop.html QCop\endlink \a message, acts as a wildcard meaning "any". |
347 | Similarly, passing -1 for \a data indicates "any". | ||
348 | |||
349 | If there is no matching alarm, nothing happens. | ||
350 | |||
351 | \sa addAlarm() | ||
326 | 352 | ||
327 | \sa deleteAlarm() | ||
328 | */ | 353 | */ |
329 | void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data) | 354 | void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data) |
330 | { | 355 | { |
@@ -359,8 +384,10 @@ void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QC | |||
359 | if ( needSave ) | 384 | if ( needSave ) |
360 | saveState(); | 385 | saveState(); |
361 | } else { | 386 | } else { |
387 | #ifndef QT_NO_COP | ||
362 | QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" ); | 388 | QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" ); |
363 | e << when << channel << message << data; | 389 | e << when << channel << message << data; |
390 | #endif | ||
364 | } | 391 | } |
365 | } | 392 | } |
366 | 393 | ||