Linux Face / QPFramework
Embed: (wiki syntax)

« Back to documentation index

QTimeEvt Class Reference

QTimeEvt Class Reference

Time Event class. More...

#include <qf.h>

Inherits QEvent.

Public Member Functions

 QTimeEvt (QSignal s)
 The Time Event constructor.
void postIn (QActive *act, QTimeEvtCtr nTicks)
 Arm a one-shot time event for direct event posting.
void postEvery (QActive *act, QTimeEvtCtr nTicks)
 Arm a periodic time event for direct event posting.
uint8_t disarm (void)
 Disarm a time event.
uint8_t rearm (QTimeEvtCtr nTicks)
 Rearm a time event.
void fireIn (QActive *act, QTimeEvtCtr nTicks)
 Arm a one-shot time event for direct event posting (obsolete).
void fireEvery (QActive *act, QTimeEvtCtr nTicks)
 Arm a periodic time event for direct event posting (obsolete).

Data Fields

QSignal sig
 signal of the event instance
uint8_t dynamic_
 attributes of a dynamic event (0 for static event)

Friends

class QF

Detailed Description

Time Event class.

Time events are special QF events equipped with the notion of time passage. The basic usage model of the time events is as follows. An active object allocates one or more QTimeEvt objects (provides the storage for them). When the active object needs to arrange for a timeout, it arms one of its time events to fire either just once (one-shot) or periodically. Each time event times out independently from the others, so a QF application can make multiple parallel timeout requests (from the same or different active objects). When QF detects that the appropriate moment has arrived, it inserts the time event directly into the recipient's event queue. The recipient then processes the time event just like any other event.

Time events, as any other QF events derive from the QEvent base class. Typically, you will use a time event as-is, but you can also further derive more specialized time events from it by adding some more data members and/or specialized functions that operate on the specialized time events.

Internally, the armed time events are organized into a bi-directional linked list. This linked list is scanned in every invocation of the QF::tick() function. Only armed (timing out) time events are in the list, so only armed time events consume CPU cycles.

Note:
QF manages the time events in the function QF::tick(), which must be called periodically, preferably from the clock tick ISR.
In this version of QF QTimeEvt objects should be allocated statically rather than dynamically from event pools. Currently, QF will not correctly recycle the dynamically allocated Time Events.

Definition at line 437 of file qf.h.


Constructor & Destructor Documentation

QTimeEvt ( QSignal  s )

The Time Event constructor.

The most important initialization performed in the constructor is assigning a signal to the Time Event. You can reuse the Time Event any number of times, but you cannot change the signal. This is because pointers to Time Events might still be held in event queues and changing signal could to hard-to-detect errors.

The following example shows the use of QTimeEvt::QTimeEvt() constructor in the constructor initializer list of the Philosopher active object constructor that owns the time event


Member Function Documentation

uint8_t disarm ( void   )

Disarm a time event.

The time event gets disarmed and can be reused. The function returns 1 (TRUE) if the time event was truly disarmed, that is, it was running. The return of 0 (FALSE) means that the time event was not truly disarmed because it was not running. The FALSE return is only possible for one-shot time events that have been automatically disarmed upon expiration. In this case the FALSE return means that the time event has already been posted or published and should be expected in the active object's state machine.

Definition at line 36 of file qte_darm.cpp.

void fireEvery ( QActive act,
QTimeEvtCtr  nTicks 
)

Arm a periodic time event for direct event posting (obsolete).

This facility is now obsolete, please use

See also:
QTimeEvt::postEvery().

Definition at line 565 of file qf.h.

void fireIn ( QActive act,
QTimeEvtCtr  nTicks 
)

Arm a one-shot time event for direct event posting (obsolete).

This facility is now obsolete, please use

See also:
QTimeEvt::postIn().

Definition at line 558 of file qf.h.

void postEvery ( QActive act,
QTimeEvtCtr  nTicks 
)

Arm a periodic time event for direct event posting.

Arms a time event to fire every nTicks clock ticks (periodic time event). The time event gets directly posted (using the FIFO policy) into the event queue of the active object act.

After posting, the time event gets automatically re-armed to fire again in the specified nTicks clock ticks.

A periodic time event can be disarmed only by calling the QTimeEvt::disarm() function. After disarming, the time event can be reused for a one-shot or periodic timeout requests.

Note:
An attempt to reuse (arm again) a running periodic time event raises an assertion.

Also, a periodic time event can be re-armed to shorten or extend the current period by calling the QTimeEvt_rearm() function. After adjusting the current period, the periodic time event goes back timing out at the original rate.

Definition at line 518 of file qf.h.

void postIn ( QActive act,
QTimeEvtCtr  nTicks 
)

Arm a one-shot time event for direct event posting.

Arms a time event to fire in nTicks clock ticks (one-shot time event). The time event gets directly posted (using the FIFO policy) into the event queue of the active object act.

After posting, the time event gets automatically disarmed and can be reused for a one-shot or periodic timeout requests.

A one-shot time event can be disarmed at any time by calling the QTimeEvt::disarm() function. Also, a one-shot time event can be re-armed to fire in a different number of clock ticks by calling the QTimeEvt::rearm() function.

The following example shows how to arm a one-shot time event from a state machine of an active object:

Definition at line 493 of file qf.h.

uint8_t rearm ( QTimeEvtCtr  nTicks )

Rearm a time event.

The time event gets rearmed with a new number of clock ticks nTicks. This facility can be used to prevent a one-shot time event from expiring (e.g., a watchdog time event), or to adjusts the current period of a periodic time event. Rearming a periodic timer leaves the interval unchanged and is a convenient method to adjust the phasing of the periodic time event.

The function returns 1 (TRUE) if the time event was running as it was re-armed. The return of 0 (FALSE) means that the time event was not truly rearmed because it was not running. The FALSE return is only possible for one-shot time events that have been automatically disarmed upon expiration. In this case the FALSE return means that the time event has already been posted or published and should be expected in the active object's state machine.


Field Documentation

uint8_t dynamic_ [inherited]

attributes of a dynamic event (0 for static event)

Definition at line 141 of file qevent.h.

QSignal sig [inherited]

signal of the event instance

Definition at line 140 of file qevent.h.