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.45 by root, Fri Jul 10 00:36:21 2009 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 == (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
210 unsigned int backend () const throw ()
211 {
212 return ev_backend (EV_AX);
213 }
214
215 tstamp now () const throw ()
216 {
217 return ev_now (EV_AX);
218 }
219
220 void ref () throw ()
221 {
222 ev_ref (EV_AX);
223 }
224
225 void unref () throw ()
226 {
227 ev_unref (EV_AX);
228 }
229
230#if EV_MINIMAL < 2
220 unsigned int count () const EV_THROW () 231 unsigned int count () const throw ()
221 { 232 {
222 return ev_loop_count (EV_AX); 233 return ev_loop_count (EV_AX);
223 } 234 }
224 235
225 unsigned int backend () const EV_THROW () 236 unsigned int depth () const throw ()
226 {
227 return ev_backend (EV_AX);
228 } 237 {
229
230 tstamp now () const EV_THROW ()
231 {
232 return ev_now (EV_AX); 238 return ev_loop_depth (EV_AX);
233 }
234
235 void ref () EV_THROW ()
236 { 239 }
237 ev_ref (EV_AX);
238 }
239 240
240 void unref () EV_THROW ()
241 {
242 ev_unref (EV_AX);
243 }
244
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
434 void set (EV_PX) EV_THROW () 418 void set (EV_P) throw ()
435 { 419 {
436 this->EV_A = EV_A; 420 this->EV_A = EV_A;
437 } 421 }
438 #endif 422 #endif
439 423
440 base (EV_PX) EV_THROW () 424 base (EV_PX) throw ()
441 #if EV_MULTIPLICITY 425 #if EV_MULTIPLICITY
442 : EV_A (EV_A) 426 : EV_A (EV_A)
443 #endif 427 #endif
444 { 428 {
445 ev_init (this, 0); 429 ev_init (this, 0);
446 } 430 }
447 431
448 void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) EV_THROW () 432 void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw ()
449 { 433 {
450 this->data = data; 434 this->data = (void *)data;
451 ev_set_cb (static_cast<ev_watcher *>(this), cb); 435 ev_set_cb (static_cast<ev_watcher *>(this), cb);
436 }
437
438 // function callback
439 template<void (*function)(watcher &w, int)>
440 void set (void *data = 0) throw ()
441 {
442 set_ (data, function_thunk<function>);
443 }
444
445 template<void (*function)(watcher &w, int)>
446 static void function_thunk (EV_P_ ev_watcher *w, int revents)
447 {
448 function
449 (*static_cast<watcher *>(w), revents);
452 } 450 }
453 451
454 // method callback 452 // method callback
455 template<class K, void (K::*method)(watcher &w, int)> 453 template<class K, void (K::*method)(watcher &w, int)>
456 void set (K *object) EV_THROW () 454 void set (K *object) throw ()
457 { 455 {
458 set_ (object, method_thunk<K, method>); 456 set_ (object, method_thunk<K, method>);
457 }
458
459 // default method == operator ()
460 template<class K>
461 void set (K *object) throw ()
462 {
463 set_ (object, method_thunk<K, &K::operator ()>);
459 } 464 }
460 465
461 template<class K, void (K::*method)(watcher &w, int)> 466 template<class K, void (K::*method)(watcher &w, int)>
462 static void method_thunk (EV_P_ ev_watcher *w, int revents) 467 static void method_thunk (EV_P_ ev_watcher *w, int revents)
463 { 468 {
464 K *obj = static_cast<K *>(w->data); 469 (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); 470 (*static_cast<watcher *>(w), revents);
493 } 471 }
494 472
495 // simple callback 473 // no-argument callback
496 template<class K, void (K::*method)()> 474 template<class K, void (K::*method)()>
497 void set (K *object) EV_THROW () 475 void set (K *object) throw ()
498 { 476 {
499 set_ (object, method_noargs_thunk<K, method>); 477 set_ (object, method_noargs_thunk<K, method>);
500 } 478 }
501 479
502 template<class K, void (K::*method)()> 480 template<class K, void (K::*method)()>
503 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) 481 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
504 { 482 {
505 K *obj = static_cast<K *>(w->data); 483 static_cast<K *>(w->data)->*method
506 (obj->*method) (); 484 ();
507 } 485 }
508 486
509 void operator ()(int events = EV_UNDEF) 487 void operator ()(int events = EV_UNDEF)
510 { 488 {
489 return
511 return ev_cb (static_cast<ev_watcher *>(this)) 490 ev_cb (static_cast<ev_watcher *>(this))
512 (static_cast<ev_watcher *>(this), events); 491 (static_cast<ev_watcher *>(this), events);
513 } 492 }
514 493
515 bool is_active () const EV_THROW () 494 bool is_active () const throw ()
516 { 495 {
517 return ev_is_active (static_cast<const ev_watcher *>(this)); 496 return ev_is_active (static_cast<const ev_watcher *>(this));
518 } 497 }
519 498
520 bool is_pending () const EV_THROW () 499 bool is_pending () const throw ()
521 { 500 {
522 return ev_is_pending (static_cast<const ev_watcher *>(this)); 501 return ev_is_pending (static_cast<const ev_watcher *>(this));
523 } 502 }
524 503
525 void feed_event (int revents) EV_THROW () 504 void feed_event (int revents) throw ()
526 { 505 {
527 ev_feed_event (EV_A_ static_cast<const ev_watcher *>(this), revents); 506 ev_feed_event (EV_A_ static_cast<const ev_watcher *>(this), revents);
528 } 507 }
529 }; 508 };
530 509
531 inline tstamp now () EV_THROW () 510 inline tstamp now () throw ()
532 { 511 {
533 return ev_time (); 512 return ev_time ();
534 } 513 }
535 514
536 inline void delay (tstamp interval) EV_THROW () 515 inline void delay (tstamp interval) throw ()
537 { 516 {
538 ev_sleep (interval); 517 ev_sleep (interval);
539 } 518 }
540 519
541 inline int version_major () EV_THROW () 520 inline int version_major () throw ()
542 { 521 {
543 return ev_version_major (); 522 return ev_version_major ();
544 } 523 }
545 524
546 inline int version_minor () EV_THROW () 525 inline int version_minor () throw ()
547 { 526 {
548 return ev_version_minor (); 527 return ev_version_minor ();
549 } 528 }
550 529
551 inline unsigned int supported_backends () EV_THROW () 530 inline unsigned int supported_backends () throw ()
552 { 531 {
553 return ev_supported_backends (); 532 return ev_supported_backends ();
554 } 533 }
555 534
556 inline unsigned int recommended_backends () EV_THROW () 535 inline unsigned int recommended_backends () throw ()
557 { 536 {
558 return ev_recommended_backends (); 537 return ev_recommended_backends ();
559 } 538 }
560 539
561 inline unsigned int embeddable_backends () EV_THROW () 540 inline unsigned int embeddable_backends () throw ()
562 { 541 {
563 return ev_embeddable_backends (); 542 return ev_embeddable_backends ();
564 } 543 }
565 544
566 inline void set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW () 545 inline void set_allocator (void *(*cb)(void *ptr, long size)) throw ()
567 { 546 {
568 ev_set_allocator (cb); 547 ev_set_allocator (cb);
569 } 548 }
570 549
571 inline void set_syserr_cb (void (*cb)(const char *msg)) EV_THROW () 550 inline void set_syserr_cb (void (*cb)(const char *msg)) throw ()
572 { 551 {
573 ev_set_syserr_cb (cb); 552 ev_set_syserr_cb (cb);
574 } 553 }
575 554
576 #if EV_MULTIPLICITY 555 #if EV_MULTIPLICITY
577 #define EV_CONSTRUCT(cppstem,cstem) \ 556 #define EV_CONSTRUCT(cppstem,cstem) \
578 (EV_PX = get_default_loop ()) EV_THROW () \ 557 (EV_PX = get_default_loop ()) throw () \
579 : base<ev_ ## cstem, cppstem> (EV_A) \ 558 : base<ev_ ## cstem, cppstem> (EV_A) \
580 { \ 559 { \
581 } 560 }
582 #else 561 #else
583 #define EV_CONSTRUCT(cppstem,cstem) \ 562 #define EV_CONSTRUCT(cppstem,cstem) \
584 () EV_THROW () \ 563 () throw () \
585 { \ 564 { \
586 } 565 }
587 #endif 566 #endif
588 567
589 /* using a template here would require quite a bit more lines, 568 /* using a template here would require quite a bit more lines,
590 * so a macro solution was chosen */ 569 * so a macro solution was chosen */
591 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 570 #define EV_BEGIN_WATCHER(cppstem,cstem) \
592 \ 571 \
593 struct cppstem : base<ev_ ## cstem, cppstem> \ 572 struct cppstem : base<ev_ ## cstem, cppstem> \
594 { \ 573 { \
595 void start () EV_THROW () \ 574 void start () throw () \
596 { \ 575 { \
597 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 576 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
598 } \ 577 } \
599 \ 578 \
600 void stop () EV_THROW () \ 579 void stop () throw () \
601 { \ 580 { \
602 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 581 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
603 } \ 582 } \
604 \ 583 \
605 cppstem EV_CONSTRUCT(cppstem,cstem) \ 584 cppstem EV_CONSTRUCT(cppstem,cstem) \
606 \ 585 \
607 ~cppstem () EV_THROW () \ 586 ~cppstem () throw () \
608 { \ 587 { \
609 stop (); \ 588 stop (); \
610 } \ 589 } \
611 \ 590 \
612 using base<ev_ ## cstem, cppstem>::set; \ 591 using base<ev_ ## cstem, cppstem>::set; \
613 \ 592 \
614 private: \ 593 private: \
615 \ 594 \
616 cppstem (const cppstem &o); \ 595 cppstem (const cppstem &o); \
617 \ 596 \
618 cppstem & operator =(const cppstem &o); \ 597 cppstem &operator =(const cppstem &o); \
619 \ 598 \
620 public: 599 public:
621 600
622 #define EV_END_WATCHER(cppstem,cstem) \ 601 #define EV_END_WATCHER(cppstem,cstem) \
623 }; 602 };
624 603
625 EV_BEGIN_WATCHER (io, io) 604 EV_BEGIN_WATCHER (io, io)
626 void set (int fd, int events) EV_THROW () 605 void set (int fd, int events) throw ()
627 { 606 {
628 int active = is_active (); 607 int active = is_active ();
629 if (active) stop (); 608 if (active) stop ();
630 ev_io_set (static_cast<ev_io *>(this), fd, events); 609 ev_io_set (static_cast<ev_io *>(this), fd, events);
631 if (active) start (); 610 if (active) start ();
632 } 611 }
633 612
634 void set (int events) EV_THROW () 613 void set (int events) throw ()
635 { 614 {
636 int active = is_active (); 615 int active = is_active ();
637 if (active) stop (); 616 if (active) stop ();
638 ev_io_set (static_cast<ev_io *>(this), fd, events); 617 ev_io_set (static_cast<ev_io *>(this), fd, events);
639 if (active) start (); 618 if (active) start ();
640 } 619 }
641 620
642 void start (int fd, int events) EV_THROW () 621 void start (int fd, int events) throw ()
643 { 622 {
644 set (fd, events); 623 set (fd, events);
645 start (); 624 start ();
646 } 625 }
647 EV_END_WATCHER (io, io) 626 EV_END_WATCHER (io, io)
648 627
649 EV_BEGIN_WATCHER (timer, timer) 628 EV_BEGIN_WATCHER (timer, timer)
650 void set (ev_tstamp after, ev_tstamp repeat = 0.) EV_THROW () 629 void set (ev_tstamp after, ev_tstamp repeat = 0.) throw ()
651 { 630 {
652 int active = is_active (); 631 int active = is_active ();
653 if (active) stop (); 632 if (active) stop ();
654 ev_timer_set (static_cast<ev_timer *>(this), after, repeat); 633 ev_timer_set (static_cast<ev_timer *>(this), after, repeat);
655 if (active) start (); 634 if (active) start ();
656 } 635 }
657 636
658 void start (ev_tstamp after, ev_tstamp repeat = 0.) EV_THROW () 637 void start (ev_tstamp after, ev_tstamp repeat = 0.) throw ()
659 { 638 {
660 set (after, repeat); 639 set (after, repeat);
661 start (); 640 start ();
662 } 641 }
663 642
664 void again () EV_THROW () 643 void again () throw ()
665 { 644 {
666 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 645 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
667 } 646 }
668 EV_END_WATCHER (timer, timer) 647 EV_END_WATCHER (timer, timer)
669 648
670 #if EV_PERIODIC_ENABLE 649 #if EV_PERIODIC_ENABLE
671 EV_BEGIN_WATCHER (periodic, periodic) 650 EV_BEGIN_WATCHER (periodic, periodic)
672 void set (ev_tstamp at, ev_tstamp interval = 0.) EV_THROW () 651 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
673 { 652 {
674 int active = is_active (); 653 int active = is_active ();
675 if (active) stop (); 654 if (active) stop ();
676 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); 655 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0);
677 if (active) start (); 656 if (active) start ();
678 } 657 }
679 658
680 void start (ev_tstamp at, ev_tstamp interval = 0.) EV_THROW () 659 void start (ev_tstamp at, ev_tstamp interval = 0.) throw ()
681 { 660 {
682 set (at, interval); 661 set (at, interval);
683 start (); 662 start ();
684 } 663 }
685 664
686 void again () EV_THROW () 665 void again () throw ()
687 { 666 {
688 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 667 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
689 } 668 }
690 EV_END_WATCHER (periodic, periodic) 669 EV_END_WATCHER (periodic, periodic)
691 #endif 670 #endif
692 671
693 EV_BEGIN_WATCHER (sig, signal) 672 EV_BEGIN_WATCHER (sig, signal)
694 void set (int signum) EV_THROW () 673 void set (int signum) throw ()
695 { 674 {
696 int active = is_active (); 675 int active = is_active ();
697 if (active) stop (); 676 if (active) stop ();
698 ev_signal_set (static_cast<ev_signal *>(this), signum); 677 ev_signal_set (static_cast<ev_signal *>(this), signum);
699 if (active) start (); 678 if (active) start ();
700 } 679 }
701 680
702 void start (int signum) EV_THROW () 681 void start (int signum) throw ()
703 { 682 {
704 set (signum); 683 set (signum);
705 start (); 684 start ();
706 } 685 }
707 EV_END_WATCHER (sig, signal) 686 EV_END_WATCHER (sig, signal)
708 687
709 EV_BEGIN_WATCHER (child, child) 688 EV_BEGIN_WATCHER (child, child)
710 void set (int pid) EV_THROW () 689 void set (int pid, int trace = 0) throw ()
711 { 690 {
712 int active = is_active (); 691 int active = is_active ();
713 if (active) stop (); 692 if (active) stop ();
714 ev_child_set (static_cast<ev_child *>(this), pid); 693 ev_child_set (static_cast<ev_child *>(this), pid, trace);
715 if (active) start (); 694 if (active) start ();
716 } 695 }
717 696
718 void start (int pid) EV_THROW () 697 void start (int pid, int trace = 0) throw ()
719 { 698 {
720 set (pid); 699 set (pid, trace);
721 start (); 700 start ();
722 } 701 }
723 EV_END_WATCHER (child, child) 702 EV_END_WATCHER (child, child)
724 703
725 #if EV_STAT_ENABLE 704 #if EV_STAT_ENABLE
726 EV_BEGIN_WATCHER (stat, stat) 705 EV_BEGIN_WATCHER (stat, stat)
727 void set (const char *path, ev_tstamp interval = 0.) EV_THROW () 706 void set (const char *path, ev_tstamp interval = 0.) throw ()
728 { 707 {
729 int active = is_active (); 708 int active = is_active ();
730 if (active) stop (); 709 if (active) stop ();
731 ev_stat_set (static_cast<ev_stat *>(this), path, interval); 710 ev_stat_set (static_cast<ev_stat *>(this), path, interval);
732 if (active) start (); 711 if (active) start ();
733 } 712 }
734 713
735 void start (const char *path, ev_tstamp interval = 0.) EV_THROW () 714 void start (const char *path, ev_tstamp interval = 0.) throw ()
736 { 715 {
737 stop (); 716 stop ();
738 set (path, interval); 717 set (path, interval);
739 start (); 718 start ();
740 } 719 }
741 720
742 void update () EV_THROW () 721 void update () throw ()
743 { 722 {
744 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); 723 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
745 } 724 }
746 EV_END_WATCHER (stat, stat) 725 EV_END_WATCHER (stat, stat)
747 #endif 726 #endif
748 727
749 EV_BEGIN_WATCHER (idle, idle) 728 EV_BEGIN_WATCHER (idle, idle)
750 void set () EV_THROW () { } 729 void set () throw () { }
751 EV_END_WATCHER (idle, idle) 730 EV_END_WATCHER (idle, idle)
752 731
753 EV_BEGIN_WATCHER (prepare, prepare) 732 EV_BEGIN_WATCHER (prepare, prepare)
754 void set () EV_THROW () { } 733 void set () throw () { }
755 EV_END_WATCHER (prepare, prepare) 734 EV_END_WATCHER (prepare, prepare)
756 735
757 EV_BEGIN_WATCHER (check, check) 736 EV_BEGIN_WATCHER (check, check)
758 void set () EV_THROW () { } 737 void set () throw () { }
759 EV_END_WATCHER (check, check) 738 EV_END_WATCHER (check, check)
760 739
761 #if EV_EMBED_ENABLE 740 #if EV_EMBED_ENABLE
762 EV_BEGIN_WATCHER (embed, embed) 741 EV_BEGIN_WATCHER (embed, embed)
763 void start (struct ev_loop *embedded_loop) EV_THROW () 742 void set (struct ev_loop *embedded_loop) throw ()
764 { 743 {
765 stop (); 744 int active = is_active ();
745 if (active) stop ();
766 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop); 746 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
747 if (active) start ();
748 }
749
750 void start (struct ev_loop *embedded_loop) throw ()
751 {
752 set (embedded_loop);
767 start (); 753 start ();
768 } 754 }
769 755
770 void sweep () 756 void sweep ()
771 { 757 {
774 EV_END_WATCHER (embed, embed) 760 EV_END_WATCHER (embed, embed)
775 #endif 761 #endif
776 762
777 #if EV_FORK_ENABLE 763 #if EV_FORK_ENABLE
778 EV_BEGIN_WATCHER (fork, fork) 764 EV_BEGIN_WATCHER (fork, fork)
779 void set () EV_THROW () { } 765 void set () throw () { }
780 EV_END_WATCHER (fork, fork) 766 EV_END_WATCHER (fork, fork)
767 #endif
768
769 #if EV_ASYNC_ENABLE
770 EV_BEGIN_WATCHER (async, async)
771 void set () throw () { }
772
773 void send () throw ()
774 {
775 ev_async_send (EV_A_ static_cast<ev_async *>(this));
776 }
777
778 bool async_pending () throw ()
779 {
780 return ev_async_pending (static_cast<ev_async *>(this));
781 }
782 EV_END_WATCHER (async, async)
781 #endif 783 #endif
782 784
783 #undef EV_PX 785 #undef EV_PX
784 #undef EV_PX_ 786 #undef EV_PX_
785 #undef EV_CONSTRUCT 787 #undef EV_CONSTRUCT
786 #undef EV_BEGIN_WATCHER 788 #undef EV_BEGIN_WATCHER
787 #undef EV_END_WATCHER 789 #undef EV_END_WATCHER
788
789} 790}
790 791
791#undef EV_THROW
792
793#endif 792#endif
794 793

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines