accessing handlers
Eddie Kohler
kohler at icir.org
Wed May 7 01:13:38 EDT 2003
Hi Will,
It looks like you're not checking the return value of cp_unsigned_real10.
You should do that. It is returning false, meaning it did not succeed in
parsing your string; and whenever a cp_ function returns false it is
guaranteed not to have touched any of the other variables you passed it,
which is why your chatter prints garbage.
Now, why is cp_unsigned_real10 not parsing your number? Probably because
your number is a handler result, so it ends in whitespace, namely \n. The
cp_ functions expect that you will give them exactly what they need, no
more and no less -- certainly no extra whitespace.
The magic key is 'cp_uncomment(str)'. The cp_uncomment function gets rid of
comments (by replacing them with single whitespace characters) and removes
leading and trailing space. This is exactly the set of transformations
carried out on a configuration argument before it is passed to a cp_
function, and exactly what you need here. Look at many write handlers; they
call cp_uncomment() on their argument before parsing it.
So I'm suggesting your code look like
for(int i = 0; i < _elements.size(); i++) {
e = _elements[i];
const Router::Handler *rh = Router::handler(e, String("rate"));
str = cp_uncomment(rh->call_read(e));
if (!cp_unsigned_real10(str, 3, &rate, &frac))
assert(0);
errh->message("%s", str);
errh->message("output %d rate %d", i, rate);
if(rate < minRate) {
minRate = rate;
eoutput = i;
}
}
Let us know if that doesn;t work.
love,
ed
More information about the click
mailing list