|
| enum | Flags {
readable = Handler::f_read
, f_read = Handler::f_read
, writable = Handler::f_write
, f_write = Handler::f_write
,
f_preinitialize = 4
, f_unquote_param = 8
} |
| |
|
typedef bool(HandlerCall::* | unspecified_bool_type) () const |
| |
| static String | call_read (Element *e, const String &hname, ErrorHandler *errh=0) |
| | Call a read handler specified by element and handler name.
|
| |
| static String | call_read (const String &hdesc, const Element *context, ErrorHandler *errh=0) |
| | Call a read handler.
|
| |
| static int | call_write (Element *e, const String &hname, ErrorHandler *errh=0) |
| | Call a write handler specified by element and handler name.
|
| |
| static int | call_write (Element *e, const String &hname, const String &value, ErrorHandler *errh=0) |
| | Call a write handler specified by element and handler name.
|
| |
| static int | call_write (const String &hdesc, const Element *context, ErrorHandler *errh=0) |
| | Call a write handler.
|
| |
| static int | call_write (const String &hdesc, const String &value, const Element *context, ErrorHandler *errh=0) |
| | Call a write handler with a specified value.
|
| |
| static int | reset (HandlerCall *&hcall, const String &hdesc, int flags, const Element *context, ErrorHandler *errh=0) |
| | Create and initialize a HandlerCall from hdesc.
|
| |
| static int | reset (HandlerCall *&hcall, Element *e, const String &hname, const String &value, int flags, ErrorHandler *errh=0) |
| | Create and initialize a HandlerCall on element e.
|
| |
| static int | reset_read (HandlerCall *&hcall, const String &hdesc, const Element *context, ErrorHandler *errh=0) |
| | Create and initialize a read HandlerCall from hdesc.
|
| |
| static int | reset_read (HandlerCall *&hcall, Element *e, const String &hname, ErrorHandler *errh=0) |
| | Create and initialize a read HandlerCall from hdesc.
|
| |
| static int | reset_write (HandlerCall *&hcall, const String &hdesc, const Element *context, ErrorHandler *errh=0) |
| | Create and initialize a write HandlerCall from hdesc.
|
| |
| static int | reset_write (HandlerCall *&hcall, Element *e, const String &hname, const String &value=String(), ErrorHandler *errh=0) |
| | Create and initialize a read HandlerCall from hdesc.
|
| |
| | HandlerCall () |
| | Construct an empty HandlerCall.
|
| |
| | HandlerCall (const String &hdesc) |
| | Construct a HandlerCall described by hdesc.
|
| |
| int | initialize (int flags, const Element *context, ErrorHandler *errh=0) |
| | Initialize the HandlerCall.
|
| |
| int | initialize_read (const Element *context, ErrorHandler *errh=0) |
| | Initialize the HandlerCall for reading.
|
| |
| int | initialize_write (const Element *context, ErrorHandler *errh=0) |
| | Initialize the HandlerCall for writing.
|
| |
| | operator unspecified_bool_type () const |
| | Test if HandlerCall is empty.
|
| |
| bool | empty () const |
| | Test if HandlerCall is empty.
|
| |
| bool | initialized () const |
| | Test if HandlerCall is initialized.
|
| |
| String | call_read (ErrorHandler *errh=0) const |
| | Call a read handler.
|
| |
| int | call_write (ErrorHandler *errh=0) const |
| | Call a write handler.
|
| |
| int | call_write (const VariableExpander &scope, ErrorHandler *errh=0) const |
| | Call a write handler, expanding its argument.
|
| |
| int | call_write (const String &value_ext, ErrorHandler *errh=0) const |
| | Call a write handler with an additional value.
|
| |
| Element * | element () const |
| | Return the Element corresponding to this HandlerCall.
|
| |
| const Handler * | handler () const |
| | Return the Handler corresponding to this HandlerCall.
|
| |
| const String & | value () const |
| | Return the write handler value and/or read handler parameters.
|
| |
| void | set_value (const String &value) |
| | Sets the write handler value and/or read handler parameters.
|
| |
| String | unparse () const |
| | Return a String that will parse into an equivalent HandlerCall.
|
| |
| void | clear () |
| | Make this HandlerCall empty.
|
| |
Convenience class for calling handlers.
The HandlerCall class simplifies the process of calling Click handlers. (The lower-level interface is the Handler class.) HandlerCall is used in two ways: (1) to call handlers immediately via static member functions, and (2) to set up future handler calls via HandlerCall objects. The immediate handler call functions take handler names as arguments and perform all necessary error checks before calling handlers, if any. A HandlerCall object encapsulates a handler reference (possibly including parameters), again automating all necessary error checks.
Immediate Handler Calls
This example code shows how to use the HandlerCall functions for calling handlers immediately.
class YourElement { ...
}
void YourElement::function() {
}
Base class for Click elements.
Definition element.hh:42
Error reporting class.
Definition error.hh:90
static ErrorHandler * default_handler()
Return the default ErrorHandler.
Definition error.hh:159
static int call_write(Element *e, const String &hname, ErrorHandler *errh=0)
Call a write handler specified by element and handler name.
Definition handlercall.hh:550
static String call_read(Element *e, const String &hname, ErrorHandler *errh=0)
Call a read handler specified by element and handler name.
Definition handlercall.cc:134
A string of characters.
Definition string.hh:22
This example code shows how to use the HandlerCall objects to call handlers with simplified error checking.
class YourElement { ...
}
YourElement::YourElement()
: _read_call(), _write_call() {
}
}
if ((_read_call && _read_call.initialize_read(this, errh) < 0)
|| (_write_call && _write_call.initialize_write(this, errh) < 0))
return -1;
return 0;
}
void YourElement::function() {
if (_read_call)
click_chatter("%s", _read_call.call_read());
if (_write_call)
}
Convenience class for calling handlers.
Definition handlercall.hh:143
Vector template.
Definition vector.hh:111
const CpVaParseCmd cpHandlerCallWrite
Result storage HandlerCall*, parsed by HandlerCall.
Definition confparse.hh:298
const CpVaParseCmd cpEnd
Use as argument name. Ends cp_va argument list.
Definition confparse.cc:2197
@ cpkP
Argument may be specified positionally.
Definition confparse.hh:239
int cp_va_kparse(const Vector< String > &conf, const Element *context, ErrorHandler *errh,...) CP_SENTINEL
Parse a list of arguments.
Definition confparse.cc:3779
const CpVaParseCmd cpHandlerCallRead
Result storage HandlerCall*, parsed by HandlerCall.
Definition confparse.hh:297
If usually your element's handler calls aren't used, you can save a small amount of space by using pointers to HandlerCall objects, as in this example. The cpHandlerCallPtrRead and cpHandlerCallPtrWrite types allow the _read_call and _write_call members to start out as null pointers.
class YourElement { ...
}
YourElement::YourElement()
: _read_call(0), _write_call(0) {
}
}
if ((_read_call && _read_call->initialize_read(this, errh) < 0)
|| (_write_call && _write_call->initialize_write(this, errh) < 0))
return -1;
return 0;
}
void YourElement::cleanup(CleanupStage) {
delete _read_call;
delete _write_call;
}
void YourElement::function() {
if (_read_call)
click_chatter("%s", _read_call->call_read());
if (_write_call)
}
const CpVaParseCmd cpHandlerCallPtrRead
Result storage HandlerCall**, parsed by HandlerCall::reset_read.
Definition confparse.hh:299
const CpVaParseCmd cpHandlerCallPtrWrite
Result storage HandlerCall**, parsed by HandlerCall::reset_write.
Definition confparse.hh:300
Initialize the HandlerCall.
- Parameters
-
| flags | zero or more of f_read, f_write, f_preinitialize, f_unquote_param |
| context | optional element context |
| errh | optional error handler |
- Returns
- 0 on success, negative on failure
Initializes the HandlerCall object. The handler description supplied to the constructor is parsed and checked for syntax errors. Any element reference is looked up relative to context, if any. (For example, if hdesc was "x.config" and context's name is "aaa/bbb/ccc", this will search for elements named aaa/bbb/x, aaa/x, and finally x. If context is null, then the description must refer to a global handler.) If f_read is set in flags, then there must be a read handler named appropriately; if f_write is set, then there must be a write handler. If f_unquote_param is set, then any parameters are unquoted.
Initialization fails if the handler description was bogus (for example, an empty string, or something like "*#!$&!(#&$."), if the named handler does not exist, if a read handler description has parameters but the read handler doesn't actually take parameters, and so forth. If errh is nonnull, errors are reported there. The HandlerCall becomes empty on failure: empty() will return true, and (bool) *this will return false. Future call_read() and call_write() attempts will correctly fail.
If the f_preinitialize flag is set, the initialize function will check whether the router's handlers are ready (Router::handlers_ready()). If handlers are not ready, then initialize() will check for syntax errors, but not actually look up the handler (since we don't know yet whether or not the handler exists). Absent a syntax error, initialize() will return 0 for success even though the HandlerCall remains uninitialized.