[Click] Timer !

Beyers Cronje bcronje at gmail.com
Mon Jul 23 13:00:53 EDT 2007


Hi Massimo,

If you actually looked at /include/click/timer.hh:212 you'll see one line
above it it says "deprecated Use schedule_after_msec() instead". So change
all schedule_after_ms() to schedule_after_msec() will sort out the compiler
warning.

Regarding the assertion, you should initialize the timer in your element
initialize() function. There are numerous examples in the elements directory
that use a simple timer like this. For one see
<clickdir>/elements/standard/burster.(hh/cc)

So change to:

class MyElement: public Element {
  public:
  …
  void run_timer();
  int initialize(ErrorHandler *);
  private:
  Timer timer;
}

MyElement::MyElement(): timer(this){
}

int MyElement::initialize(ErrorHandler *) {
  timer.initialize(this);
  timer.schedule_after_msec(1000);
  return 0;
}

void MyElement ::run_timer(){
  // do something
  timer.schedule_after_msec(1000);
}

Beyers

On 7/23/07, el.drago at tiscali.it <el.drago at tiscali.it> wrote:
>
> Hi to all!
> I am trying to introduce a very (hopefully) simple timer in my
> module.
> It WOULD simply call a function when it expires (well, it will be
> reset many times and only if nobody resets it for some time, and its
> time expires, it has to call a function, then re-reset itself).
>
> Searching in the mailing list i have found this tip:
>
> // Runs the run_timer function upon expiry
> class MyElement: public Element {
>    public:
>>    void run_timer();
>    private:
>    Timer timer;
> }
> MyElement::MyElement(): timer(this){
>    timer.initialize(this);
>    timer.schedule_after_ms(1000);
>    return 0;
> }
> void MyElement ::run_timer(){
>    // do something
>    timer.schedule_after_ms(1000);
> }
>
>
> Well, I tried to fit this in my module but first of all i got an
> error:
>           "error: returning a value from a constructor"
> so I pull out the "return 0" from the constructor (originally in my
> code there isn't it).
> After fixing minor errors i got only 2 identical warnings:
>           "warning: 'schedule_after_ms' is deprecated (declared at ..
> /include/click/timer.hh:212)"
> but I have no idea how to fix them.
> So i try to run click but.. DAMN! as I hit -return- i got:
>      "click: ../lib/timer.cc:130: void Timer::schedule_at(const
> Timestamp&): Assertion `_router && initialized()' failed.
>      Aborted"
>
> I "googled" for at least 3 hours searching how to make this
> (apparently) easy timer (or better a trigger for time-out) but, really
> i didn't found real help.
> Anyone can advice me how I could write it down, or knows where i can
> find an easy explanation [I tried understanding timer.cc and .hh but it
> doesn't help me :( ]
>
> Thanks in advance for any kind of help.
> Massimo
>
>
>
>
> _______________________________________
> Stampa on line i tuoi ricordi con Tiscali.Photo
> http://photo.tiscali.it//
>
>
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>


More information about the click mailing list