Re: info about HandlerCall::call_read()

Cliff Frey <[email protected]>
Newsgroups gmane.network.routing.click
Message-ID <CAFtVOqkAe2CeWP3moqnGzxTQj9Vm3JDMpWRUFxnkPLUoRWr8zQ@mail.gmail.com>
please always CC the mailing list in your replies.

You could probably do much of this with a script

Script(wait 1.0, print "the energy used in the last second was: " ${add
${control_a.energy} ${control_b.energy}, loop);

But, scripts are hard to use when there is a lot of logic that you want to
express.

So I advising that you make an element to do this calculation... the element
is something like  (please excuse my pseudo-code)

controlelement.hh defines a function
  int get_energy_usage();

energytracker.hh defines members
public:
  configure(...);
  element_name() ...;
  etc.

private:
  ControlElement *_control_a;
  ControlElement *_control_b;
}

then
energytracker.hh has
int EnergyTracker::configure(...) {
  Args(conf, this, errh)
    .read("CONTROL_A", ElementCastArg("ControlElement"), _control_a)
    .read("CONTROL_B", ElementCastArg("ControlElement"), _control_b)
    .complete();
}

String EnergyTracker::read_out_energy_handler(...) {
  EnergyTracker *et = (EnergyTracker *) e;
  return String(et->_control_a->get_energy_usage() +
et->_control_b->get_energy_usage());
}

good luck.

Cliff

On Tue, Oct 11, 2011 at 3:24 PM, Xavier Salip <[email protected]> wrote:

> Ok. I don't really get the option with the pointers. I'll try to explain
> better my situation:
>
> I have different CONTROL elements, one of them for each different element i
> have programmed (f.e: CONTROL_A will calculate energy consumption of an A
> element). To do that, the CONTROL element has a handler called "Energy",
> which i can eventually call on router execution to read the Energy
> consumption of a desired element. My purpose is to calculate the energy
> consumption of this desired element by calling the handler "time" (which is
> programmed in all my different kind of elements) and multiplying this "time"
> by a power formula.
> The problem is that i don't really know how to use* HandlerCall::call_read
> * to do that.
> For example, i would like to write *READ CONTROL_A.Energy* to get the
> energy consumption of an element called A.
> Despite my confusion, I hope you to understand what i mean.
>
> Thanks!
>
>
> On Tue, Oct 11, 2011 at 6:46 PM, Cliff Frey <[email protected]> wrote:
>
>> You can look at the HandlerCall interface if you really want to use
>> read-handlers.
>>
>> Often in cases like this, it is easier to actually pass a pointer from one
>> element to another through the config.  ARPQuerier can do this with
>> ARPTable, or etherswitch/spantree.cc does this as well.  Search for
>> ElementCastArg in the source.
>>
>> Cliff
>>
>> On Tue, Oct 11, 2011 at 7:54 AM, Xavier Salip <[email protected]>wrote:
>>
>>> Hi list,
>>>
>>> I have created an element called WC.
>>> In a configuration .click file i have a bank of 5 WC elements (WC1,
>>> WC2...WC5),  each one of them with a read handler called "energy".
>>> I would like to create a control element CONTROL which reads the handler
>>> "energy" on the desired WC and make some calculations with it.
>>> I'm trying with this function to call the handler, but i don't manage to
>>> find how to use it in a correct way:
>>>
>>> String <http://www.read.cs.ucla.edu/click/doxygen/class_string.html
>>> >HandlerCall::call_read
>>> ( Element <http://www.read.cs.ucla.edu/click/doxygen/class_element.html>
>>> *
>>> *e*,
>>>
>>> const String <
>>> http://www.read.cs.ucla.edu/click/doxygen/class_string.html>&
>>> *hname*,
>>>
>>> ErrorHandler<
>>> http://www.read.cs.ucla.edu/click/doxygen/class_error_handler.html>*
>>> *errh* = 0
>>>
>>> )
>>>
>>> Any ideas or suggestions?
>>>
>>> Thanks!
>>> _______________________________________________
>>> click mailing list
>>> [email protected]
>>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>>>
>>
>>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.