next up previous contents index
Next: 10.1.2 Example: Tcp retransmission Up: 10.1 C++ abstract base Previous: 10.1 C++ abstract base

   
10.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.




2000-08-24