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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines