[Click] How to reference Method Interfaces?

Eddie Kohler kohler at cs.ucla.edu
Wed Jun 4 16:24:59 EDT 2008


Your code can and should be done differently, in this simpler manner.

#include <click/handlercall.hh>
...
private:
   HandlerCall _hc;

...configure()...
    if (cp_va_kparse(conf, this, errh,
                     "HANDLER", cpkP+cpkM, cpHandlerCallRead, &_hc,
                     cpEnd) < 0)
        return -1;

...initialize()...
    if (_hc.initialize_read(this, errh) < 0)
        return -1;

...push() or pull() or simple_action()...
    String s = _hc.call_read();

Eddie


Javier Sánchez Recacha wrote:
> 3) Read the capacity handler of the queue element
> 
> click script:
> 
> RatedSource(\<0800>) -> q::Queue -> MyPrint(q.capacity) -> Discard();
> 
> 
> MyPrint.hh:
> 
> ...
> 
>   const Handler* parse_handler(const String &, Element **);
> 
>   private:
>   String _handler_to_read;
> 
> ...
> 
> MyPrint.cc:
> 
> #include <click/config.h>
> #include "myprint.hh"
> #include <click/confparse.hh>
> #include <click/error.hh>
> #include <click/packet_anno.hh>
> #include <click/router.hh>
> 
> CLICK_DECLS
> 
> MyPrint::MyPrint()
> {
> }
> 
> MyPrint::~MyPrint()
> {
> }
> 
> static String
> canonical_handler_name(const String &n)
> {
>   const char *dot = find(n, '.');
>   if (dot == n.begin() || (dot == n.begin() + 1 && n.front() == '0'))
>     return n.substring(dot + 1, n.end());
>   else
>     return n;
> }
> 
> const Handler*
> MyPrint::parse_handler(const String &full_name, Element **es)
> {
>   // Parse full_name into element_name and handler_name.
>   String canonical_name = canonical_handler_name(full_name);
> 
>   // find element.
>   Element *e;
>   const char *dot = find(canonical_name, '.');
>   String hname;
> 
>   if (dot != canonical_name.end()) {
>     String ename = canonical_name.substring(canonical_name.begin(), dot);
>     e = router()->find(ename);
> 
>     if (!e) {
>       click_chatter ("fails to read handler");
>       return 0;
>     }
>     hname = canonical_name.substring(dot + 1, canonical_name.end());
>   } else {
>     e = router()->root_element();
>     hname = canonical_name;
>   }
> 
>   // Then find handler.
>   const Handler* h = Router::handler(e, hname);
>   if (h && h->visible()) {
>     *es = e;
>     return h;
>   } else {
>    click_chatter ("fails to read handler");
>     return 0;
>   }
> }
> 
> int
> MyPrint::configure(Vector<String> &conf, ErrorHandler *errh)
> {
>   String a;
>   if (cp_va_kparse(conf, this, errh,
>              "HANDLER", cpkP+cpkM, cpString, &a,
>              cpEnd) < 0)
>   return -1;
>   _handler_to_read = a;
>   return 0;
> }
> 
> Packet *
> MyPrint::simple_action(Packet *p)
> {
>   Element *e;
>   const Handler* h = parse_handler(_handler_to_read.c_str(), &e);
>   if (h->read_visible())
>   {
>     String data = h->call_read(e, NULL);
>     click_chatter ("HANDLER DATA %s : %s",_handler_to_read.c_str(), 
> data.c_str());
>   }
>  
>   return p;
> }
> 
> CLICK_ENDDECLS
> EXPORT_ELEMENT(MyPrint)
> ELEMENT_MT_SAFE(MyPrint)
> 
> I think method 2 should be more efficient.
> 
> Salutations
> Javier
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click



More information about the click mailing list