ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev++.h
(Generate patch)

Comparing libev/ev++.h (file contents):
Revision 1.28 by llucax, Fri Jan 18 18:14:41 2008 UTC vs.
Revision 1.42 by root, Mon Nov 3 14:27:06 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines