Communication Ring Preview Functions Globals Table of Contents

Timer

Availability  LightWave® 9.5
Component  Layout
Header  lwtimer.h

Timers can be used to execute code at specified intervals.  This interface provides a means of creating one or more interval-based timer instances.

Global Call

   LWTimer *sdkTimer;
   sdkTimer = global( LWTIMER_GLOBAL, GFUSE_TRANSIENT );

The global function returns a pointer to an LWTimer structure.

    typedef struct st_LWTimer {
        void    (*timerAdd)(TimerEventProc proc,void *data,unsigned long interval);
        void    (*timerRemove)(TimerEventProc proc,unsigned long interval);
    } LWTimer;
      

Event Support

When creating a timer instance, you must provide a pointer to a callback function that will be invoked whenever the timer expires.  The function has the following prototype:

    typedef int (*TimerEventProc)(void *clientData);

The clientData pointer is the one provided to the timerAdd() function when the you create the instance.

Timers return an integer value of either 0 or 1.  This Boolean value indicates to the timer management system whether or not this particular timer instance should be implicitly removed from the timer list, and from further processing.  If a value of 1 is returned, then the timer is removed from the system, and a subsequent call to timerRemove() will not be required for this instance.

Exported Timer Functions

timerAdd( proc, data, interval )
Registers a new timer instance.  proc is a pointer to a function of type TimerEventProc.  The data pointer is instance data for this particular timer, and is user defined.  The interval value is interpreted as the number of milliseconds before each timer event expires, and the proc callback function is activated.
timerRemove( proc, interval )
A timer instance can be explicitly removed using this call.  Unless the timer instance has implicitly removed itself by returning 1, this call must be made for each instance created by timerAdd().  The proc pointer used in timerAdd() is used to identify the instance.  The interval value is considered optional, where a value of 0 will cause the first timer instance that uses proc as its event callback to be removed.  Otherwise, the instance that uses proc and interval will be removed.