[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] Timer implementation



i implemented some new agents and needed a timer for each of these
agents. they do the very same  but i have to implement them for each
class. so i wonder if this could be done by a template (this covers
RTPTimer and RTCPTimer).

My suggestion is to use a generic class like this:

template <class X> class TimerA : public TimerHandler {
public:
  TimerA(X *a) : TimerHandler() { a_ = a; }
protected:
  virtual void expire(Event *e) { a_->timeout(0); }
  X *a_;
};

and use it in the agents like this:

class RTCPAgent : public Agent {
public:
...
  virtual void timeout(int);
protected:
...
  TimerA<RTCPAgentA> rtcp_timer_;
};

this is the normal use of a timer implementation i guess. it is possible
to override this for special classes if required. 

od

-- 
   Oliver Dawid * [email protected] * http://www.fet.uni-hannover.de/~od/