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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines