class PTimer: public PTimeInterval

A class representing a system timer.

Inheritance:


Public

[more] Construction
[more] Control functions
[more] Notification functions
[more] Global real time functions


Inherited from PTimeInterval:

Public

Overrides from class PObject

Access functions

Operations

Comparison functions

Protected Fields

oPInt64 milliseconds


Inherited from PObject:

Public

Run Time Type functions

I/O functions

Miscellaneous functions


Documentation

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.

Note that only one timeout function can be executed at a time. The timeout function is also executed in the context of the PProcess instances thread of execution.

A list of active timers is maintained by the applications PProcess instance. This is used for sstealing the processor time to decrement the timers and call the timeout functions. A consequence of this is that no static timer instances can be running when the program terminates.

o Construction

o PTimer( long milliseconds = 0, int seconds = 0, int minutes = 0, int hours = 0, int days = 0 )
Create a new timer object and start it in one shot mode for the specified amount of time. If the time was zero milliseconds then the timer is not started, ie the callback function is not executed immediately.
Parameters:
milliseconds - Number of milliseconds for timer.
seconds - Number of seconds for timer.
minutes - Number of minutes for timer.
hours - Number of hours for timer.
days - Number of days for timer.

oPTimer& operator=( DWORD milliseconds )
Restart the timer in one shot mode using the specified time value. If the timer was already running, the "time left" is simply reset.

Returns:
reference to the timer.
Parameters:
milliseconds - New time interval for timer.

ovirtual ~PTimer()
Destroy the timer object, removing it from the applications timer list if it was running

o Control functions

ovoid RunContinuous( const PTimeInterval & time )
Start a timer in continous cycle mode. Whenever the timer runs out it is automatically reset to the time specified. Thus, it calls the notification function every time interval.

ovoid Stop()
Stop a running timer. The imer will not call the notification function and is reset back to the original timer value. Thus when the timer is restarted it begins again from the beginning.

oBOOL IsRunning() const
Determine if the timer is currently running. This really is only useful for one shot timers as repeating timers are always running.

Returns:
TRUE if timer is still counting.

ovoid Pause()
Pause a running timer. This differs from the Stop() function in that the timer may be resumed at the point that it left off. That is time is "frozen" while the timer is paused.

ovoid Resume()
Restart a paused timer continuing at the time it was paused. The time left at the moment the timer was paused is the time until the next call to the notification function.

oBOOL IsPaused() const
Determine if the timer is currently paused.

Returns:
TRUE if timer paused.

o Notification functions

ovirtual void OnTimeout()
This function is called on time out. That is when the system timer processing decrements the timer from a positive value to less than or equal to zero. The interval is then reset to zero and the function called.

The default behaviour of this function is to call the PNotifier callback function.

oconst PNotifier& GetNotifier() const
Get the current call back function that is called whenever the timer expires. This is called by the OnTimeout() function.

Returns:
current notifier for the timer.

ovoid SetNotifier( const PNotifier & func )
Set the call back function that is called whenever the timer expires. This is called by the OnTimeout() function.

o Global real time functions

ostatic PTimeInterval Tick()
Get the number of milliseconds since some arbtrary point in time. This is a platform dependent function that yields a real time counter.

Note that even though this function returns milliseconds, the value may jump in minimum quanta according the platforms timer system, eg under MS-DOS and MS-Windows the values jump by 55 every 55 milliseconds. The Resolution() function may be used to determine what the minimum time interval is.

Returns:
millisecond counter.

ostatic unsigned Resolution()
Get the smallest number of milliseconds that the timer can be set to. All actual timing events will be rounded up to the next value. This is typically the platforms internal timing units used in the Tick() function.

Returns:
minimum number of milliseconds per timer "tick".


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.