11.1.1 Definition of a new timer

To define a new timer, subclass this function and define []handle if needed ([]handle is not always required):

        class MyTimer : public TimerHandler {
        public:
          MyTimer(MyAgentClass *a) : TimerHandler() { a_ = a; }
          virtual double expire(Event *e);
        protected:
          MyAgentClass *a_;
        };
Then define expire:
        double
        MyTimer::expire(Event *e)
        {
          // do the work
          // return TIMER_HANDLED;    // =\> do not reschedule timer
          // return delay;            // =\> reschedule timer after delay
        }
Note that []expire can return either the flag TIMER_HANDLED or a delay value, depending on the requirements for this timer.

Often MyTimer will be a friend of MyAgentClass, or []expire will only call a public function of MyAgentClass.

Timers are not directly accessible from the OTcl level, although users are free to establish method bindings if they so desire.



Tom Henderson 2011-11-05