… | |
… | |
91 | |
91 | |
92 | #endif |
92 | #endif |
93 | |
93 | |
94 | /* using a template here would require quite a bit more lines, |
94 | /* using a template here would require quite a bit more lines, |
95 | * so a macro solution was chosen */ |
95 | * so a macro solution was chosen */ |
96 | #define EV_DECLARE_WATCHER(cppstem,cstem) \ |
96 | #define EV_BEGIN_WATCHER(cppstem,cstem) \ |
97 | \ |
97 | \ |
98 | extern "C" void cb_ ## cppstem (struct ev_ ## cstem *w, int revents); \ |
98 | static void cb_ ## cppstem (struct ev_ ## cstem *w, int revents); \ |
99 | \ |
99 | \ |
100 | struct cppstem : ev_ ## cstem, callback<cppstem> \ |
100 | struct cppstem : ev_ ## cstem, callback<cppstem> \ |
101 | { \ |
101 | { \ |
102 | EV_CONSTRUCT (cppstem) \ |
102 | EV_CONSTRUCT (cppstem) \ |
103 | { \ |
103 | { \ |
… | |
… | |
141 | { /* disabled */ } \ |
141 | { /* disabled */ } \ |
142 | void operator =(const cppstem &o) { /* disabled */ } \ |
142 | void operator =(const cppstem &o) { /* disabled */ } \ |
143 | \ |
143 | \ |
144 | public: |
144 | public: |
145 | |
145 | |
|
|
146 | #define EV_END_WATCHER(cppstem,cstem) \ |
|
|
147 | }; \ |
|
|
148 | \ |
|
|
149 | static void cb_ ## cppstem (struct ev_ ## cstem *w, int revents) \ |
|
|
150 | { \ |
|
|
151 | (*static_cast<cppstem *>(w))(revents); \ |
|
|
152 | } |
|
|
153 | |
146 | EV_DECLARE_WATCHER (io, io) |
154 | EV_BEGIN_WATCHER (io, io) |
147 | void set (int fd, int events) |
155 | void set (int fd, int events) |
148 | { |
156 | { |
149 | int active = is_active (); |
157 | int active = is_active (); |
150 | if (active) stop (); |
158 | if (active) stop (); |
151 | ev_io_set (static_cast<ev_io *>(this), fd, events); |
159 | ev_io_set (static_cast<ev_io *>(this), fd, events); |
… | |
… | |
163 | void start (int fd, int events) |
171 | void start (int fd, int events) |
164 | { |
172 | { |
165 | set (fd, events); |
173 | set (fd, events); |
166 | start (); |
174 | start (); |
167 | } |
175 | } |
168 | }; |
176 | EV_END_WATCHER (io, io) |
169 | |
177 | |
170 | EV_DECLARE_WATCHER (timer, timer) |
178 | EV_BEGIN_WATCHER (timer, timer) |
171 | void set (ev_tstamp after, ev_tstamp repeat = 0.) |
179 | void set (ev_tstamp after, ev_tstamp repeat = 0.) |
172 | { |
180 | { |
173 | int active = is_active (); |
181 | int active = is_active (); |
174 | if (active) stop (); |
182 | if (active) stop (); |
175 | ev_timer_set (static_cast<ev_timer *>(this), after, repeat); |
183 | ev_timer_set (static_cast<ev_timer *>(this), after, repeat); |
… | |
… | |
184 | |
192 | |
185 | void again () |
193 | void again () |
186 | { |
194 | { |
187 | ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); |
195 | ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); |
188 | } |
196 | } |
189 | }; |
197 | EV_END_WATCHER (timer, timer) |
190 | |
198 | |
191 | #if EV_PERIODICS |
199 | #if EV_PERIODICS |
192 | EV_DECLARE_WATCHER (periodic, periodic) |
200 | EV_BEGIN_WATCHER (periodic, periodic) |
193 | void set (ev_tstamp at, ev_tstamp interval = 0.) |
201 | void set (ev_tstamp at, ev_tstamp interval = 0.) |
194 | { |
202 | { |
195 | int active = is_active (); |
203 | int active = is_active (); |
196 | if (active) stop (); |
204 | if (active) stop (); |
197 | ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); |
205 | ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); |
… | |
… | |
206 | |
214 | |
207 | void again () |
215 | void again () |
208 | { |
216 | { |
209 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
217 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
210 | } |
218 | } |
211 | }; |
219 | EV_END_WATCHER (periodic, periodic) |
212 | #endif |
220 | #endif |
213 | |
221 | |
|
|
222 | EV_BEGIN_WATCHER (idle, idle) |
214 | EV_DECLARE_WATCHER (idle, idle) |
223 | EV_END_WATCHER (idle, idle) |
215 | }; |
|
|
216 | |
224 | |
|
|
225 | EV_BEGIN_WATCHER (prepare, prepare) |
217 | EV_DECLARE_WATCHER (prepare, prepare) |
226 | EV_END_WATCHER (prepare, prepare) |
218 | }; |
|
|
219 | |
227 | |
|
|
228 | EV_BEGIN_WATCHER (check, check) |
220 | EV_DECLARE_WATCHER (check, check) |
229 | EV_END_WATCHER (check, check) |
221 | }; |
|
|
222 | |
230 | |
223 | EV_DECLARE_WATCHER (sig, signal) |
231 | EV_BEGIN_WATCHER (sig, signal) |
224 | void set (int signum) |
232 | void set (int signum) |
225 | { |
233 | { |
226 | int active = is_active (); |
234 | int active = is_active (); |
227 | if (active) stop (); |
235 | if (active) stop (); |
228 | ev_signal_set (static_cast<ev_signal *>(this), signum); |
236 | ev_signal_set (static_cast<ev_signal *>(this), signum); |
… | |
… | |
232 | void start (int signum) |
240 | void start (int signum) |
233 | { |
241 | { |
234 | set (signum); |
242 | set (signum); |
235 | start (); |
243 | start (); |
236 | } |
244 | } |
237 | }; |
245 | EV_END_WATCHER (sig, signal) |
238 | |
246 | |
239 | EV_DECLARE_WATCHER (child, child) |
247 | EV_BEGIN_WATCHER (child, child) |
240 | void set (int pid) |
248 | void set (int pid) |
241 | { |
249 | { |
242 | int active = is_active (); |
250 | int active = is_active (); |
243 | if (active) stop (); |
251 | if (active) stop (); |
244 | ev_child_set (static_cast<ev_child *>(this), pid); |
252 | ev_child_set (static_cast<ev_child *>(this), pid); |
… | |
… | |
248 | void start (int pid) |
256 | void start (int pid) |
249 | { |
257 | { |
250 | set (pid); |
258 | set (pid); |
251 | start (); |
259 | start (); |
252 | } |
260 | } |
253 | }; |
261 | EV_END_WATCHER (child, child) |
254 | |
262 | |
255 | #undef EV_CONSTRUCT |
263 | #undef EV_CONSTRUCT |
256 | #undef EV_DECLARE_WATCHER |
264 | #undef EV_BEGIN_WATCHER |
257 | } |
265 | } |
258 | |
266 | |
259 | #endif |
267 | #endif |
260 | |
268 | |