QmHeartbeat provides the system heartbeat service, which resembles a single-shot timer. More...
Public Types |
|
enum | SignalNeed { NoSignalNeeded = 0, SignalNeeded } |
Signal needs. More... |
|
enum | WaitMode { DoNotWaitHeartbeat = 0, WaitHeartbeat } |
Wait modes. More... |
|
Signals |
|
void | wakeUp (QTime time) |
Signaled when a heartbeat is received. To get the signal, use open() with the QmHeartbeat::SignalNeed mode. |
|
Public Member Functions |
|
QmHeartbeat (QObject *parent=0) | |
Constructor. |
|
~QmHeartbeat () | |
bool | open (QmHeartbeat::SignalNeed signalNeed) |
Opens the heartbeat service. |
|
void | close (void) |
Closes the heartbeat service. |
|
int | getFD () |
Gets the file descriptor for heartbeat (for use with QSocketNotifier). |
|
QTime | wait (unsigned short mintime, unsigned short maxtime, QmHeartbeat::WaitMode wait) |
Waits for the next heartbeat. |
|
bool | IWokeUp (void) |
This should be called when the application wakes up via other means than a heartbeat. |
|
Static Public Attributes |
|
static const unsigned short | WAKEUP_SLOT_30_SEC |
30 second wakeup slot |
|
static const unsigned short | WAKEUP_SLOT_2_5_MINS |
2.5 minute wakeup slot, the users of the previous slots wake here as well |
|
static const unsigned short | WAKEUP_SLOT_5_MINS |
5 minute wakeup slot, the users of the previous slots wake here as well |
|
static const unsigned short | WAKEUP_SLOT_10_MINS |
10 minute wakeup slot, the users of the previous slots wake here as well; you can use any multiplication of WAKEUP_SLOT_10_MINS, although it is recommended to use these predefined values |
|
static const unsigned short | WAKEUP_SLOT_30_MINS |
30 minute wakeup slot, the users of the previous slots wake here as well |
|
static const unsigned short | WAKEUP_SLOT_1_HOUR |
1 hour wakeup slot, the users of the previous slots wake here as well |
|
static const unsigned short | WAKEUP_SLOT_2_HOURS |
2 hours wakeup slot, the users of the previous slots wake here as well |
|
static const unsigned short | WAKEUP_SLOT_10_HOURS |
10 hours wakeup slot, the users of the previous slots wake here as well |
QmHeartbeat provides the system heartbeat service, which resembles a single-shot timer.
System heartbeat is a service for applications to synchronize their activities to save the battery use time.
The main idea is that applications that must do periodic activity – after being in sleep a certain period – do that at the same time: for example send network "alive" messages at the same time (for example turn the wireless radio on at the same time).
The service is not only for network-aware applications: in fact it must be used by any applications that need to periodic wake-ups.
It is preferable to use the predefined wait times. The system guarantees all waiters for a certain slot are woken up at the same time (also the lower-value waiters). For global sync predefined values (slots), see wait()
Note: the Qt Mobility System Information API provides the class QSystemAlignedTimer with similar functionality.
MeeGo::QmHeartbeat::QmHeartbeat | ( | QObject * | parent = 0 |
) |
Constructor.
parent | The parent object |
MeeGo::QmHeartbeat::~QmHeartbeat | ( | ) |
void MeeGo::QmHeartbeat::close | ( | void | ) |
Closes the heartbeat service.
int MeeGo::QmHeartbeat::getFD | ( | ) |
Gets the file descriptor for heartbeat (for use with QSocketNotifier).
bool MeeGo::QmHeartbeat::IWokeUp | ( | void | ) |
This should be called when the application wakes up via other means than a heartbeat.
Effectively cancels the next heartbeat. The wakeUp signal will not be signaled after calling this and a wait() call is needed for listening to the heartbeat again. Other applications that are in their wakeup window *may* be woken up.
bool MeeGo::QmHeartbeat::open | ( | QmHeartbeat::SignalNeed | signalNeed | ) |
Opens the heartbeat service.
signalNeed | True if wakeUp signal is to be used |
QTime MeeGo::QmHeartbeat::wait | ( | unsigned short | mintime, | |
unsigned short | maxtime, | |||
QmHeartbeat::WaitMode | wait | |||
) |
Waits for the next heartbeat.
The function supports non-blocking and blocking behavior: in the blocking mode (WaitHeartbeat) the function blocks until the timeout has occurred. In the non-blocking mode (DoNotWaitHeartbeat) the wakeUp() signal is emitted when the timeout has occurred. If the timeout has not occurred, subsequent wait() calls adjust the current wait time. If a continuous timer like behavior is needed, you can place a new wake-up with wait() when the wakeUp() signal is received.
mintime | Time in seconds that MUST be waited before heartbeat is reacted to. Value 0 means 'wake me up when someboy else is woken'. It is recommended that the first wait (if possible) uses minvalue as 0 to "jump to the train" | |
maxtime | Time in seconds when the wait MUST end. It is wise to have maxtime-mintime quite big so all users of this service get synced. For example if you preferred wait is 120 seconds, use minval 110 and maxval 130. It is also possible to use "global synchronization" by setting a WAKEUP_SLOT_* value to both mintime and maxtime (same value for both) - you will be waken up when the next proper slot is fired. | |
wait | WaitHeartbeat if this method waits for heartbeat, DoNotWaitHeartbeat if the wakeUp signal or file descriptor for QSocketNotifier is used |
void MeeGo::QmHeartbeat::wakeUp | ( | QTime | time | ) | [signal] |
Signaled when a heartbeat is received. To get the signal, use open() with the QmHeartbeat::SignalNeed mode.
time | The wakeup time |
const unsigned short MeeGo::QmHeartbeat::WAKEUP_SLOT_10_HOURS [static] |
10 hours wakeup slot, the users of the previous slots wake here as well
const unsigned short MeeGo::QmHeartbeat::WAKEUP_SLOT_10_MINS [static] |
10 minute wakeup slot, the users of the previous slots wake here as well; you can use any multiplication of WAKEUP_SLOT_10_MINS, although it is recommended to use these predefined values
const unsigned short MeeGo::QmHeartbeat::WAKEUP_SLOT_1_HOUR [static] |
1 hour wakeup slot, the users of the previous slots wake here as well
const unsigned short MeeGo::QmHeartbeat::WAKEUP_SLOT_2_5_MINS [static] |
2.5 minute wakeup slot, the users of the previous slots wake here as well
const unsigned short MeeGo::QmHeartbeat::WAKEUP_SLOT_2_HOURS [static] |
2 hours wakeup slot, the users of the previous slots wake here as well
const unsigned short MeeGo::QmHeartbeat::WAKEUP_SLOT_30_MINS [static] |
30 minute wakeup slot, the users of the previous slots wake here as well
const unsigned short MeeGo::QmHeartbeat::WAKEUP_SLOT_30_SEC [static] |
30 second wakeup slot
const unsigned short MeeGo::QmHeartbeat::WAKEUP_SLOT_5_MINS [static] |
5 minute wakeup slot, the users of the previous slots wake here as well
(C) 2009-2011 Nokia Corporation LGPL Lesser General Public License |
MeeGo 1.2 Harmattan API
|