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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines