… | |
… | |
44 | # include EV_H |
44 | # include EV_H |
45 | #else |
45 | #else |
46 | # include "ev.h" |
46 | # include "ev.h" |
47 | #endif |
47 | #endif |
48 | |
48 | |
|
|
49 | #ifndef EV_USE_STDEXCEPT |
|
|
50 | # define EV_USE_STDEXCEPT 1 |
|
|
51 | #endif |
|
|
52 | |
|
|
53 | #if EV_USE_STDEXCEPT |
|
|
54 | # include <stdexcept> |
|
|
55 | #endif |
|
|
56 | |
49 | namespace ev { |
57 | namespace ev { |
50 | |
58 | |
51 | typedef ev_tstamp tstamp; |
59 | typedef ev_tstamp tstamp; |
52 | |
60 | |
53 | enum { |
61 | enum { |
… | |
… | |
91 | { |
99 | { |
92 | ONE = EVUNLOOP_ONE, |
100 | ONE = EVUNLOOP_ONE, |
93 | ALL = EVUNLOOP_ALL |
101 | ALL = EVUNLOOP_ALL |
94 | }; |
102 | }; |
95 | |
103 | |
|
|
104 | struct bad_loop |
|
|
105 | #if EV_USE_STDEXCEPT |
|
|
106 | : std::runtime_error |
|
|
107 | #endif |
|
|
108 | { |
|
|
109 | #if EV_USE_STDEXCEPT |
|
|
110 | bad_loop () |
|
|
111 | : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?") |
|
|
112 | { |
|
|
113 | } |
|
|
114 | #endif |
|
|
115 | }; |
|
|
116 | |
96 | #ifdef EV_AX |
117 | #ifdef EV_AX |
97 | # undef EV_AX |
118 | # undef EV_AX |
98 | #endif |
119 | #endif |
99 | |
120 | |
100 | #ifdef EV_AX_ |
121 | #ifdef EV_AX_ |
… | |
… | |
112 | struct loop_ref |
133 | struct loop_ref |
113 | { |
134 | { |
114 | |
135 | |
115 | loop_ref (EV_P) |
136 | loop_ref (EV_P) |
116 | #if EV_MULTIPLICITY |
137 | #if EV_MULTIPLICITY |
117 | : EV_AX (EV_A) |
138 | throw (bad_loop) : EV_AX (EV_A) |
118 | #endif |
|
|
119 | { |
|
|
120 | } |
139 | { |
|
|
140 | if (!EV_AX) |
|
|
141 | throw bad_loop (); |
|
|
142 | } |
|
|
143 | #else |
|
|
144 | throw () |
|
|
145 | { |
|
|
146 | } |
|
|
147 | #endif |
121 | |
148 | |
122 | bool operator== (const loop_ref &other) const |
149 | bool operator == (const loop_ref &other) const throw () |
123 | { |
150 | { |
124 | #if EV_MULTIPLICITY |
151 | #if EV_MULTIPLICITY |
125 | return this->EV_AX == other.EV_AX; |
152 | return EV_AX == other.EV_AX; |
126 | #else |
153 | #else |
127 | return true; |
154 | return true; |
128 | #endif |
155 | #endif |
129 | } |
156 | } |
130 | |
157 | |
131 | bool operator!= (const loop_ref &other) const |
158 | bool operator != (const loop_ref &other) const throw () |
132 | { |
159 | { |
133 | #if EV_MULTIPLICITY |
160 | #if EV_MULTIPLICITY |
134 | return ! (*this == other); |
161 | return ! (*this == other); |
135 | #else |
162 | #else |
136 | return false; |
163 | return false; |
137 | #endif |
164 | #endif |
138 | } |
165 | } |
139 | |
166 | |
140 | #if EV_MULTIPLICITY |
167 | #if EV_MULTIPLICITY |
141 | bool operator== (struct ev_loop *other) const |
168 | bool operator== (struct ev_loop *other) const throw () |
142 | { |
169 | { |
143 | return this->EV_AX == other; |
170 | return this->EV_AX == other; |
144 | } |
171 | } |
145 | |
172 | |
146 | bool operator!= (struct ev_loop *other) const |
173 | bool operator!= (struct ev_loop *other) const throw () |
147 | { |
174 | { |
148 | return ! (*this == other); |
175 | return ! (*this == other); |
149 | } |
176 | } |
150 | |
177 | |
151 | bool operator== (const struct ev_loop *other) const |
178 | bool operator== (const struct ev_loop *other) const throw () |
152 | { |
179 | { |
153 | return this->EV_AX == other; |
180 | return this->EV_AX == other; |
154 | } |
181 | } |
155 | |
182 | |
156 | bool operator!= (const struct ev_loop *other) const |
183 | bool operator!= (const struct ev_loop *other) const throw () |
157 | { |
184 | { |
158 | return (*this == other); |
185 | return (*this == other); |
159 | } |
186 | } |
160 | |
187 | |
161 | operator struct ev_loop * () const |
188 | operator struct ev_loop * () const throw () |
162 | { |
189 | { |
163 | return EV_AX; |
190 | return EV_AX; |
164 | } |
191 | } |
165 | |
192 | |
166 | operator const struct ev_loop * () const |
193 | operator const struct ev_loop * () const throw () |
167 | { |
194 | { |
168 | return EV_AX; |
195 | return EV_AX; |
169 | } |
196 | } |
170 | |
197 | |
171 | bool is_default () const |
198 | bool is_default () const throw () |
172 | { |
199 | { |
173 | return EV_AX == ev_default_loop (0); |
200 | return EV_AX == ev_default_loop (0); |
174 | } |
201 | } |
175 | #endif |
202 | #endif |
176 | |
203 | |
177 | void loop (int flags = 0) |
204 | void loop (int flags = 0) |
178 | { |
205 | { |
179 | ev_loop (EV_AX_ flags); |
206 | ev_loop (EV_AX_ flags); |
180 | } |
207 | } |
181 | |
208 | |
182 | void unloop (how_t how = ONE) |
209 | void unloop (how_t how = ONE) throw () |
183 | { |
210 | { |
184 | ev_unloop (EV_AX_ how); |
211 | ev_unloop (EV_AX_ how); |
185 | } |
212 | } |
186 | |
213 | |
187 | void post_fork () |
214 | void post_fork () throw () |
188 | { |
215 | { |
189 | #if EV_MULTIPLICITY |
216 | #if EV_MULTIPLICITY |
190 | ev_loop_fork (EV_AX); |
217 | ev_loop_fork (EV_AX); |
191 | #else |
218 | #else |
192 | ev_default_fork (); |
219 | ev_default_fork (); |
193 | #endif |
220 | #endif |
194 | } |
221 | } |
195 | |
222 | |
196 | unsigned int count () const |
223 | unsigned int count () const throw () |
197 | { |
224 | { |
198 | return ev_loop_count (EV_AX); |
225 | return ev_loop_count (EV_AX); |
199 | } |
226 | } |
200 | |
227 | |
201 | unsigned int backend () const |
228 | unsigned int backend () const throw () |
202 | { |
229 | { |
203 | return ev_backend (EV_AX); |
230 | return ev_backend (EV_AX); |
204 | } |
231 | } |
205 | |
232 | |
206 | tstamp now () const |
233 | tstamp now () const throw () |
207 | { |
234 | { |
208 | return ev_now (EV_AX); |
235 | return ev_now (EV_AX); |
209 | } |
236 | } |
210 | |
237 | |
211 | void ref () |
238 | void ref () throw () |
212 | { |
239 | { |
213 | ev_ref (EV_AX); |
240 | ev_ref (EV_AX); |
214 | } |
241 | } |
215 | |
242 | |
216 | void unref () |
243 | void unref () throw () |
217 | { |
244 | { |
218 | ev_unref (EV_AX); |
245 | ev_unref (EV_AX); |
219 | } |
246 | } |
220 | |
247 | |
221 | void set_io_collect_interval (tstamp interval) |
248 | void set_io_collect_interval (tstamp interval) throw () |
222 | { |
249 | { |
223 | ev_set_io_collect_interval (EV_AX_ interval); |
250 | ev_set_io_collect_interval (EV_AX_ interval); |
224 | } |
251 | } |
225 | |
252 | |
226 | void set_timeout_collect_interval (tstamp interval) |
253 | void set_timeout_collect_interval (tstamp interval) throw () |
227 | { |
254 | { |
228 | ev_set_timeout_collect_interval (EV_AX_ interval); |
255 | ev_set_timeout_collect_interval (EV_AX_ interval); |
229 | } |
256 | } |
230 | |
257 | |
231 | // function callback |
258 | // function callback |
232 | void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) |
259 | void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw () |
233 | { |
260 | { |
234 | ev_once (EV_AX_ fd, events, timeout, cb, arg); |
261 | ev_once (EV_AX_ fd, events, timeout, cb, arg); |
235 | } |
262 | } |
236 | |
263 | |
237 | // method callback |
264 | // method callback |
238 | template<class K, void (K::*method)(int)> |
265 | template<class K, void (K::*method)(int)> |
239 | void once (int fd, int events, tstamp timeout, K *object) |
266 | void once (int fd, int events, tstamp timeout, K *object) throw () |
240 | { |
267 | { |
241 | once (fd, events, timeout, method_thunk<K, method>, object); |
268 | once (fd, events, timeout, method_thunk<K, method>, object); |
242 | } |
269 | } |
243 | |
270 | |
244 | template<class K, void (K::*method)(int)> |
271 | template<class K, void (K::*method)(int)> |
… | |
… | |
248 | (obj->*method) (revents); |
275 | (obj->*method) (revents); |
249 | } |
276 | } |
250 | |
277 | |
251 | // const method callback |
278 | // const method callback |
252 | template<class K, void (K::*method)(int) const> |
279 | template<class K, void (K::*method)(int) const> |
253 | void once (int fd, int events, tstamp timeout, const K *object) |
280 | void once (int fd, int events, tstamp timeout, const K *object) throw () |
254 | { |
281 | { |
255 | once (fd, events, timeout, const_method_thunk<K, method>, object); |
282 | once (fd, events, timeout, const_method_thunk<K, method>, object); |
256 | } |
283 | } |
257 | |
284 | |
258 | template<class K, void (K::*method)(int) const> |
285 | template<class K, void (K::*method)(int) const> |
… | |
… | |
262 | (obj->*method) (revents); |
289 | (obj->*method) (revents); |
263 | } |
290 | } |
264 | |
291 | |
265 | // simple method callback |
292 | // simple method callback |
266 | template<class K, void (K::*method)()> |
293 | template<class K, void (K::*method)()> |
267 | void once (int fd, int events, tstamp timeout, K *object) |
294 | void once (int fd, int events, tstamp timeout, K *object) throw () |
268 | { |
295 | { |
269 | once (fd, events, timeout, method_noargs_thunk<K, method>, object); |
296 | once (fd, events, timeout, method_noargs_thunk<K, method>, object); |
270 | } |
297 | } |
271 | |
298 | |
272 | template<class K, void (K::*method)()> |
299 | template<class K, void (K::*method)()> |
… | |
… | |
276 | (obj->*method) (); |
303 | (obj->*method) (); |
277 | } |
304 | } |
278 | |
305 | |
279 | // simpler function callback |
306 | // simpler function callback |
280 | template<void (*cb)(int)> |
307 | template<void (*cb)(int)> |
281 | void once (int fd, int events, tstamp timeout) |
308 | void once (int fd, int events, tstamp timeout) throw () |
282 | { |
309 | { |
283 | once (fd, events, timeout, simpler_func_thunk<cb>); |
310 | once (fd, events, timeout, simpler_func_thunk<cb>); |
284 | } |
311 | } |
285 | |
312 | |
286 | template<void (*cb)(int)> |
313 | template<void (*cb)(int)> |
… | |
… | |
289 | (*cb) (revents); |
316 | (*cb) (revents); |
290 | } |
317 | } |
291 | |
318 | |
292 | // simplest function callback |
319 | // simplest function callback |
293 | template<void (*cb)()> |
320 | template<void (*cb)()> |
294 | void once (int fd, int events, tstamp timeout) |
321 | void once (int fd, int events, tstamp timeout) throw () |
295 | { |
322 | { |
296 | once (fd, events, timeout, simplest_func_thunk<cb>); |
323 | once (fd, events, timeout, simplest_func_thunk<cb>); |
297 | } |
324 | } |
298 | |
325 | |
299 | template<void (*cb)()> |
326 | template<void (*cb)()> |
300 | static void simplest_func_thunk (int revents, void* arg) |
327 | static void simplest_func_thunk (int revents, void* arg) |
301 | { |
328 | { |
302 | (*cb) (); |
329 | (*cb) (); |
303 | } |
330 | } |
304 | |
331 | |
305 | void feed_fd_event (int fd, int revents) |
332 | void feed_fd_event (int fd, int revents) throw () |
306 | { |
333 | { |
307 | ev_feed_fd_event (EV_AX_ fd, revents); |
334 | ev_feed_fd_event (EV_AX_ fd, revents); |
308 | } |
335 | } |
309 | |
336 | |
310 | void feed_signal_event (int signum) |
337 | void feed_signal_event (int signum) throw () |
311 | { |
338 | { |
312 | ev_feed_signal_event (EV_AX_ signum); |
339 | ev_feed_signal_event (EV_AX_ signum); |
313 | } |
340 | } |
314 | |
341 | |
315 | #if EV_MULTIPLICITY |
342 | #if EV_MULTIPLICITY |
… | |
… | |
320 | |
347 | |
321 | #if EV_MULTIPLICITY |
348 | #if EV_MULTIPLICITY |
322 | struct dynamic_loop: loop_ref |
349 | struct dynamic_loop: loop_ref |
323 | { |
350 | { |
324 | |
351 | |
325 | dynamic_loop (unsigned int flags = AUTO) |
352 | dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) |
326 | : loop_ref (ev_loop_new (flags)) |
353 | : loop_ref (ev_loop_new (flags)) |
327 | { |
354 | { |
328 | } |
355 | } |
329 | |
356 | |
330 | ~dynamic_loop () |
357 | ~dynamic_loop () throw () |
331 | { |
358 | { |
332 | ev_loop_destroy (EV_AX); |
359 | ev_loop_destroy (EV_AX); |
333 | EV_AX = 0; |
360 | EV_AX = 0; |
334 | } |
361 | } |
335 | |
362 | |
… | |
… | |
343 | #endif |
370 | #endif |
344 | |
371 | |
345 | struct default_loop: loop_ref |
372 | struct default_loop: loop_ref |
346 | { |
373 | { |
347 | |
374 | |
348 | default_loop (unsigned int flags = AUTO) |
375 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
349 | #if EV_MULTIPLICITY |
376 | #if EV_MULTIPLICITY |
350 | : loop_ref (ev_default_loop (flags)) |
377 | : loop_ref (ev_default_loop (flags)) |
351 | { |
378 | #endif |
352 | } |
379 | { |
353 | #else |
380 | #ifndef EV_MULTIPLICITY |
354 | { |
|
|
355 | ev_default_loop (flags); |
381 | if (!ev_default_loop (flags)) |
356 | } |
382 | throw bad_loop (); |
357 | #endif |
383 | #endif |
|
|
384 | } |
358 | |
385 | |
359 | ~default_loop () |
386 | ~default_loop () throw () |
360 | { |
387 | { |
361 | ev_default_destroy (); |
388 | ev_default_destroy (); |
362 | #if EV_MULTIPLICITY |
|
|
363 | EV_AX = 0; |
|
|
364 | #endif |
|
|
365 | } |
389 | } |
366 | |
390 | |
367 | private: |
391 | private: |
368 | |
|
|
369 | default_loop (const default_loop &); |
392 | default_loop (const default_loop &); |
370 | |
|
|
371 | default_loop & operator= (const default_loop &); |
393 | default_loop &operator = (const default_loop &); |
372 | |
|
|
373 | }; |
394 | }; |
374 | |
395 | |
375 | inline loop_ref get_default_loop () |
396 | inline loop_ref get_default_loop () throw () |
376 | { |
397 | { |
377 | #if EV_MULTIPLICITY |
398 | #if EV_MULTIPLICITY |
378 | return ev_default_loop (0); |
399 | return ev_default_loop (0); |
379 | #else |
400 | #else |
380 | return loop_ref (); |
401 | return loop_ref (); |
… | |
… | |
398 | struct base : ev_watcher |
419 | struct base : ev_watcher |
399 | { |
420 | { |
400 | #if EV_MULTIPLICITY |
421 | #if EV_MULTIPLICITY |
401 | EV_PX; |
422 | EV_PX; |
402 | |
423 | |
403 | void set (EV_PX) |
424 | void set (EV_PX) throw () |
404 | { |
425 | { |
405 | this->EV_A = EV_A; |
426 | this->EV_A = EV_A; |
406 | } |
427 | } |
407 | #endif |
428 | #endif |
408 | |
429 | |
409 | base (EV_PX) |
430 | base (EV_PX) throw () |
410 | #if EV_MULTIPLICITY |
431 | #if EV_MULTIPLICITY |
411 | : EV_A (EV_A) |
432 | : EV_A (EV_A) |
412 | #endif |
433 | #endif |
413 | { |
434 | { |
414 | ev_init (this, 0); |
435 | ev_init (this, 0); |
415 | } |
436 | } |
416 | |
437 | |
417 | void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) |
438 | void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () |
418 | { |
439 | { |
419 | this->data = data; |
440 | this->data = data; |
420 | ev_set_cb (static_cast<ev_watcher *>(this), cb); |
441 | ev_set_cb (static_cast<ev_watcher *>(this), cb); |
421 | } |
442 | } |
422 | |
443 | |
423 | // method callback |
444 | // method callback |
424 | template<class K, void (K::*method)(watcher &w, int)> |
445 | template<class K, void (K::*method)(watcher &w, int)> |
425 | void set (K *object) |
446 | void set (K *object) throw () |
426 | { |
447 | { |
427 | set_ (object, method_thunk<K, method>); |
448 | set_ (object, method_thunk<K, method>); |
428 | } |
449 | } |
429 | |
450 | |
430 | template<class K, void (K::*method)(watcher &w, int)> |
451 | template<class K, void (K::*method)(watcher &w, int)> |
… | |
… | |
434 | (obj->*method) (*static_cast<watcher *>(w), revents); |
455 | (obj->*method) (*static_cast<watcher *>(w), revents); |
435 | } |
456 | } |
436 | |
457 | |
437 | // const method callback |
458 | // const method callback |
438 | template<class K, void (K::*method)(watcher &w, int) const> |
459 | template<class K, void (K::*method)(watcher &w, int) const> |
439 | void set (const K *object) |
460 | void set (const K *object) throw () |
440 | { |
461 | { |
441 | set_ (object, const_method_thunk<K, method>); |
462 | set_ (object, const_method_thunk<K, method>); |
442 | } |
463 | } |
443 | |
464 | |
444 | template<class K, void (K::*method)(watcher &w, int) const> |
465 | template<class K, void (K::*method)(watcher &w, int) const> |
… | |
… | |
448 | (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents); |
469 | (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents); |
449 | } |
470 | } |
450 | |
471 | |
451 | // function callback |
472 | // function callback |
452 | template<void (*function)(watcher &w, int)> |
473 | template<void (*function)(watcher &w, int)> |
453 | void set (void *data = 0) |
474 | void set (void *data = 0) throw () |
454 | { |
475 | { |
455 | set_ (data, function_thunk<function>); |
476 | set_ (data, function_thunk<function>); |
456 | } |
477 | } |
457 | |
478 | |
458 | template<void (*function)(watcher &w, int)> |
479 | template<void (*function)(watcher &w, int)> |
… | |
… | |
461 | function (*static_cast<watcher *>(w), revents); |
482 | function (*static_cast<watcher *>(w), revents); |
462 | } |
483 | } |
463 | |
484 | |
464 | // simple callback |
485 | // simple callback |
465 | template<class K, void (K::*method)()> |
486 | template<class K, void (K::*method)()> |
466 | void set (K *object) |
487 | void set (K *object) throw () |
467 | { |
488 | { |
468 | set_ (object, method_noargs_thunk<K, method>); |
489 | set_ (object, method_noargs_thunk<K, method>); |
469 | } |
490 | } |
470 | |
491 | |
471 | template<class K, void (K::*method)()> |
492 | template<class K, void (K::*method)()> |
… | |
… | |
479 | { |
500 | { |
480 | return ev_cb (static_cast<ev_watcher *>(this)) |
501 | return ev_cb (static_cast<ev_watcher *>(this)) |
481 | (static_cast<ev_watcher *>(this), events); |
502 | (static_cast<ev_watcher *>(this), events); |
482 | } |
503 | } |
483 | |
504 | |
484 | bool is_active () const |
505 | bool is_active () const throw () |
485 | { |
506 | { |
486 | return ev_is_active (static_cast<const ev_watcher *>(this)); |
507 | return ev_is_active (static_cast<const ev_watcher *>(this)); |
487 | } |
508 | } |
488 | |
509 | |
489 | bool is_pending () const |
510 | bool is_pending () const throw () |
490 | { |
511 | { |
491 | return ev_is_pending (static_cast<const ev_watcher *>(this)); |
512 | return ev_is_pending (static_cast<const ev_watcher *>(this)); |
492 | } |
513 | } |
493 | |
514 | |
494 | void feed_event (int revents) |
515 | void feed_event (int revents) throw () |
495 | { |
516 | { |
496 | ev_feed_event (EV_A_ static_cast<const ev_watcher *>(this), revents); |
517 | ev_feed_event (EV_A_ static_cast<const ev_watcher *>(this), revents); |
497 | } |
518 | } |
498 | }; |
519 | }; |
499 | |
520 | |
|
|
521 | inline tstamp now () throw () |
|
|
522 | { |
|
|
523 | return ev_time (); |
|
|
524 | } |
|
|
525 | |
500 | inline void delay (tstamp interval) |
526 | inline void delay (tstamp interval) throw () |
501 | { |
527 | { |
502 | ev_sleep (interval); |
528 | ev_sleep (interval); |
503 | } |
529 | } |
504 | |
530 | |
505 | inline int version_major () |
531 | inline int version_major () throw () |
506 | { |
532 | { |
507 | return ev_version_major (); |
533 | return ev_version_major (); |
508 | } |
534 | } |
509 | |
535 | |
510 | inline int version_minor () |
536 | inline int version_minor () throw () |
511 | { |
537 | { |
512 | return ev_version_minor (); |
538 | return ev_version_minor (); |
513 | } |
539 | } |
514 | |
540 | |
515 | inline unsigned int supported_backends () |
541 | inline unsigned int supported_backends () throw () |
516 | { |
542 | { |
517 | return ev_supported_backends (); |
543 | return ev_supported_backends (); |
518 | } |
544 | } |
519 | |
545 | |
520 | inline unsigned int recommended_backends () |
546 | inline unsigned int recommended_backends () throw () |
521 | { |
547 | { |
522 | return ev_recommended_backends (); |
548 | return ev_recommended_backends (); |
523 | } |
549 | } |
524 | |
550 | |
525 | inline unsigned int embeddable_backends () |
551 | inline unsigned int embeddable_backends () throw () |
526 | { |
552 | { |
527 | return ev_embeddable_backends (); |
553 | return ev_embeddable_backends (); |
528 | } |
554 | } |
529 | |
555 | |
530 | inline void set_allocator (void *(*cb)(void *ptr, long size)) |
556 | inline void set_allocator (void *(*cb)(void *ptr, long size)) throw () |
531 | { |
557 | { |
532 | ev_set_allocator (cb); |
558 | ev_set_allocator (cb); |
533 | } |
559 | } |
534 | |
560 | |
535 | inline void set_syserr_cb (void (*cb)(const char *msg)) |
561 | inline void set_syserr_cb (void (*cb)(const char *msg)) throw () |
536 | { |
562 | { |
537 | ev_set_syserr_cb (cb); |
563 | ev_set_syserr_cb (cb); |
538 | } |
564 | } |
539 | |
565 | |
540 | #if EV_MULTIPLICITY |
566 | #if EV_MULTIPLICITY |
541 | #define EV_CONSTRUCT(cppstem,cstem) \ |
567 | #define EV_CONSTRUCT(cppstem,cstem) \ |
542 | (EV_PX = get_default_loop ()) \ |
568 | (EV_PX = get_default_loop ()) throw () \ |
543 | : base<ev_ ## cstem, cppstem> (EV_A) \ |
569 | : base<ev_ ## cstem, cppstem> (EV_A) \ |
544 | { \ |
570 | { \ |
545 | } |
571 | } |
546 | #else |
572 | #else |
547 | #define EV_CONSTRUCT(cppstem,cstem) \ |
573 | #define EV_CONSTRUCT(cppstem,cstem) \ |
548 | () \ |
574 | () throw () \ |
549 | { \ |
575 | { \ |
550 | } |
576 | } |
551 | #endif |
577 | #endif |
552 | |
578 | |
553 | /* using a template here would require quite a bit more lines, |
579 | /* using a template here would require quite a bit more lines, |
554 | * so a macro solution was chosen */ |
580 | * so a macro solution was chosen */ |
555 | #define EV_BEGIN_WATCHER(cppstem,cstem) \ |
581 | #define EV_BEGIN_WATCHER(cppstem,cstem) \ |
556 | \ |
582 | \ |
557 | struct cppstem : base<ev_ ## cstem, cppstem> \ |
583 | struct cppstem : base<ev_ ## cstem, cppstem> \ |
558 | { \ |
584 | { \ |
559 | void start () \ |
585 | void start () throw () \ |
560 | { \ |
586 | { \ |
561 | ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
587 | ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
562 | } \ |
588 | } \ |
563 | \ |
589 | \ |
564 | void stop () \ |
590 | void stop () throw () \ |
565 | { \ |
591 | { \ |
566 | ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
592 | ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
567 | } \ |
593 | } \ |
568 | \ |
594 | \ |
569 | cppstem EV_CONSTRUCT(cppstem,cstem) \ |
595 | cppstem EV_CONSTRUCT(cppstem,cstem) \ |
570 | \ |
596 | \ |
571 | ~cppstem () \ |
597 | ~cppstem () throw () \ |
572 | { \ |
598 | { \ |
573 | stop (); \ |
599 | stop (); \ |
574 | } \ |
600 | } \ |
575 | \ |
601 | \ |
576 | using base<ev_ ## cstem, cppstem>::set; \ |
602 | using base<ev_ ## cstem, cppstem>::set; \ |
… | |
… | |
585 | |
611 | |
586 | #define EV_END_WATCHER(cppstem,cstem) \ |
612 | #define EV_END_WATCHER(cppstem,cstem) \ |
587 | }; |
613 | }; |
588 | |
614 | |
589 | EV_BEGIN_WATCHER (io, io) |
615 | EV_BEGIN_WATCHER (io, io) |
590 | void set (int fd, int events) |
616 | void set (int fd, int events) throw () |
591 | { |
617 | { |
592 | int active = is_active (); |
618 | int active = is_active (); |
593 | if (active) stop (); |
619 | if (active) stop (); |
594 | ev_io_set (static_cast<ev_io *>(this), fd, events); |
620 | ev_io_set (static_cast<ev_io *>(this), fd, events); |
595 | if (active) start (); |
621 | if (active) start (); |
596 | } |
622 | } |
597 | |
623 | |
598 | void set (int events) |
624 | void set (int events) throw () |
599 | { |
625 | { |
600 | int active = is_active (); |
626 | int active = is_active (); |
601 | if (active) stop (); |
627 | if (active) stop (); |
602 | ev_io_set (static_cast<ev_io *>(this), fd, events); |
628 | ev_io_set (static_cast<ev_io *>(this), fd, events); |
603 | if (active) start (); |
629 | if (active) start (); |
604 | } |
630 | } |
605 | |
631 | |
606 | void start (int fd, int events) |
632 | void start (int fd, int events) throw () |
607 | { |
633 | { |
608 | set (fd, events); |
634 | set (fd, events); |
609 | start (); |
635 | start (); |
610 | } |
636 | } |
611 | EV_END_WATCHER (io, io) |
637 | EV_END_WATCHER (io, io) |
612 | |
638 | |
613 | EV_BEGIN_WATCHER (timer, timer) |
639 | EV_BEGIN_WATCHER (timer, timer) |
614 | void set (ev_tstamp after, ev_tstamp repeat = 0.) |
640 | void set (ev_tstamp after, ev_tstamp repeat = 0.) throw () |
615 | { |
641 | { |
616 | int active = is_active (); |
642 | int active = is_active (); |
617 | if (active) stop (); |
643 | if (active) stop (); |
618 | ev_timer_set (static_cast<ev_timer *>(this), after, repeat); |
644 | ev_timer_set (static_cast<ev_timer *>(this), after, repeat); |
619 | if (active) start (); |
645 | if (active) start (); |
620 | } |
646 | } |
621 | |
647 | |
622 | void start (ev_tstamp after, ev_tstamp repeat = 0.) |
648 | void start (ev_tstamp after, ev_tstamp repeat = 0.) throw () |
623 | { |
649 | { |
624 | set (after, repeat); |
650 | set (after, repeat); |
625 | start (); |
651 | start (); |
626 | } |
652 | } |
627 | |
653 | |
628 | void again () |
654 | void again () throw () |
629 | { |
655 | { |
630 | ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); |
656 | ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); |
631 | } |
657 | } |
632 | EV_END_WATCHER (timer, timer) |
658 | EV_END_WATCHER (timer, timer) |
633 | |
659 | |
634 | #if EV_PERIODIC_ENABLE |
660 | #if EV_PERIODIC_ENABLE |
635 | EV_BEGIN_WATCHER (periodic, periodic) |
661 | EV_BEGIN_WATCHER (periodic, periodic) |
636 | void set (ev_tstamp at, ev_tstamp interval = 0.) |
662 | void set (ev_tstamp at, ev_tstamp interval = 0.) throw () |
637 | { |
663 | { |
638 | int active = is_active (); |
664 | int active = is_active (); |
639 | if (active) stop (); |
665 | if (active) stop (); |
640 | ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); |
666 | ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); |
641 | if (active) start (); |
667 | if (active) start (); |
642 | } |
668 | } |
643 | |
669 | |
644 | void start (ev_tstamp at, ev_tstamp interval = 0.) |
670 | void start (ev_tstamp at, ev_tstamp interval = 0.) throw () |
645 | { |
671 | { |
646 | set (at, interval); |
672 | set (at, interval); |
647 | start (); |
673 | start (); |
648 | } |
674 | } |
649 | |
675 | |
650 | void again () |
676 | void again () throw () |
651 | { |
677 | { |
652 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
678 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
653 | } |
679 | } |
654 | EV_END_WATCHER (periodic, periodic) |
680 | EV_END_WATCHER (periodic, periodic) |
655 | #endif |
681 | #endif |
656 | |
682 | |
657 | EV_BEGIN_WATCHER (sig, signal) |
683 | EV_BEGIN_WATCHER (sig, signal) |
658 | void set (int signum) |
684 | void set (int signum) throw () |
659 | { |
685 | { |
660 | int active = is_active (); |
686 | int active = is_active (); |
661 | if (active) stop (); |
687 | if (active) stop (); |
662 | ev_signal_set (static_cast<ev_signal *>(this), signum); |
688 | ev_signal_set (static_cast<ev_signal *>(this), signum); |
663 | if (active) start (); |
689 | if (active) start (); |
664 | } |
690 | } |
665 | |
691 | |
666 | void start (int signum) |
692 | void start (int signum) throw () |
667 | { |
693 | { |
668 | set (signum); |
694 | set (signum); |
669 | start (); |
695 | start (); |
670 | } |
696 | } |
671 | EV_END_WATCHER (sig, signal) |
697 | EV_END_WATCHER (sig, signal) |
672 | |
698 | |
673 | EV_BEGIN_WATCHER (child, child) |
699 | EV_BEGIN_WATCHER (child, child) |
674 | void set (int pid) |
700 | void set (int pid) throw () |
675 | { |
701 | { |
676 | int active = is_active (); |
702 | int active = is_active (); |
677 | if (active) stop (); |
703 | if (active) stop (); |
678 | ev_child_set (static_cast<ev_child *>(this), pid); |
704 | ev_child_set (static_cast<ev_child *>(this), pid); |
679 | if (active) start (); |
705 | if (active) start (); |
680 | } |
706 | } |
681 | |
707 | |
682 | void start (int pid) |
708 | void start (int pid) throw () |
683 | { |
709 | { |
684 | set (pid); |
710 | set (pid); |
685 | start (); |
711 | start (); |
686 | } |
712 | } |
687 | EV_END_WATCHER (child, child) |
713 | EV_END_WATCHER (child, child) |
688 | |
714 | |
689 | #if EV_STAT_ENABLE |
715 | #if EV_STAT_ENABLE |
690 | EV_BEGIN_WATCHER (stat, stat) |
716 | EV_BEGIN_WATCHER (stat, stat) |
691 | void set (const char *path, ev_tstamp interval = 0.) |
717 | void set (const char *path, ev_tstamp interval = 0.) throw () |
692 | { |
718 | { |
693 | int active = is_active (); |
719 | int active = is_active (); |
694 | if (active) stop (); |
720 | if (active) stop (); |
695 | ev_stat_set (static_cast<ev_stat *>(this), path, interval); |
721 | ev_stat_set (static_cast<ev_stat *>(this), path, interval); |
696 | if (active) start (); |
722 | if (active) start (); |
697 | } |
723 | } |
698 | |
724 | |
699 | void start (const char *path, ev_tstamp interval = 0.) |
725 | void start (const char *path, ev_tstamp interval = 0.) throw () |
700 | { |
726 | { |
701 | stop (); |
727 | stop (); |
702 | set (path, interval); |
728 | set (path, interval); |
703 | start (); |
729 | start (); |
704 | } |
730 | } |
705 | |
731 | |
706 | void update () |
732 | void update () throw () |
707 | { |
733 | { |
708 | ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); |
734 | ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); |
709 | } |
735 | } |
710 | EV_END_WATCHER (stat, stat) |
736 | EV_END_WATCHER (stat, stat) |
711 | #endif |
737 | #endif |
712 | |
738 | |
713 | EV_BEGIN_WATCHER (idle, idle) |
739 | EV_BEGIN_WATCHER (idle, idle) |
714 | void set () { } |
740 | void set () throw () { } |
715 | EV_END_WATCHER (idle, idle) |
741 | EV_END_WATCHER (idle, idle) |
716 | |
742 | |
717 | EV_BEGIN_WATCHER (prepare, prepare) |
743 | EV_BEGIN_WATCHER (prepare, prepare) |
718 | void set () { } |
744 | void set () throw () { } |
719 | EV_END_WATCHER (prepare, prepare) |
745 | EV_END_WATCHER (prepare, prepare) |
720 | |
746 | |
721 | EV_BEGIN_WATCHER (check, check) |
747 | EV_BEGIN_WATCHER (check, check) |
722 | void set () { } |
748 | void set () throw () { } |
723 | EV_END_WATCHER (check, check) |
749 | EV_END_WATCHER (check, check) |
724 | |
750 | |
725 | #if EV_EMBED_ENABLE |
751 | #if EV_EMBED_ENABLE |
726 | EV_BEGIN_WATCHER (embed, embed) |
752 | EV_BEGIN_WATCHER (embed, embed) |
727 | void start (struct ev_loop *embedded_loop) |
753 | void start (struct ev_loop *embedded_loop) throw () |
728 | { |
754 | { |
729 | stop (); |
755 | stop (); |
730 | ev_embed_set (static_cast<ev_embed *>(this), embedded_loop); |
756 | ev_embed_set (static_cast<ev_embed *>(this), embedded_loop); |
731 | start (); |
757 | start (); |
732 | } |
758 | } |
… | |
… | |
738 | EV_END_WATCHER (embed, embed) |
764 | EV_END_WATCHER (embed, embed) |
739 | #endif |
765 | #endif |
740 | |
766 | |
741 | #if EV_FORK_ENABLE |
767 | #if EV_FORK_ENABLE |
742 | EV_BEGIN_WATCHER (fork, fork) |
768 | EV_BEGIN_WATCHER (fork, fork) |
743 | void set () { } |
769 | void set () throw () { } |
744 | EV_END_WATCHER (fork, fork) |
770 | EV_END_WATCHER (fork, fork) |
745 | #endif |
771 | #endif |
746 | |
772 | |
747 | #undef EV_PX |
773 | #undef EV_PX |
748 | #undef EV_PX_ |
774 | #undef EV_PX_ |