write handler and global symbol table

Brecht Vermeulen brecht.vermeulen at rug.ac.be
Wed Jan 16 23:29:52 EST 2002


Hi Powell,

well, the most important is to look at the element source code to learn:
e.g. the queue.cc (elements/standard)

int
Queue::write_handler(const String &, Element *e, void *thunk,
ErrorHandler *errh)
{
  Queue *q = static_cast<Queue *>(e);
  int which = reinterpret_cast<int>(thunk);
  switch (which) {
   case 0:
    q->_drops = 0;
    q->_highwater_length = 0;
    return 0;
   case 1:
    while (q->_head != q->_tail) {
      int i = q->_head;
      q->_head = q->next_i(q->_head);
      q->_q[i]->kill();
    }
    return 0;
   default:
    return errh->error("internal error");
  }
}
 
void
Queue::add_handlers()
{
  add_read_handler("length", read_handler, (void *)0);
  add_read_handler("highwater_length", read_handler, (void *)1);
  add_read_handler("capacity", read_handler, (void *)2);
  add_read_handler("drops", read_handler, (void *)3);
  add_write_handler("capacity", reconfigure_positional_handler, (void
*)0);
  add_write_handler("reset_counts", write_handler, (void *)0);
  add_write_handler("reset", write_handler, (void *)1);
}

what comes up in your write_handler as 'thunk', is the third argument of
the add_write_handler function 
(here 0 or 1)
This is used in the queue write_handler (the first element String isn't
used here).

"capacity" is a special handler as it uses the
reconfigure_positional_handler (0) which stands for the first argument
as in the configuration of the element (as far as I know). There is also
something as 
reconfigure_keyword_handler I believe, see the elements for examples.

So; the first argument to your write_handler is a string as you get it
in the configure method, so you can use the same methods to break down
the string. See e.g. timedsource.cc for an example.

About calling other kernel methods. I think you can, but I am not sure.
Just try it :-).

regards,
Brecht

powell molleti wrote:
> 
> Hi all,
> 
>  how does a write_handler work.
> 
>  When one adds a write_handler a proc entry comes up.
>  so one has to echo something to that entry.
> 
>  ok that entry comes up as thunk? the string?
> 
>  when i do
> 
>  echo "1" > /proc/click/myelement/mywritehandler
> 
>  i get the (int)thunk as zero.
>  and (char *)thunk as NULL?
> 
>  could someone please through some light on
>  write_handlers , no documentation in the doc
>  for this method :(.
> 
>  And when click module is insmoded can the
>  entry in the global symbol entry be use by
>  any part of the kernel? to call that function.
> 
>  like can i call run_schedule method of
>  a element from the kernel?. sorry this may
>  sound stupid or strange but i just had a thought
>  if one can accomplish this.
> 
>  Thanks
>  cya
>  Powell
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Send FREE video emails in Yahoo! Mail!
> http://promo.yahoo.com/videomail/



More information about the click mailing list