[Click] How to reference Method Interfaces?
Javier Sánchez Recacha
javier.recacha at gmail.com
Wed Jun 4 15:17:23 EDT 2008
2) Acces to the capacity variable of the queue element.
click script:
RatedSource(\<0800>) -> q::Queue -> MyPrint(q) -> Discard();
MyPrint.hh
...
private:
Element *_e;
...
MyPrint.cc
#include <click/config.h>
#include "myprint.hh"
#include <click/confparse.hh>
#include <click/error.hh>
// to read a variable from an element you need 2 conditions
// 1) Element has to have the cast() method, if it doesn't,
// is easy to implement, f.e. look at click/standard/storage.hh
// 2) Element has to have a public function that returns the value you want
//
// p.e. Queues has the function cast() (inherited from simplequeue.hh )
// that returns the element type Storage and the function capacity()
(inherited from
// storage.hh) that returns the capacity value
#include <click/standard/storage.hh>
CLICK_DECLS
MyPrint::MyPrint()
{
}
MyPrint::~MyPrint()
{
}
int
MyPrint::configure(Vector<String> &conf, ErrorHandler *errh)
{
Element *e;
if (cp_va_kparse(conf, this, errh,
// here we take the pointer to the element
"ELEMENT", cpkP+cpkM, cpElement, &e,
cpEnd) < 0)
return -1;
_e = e;
return 0;
}
Packet *
MyPrint::simple_action(Packet *p)
{
//here the general element _e is read as storage element s.
if (Storage *s = (Storage *)_e->cast("Storage")){
click_chatter ("Element %s capacity: %d",_e->name().c_str(),
s->capacity());
}
return p;
}
CLICK_ENDDECLS
EXPORT_ELEMENT(MyPrint)
ELEMENT_MT_SAFE(MyPrint)
More information about the click
mailing list