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

Re: [ns] creating an new protocol



hi,

> 
> I have some question regarding to the example in ns-manual ch9.6(creating an new protocol) as follows:
> 
> 
> class ECHO_Timer;
> class ECHO_Agent : public Agent {
> ....
> protected:
> ECHO_Timer echo_timer_;
> }
> 
> class ECHO_Timer : public TimerHandler {
> public:
> ECHO_Timer(ECHO_Agent *a) : TimerHandler() { a_ = a;}
> protected:
> virtual void expire(Event *e)
> {
> a_->timeout(0);
> }
> ECHO_Agent *a_
> }

i had the same problem a few weeks ago. you cannot implement expire inline
- declare the member function and implement it later.

a solution for this is to use a template class, as i wrote some time ago.

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_;
};

then you can use it in your agent like this:

class MyAgent : public Agent {
  ...
protected:
  ...
  TimerA<MyAgent> my_timer_;
  ...
}

od

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