[Click] Errors trying to get arguments in my element

Ian Rose ianrose at eecs.harvard.edu
Thu Mar 24 14:00:44 EDT 2011


Hi -

Firstly, read handlers always return strings so technically you cannot 
write one to return an unsigned int.  If you want to do this, simply 
return an ASCII string of the value.  e.g.  "return 
String(my_unsigned_int_value)"

Next, you said you are having problems with your handlers, but I don't 
think you actually spelled out what the problem is.  Are you getting a 
compile error (if so what)?  Are the runtime results different than you 
expect?  If so, please provide your text script, actual results 
observed, and expected results.

Lastly, what are you trying to accomplish with these lines:
> add_write_handler("src", reconfigure_keyword_handler, "1 SRC");
> add_write_handler("dst", reconfigure_keyword_handler, "2 DST");

Argument #3 in each case looks wrong to me.  Regardless, if these are 
not related to what you are trying to accomplish right now, I would 
delete these for the time being to simplify things.

- Ian



On 03/24/2011 12:35 PM, Fabrice Schuler wrote:
>    Hello,
>
> I'm writing a basic element, which I'd like to get 2 elements, unsigned
> int to be precised. I had a look to the doxygen and to ipencap.xx and
> etherencap.xx files, but I'm facing problems with the handlers...Secondly,
> Could anyone give me some clues about my mistakes ?
>
> My first problem is that I could not successfully write a function
> read_handler that would return an unsigned int.
> And probably some other problems, but I could not find them. I think the
> configure function is right (thanks to documentation), but even that I'm
> not sure.
>
> Here is the configure function (ip_src and ip_dst are private unsigned) : |
> |
> int
> XorEncap::configure (Vector<String>  &conf, ErrorHandler *errh)
> {
>       int return_value;
>
>       if (cp_va_kparse (conf, this, errh,
>                   "SRC", cpkM+cpkP, cpUnsigned,&ip_src,
>                   "DST", cpkM+cpkP, cpUnsigned,&ip_dst,
>                   cpEnd)<  0)
>       {
>           return_value = -1;
>       }
>       else
>       {
>           return_value = 0;
>       }
>       return return_value;
> }
>
>
> And here are my problems with the handlers :
>
> String
> XorEncap::read_handler(Element *e, void *thunk)
> {
>       XorEncap *xe = static_cast<XorEncap *>(e);
>
>           std::cout<<  "in read_handler \n" ;
>
>       switch ((intptr_t)thunk)
>       {
>           case 0:  return (xe->ip_src);
>           case 1:  return (xe->ip_dst);
>           default: return "<error>";
>       }
> }
>
>       void
> XorEncap::add_handlers(void)
> {
>           std::cout<<  "in add_handler \n" ;
>
>       add_read_handler("src", read_handler, (void*)0);
>       add_write_handler("src", reconfigure_keyword_handler, "1 SRC");
>       add_read_handler("dst", read_handler, (void*)1);
>       add_write_handler("dst", reconfigure_keyword_handler, "2 DST");
> }
>
>
>
> Thanks for your answers,
> Fabrice
>
>
>
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click


More information about the click mailing list