Click
Loading...
Searching...
No Matches
handlercall.hh
Go to the documentation of this file.
1// -*- c-basic-offset: 4; related-file-name: "../../lib/handlercall.cc" -*-
2#ifndef CLICK_HANDLERCALL_HH
3#define CLICK_HANDLERCALL_HH
4#include <click/router.hh>
5CLICK_DECLS
6class VariableExpander;
7
143class HandlerCall { public:
144
147 static String call_read(Element *e, const String &hname,
148 ErrorHandler *errh = 0);
149 static String call_read(const String &hdesc, const Element *context,
150 ErrorHandler *errh = 0);
151 static int call_write(Element *e, const String &hname,
152 ErrorHandler *errh = 0);
153 static int call_write(Element *e, const String &hname, const String &value,
154 ErrorHandler *errh = 0);
155 static int call_write(const String &hdesc,
156 const Element *context, ErrorHandler *errh = 0);
157 static int call_write(const String &hdesc, const String &value,
158 const Element *context, ErrorHandler *errh = 0);
160
161
162
168 : _e(0), _h(Handler::blank_handler()) {
169 }
170
178 HandlerCall(const String &hdesc)
179 : _e(reinterpret_cast<Element *>(4)), _h(Handler::blank_handler()),
180 _value(hdesc) {
181 }
182
183
184 enum Flags {
185 readable = Handler::f_read,
186 f_read = Handler::f_read,
187 writable = Handler::f_write,
188 f_write = Handler::f_write,
189 f_preinitialize = 4,
190 f_unquote_param = 8
191 };
192
227 int initialize(int flags, const Element *context, ErrorHandler *errh = 0);
228
235 inline int initialize_read(const Element *context, ErrorHandler *errh = 0);
236
243 inline int initialize_write(const Element *context, ErrorHandler *errh = 0);
244
245
246 typedef bool (HandlerCall::*unspecified_bool_type)() const;
247
252 operator unspecified_bool_type() const {
253 return _h != Handler::blank_handler() || _e ? &HandlerCall::empty : 0;
254 }
255
258 bool empty() const {
259 return _h == Handler::blank_handler() && !_e;
260 }
261
264 bool initialized() const {
265 return _h != Handler::blank_handler();
266 }
267
268
276 inline String call_read(ErrorHandler *errh = 0) const;
277
285 inline int call_write(ErrorHandler *errh = 0) const;
286
296 inline int call_write(const VariableExpander &scope, ErrorHandler *errh = 0) const;
297
309 inline int call_write(const String &value_ext, ErrorHandler *errh = 0) const;
310
311
333 static int reset(HandlerCall *&hcall, const String &hdesc, int flags,
334 const Element *context, ErrorHandler *errh = 0);
335
347 static int reset(HandlerCall *&hcall,
348 Element *e, const String &hname, const String &value,
349 int flags, ErrorHandler *errh = 0);
350
351
361 static inline int reset_read(HandlerCall *&hcall, const String &hdesc,
362 const Element *context, ErrorHandler *errh = 0);
363
373 static inline int reset_read(HandlerCall *&hcall,
374 Element *e, const String &hname,
375 ErrorHandler *errh = 0);
376
386 static inline int reset_write(HandlerCall *&hcall, const String &hdesc,
387 const Element *context, ErrorHandler *errh = 0);
388
399 static inline int reset_write(HandlerCall *&hcall,
400 Element *e, const String &hname,
401 const String &value = String(),
402 ErrorHandler *errh = 0);
403
404
409 Element *element() const {
410 return _e;
411 }
412
416 const Handler *handler() const {
417 return _h;
418 }
419
423 const String &value() const {
424 return initialized() ? _value : String::make_empty();
425 }
426
431 void set_value(const String &value) {
432 if (initialized())
433 _value = value;
434 }
435
439 String unparse() const;
440
445 void clear() {
446 _e = 0;
448 _value = String();
449 }
450
451
453 enum {
454 CHECK_READ = f_read, OP_READ = f_read, h_read = f_read,
455 CHECK_WRITE = f_write, OP_WRITE = f_write, h_write = f_write,
456 PREINITIALIZE = f_preinitialize, h_preinitialize = f_preinitialize,
457 UNQUOTE_PARAM = f_unquote_param, h_unquote_param = f_unquote_param
458 };
461 private:
462
463 Element *_e;
464 const Handler *_h;
465 String _value;
466
467 int parse(int flags, Element*, ErrorHandler*);
468 int assign(Element*, const String&, const String&, int flags, ErrorHandler*);
469
470};
471
472inline int
473HandlerCall::reset_read(HandlerCall*& hcall, const String& hdesc, const Element* context, ErrorHandler* errh)
474{
475 return reset(hcall, hdesc, f_read, context, errh);
476}
477
478inline int
479HandlerCall::reset_write(HandlerCall*& hcall, const String& hdesc, const Element* context, ErrorHandler* errh)
480{
481 return reset(hcall, hdesc, f_write, context, errh);
482}
483
484inline int
486{
487 return reset(hcall, e, hname, String(), f_read, errh);
488}
489
490inline int
491HandlerCall::reset_write(HandlerCall*& hcall, Element* e, const String& hname, const String& value, ErrorHandler* errh)
492{
493 return reset(hcall, e, hname, value, f_write, errh);
494}
495
496inline int
498{
499 return initialize(f_read, context, errh);
500}
501
502inline int
504{
505 return initialize(f_write, context, errh);
506}
507
508inline String
510{
511 return _h->call_read(_e, _value, errh);
512}
513
514inline int
516{
517 return _h->call_write(_value, _e, errh);
518}
519
520String cp_expand(const String &str, const VariableExpander &env, bool expand_quote, int depth);
521
522inline int
523HandlerCall::call_write(const VariableExpander &scope, ErrorHandler *errh) const
524{
525 return _h->call_write(cp_expand(_value, scope, false, 0), _e, errh);
526}
527
528inline int
529HandlerCall::call_write(const String &value_ext, ErrorHandler *errh) const
530{
531 if (_value && value_ext)
532 return _h->call_write(_value + " " + value_ext, _e, errh);
533 else
534 return _h->call_write(_value ? _value : value_ext, _e, errh);
535}
536
549inline int
551{
552 return call_write(e, hname, String(), errh);
553}
554
555
569 HandlerCallArg(int f)
570 : flags(f) {
571 }
572 bool parse(const String &str, HandlerCall &result, const ArgContext &args);
573 int flags;
574};
575
576CLICK_ENDDECLS
577#endif
Argument context class.
Definition args.hh:31
Base class for Click elements.
Definition element.hh:42
Error reporting class.
Definition error.hh:90
Convenience class for calling handlers.
Definition handlercall.hh:143
HandlerCall()
Construct an empty HandlerCall.
Definition handlercall.hh:167
bool empty() const
Test if HandlerCall is empty.
Definition handlercall.hh:258
static int reset_read(HandlerCall *&hcall, const String &hdesc, const Element *context, ErrorHandler *errh=0)
Create and initialize a read HandlerCall from hdesc.
Definition handlercall.hh:473
int initialize_read(const Element *context, ErrorHandler *errh=0)
Initialize the HandlerCall for reading.
Definition handlercall.hh:497
static int reset_write(HandlerCall *&hcall, const String &hdesc, const Element *context, ErrorHandler *errh=0)
Create and initialize a write HandlerCall from hdesc.
Definition handlercall.hh:479
Element * element() const
Return the Element corresponding to this HandlerCall.
Definition handlercall.hh:409
int initialize(int flags, const Element *context, ErrorHandler *errh=0)
Initialize the HandlerCall.
Definition handlercall.cc:32
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
void clear()
Make this HandlerCall empty.
Definition handlercall.hh:445
String unparse() const
Return a String that will parse into an equivalent HandlerCall.
Definition handlercall.cc:242
bool initialized() const
Test if HandlerCall is initialized.
Definition handlercall.hh:264
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
int initialize_write(const Element *context, ErrorHandler *errh=0)
Initialize the HandlerCall for writing.
Definition handlercall.hh:503
HandlerCall(const String &hdesc)
Construct a HandlerCall described by hdesc.
Definition handlercall.hh:178
const String & value() const
Return the write handler value and/or read handler parameters.
Definition handlercall.hh:423
const Handler * handler() const
Return the Handler corresponding to this HandlerCall.
Definition handlercall.hh:416
void set_value(const String &value)
Sets the write handler value and/or read handler parameters.
Definition handlercall.hh:431
static int reset(HandlerCall *&hcall, const String &hdesc, int flags, const Element *context, ErrorHandler *errh=0)
Create and initialize a HandlerCall from hdesc.
Definition handlercall.cc:96
Represents a router's handlers.
Definition handler.hh:19
static const Handler * blank_handler()
Returns a handler incapable of doing anything.
Definition handler.hh:223
int call_write(const String &value, Element *e, ErrorHandler *errh) const
Call a write handler.
Definition router.cc:1709
@ f_read
Handler supports read operations.
Definition handler.hh:22
@ f_write
Handler supports write operations.
Definition handler.hh:23
String call_read(Element *e, const String &param, ErrorHandler *errh) const
Call a read handler, possibly with parameters.
Definition router.cc:1691
A string of characters.
Definition string.hh:22
static const String & make_empty()
Return a const reference to an empty String.
Definition string.hh:439
The Router class implementing a router configuration.
Parser class for handler call specifications.
Definition handlercall.hh:568