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