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.39 by root, Tue Apr 15 04:34:07 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines