… | |
… | |
39 | |
39 | |
40 | #ifndef EV_H_ |
40 | #ifndef EV_H_ |
41 | #define EV_H_ |
41 | #define EV_H_ |
42 | |
42 | |
43 | #ifdef __cplusplus |
43 | #ifdef __cplusplus |
|
|
44 | # define EV_CPP(x) x |
|
|
45 | #else |
|
|
46 | # define EV_CPP(x) |
|
|
47 | #endif |
|
|
48 | |
44 | extern "C" { |
49 | EV_CPP(extern "C" {) |
45 | #endif |
|
|
46 | |
50 | |
47 | /*****************************************************************************/ |
51 | /*****************************************************************************/ |
48 | |
52 | |
49 | /* pre-4.0 compatibility */ |
53 | /* pre-4.0 compatibility */ |
50 | #ifndef EV_COMPAT3 |
54 | #ifndef EV_COMPAT3 |
… | |
… | |
148 | #endif |
152 | #endif |
149 | |
153 | |
150 | /* support multiple event loops? */ |
154 | /* support multiple event loops? */ |
151 | #if EV_MULTIPLICITY |
155 | #if EV_MULTIPLICITY |
152 | struct ev_loop; |
156 | struct ev_loop; |
153 | # define EV_P struct ev_loop *loop |
157 | # define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */ |
154 | # define EV_P_ EV_P, |
158 | # define EV_P_ EV_P, /* a loop as first of multiple parameters */ |
155 | # define EV_A loop |
159 | # define EV_A loop /* a loop as sole argument to a function call */ |
156 | # define EV_A_ EV_A, |
160 | # define EV_A_ EV_A, /* a loop as first of multiple arguments */ |
157 | # define EV_DEFAULT_UC ev_default_loop_uc () |
161 | # define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */ |
158 | # define EV_DEFAULT_UC_ EV_DEFAULT_UC, |
162 | # define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */ |
159 | # define EV_DEFAULT ev_default_loop (0) |
163 | # define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */ |
160 | # define EV_DEFAULT_ EV_DEFAULT, |
164 | # define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */ |
161 | #else |
165 | #else |
162 | # define EV_P void |
166 | # define EV_P void |
163 | # define EV_P_ |
167 | # define EV_P_ |
164 | # define EV_A |
168 | # define EV_A |
165 | # define EV_A_ |
169 | # define EV_A_ |
… | |
… | |
168 | # define EV_DEFAULT_UC |
172 | # define EV_DEFAULT_UC |
169 | # define EV_DEFAULT_UC_ |
173 | # define EV_DEFAULT_UC_ |
170 | # undef EV_EMBED_ENABLE |
174 | # undef EV_EMBED_ENABLE |
171 | #endif |
175 | #endif |
172 | |
176 | |
|
|
177 | /* EV_INLINE is used for functions in header files */ |
173 | #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 |
178 | #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 |
174 | # define EV_INLINE static inline |
179 | # define EV_INLINE static inline |
175 | #else |
180 | #else |
176 | # define EV_INLINE static |
181 | # define EV_INLINE static |
177 | #endif |
182 | #endif |
178 | |
183 | |
|
|
184 | /* EV_PROTOTYPES can be sued to switch of prototype declarations */ |
179 | #ifndef EV_PROTOTYPES |
185 | #ifndef EV_PROTOTYPES |
180 | # define EV_PROTOTYPES 1 |
186 | # define EV_PROTOTYPES 1 |
181 | #endif |
187 | #endif |
182 | |
188 | |
183 | /*****************************************************************************/ |
189 | /*****************************************************************************/ |
… | |
… | |
192 | EV_READ = 0x01, /* ev_io detected read will not block */ |
198 | EV_READ = 0x01, /* ev_io detected read will not block */ |
193 | EV_WRITE = 0x02, /* ev_io detected write will not block */ |
199 | EV_WRITE = 0x02, /* ev_io detected write will not block */ |
194 | EV__IOFDSET = 0x80, /* internal use only */ |
200 | EV__IOFDSET = 0x80, /* internal use only */ |
195 | EV_IO = EV_READ, /* alias for type-detection */ |
201 | EV_IO = EV_READ, /* alias for type-detection */ |
196 | EV_TIMER = 0x00000100, /* timer timed out */ |
202 | EV_TIMER = 0x00000100, /* timer timed out */ |
|
|
203 | #if EV_COMPAT3 |
197 | EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */ |
204 | EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */ |
|
|
205 | #endif |
198 | EV_PERIODIC = 0x00000200, /* periodic timer timed out */ |
206 | EV_PERIODIC = 0x00000200, /* periodic timer timed out */ |
199 | EV_SIGNAL = 0x00000400, /* signal was received */ |
207 | EV_SIGNAL = 0x00000400, /* signal was received */ |
200 | EV_CHILD = 0x00000800, /* child/pid had status change */ |
208 | EV_CHILD = 0x00000800, /* child/pid had status change */ |
201 | EV_STAT = 0x00001000, /* stat data changed */ |
209 | EV_STAT = 0x00001000, /* stat data changed */ |
202 | EV_IDLE = 0x00002000, /* event loop is idling */ |
210 | EV_IDLE = 0x00002000, /* event loop is idling */ |
… | |
… | |
511 | } |
519 | } |
512 | |
520 | |
513 | /* the default loop is the only one that handles signals and child watchers */ |
521 | /* the default loop is the only one that handles signals and child watchers */ |
514 | /* you can call this as often as you like */ |
522 | /* you can call this as often as you like */ |
515 | EV_INLINE struct ev_loop * |
523 | EV_INLINE struct ev_loop * |
516 | ev_default_loop (unsigned int flags) |
524 | ev_default_loop (unsigned int flags EV_CPP (= 0)) |
517 | { |
525 | { |
518 | struct ev_loop *loop = ev_default_loop_uc (); |
526 | struct ev_loop *loop = ev_default_loop_uc (); |
519 | |
527 | |
520 | if (!loop) |
528 | if (!loop) |
521 | { |
529 | { |
… | |
… | |
526 | |
534 | |
527 | return loop; |
535 | return loop; |
528 | } |
536 | } |
529 | |
537 | |
530 | /* create and destroy alternative loops that don't handle signals */ |
538 | /* create and destroy alternative loops that don't handle signals */ |
531 | struct ev_loop *ev_loop_new (unsigned int flags); |
539 | struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)); |
532 | void ev_loop_destroy (EV_P); |
540 | void ev_loop_destroy (EV_P); |
533 | void ev_loop_fork (EV_P); |
541 | void ev_loop_fork (EV_P); |
534 | |
542 | |
535 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
543 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
536 | |
544 | |
537 | #else |
545 | #else |
538 | |
546 | |
539 | int ev_default_loop (unsigned int flags); /* returns true when successful */ |
547 | int ev_default_loop (unsigned int flags EV_CPP (= 0)); /* returns true when successful */ |
540 | |
548 | |
541 | EV_INLINE ev_tstamp |
549 | EV_INLINE ev_tstamp |
542 | ev_now (void) |
550 | ev_now (void) |
543 | { |
551 | { |
544 | extern ev_tstamp ev_rt_now; |
552 | extern ev_tstamp ev_rt_now; |
… | |
… | |
591 | EVBREAK_ONE = 1, /* unloop once */ |
599 | EVBREAK_ONE = 1, /* unloop once */ |
592 | EVBREAK_ALL = 2 /* unloop all loops */ |
600 | EVBREAK_ALL = 2 /* unloop all loops */ |
593 | }; |
601 | }; |
594 | |
602 | |
595 | #if EV_PROTOTYPES |
603 | #if EV_PROTOTYPES |
596 | void ev_run (EV_P_ int flags); |
604 | void ev_run (EV_P_ int flags EV_CPP (= 0)); |
597 | void ev_break (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */ |
605 | void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)); /* break out of the loop */ |
598 | |
606 | |
599 | /* |
607 | /* |
600 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
608 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
601 | * keeps one reference. if you have a long-running watcher you never unregister that |
609 | * keeps one reference. if you have a long-running watcher you never unregister that |
602 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
610 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
… | |
… | |
790 | typedef struct ev_loop ev_loop; |
798 | typedef struct ev_loop ev_loop; |
791 | #endif |
799 | #endif |
792 | |
800 | |
793 | #endif |
801 | #endif |
794 | |
802 | |
795 | #ifdef __cplusplus |
803 | EV_CPP(}) |
796 | } |
|
|
797 | #endif |
|
|
798 | |
804 | |
799 | #endif |
805 | #endif |
800 | |
806 | |