Click
Loading...
Searching...
No Matches
handler.hh
Go to the documentation of this file.
1#ifndef CLICK_HANDLER_HH
2#define CLICK_HANDLER_HH 1
3#include <click/string.hh>
4CLICK_DECLS
5class Element;
6class ErrorHandler;
7class Handler;
8
13typedef int (*HandlerCallback)(int operation, String &data, Element *element,
14 const Handler *handler, ErrorHandler *errh);
15typedef String (*ReadHandlerCallback)(Element *handler, void *user_data);
16typedef int (*WriteHandlerCallback)(const String &data, Element *element,
17 void *user_data, ErrorHandler *errh);
18
19class Handler { public:
20
21 enum Flags {
22 f_read = 0x0001,
23 f_write = 0x0002,
24 f_read_param = 0x0004,
25 f_exclusive = 0,
28 f_nonexclusive = 0x0020,
31 f_raw = 0x0040,
32 f_read_private = 0x0080,
36 f_deprecated = 0x0200,
38 f_uncommon = 0x0400,
40 f_calm = 0x0800,
41 f_expensive = 0x1000,
42 f_button = 0x2000,
43 f_checkbox = 0x4000,
45 f_driver0 = 1U << 26,
46 f_driver1 = 1U << 27,
48 f_user_shift = 28,
49 f_user0 = 1U << f_user_shift,
53
54 f_read_comprehensive = 0x0008,
55 f_write_comprehensive = 0x0010,
56 f_special = f_read | f_write | f_read_param | f_read_comprehensive | f_write_comprehensive
59 };
60
62 inline const String &name() const {
63 return _name;
64 }
65
69 inline uint32_t flags() const {
70 return _flags;
71 }
72
75 inline void *user_data(int op) const {
76 return op == f_write ? _write_user_data : _read_user_data;
77 }
78
80 inline void *read_user_data() const {
81 return _read_user_data;
82 }
83
85 inline void *write_user_data() const {
86 return _write_user_data;
87 }
88
90 inline void *user_data1() const CLICK_DEPRECATED;
91 inline void *user_data2() const CLICK_DEPRECATED;
96 inline bool readable() const {
97 return _flags & f_read;
98 }
99
102 inline bool read_param() const {
103 return _flags & f_read_param;
104 }
105
111 inline bool read_visible() const {
112 return (_flags & (f_read | f_read_private)) == f_read;
113 }
114
116 inline bool writable() const {
117 return _flags & f_write;
118 }
119
125 inline bool write_visible() const {
126 return (_flags & (f_write | f_write_private)) == f_write;
127 }
128
130 inline bool visible() const {
131 return read_visible() || write_visible();
132 }
133
136 inline bool allow_concurrent_handlers() const {
137 return (_flags & f_nonexclusive);
138 }
139
142 inline bool allow_concurrent_threads() const {
143 return (_flags & f_nonexclusive);
144 }
145
164 inline bool raw() const {
165 return _flags & f_raw;
166 }
167
168
177 String call_read(Element *e, const String &param, ErrorHandler *errh) const;
178
186 inline String call_read(Element *e, ErrorHandler *errh = 0) const {
187 return call_read(e, String(), errh);
188 }
189
198 int call_write(const String &value, Element *e, ErrorHandler *errh) const;
199
200
207 String unparse_name(Element *e) const;
208
216 static String unparse_name(Element *e, const String &hname);
217
218
223 static inline const Handler *blank_handler() {
224 return the_blank_handler;
225 }
226
227
229 enum {
230 h_read = f_read,
231 h_write = f_write,
232 h_read_param = f_read_param,
233 h_exclusive = f_exclusive,
234 h_nonexclusive = f_nonexclusive,
235 h_raw = f_raw,
236 h_read_private = f_read_private,
237 h_write_private = f_write_private,
238 h_deprecated = f_deprecated,
239 h_uncommon = f_uncommon,
240 h_calm = f_calm,
241 h_expensive = f_expensive,
242 h_button = f_button,
243 h_checkbox = f_checkbox,
244 h_driver_flag_0 = f_driver0,
245 h_driver_flag_1 = f_driver1,
246 h_user_flag_shift = f_user_shift,
247 h_user_flag_0 = f_user0,
248 h_read_comprehensive = f_read_comprehensive,
249 h_write_comprehensive = f_write_comprehensive,
250 h_special_flags = f_special
251 };
252 enum DeprecatedFlags {
253 OP_READ = f_read,
254 OP_WRITE = f_write,
255 READ_PARAM = f_read_param,
256 RAW = f_raw,
257 // READ_PRIVATE = f_read_private,
258 // WRITE_PRIVATE = f_write_private,
259 // DEPRECATED = f_deprecated,
260 // UNCOMMON = f_uncommon,
261 CALM = f_calm,
262 EXPENSIVE = f_expensive,
263 BUTTON = f_button,
264 CHECKBOX = f_checkbox,
265 USER_FLAG_SHIFT = f_user_shift,
266 USER_FLAG_0 = f_user0
267 };
268 enum CLICK_DEPRECATED {
269 EXCLUSIVE = f_exclusive,
270 NONEXCLUSIVE = f_nonexclusive
271 };
281 inline String __call_read(Element *e, void *new_user_data) const {
282 assert((_flags & (f_read | f_read_comprehensive)) == f_read);
283 return _read_hook.r(e, new_user_data);
284 }
287 private:
288
289 String _name;
290 union {
291 HandlerCallback h;
292 ReadHandlerCallback r;
293 } _read_hook;
294 union {
295 HandlerCallback h;
296 WriteHandlerCallback w;
297 } _write_hook;
298 void *_read_user_data;
299 void *_write_user_data;
300 uint32_t _flags;
301 int _use_count;
302 int _next_by_name;
303
304 static const Handler *the_blank_handler;
305
306 Handler(const String & = String());
307
308 inline void combine(const Handler &x);
309 inline bool compatible(const Handler &x) const;
310
311 friend class Router;
312
313};
314
315/* The largest size a write handler is allowed to have. */
316#define LARGEST_HANDLER_WRITE 65536
317
318typedef HandlerCallback HandlerHook CLICK_DEPRECATED;
319typedef ReadHandlerCallback ReadHandlerHook CLICK_DEPRECATED;
320typedef WriteHandlerCallback WriteHandlerHook CLICK_DEPRECATED;
321
323inline void *
324Handler::user_data1() const
325{
326 return _read_user_data;
327}
328
329inline void *
330Handler::user_data2() const
331{
332 return _write_user_data;
333}
336CLICK_ENDDECLS
337#endif
Base class for Click elements.
Definition element.hh:42
Error reporting class.
Definition error.hh:90
Represents a router's handlers.
Definition handler.hh:19
bool allow_concurrent_threads() const
Test if this handler can execute concurrently with router threads.
Definition handler.hh:142
const String & name() const
Return this handler's name.
Definition handler.hh:62
static const Handler * blank_handler()
Returns a handler incapable of doing anything.
Definition handler.hh:223
uint32_t flags() const
Return this handler's flags.
Definition handler.hh:69
String unparse_name(Element *e) const
Unparse this handler's name.
Definition router.cc:1733
bool visible() const
Test if this is a public read or write handler.
Definition handler.hh:130
int call_write(const String &value, Element *e, ErrorHandler *errh) const
Call a write handler.
Definition router.cc:1709
bool readable() const
Test if this is a valid read handler.
Definition handler.hh:96
bool read_param() const
Test if this is a valid read handler that may accept parameters.
Definition handler.hh:102
void * user_data(int op) const
Return this handler's callback data.
Definition handler.hh:75
bool raw() const
Test if spaces should be preserved when calling this handler.
Definition handler.hh:164
Flags
Definition handler.hh:21
@ f_uncommon
User interfaces should not display handler by default.
Definition handler.hh:38
@ f_calm
Read handler value changes rarely.
Definition handler.hh:40
@ f_expensive
Read handler is expensive to call.
Definition handler.hh:41
@ f_special
These flags may not be set by Router::set_handler_flags().
Definition handler.hh:56
@ f_read
Handler supports read operations.
Definition handler.hh:22
@ f_exclusive
Handler is exclusive (the default): router threads must stop while it is called.
Definition handler.hh:25
@ f_button
Write handler ignores data.
Definition handler.hh:42
@ f_user0
First uninterpreted handler flag available for element-specific use. Equals 1 << f_user_shift.
Definition handler.hh:49
@ f_raw
Don't add newline to results.
Definition handler.hh:31
@ f_deprecated
outside the router configuration).
Definition handler.hh:36
@ f_nonexclusive
Handler is nonexclusive: router threads don't need to stop while it is called.
Definition handler.hh:28
@ f_read_param
Read handler takes parameters.
Definition handler.hh:24
@ f_write_private
Write handler private (invisible.
Definition handler.hh:34
@ f_read_private
Read handler private (invisible outside the router configuration).
Definition handler.hh:32
@ f_driver1
Uninterpreted handler flags available for drivers.
Definition handler.hh:46
@ f_checkbox
Read/write handler is boolean and should be rendered as a checkbox.
Definition handler.hh:43
@ f_write
Handler supports write operations.
Definition handler.hh:23
void * write_user_data() const
Return this handler's write callback data.
Definition handler.hh:85
String call_read(Element *e, ErrorHandler *errh=0) const
Call a read handler without parameters.
Definition handler.hh:186
bool write_visible() const
Test if this is a public write handler.
Definition handler.hh:125
void * read_user_data() const
Return this handler's read callback data.
Definition handler.hh:80
bool read_visible() const
Test if this is a public read handler.
Definition handler.hh:111
bool allow_concurrent_handlers() const
Test if this handler can execute concurrently with other handlers.
Definition handler.hh:136
bool writable() const
Test if this is a valid write handler.
Definition handler.hh:116
String call_read(Element *e, const String &param, ErrorHandler *errh) const
Call a read handler, possibly with parameters.
Definition router.cc:1691
A router configuration.
Definition router.hh:28
A string of characters.
Definition string.hh:22
Click's String class.