Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PTimer Class Reference

#include <timer.h>

Inheritance diagram for PTimer:

PTimeInterval PObject

List of all members.

Detailed Description

A class representing a system timer. The time interval ancestor value is the amount of time left in the timer.

A timer on completion calls the virtual function OnTimeout()#. This will in turn call the callback function provided by the instance. The user may either override the virtual function or set a callback as desired.

A list of active timers is maintained by the applications PProcess# instance and the timeout functions are executed in the context of a single thread of execution. There are many consequences of this: only one timeout function can be executed at a time and thus a user should not execute a lot of code in the timeout call-back functions or it will dealy the timely execution of other timers call-back functions.

Also timers are not very accurate in sub-second delays, even though you can set the timer in milliseconds, its accuracy is only to -0/+250 ms. Even more (potentially MUCH more) if there are delays in the user call-back functions.

Another trap is you cannot destroy a timer in its own call-back. There is code to cause an assert if you try but it is very easy to accidentally do this when you delete an object that contains an onject that contains the timer!

Finally static timers cause race conditions on start up and termination and should be avoided.

Definition at line 163 of file timer.h.

Conversion functions

PString AsString (int decimals=3, Formats format=NormalFormat, int width=1) const
enum  Formats { NormalFormat, IncludeDays, SecondsOnly }

Comparison functions

virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
bool operator!= (const PObject &obj) const
bool operator< (const PObject &obj) const
bool operator<= (const PObject &obj) const
bool operator== (const PObject &obj) const
bool operator> (const PObject &obj) const
bool operator>= (const PObject &obj) const
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }

Run Time Type functions

virtual const char * GetClass (unsigned=0) const
virtual BOOL InternalIsDescendant (const char *clsName) const
BOOL IsClass (const char *cls) const
static const char * Class ()

Public Member Functions

Overrides from class PObject
PObjectClone () const
virtual Comparison Compare (const PObject &obj) const
virtual void PrintOn (ostream &strm) const
virtual void ReadFrom (istream &strm)
Access functions
int GetDays () const
int GetHours () const
DWORD GetInterval () const
PInt64 GetMilliSeconds () const
long GetMinutes () const
long GetSeconds () const
Notification functions
const PNotifierGetNotifier () const
virtual void OnTimeout ()
void SetNotifier (const PNotifier &func)
Control functions
const PTimeIntervalGetResetTime () const
BOOL IsPaused () const
BOOL IsRunning () const
void Pause ()
void Reset ()
void Resume ()
void RunContinuous (const PTimeInterval &time)
virtual void SetInterval (PInt64 milliseconds=0, long seconds=0, long minutes=0, long hours=0, int days=0)
void Stop ()
Miscellaneous functions
virtual PINDEX HashFunction () const
Comparison functions
bool operator!= (long msecs) const
bool operator!= (const PTimeInterval &interval) const
bool operator< (long msecs) const
bool operator< (const PTimeInterval &interval) const
bool operator<= (long msecs) const
bool operator<= (const PTimeInterval &interval) const
bool operator== (long msecs) const
bool operator== (const PTimeInterval &interval) const
bool operator> (long msecs) const
bool operator> (const PTimeInterval &interval) const
bool operator>= (long msecs) const
bool operator>= (const PTimeInterval &interval) const
PTimeInterval operator* (int factor) const
PTimeIntervaloperator*= (int factor)
PTimeInterval operator+ (const PTimeInterval &interval) const
PTimeIntervaloperator+= (const PTimeInterval &interval)
PTimeInterval operator- (const PTimeInterval &interval) const
PTimeInterval operator- () const
PTimeIntervaloperator-= (const PTimeInterval &interval)
PTimeInterval operator/ (int factor) const
PTimeIntervaloperator/= (int factor)
PTimeroperator= (const PTimeInterval &time)
PTimeroperator= (DWORD milliseconds)
 PTimer (const PTimeInterval &time)
 PTimer (long milliseconds=0, int seconds=0, int minutes=0, int hours=0, int days=0)
virtual ~PTimer ()

Static Public Member Functions

Global real time functions
static unsigned Resolution ()
static PTimeInterval Tick ()

Protected Attributes

PInt64 milliseconds
 Number of milliseconds in time interval.

Private Types

enum  { Stopped, Starting, Running, Paused }

Private Member Functions

void Construct ()
 PCLASSINFO (PTimer, PTimeInterval)
void Process (const PTimeInterval &delta, PTimeInterval &minTimeLeft)
void StartRunning (BOOL once)

Private Attributes

PNotifier callback
BOOL oneshot
PTimeInterval resetTime
enum PTimer:: { ... }  state
class PTimerList * timerList


class PTimerList
I/O functions
ostream & operator<< (ostream &strm, const PObject &obj)
istream & operator>> (istream &strm, PObject &obj)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index