ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev++.h
(Generate patch)

Comparing libev/ev++.h (file contents):
Revision 1.31 by root, Sat Jan 19 00:39:38 2008 UTC vs.
Revision 1.39 by root, Tue Apr 15 04:34:07 2008 UTC

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;
74 STAT = EV_STAT, 70 STAT = EV_STAT,
75 IDLE = EV_IDLE, 71 IDLE = EV_IDLE,
76 CHECK = EV_CHECK, 72 CHECK = EV_CHECK,
77 PREPARE = EV_PREPARE, 73 PREPARE = EV_PREPARE,
78 FORK = EV_FORK, 74 FORK = EV_FORK,
75 ASYNC = EV_ASYNC,
79 EMBED = EV_EMBED, 76 EMBED = EV_EMBED,
80 ERROR = EV_ERROR, 77 ERROR = EV_ERROR,
81 }; 78 };
82 79
83 enum 80 enum
103 { 100 {
104 ONE = EVUNLOOP_ONE, 101 ONE = EVUNLOOP_ONE,
105 ALL = EVUNLOOP_ALL 102 ALL = EVUNLOOP_ALL
106 }; 103 };
107 104
108#if EV_CXX_EXCEPTIONS 105 struct bad_loop
109 struct bad_loop : std::runtime_error 106#if EV_USE_STDEXCEPT
107 : std::runtime_error
108#endif
110 { 109 {
110#if EV_USE_STDEXCEPT
111 bad_loop () 111 bad_loop ()
112 : std::runtime_error ("loop can't be initialized") 112 : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?")
113 {
114 } 113 {
115 }; 114 }
116#endif 115#endif
116 };
117 117
118#ifdef EV_AX 118#ifdef EV_AX
119# undef EV_AX 119# undef EV_AX
120#endif 120#endif
121 121
131# define EV_AX_ 131# define EV_AX_
132#endif 132#endif
133 133
134 struct loop_ref 134 struct loop_ref
135 { 135 {
136
137 loop_ref (EV_P) 136 loop_ref (EV_P) throw ()
138#if EV_MULTIPLICITY 137#if EV_MULTIPLICITY
139 EV_THROW (bad_loop) : EV_AX (EV_A) 138 : EV_AX (EV_A)
140#endif 139#endif
141 {
142#if EV_MULTIPLICIY && EV_CXX_EXCEPTIONS
143 if (!EV_A)
144 throw bad_loop ();
145#endif
146 } 140 {
141 }
147 142
148 bool operator== (const loop_ref &other) const throw () 143 bool operator == (const loop_ref &other) const throw ()
149 { 144 {
150#if EV_MULTIPLICITY 145#if EV_MULTIPLICITY
151 return this->EV_AX == other.EV_AX; 146 return EV_AX == other.EV_AX;
152#else 147#else
153 return true; 148 return true;
154#endif 149#endif
155 } 150 }
156 151
157 bool operator!= (const loop_ref &other) const throw () 152 bool operator != (const loop_ref &other) const throw ()
158 { 153 {
159#if EV_MULTIPLICITY 154#if EV_MULTIPLICITY
160 return ! (*this == other); 155 return ! (*this == other);
161#else 156#else
162 return false; 157 return false;
163#endif 158#endif
164 } 159 }
165 160
166#if EV_MULTIPLICITY 161#if EV_MULTIPLICITY
167 bool operator== (struct ev_loop *other) const throw () 162 bool operator == (struct ev_loop *other) const throw ()
168 { 163 {
169 return this->EV_AX == other; 164 return this->EV_AX == other;
170 } 165 }
171 166
172 bool operator!= (struct ev_loop *other) const throw () 167 bool operator != (struct ev_loop *other) const throw ()
173 { 168 {
174 return ! (*this == other); 169 return ! (*this == other);
175 } 170 }
176 171
177 bool operator== (const struct ev_loop *other) const throw () 172 bool operator == (const struct ev_loop *other) const throw ()
178 { 173 {
179 return this->EV_AX == other; 174 return this->EV_AX == other;
180 } 175 }
181 176
182 bool operator!= (const struct ev_loop *other) const throw () 177 bool operator != (const struct ev_loop *other) const throw ()
183 { 178 {
184 return (*this == other); 179 return (*this == other);
185 } 180 }
186 181
187 operator struct ev_loop * () const throw () 182 operator struct ev_loop * () const throw ()
343#endif 338#endif
344 339
345 }; 340 };
346 341
347#if EV_MULTIPLICITY 342#if EV_MULTIPLICITY
348 struct dynamic_loop: loop_ref 343 struct dynamic_loop : loop_ref
349 { 344 {
350 345
351 dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) 346 dynamic_loop (unsigned int flags = AUTO) throw (bad_loop)
352 : loop_ref (ev_loop_new (flags)) 347 : loop_ref (ev_loop_new (flags))
353 { 348 {
349 if (!EV_AX)
350 throw bad_loop ();
354 } 351 }
355 352
356 ~dynamic_loop () throw () 353 ~dynamic_loop () throw ()
357 { 354 {
358 ev_loop_destroy (EV_AX); 355 ev_loop_destroy (EV_AX);
366 dynamic_loop & operator= (const dynamic_loop &); 363 dynamic_loop & operator= (const dynamic_loop &);
367 364
368 }; 365 };
369#endif 366#endif
370 367
371 struct default_loop: loop_ref 368 struct default_loop : loop_ref
372 { 369 {
373
374 default_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) 370 default_loop (unsigned int flags = AUTO) throw (bad_loop)
375#if EV_MULTIPLICITY 371#if EV_MULTIPLICITY
376 : loop_ref (ev_default_loop (flags)) 372 : loop_ref (ev_default_loop (flags))
377 { 373#endif
378 } 374 {
375 if (
376#if EV_MULTIPLICITY
377 !EV_AX
379#else 378#else
380 {
381 #if EV_CXX_EXCEPTIONS
382 int r =
383 #endif
384 ev_default_loop (flags); 379 !ev_default_loop (flags)
385 #if EV_CXX_EXCEPTIONS 380#endif
386 if (!r) 381 )
387 throw bad_loop (); 382 throw bad_loop ();
388 #endif
389 } 383 }
390#endif
391 384
392 ~default_loop () throw () 385 ~default_loop () throw ()
393 { 386 {
394 ev_default_destroy (); 387 ev_default_destroy ();
395#if EV_MULTIPLICITY
396 EV_AX = 0;
397#endif
398 } 388 }
399 389
400 private: 390 private:
401
402 default_loop (const default_loop &); 391 default_loop (const default_loop &);
403
404 default_loop & operator= (const default_loop &); 392 default_loop &operator = (const default_loop &);
405
406 }; 393 };
407 394
408 inline loop_ref get_default_loop () throw () 395 inline loop_ref get_default_loop () throw ()
409 { 396 {
410#if EV_MULTIPLICITY 397#if EV_MULTIPLICITY
575 ev_set_syserr_cb (cb); 562 ev_set_syserr_cb (cb);
576 } 563 }
577 564
578 #if EV_MULTIPLICITY 565 #if EV_MULTIPLICITY
579 #define EV_CONSTRUCT(cppstem,cstem) \ 566 #define EV_CONSTRUCT(cppstem,cstem) \
580 (EV_PX = get_default_loop ()) throw () \ 567 (EV_PX = get_default_loop ()) throw () \
581 : base<ev_ ## cstem, cppstem> (EV_A) \ 568 : base<ev_ ## cstem, cppstem> (EV_A) \
582 { \ 569 { \
583 } 570 }
584 #else 571 #else
585 #define EV_CONSTRUCT(cppstem,cstem) \ 572 #define EV_CONSTRUCT(cppstem,cstem) \
586 () throw () \ 573 () throw () \
587 { \ 574 { \
588 } 575 }
589 #endif 576 #endif
590 577
591 /* using a template here would require quite a bit more lines, 578 /* using a template here would require quite a bit more lines,
592 * so a macro solution was chosen */ 579 * so a macro solution was chosen */
593 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 580 #define EV_BEGIN_WATCHER(cppstem,cstem) \
594 \ 581 \
595 struct cppstem : base<ev_ ## cstem, cppstem> \ 582 struct cppstem : base<ev_ ## cstem, cppstem> \
596 { \ 583 { \
597 void start () throw () \ 584 void start () throw () \
598 { \ 585 { \
599 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 586 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
600 } \ 587 } \
601 \ 588 \
602 void stop () throw () \ 589 void stop () throw () \
603 { \ 590 { \
604 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 591 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
605 } \ 592 } \
606 \ 593 \
607 cppstem EV_CONSTRUCT(cppstem,cstem) \ 594 cppstem EV_CONSTRUCT(cppstem,cstem) \
608 \ 595 \
609 ~cppstem () throw () \ 596 ~cppstem () throw () \
610 { \ 597 { \
611 stop (); \ 598 stop (); \
612 } \ 599 } \
613 \ 600 \
614 using base<ev_ ## cstem, cppstem>::set; \ 601 using base<ev_ ## cstem, cppstem>::set; \
615 \ 602 \
616 private: \ 603 private: \
617 \ 604 \
618 cppstem (const cppstem &o); \ 605 cppstem (const cppstem &o); \
619 \ 606 \
620 cppstem & operator =(const cppstem &o); \ 607 cppstem &operator =(const cppstem &o); \
621 \ 608 \
622 public: 609 public:
623 610
624 #define EV_END_WATCHER(cppstem,cstem) \ 611 #define EV_END_WATCHER(cppstem,cstem) \
625 }; 612 };
707 start (); 694 start ();
708 } 695 }
709 EV_END_WATCHER (sig, signal) 696 EV_END_WATCHER (sig, signal)
710 697
711 EV_BEGIN_WATCHER (child, child) 698 EV_BEGIN_WATCHER (child, child)
712 void set (int pid) throw () 699 void set (int pid, int trace = 0) throw ()
713 { 700 {
714 int active = is_active (); 701 int active = is_active ();
715 if (active) stop (); 702 if (active) stop ();
716 ev_child_set (static_cast<ev_child *>(this), pid); 703 ev_child_set (static_cast<ev_child *>(this), pid, trace);
717 if (active) start (); 704 if (active) start ();
718 } 705 }
719 706
720 void start (int pid) throw () 707 void start (int pid, int trace = 0) throw ()
721 { 708 {
722 set (pid); 709 set (pid, trace);
723 start (); 710 start ();
724 } 711 }
725 EV_END_WATCHER (child, child) 712 EV_END_WATCHER (child, child)
726 713
727 #if EV_STAT_ENABLE 714 #if EV_STAT_ENABLE
760 void set () throw () { } 747 void set () throw () { }
761 EV_END_WATCHER (check, check) 748 EV_END_WATCHER (check, check)
762 749
763 #if EV_EMBED_ENABLE 750 #if EV_EMBED_ENABLE
764 EV_BEGIN_WATCHER (embed, embed) 751 EV_BEGIN_WATCHER (embed, embed)
752 void set (struct ev_loop *embedded_loop) throw ()
753 {
754 int active = is_active ();
755 if (active) stop ();
756 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
757 if (active) start ();
758 }
759
765 void start (struct ev_loop *embedded_loop) throw () 760 void start (struct ev_loop *embedded_loop) throw ()
766 { 761 {
767 stop (); 762 set (embedded_loop);
768 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
769 start (); 763 start ();
770 } 764 }
771 765
772 void sweep () 766 void sweep ()
773 { 767 {
780 EV_BEGIN_WATCHER (fork, fork) 774 EV_BEGIN_WATCHER (fork, fork)
781 void set () throw () { } 775 void set () throw () { }
782 EV_END_WATCHER (fork, fork) 776 EV_END_WATCHER (fork, fork)
783 #endif 777 #endif
784 778
779 #if EV_ASYNC_ENABLE
780 EV_BEGIN_WATCHER (async, async)
781 void set () throw () { }
782
783 void send () throw ()
784 {
785 ev_async_send (EV_A_ static_cast<ev_async *>(this));
786 }
787
788 bool async_pending () throw ()
789 {
790 return ev_async_pending (static_cast<ev_async *>(this));
791 }
792 EV_END_WATCHER (async, async)
793 #endif
794
785 #undef EV_PX 795 #undef EV_PX
786 #undef EV_PX_ 796 #undef EV_PX_
787 #undef EV_CONSTRUCT 797 #undef EV_CONSTRUCT
788 #undef EV_BEGIN_WATCHER 798 #undef EV_BEGIN_WATCHER
789 #undef EV_END_WATCHER 799 #undef EV_END_WATCHER
790
791} 800}
792 801
793#undef EV_THROW
794
795#endif 802#endif
796 803

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines