MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

MeeGo::QmHeartbeat Class Reference

QmHeartbeat provides the system heartbeat service, which resembles a single-shot timer. More...

Inheritance diagram for MeeGo::QmHeartbeat:
Inheritance graph
[legend]
Collaboration diagram for MeeGo::QmHeartbeat:
Collaboration graph
[legend]

List of all members.

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

Detailed Description

QmHeartbeat provides the system heartbeat service, which resembles a single-shot timer.

Scope:
Nokia Meego

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.


Member Enumeration Documentation

Signal needs.

Enumerator:
NoSignalNeeded 

No signal needed.

SignalNeeded 

Signal is needed.

Wait modes.

Enumerator:
DoNotWaitHeartbeat 

Do not wait for heart beat, use the wakeUp signal instead.

WaitHeartbeat 

Wait for heart beat.


Constructor & Destructor Documentation

MeeGo::QmHeartbeat::QmHeartbeat ( QObject parent = 0  ) 

Constructor.

Parameters:
parent  The parent object
MeeGo::QmHeartbeat::~QmHeartbeat (  ) 

Member Function Documentation

void MeeGo::QmHeartbeat::close ( void   ) 

Closes the heartbeat service.

int MeeGo::QmHeartbeat::getFD (  ) 

Gets the file descriptor for heartbeat (for use with QSocketNotifier).

Returns:
Descriptor that can be used for QSocketNotifier, -1 if error (check errno)
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.

Returns:
True if success, false if error
bool MeeGo::QmHeartbeat::open ( QmHeartbeat::SignalNeed  signalNeed  ) 

Opens the heartbeat service.

Parameters:
signalNeed  True if wakeUp signal is to be used
Returns:
True if success
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.

Parameters:
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
Returns:
Time waited
void MeeGo::QmHeartbeat::wakeUp ( QTime  time  )  [signal]

Signaled when a heartbeat is received. To get the signal, use open() with the QmHeartbeat::SignalNeed mode.

Parameters:
time  The wakeup time

Member Data Documentation

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