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.44 by root, Wed Dec 3 15:23:44 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines