… | |
… | |
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_CXX_EXCEPTIONS |
49 | #ifndef EV_USE_STDEXCEPT |
50 | #define EV_CXX_EXCEPTIONS 1 |
50 | # define EV_USE_STDEXCEPT 1 |
51 | #endif |
51 | #endif |
52 | |
52 | |
53 | #undef EV_THROW |
53 | #if EV_USE_STDEXCEPT |
54 | #if EV_CXX_EXCEPTIONS |
|
|
55 | # include <stdexcept> |
54 | # include <stdexcept> |
56 | # define EV_THROW(exception) throw (exception) |
|
|
57 | #else |
|
|
58 | # define EV_THROW(exception) |
|
|
59 | #endif |
55 | #endif |
60 | |
56 | |
61 | namespace ev { |
57 | namespace ev { |
62 | |
58 | |
63 | typedef ev_tstamp tstamp; |
59 | typedef ev_tstamp tstamp; |
… | |
… | |
103 | { |
99 | { |
104 | ONE = EVUNLOOP_ONE, |
100 | ONE = EVUNLOOP_ONE, |
105 | ALL = EVUNLOOP_ALL |
101 | ALL = EVUNLOOP_ALL |
106 | }; |
102 | }; |
107 | |
103 | |
108 | #if EV_CXX_EXCEPTIONS |
104 | struct bad_loop |
109 | struct bad_loop : std::runtime_error |
105 | #if EV_USE_STDEXCEPT |
|
|
106 | : std::runtime_error |
|
|
107 | #endif |
110 | { |
108 | { |
|
|
109 | #if EV_USE_STDEXCEPT |
111 | bad_loop () |
110 | bad_loop () |
112 | : std::runtime_error ("loop can't be initialized") |
111 | : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?") |
113 | { |
|
|
114 | } |
112 | { |
115 | }; |
113 | } |
116 | #endif |
114 | #endif |
|
|
115 | }; |
117 | |
116 | |
118 | #ifdef EV_AX |
117 | #ifdef EV_AX |
119 | # undef EV_AX |
118 | # undef EV_AX |
120 | #endif |
119 | #endif |
121 | |
120 | |
… | |
… | |
132 | #endif |
131 | #endif |
133 | |
132 | |
134 | struct loop_ref |
133 | struct loop_ref |
135 | { |
134 | { |
136 | |
135 | |
137 | loop_ref (EV_P) |
136 | loop_ref (EV_P) throw () |
138 | #if EV_MULTIPLICITY |
137 | #if EV_MULTIPLICITY |
139 | EV_THROW (bad_loop) : EV_AX (EV_A) |
138 | : EV_AX (EV_A) |
140 | #endif |
139 | #endif |
141 | { |
|
|
142 | #if EV_MULTIPLICIY && EV_CXX_EXCEPTIONS |
|
|
143 | if (!EV_A) |
|
|
144 | throw bad_loop (); |
|
|
145 | #endif |
|
|
146 | } |
140 | { |
|
|
141 | } |
147 | |
142 | |
148 | bool operator== (const loop_ref &other) const throw () |
143 | bool operator == (const loop_ref &other) const throw () |
149 | { |
144 | { |
150 | #if EV_MULTIPLICITY |
145 | #if EV_MULTIPLICITY |
151 | return this->EV_AX == other.EV_AX; |
146 | return EV_AX == other.EV_AX; |
152 | #else |
147 | #else |
153 | return true; |
148 | return true; |
154 | #endif |
149 | #endif |
155 | } |
150 | } |
156 | |
151 | |
157 | bool operator!= (const loop_ref &other) const throw () |
152 | bool operator != (const loop_ref &other) const throw () |
158 | { |
153 | { |
159 | #if EV_MULTIPLICITY |
154 | #if EV_MULTIPLICITY |
160 | return ! (*this == other); |
155 | return ! (*this == other); |
161 | #else |
156 | #else |
162 | return false; |
157 | return false; |
… | |
… | |
343 | #endif |
338 | #endif |
344 | |
339 | |
345 | }; |
340 | }; |
346 | |
341 | |
347 | #if EV_MULTIPLICITY |
342 | #if EV_MULTIPLICITY |
348 | struct dynamic_loop: loop_ref |
343 | struct dynamic_loop : loop_ref |
349 | { |
344 | { |
350 | |
345 | |
351 | dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) |
346 | dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) |
352 | : loop_ref (ev_loop_new (flags)) |
347 | : loop_ref (ev_loop_new (flags)) |
353 | { |
348 | { |
|
|
349 | if (!EV_AX) |
|
|
350 | throw bad_loop (); |
354 | } |
351 | } |
355 | |
352 | |
356 | ~dynamic_loop () throw () |
353 | ~dynamic_loop () throw () |
357 | { |
354 | { |
358 | ev_loop_destroy (EV_AX); |
355 | ev_loop_destroy (EV_AX); |
… | |
… | |
366 | dynamic_loop & operator= (const dynamic_loop &); |
363 | dynamic_loop & operator= (const dynamic_loop &); |
367 | |
364 | |
368 | }; |
365 | }; |
369 | #endif |
366 | #endif |
370 | |
367 | |
371 | struct default_loop: loop_ref |
368 | struct default_loop : loop_ref |
372 | { |
369 | { |
373 | |
370 | |
374 | default_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) |
371 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
375 | #if EV_MULTIPLICITY |
372 | #if EV_MULTIPLICITY |
376 | : loop_ref (ev_default_loop (flags)) |
373 | : loop_ref (ev_default_loop (flags)) |
377 | { |
374 | #endif |
378 | } |
375 | { |
|
|
376 | if ( |
|
|
377 | #if EV_MULTIPLICITY |
|
|
378 | !EV_AX |
379 | #else |
379 | #else |
380 | { |
|
|
381 | #if EV_CXX_EXCEPTIONS |
|
|
382 | int r = |
|
|
383 | #endif |
|
|
384 | ev_default_loop (flags); |
380 | !ev_default_loop (flags) |
385 | #if EV_CXX_EXCEPTIONS |
381 | #endif |
386 | if (!r) |
382 | ) |
387 | throw bad_loop (); |
383 | throw bad_loop (); |
388 | #endif |
|
|
389 | } |
384 | } |
390 | #endif |
|
|
391 | |
385 | |
392 | ~default_loop () throw () |
386 | ~default_loop () throw () |
393 | { |
387 | { |
394 | ev_default_destroy (); |
388 | ev_default_destroy (); |
395 | #if EV_MULTIPLICITY |
|
|
396 | EV_AX = 0; |
|
|
397 | #endif |
|
|
398 | } |
389 | } |
399 | |
390 | |
400 | private: |
391 | private: |
401 | |
|
|
402 | default_loop (const default_loop &); |
392 | default_loop (const default_loop &); |
403 | |
|
|
404 | default_loop & operator= (const default_loop &); |
393 | default_loop &operator = (const default_loop &); |
405 | |
|
|
406 | }; |
394 | }; |
407 | |
395 | |
408 | inline loop_ref get_default_loop () throw () |
396 | inline loop_ref get_default_loop () throw () |
409 | { |
397 | { |
410 | #if EV_MULTIPLICITY |
398 | #if EV_MULTIPLICITY |
… | |
… | |
788 | #undef EV_BEGIN_WATCHER |
776 | #undef EV_BEGIN_WATCHER |
789 | #undef EV_END_WATCHER |
777 | #undef EV_END_WATCHER |
790 | |
778 | |
791 | } |
779 | } |
792 | |
780 | |
793 | #undef EV_THROW |
|
|
794 | |
|
|
795 | #endif |
781 | #endif |
796 | |
782 | |