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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines