-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,12 +1,12 @@ | |||
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 |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
@@ -189,16 +189,18 @@ void TimerReceiverObject::deleteTimer() | |||
189 | } | 189 | } |
190 | 190 | ||
191 | void TimerReceiverObject::resetTimer() | 191 | void TimerReceiverObject::resetTimer() |
192 | { | 192 | { |
193 | const int maxsecs = 2147000; | 193 | const int maxsecs = 2147000; |
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 |
200 | secs = maxsecs; | 202 | secs = maxsecs; |
201 | } | 203 | } |
202 | 204 | ||
203 | // System timer (needed so that we wake from deep sleep), | 205 | // System timer (needed so that we wake from deep sleep), |
204 | // from the Epoch in seconds. | 206 | // from the Epoch in seconds. |
@@ -240,43 +242,60 @@ void TimerReceiverObject::resetTimer() | |||
240 | 242 | ||
241 | void TimerReceiverObject::timerEvent( QTimerEvent * ) | 243 | void TimerReceiverObject::timerEvent( QTimerEvent * ) |
242 | { | 244 | { |
243 | bool needSave = FALSE; | 245 | bool needSave = FALSE; |
244 | killTimers(); | 246 | killTimers(); |
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 | } |
255 | setNearestTimerEvent(); | 259 | setNearestTimerEvent(); |
256 | } else { | 260 | } else { |
257 | resetTimer(); | 261 | resetTimer(); |
258 | } | 262 | } |
259 | if ( needSave ) | 263 | if ( needSave ) |
260 | saveState(); | 264 | saveState(); |
261 | } | 265 | } |
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 | */ |
278 | void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, | 297 | void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, |
279 | const QCString& message, int data) | 298 | const QCString& message, int data) |
280 | { | 299 | { |
281 | if ( qApp->type() == QApplication::GuiServer ) { | 300 | if ( qApp->type() == QApplication::GuiServer ) { |
282 | bool needSave = FALSE; | 301 | bool needSave = FALSE; |
@@ -307,29 +326,35 @@ void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, | |||
307 | } | 326 | } |
308 | } else { | 327 | } else { |
309 | nearestTimerEvent = newTimerEventItem; | 328 | nearestTimerEvent = newTimerEventItem; |
310 | timerEventReceiver->resetTimer(); | 329 | timerEventReceiver->resetTimer(); |
311 | } | 330 | } |
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 | { |
331 | if ( qApp->type() == QApplication::GuiServer) { | 356 | if ( qApp->type() == QApplication::GuiServer) { |
332 | bool needSave = FALSE; | 357 | bool needSave = FALSE; |
333 | if ( timerEventReceiver != NULL ) { | 358 | if ( timerEventReceiver != NULL ) { |
334 | timerEventReceiver->killTimers(); | 359 | timerEventReceiver->killTimers(); |
335 | 360 | ||
@@ -354,18 +379,20 @@ void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QC | |||
354 | } | 379 | } |
355 | } | 380 | } |
356 | if ( nearestTimerEvent ) | 381 | if ( nearestTimerEvent ) |
357 | timerEventReceiver->resetTimer(); | 382 | timerEventReceiver->resetTimer(); |
358 | } | 383 | } |
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 | ||
367 | /*! | 394 | /*! |
368 | Writes the system clock to the hardware clock. | 395 | Writes the system clock to the hardware clock. |
369 | */ | 396 | */ |
370 | void Global::writeHWClock() | 397 | void Global::writeHWClock() |
371 | { | 398 | { |