WideStudio Logo
WideStudio
Programming Guide
WideStudio Index
Table of contents


How to use the timer

You can execute the procedure after an interval or in cycles.

The timer class Access function
WSDtimer WSGIappTimer()



How to execute the procedure after an interval

At first, prepare the procedure to execute, and register it to the timer as trigger driven.

The method Description
addTriggerProc() adds procedures as trigger driven
delTriggerProc() deletes a added procedures

#include "WSDtimer.h"
//the procedure which is executed by the timer ( trigger driven )
void triggerHandler(unsigned char clock,void* data){
   //The parameter: data is the third parameter 
   //               of the method: addTriggerProc().

   //To do:
}

void event_procedure(WSCbase* obj){
  //this parameter is passed to the procedure.
  void*  data = (void*)1234;
  //add the procedure to the timer (trigger driven)  //after 1000ms 
  long id = WSGIappTimer()->addTriggerProc( triggerHandler,WS1000MS,data );
  ...
  //if cancel...
  WSGIappTimer()->delTriggerProc( id );
}

You can implement the procedure you want in "triggerHandler()", and pass some data by the third parameter:void* of WSDtimer::addTriggerProc(). WSDtimer::addTriggerProc() returns a timer id. You can cancel the timer by the id with WSDtimer::delTriggerProc().

Notice: After executing the procedure, it will not update the instances automatically, so you have to do it yourself if needed.

//a sample of the trigger procedure.
void timerHandler(unsigned char clock,void* data){
   WSCbase* object = (WSCbase*)data;
   object->setProperty(WSNlabelString,"hello.");
   object->update(); //update the instance.
}



How to execute the procedure after in cycles

At first, prepare the procedure to execute, and register it to the timer as cycle driven.

The method Description
addTimerProc() adds procedures as cycle driven.
delTimerProc() deletes added procedure.

#include "WSDtimer.h"
//the procedure which is executed by the timer ( cycle driven )
void timerHandler(unsigned char clock,void* data){
   //clock is a counter of the interval of 250ms
   //The parameter: data is the third parameter of the method: addTimerProc().

   //To do:
}

void event_procedure(WSCbase* obj){
  //this parameter is passed to the procedure.
  void*  data = (void*)1234;
  //add the procedure to the timer (cycle driven)  //500ms interval
  long id = WSGIappTimer()->addTimerProc( timerHandler,WS500MS,data );
  ..
  //if cancel..
  WSGIappTimer()->delTimerProc( id );
}

You can implement the procedure you want in "timerHandler()", and pass some data by the third parameter:void* of WSDtimer::addTimerProc(). WSDtimer::addTimerProc() returns a timer id. You can cancel the timer by the id with WSDtimer::delTimerProc().

Notice: After executing the procedure, it will not update the instances automatically, so you have to do it yourself if needed.

The cycles: WS250MS,WS500MS,WS750,WS1000MS,WS1250MS,... (250ms interval)

//a sample of the timer procedure.
void timerHandler(unsigned char clock,void* data){
   WSCbase* object = (WSCbase*)data;
   object->setProperty(WSNlabelString,"Hello!");
   object->update(); //update the instance
}


Document Release 3.70 for WideStudio ver 3.70, May 2004


WideStudio documents index | Table of contents

Copyright(C) WideStudio Development Team, 1999-2004 Last modified: May 25, 2004