… | |
… | |
125 | #define EV_WATCHER_TIME(type) \ |
125 | #define EV_WATCHER_TIME(type) \ |
126 | EV_WATCHER (type) \ |
126 | EV_WATCHER (type) \ |
127 | ev_tstamp at; /* private */ |
127 | ev_tstamp at; /* private */ |
128 | |
128 | |
129 | /* base class, nothing to see here unless you subclass */ |
129 | /* base class, nothing to see here unless you subclass */ |
130 | struct ev_watcher |
130 | typedef struct ev_watcher |
131 | { |
131 | { |
132 | EV_WATCHER (ev_watcher) |
132 | EV_WATCHER (ev_watcher) |
133 | }; |
133 | } ev_watcher; |
134 | |
134 | |
135 | /* base class, nothing to see here unless you subclass */ |
135 | /* base class, nothing to see here unless you subclass */ |
136 | struct ev_watcher_list |
136 | typedef struct ev_watcher_list |
137 | { |
137 | { |
138 | EV_WATCHER_LIST (ev_watcher_list) |
138 | EV_WATCHER_LIST (ev_watcher_list) |
139 | }; |
139 | } ev_watcher_list; |
140 | |
140 | |
141 | /* base class, nothing to see here unless you subclass */ |
141 | /* base class, nothing to see here unless you subclass */ |
142 | struct ev_watcher_time |
142 | typedef struct ev_watcher_time |
143 | { |
143 | { |
144 | EV_WATCHER_TIME (ev_watcher_time) |
144 | EV_WATCHER_TIME (ev_watcher_time) |
145 | }; |
145 | } ev_watcher_time; |
146 | |
146 | |
147 | /* invoked after a specific time, repeatable (based on monotonic clock) */ |
147 | /* invoked after a specific time, repeatable (based on monotonic clock) */ |
148 | /* revent EV_TIMEOUT */ |
148 | /* revent EV_TIMEOUT */ |
149 | struct ev_timer |
149 | typedef struct ev_timer |
150 | { |
150 | { |
151 | EV_WATCHER_TIME (ev_timer) |
151 | EV_WATCHER_TIME (ev_timer) |
152 | |
152 | |
153 | ev_tstamp repeat; /* rw */ |
153 | ev_tstamp repeat; /* rw */ |
154 | }; |
154 | } ev_timer; |
155 | |
155 | |
156 | /* invoked at some specific time, possibly repeating at regular intervals (based on UTC) */ |
156 | /* invoked at some specific time, possibly repeating at regular intervals (based on UTC) */ |
157 | /* revent EV_PERIODIC */ |
157 | /* revent EV_PERIODIC */ |
158 | struct ev_periodic |
158 | typedef struct ev_periodic |
159 | { |
159 | { |
160 | EV_WATCHER_TIME (ev_periodic) |
160 | EV_WATCHER_TIME (ev_periodic) |
161 | |
161 | |
162 | ev_tstamp interval; /* rw */ |
162 | ev_tstamp interval; /* rw */ |
163 | ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ |
163 | ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ |
164 | }; |
164 | } ev_periodic; |
165 | |
165 | |
166 | /* invoked when fd is either EV_READable or EV_WRITEable */ |
166 | /* invoked when fd is either EV_READable or EV_WRITEable */ |
167 | /* revent EV_READ, EV_WRITE */ |
167 | /* revent EV_READ, EV_WRITE */ |
168 | struct ev_io |
168 | typedef struct ev_io |
169 | { |
169 | { |
170 | EV_WATCHER_LIST (ev_io) |
170 | EV_WATCHER_LIST (ev_io) |
171 | |
171 | |
172 | int fd; /* ro */ |
172 | int fd; /* ro */ |
173 | int events; /* ro */ |
173 | int events; /* ro */ |
174 | }; |
174 | } ev_io; |
175 | |
175 | |
176 | /* invoked when the given signal has been received */ |
176 | /* invoked when the given signal has been received */ |
177 | /* revent EV_SIGNAL */ |
177 | /* revent EV_SIGNAL */ |
178 | struct ev_signal |
178 | typedef struct ev_signal |
179 | { |
179 | { |
180 | EV_WATCHER_LIST (ev_signal) |
180 | EV_WATCHER_LIST (ev_signal) |
181 | |
181 | |
182 | int signum; /* ro */ |
182 | int signum; /* ro */ |
183 | }; |
183 | } ev_signal; |
184 | |
184 | |
185 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
185 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
186 | /* revent EV_IDLE */ |
186 | /* revent EV_IDLE */ |
187 | struct ev_idle |
187 | typedef struct ev_idle |
188 | { |
188 | { |
189 | EV_WATCHER (ev_idle) |
189 | EV_WATCHER (ev_idle) |
190 | }; |
190 | } ev_idle; |
191 | |
191 | |
192 | /* invoked for each run of the mainloop, just before the blocking call */ |
192 | /* invoked for each run of the mainloop, just before the blocking call */ |
193 | /* you can still change events in any way you like */ |
193 | /* you can still change events in any way you like */ |
194 | /* revent EV_PREPARE */ |
194 | /* revent EV_PREPARE */ |
195 | struct ev_prepare |
195 | typedef struct ev_prepare |
196 | { |
196 | { |
197 | EV_WATCHER (ev_prepare) |
197 | EV_WATCHER (ev_prepare) |
198 | }; |
198 | } ev_prepare; |
199 | |
199 | |
200 | /* invoked for each run of the mainloop, just after the blocking call */ |
200 | /* invoked for each run of the mainloop, just after the blocking call */ |
201 | /* revent EV_CHECK */ |
201 | /* revent EV_CHECK */ |
202 | struct ev_check |
202 | typedef struct ev_check |
203 | { |
203 | { |
204 | EV_WATCHER (ev_check) |
204 | EV_WATCHER (ev_check) |
205 | }; |
205 | } ev_check; |
206 | |
206 | |
207 | /* invoked when sigchld is received and waitpid indicates the given pid */ |
207 | /* invoked when sigchld is received and waitpid indicates the given pid */ |
208 | /* revent EV_CHILD */ |
208 | /* revent EV_CHILD */ |
209 | /* does not support priorities */ |
209 | /* does not support priorities */ |
210 | struct ev_child |
210 | typedef struct ev_child |
211 | { |
211 | { |
212 | EV_WATCHER_LIST (ev_child) |
212 | EV_WATCHER_LIST (ev_child) |
213 | |
213 | |
214 | int pid; /* ro */ |
214 | int pid; /* ro */ |
215 | int rpid; /* rw, holds the received pid */ |
215 | int rpid; /* rw, holds the received pid */ |
216 | int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ |
216 | int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ |
217 | }; |
217 | } ev_child; |
218 | |
218 | |
219 | #if EV_MULTIPLICITY |
219 | #if EV_MULTIPLICITY |
220 | /* used to embed an event loop inside another */ |
220 | /* used to embed an event loop inside another */ |
221 | /* the callback gets invoked when the event loop has handled events, and can be 0 */ |
221 | /* the callback gets invoked when the event loop has handled events, and can be 0 */ |
222 | struct ev_embed |
222 | typedef struct ev_embed |
223 | { |
223 | { |
224 | EV_WATCHER (ev_embed) |
224 | EV_WATCHER (ev_embed) |
225 | |
225 | |
226 | struct ev_io io; /* private */ |
226 | ev_io io; /* private */ |
227 | struct ev_loop *loop; /* ro */ |
227 | struct ev_loop *loop; /* ro */ |
228 | }; |
228 | } ev_embed; |
229 | #endif |
229 | #endif |
230 | |
230 | |
231 | /* the presence of this union forces similar struct layout */ |
231 | /* the presence of this union forces similar struct layout */ |
232 | union ev_any_watcher |
232 | union ev_any_watcher |
233 | { |
233 | { |
… | |
… | |
351 | #endif |
351 | #endif |
352 | |
352 | |
353 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
353 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
354 | /* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ |
354 | /* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ |
355 | #define ev_init(ev,cb_) do { \ |
355 | #define ev_init(ev,cb_) do { \ |
356 | ((struct ev_watcher *)(void *)(ev))->active = \ |
356 | ((ev_watcher *)(void *)(ev))->active = \ |
357 | ((struct ev_watcher *)(void *)(ev))->pending = \ |
357 | ((ev_watcher *)(void *)(ev))->pending = \ |
358 | ((struct ev_watcher *)(void *)(ev))->priority = 0; \ |
358 | ((ev_watcher *)(void *)(ev))->priority = 0; \ |
359 | ev_set_cb ((ev), cb_); \ |
359 | ev_set_cb ((ev), cb_); \ |
360 | } while (0) |
360 | } while (0) |
361 | |
361 | |
362 | #define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) |
362 | #define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) |
363 | #define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) |
363 | #define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) |
… | |
… | |
377 | #define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) |
377 | #define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) |
378 | #define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0) |
378 | #define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0) |
379 | #define ev_child_init(ev,cb,pid) do { ev_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0) |
379 | #define ev_child_init(ev,cb,pid) do { ev_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0) |
380 | #define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0) |
380 | #define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0) |
381 | |
381 | |
382 | #define ev_is_pending(ev) (0 + ((struct ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ |
382 | #define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ |
383 | #define ev_is_active(ev) (0 + ((struct ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ |
383 | #define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ |
384 | |
384 | |
385 | #define ev_priority(ev) ((struct ev_watcher *)(void *)(ev))->priority /* rw */ |
385 | #define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */ |
386 | #define ev_cb(ev) (ev)->cb /* rw */ |
386 | #define ev_cb(ev) (ev)->cb /* rw */ |
387 | #define ev_set_priority(ev,pri) ev_priority (ev) = (pri) |
387 | #define ev_set_priority(ev,pri) ev_priority (ev) = (pri) |
388 | |
388 | |
389 | #ifndef ev_set_cb |
389 | #ifndef ev_set_cb |
390 | # define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) |
390 | # define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) |
… | |
… | |
398 | /* accepts any ev_watcher type */ |
398 | /* accepts any ev_watcher type */ |
399 | void ev_feed_event (EV_P_ void *w, int revents); |
399 | void ev_feed_event (EV_P_ void *w, int revents); |
400 | void ev_feed_fd_event (EV_P_ int fd, int revents); |
400 | void ev_feed_fd_event (EV_P_ int fd, int revents); |
401 | void ev_feed_signal_event (EV_P_ int signum); |
401 | void ev_feed_signal_event (EV_P_ int signum); |
402 | |
402 | |
403 | void ev_io_start (EV_P_ struct ev_io *w); |
403 | void ev_io_start (EV_P_ ev_io *w); |
404 | void ev_io_stop (EV_P_ struct ev_io *w); |
404 | void ev_io_stop (EV_P_ ev_io *w); |
405 | |
405 | |
406 | void ev_timer_start (EV_P_ struct ev_timer *w); |
406 | void ev_timer_start (EV_P_ ev_timer *w); |
407 | void ev_timer_stop (EV_P_ struct ev_timer *w); |
407 | void ev_timer_stop (EV_P_ ev_timer *w); |
408 | /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ |
408 | /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ |
409 | void ev_timer_again (EV_P_ struct ev_timer *w); |
409 | void ev_timer_again (EV_P_ ev_timer *w); |
410 | |
410 | |
411 | #if EV_PERIODICS |
411 | #if EV_PERIODICS |
412 | void ev_periodic_start (EV_P_ struct ev_periodic *w); |
412 | void ev_periodic_start (EV_P_ ev_periodic *w); |
413 | void ev_periodic_stop (EV_P_ struct ev_periodic *w); |
413 | void ev_periodic_stop (EV_P_ ev_periodic *w); |
414 | void ev_periodic_again (EV_P_ struct ev_periodic *w); |
414 | void ev_periodic_again (EV_P_ ev_periodic *w); |
415 | #endif |
415 | #endif |
416 | |
416 | |
417 | void ev_idle_start (EV_P_ struct ev_idle *w); |
417 | void ev_idle_start (EV_P_ ev_idle *w); |
418 | void ev_idle_stop (EV_P_ struct ev_idle *w); |
418 | void ev_idle_stop (EV_P_ ev_idle *w); |
419 | |
419 | |
420 | void ev_prepare_start (EV_P_ struct ev_prepare *w); |
420 | void ev_prepare_start (EV_P_ ev_prepare *w); |
421 | void ev_prepare_stop (EV_P_ struct ev_prepare *w); |
421 | void ev_prepare_stop (EV_P_ ev_prepare *w); |
422 | |
422 | |
423 | void ev_check_start (EV_P_ struct ev_check *w); |
423 | void ev_check_start (EV_P_ ev_check *w); |
424 | void ev_check_stop (EV_P_ struct ev_check *w); |
424 | void ev_check_stop (EV_P_ ev_check *w); |
425 | |
425 | |
426 | /* only supported in the default loop */ |
426 | /* only supported in the default loop */ |
427 | void ev_signal_start (EV_P_ struct ev_signal *w); |
427 | void ev_signal_start (EV_P_ ev_signal *w); |
428 | void ev_signal_stop (EV_P_ struct ev_signal *w); |
428 | void ev_signal_stop (EV_P_ ev_signal *w); |
429 | |
429 | |
430 | /* only supported in the default loop */ |
430 | /* only supported in the default loop */ |
431 | void ev_child_start (EV_P_ struct ev_child *w); |
431 | void ev_child_start (EV_P_ ev_child *w); |
432 | void ev_child_stop (EV_P_ struct ev_child *w); |
432 | void ev_child_stop (EV_P_ ev_child *w); |
433 | |
433 | |
434 | # if EV_MULTIPLICITY |
434 | # if EV_MULTIPLICITY |
435 | /* only supported when loop to be embedded is in fact embeddable */ |
435 | /* only supported when loop to be embedded is in fact embeddable */ |
436 | void ev_embed_start (EV_P_ struct ev_embed *w); |
436 | void ev_embed_start (EV_P_ ev_embed *w); |
437 | void ev_embed_stop (EV_P_ struct ev_embed *w); |
437 | void ev_embed_stop (EV_P_ ev_embed *w); |
|
|
438 | void ev_embed_loop (EV_P_ ev_embed *w); |
438 | # endif |
439 | # endif |
439 | |
440 | |
440 | #endif |
441 | #endif |
441 | |
442 | |
442 | #ifdef __cplusplus |
443 | #ifdef __cplusplus |