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

Comparing libev/ev++.h (file contents):
Revision 1.36 by root, Tue Jan 22 18:09:23 2008 UTC vs.
Revision 1.40 by root, Sat May 17 12:15:30 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 *
70 STAT = EV_STAT, 70 STAT = EV_STAT,
71 IDLE = EV_IDLE, 71 IDLE = EV_IDLE,
72 CHECK = EV_CHECK, 72 CHECK = EV_CHECK,
73 PREPARE = EV_PREPARE, 73 PREPARE = EV_PREPARE,
74 FORK = EV_FORK, 74 FORK = EV_FORK,
75 ASYNC = EV_ASYNC,
75 EMBED = EV_EMBED, 76 EMBED = EV_EMBED,
76 ERROR = EV_ERROR, 77 ERROR = EV_ERROR,
77 }; 78 };
78 79
79 enum 80 enum
130# define EV_AX_ 131# define EV_AX_
131#endif 132#endif
132 133
133 struct loop_ref 134 struct loop_ref
134 { 135 {
135
136 loop_ref (EV_P) throw () 136 loop_ref (EV_P) throw ()
137#if EV_MULTIPLICITY 137#if EV_MULTIPLICITY
138 : EV_AX (EV_A) 138 : EV_AX (EV_A)
139#endif 139#endif
140 { 140 {
157 return false; 157 return false;
158#endif 158#endif
159 } 159 }
160 160
161#if EV_MULTIPLICITY 161#if EV_MULTIPLICITY
162 bool operator== (struct ev_loop *other) const throw () 162 bool operator == (struct ev_loop *other) const throw ()
163 { 163 {
164 return this->EV_AX == other; 164 return this->EV_AX == other;
165 } 165 }
166 166
167 bool operator!= (struct ev_loop *other) const throw () 167 bool operator != (struct ev_loop *other) const throw ()
168 { 168 {
169 return ! (*this == other); 169 return ! (*this == other);
170 } 170 }
171 171
172 bool operator== (const struct ev_loop *other) const throw () 172 bool operator == (const struct ev_loop *other) const throw ()
173 { 173 {
174 return this->EV_AX == other; 174 return this->EV_AX == other;
175 } 175 }
176 176
177 bool operator!= (const struct ev_loop *other) const throw () 177 bool operator != (const struct ev_loop *other) const throw ()
178 { 178 {
179 return (*this == other); 179 return (*this == other);
180 } 180 }
181 181
182 operator struct ev_loop * () const throw () 182 operator struct ev_loop * () const throw ()
365 }; 365 };
366#endif 366#endif
367 367
368 struct default_loop : loop_ref 368 struct default_loop : loop_ref
369 { 369 {
370
371 default_loop (unsigned int flags = AUTO) throw (bad_loop) 370 default_loop (unsigned int flags = AUTO) throw (bad_loop)
372#if EV_MULTIPLICITY 371#if EV_MULTIPLICITY
373 : loop_ref (ev_default_loop (flags)) 372 : loop_ref (ev_default_loop (flags))
374#endif 373#endif
375 { 374 {
563 ev_set_syserr_cb (cb); 562 ev_set_syserr_cb (cb);
564 } 563 }
565 564
566 #if EV_MULTIPLICITY 565 #if EV_MULTIPLICITY
567 #define EV_CONSTRUCT(cppstem,cstem) \ 566 #define EV_CONSTRUCT(cppstem,cstem) \
568 (EV_PX = get_default_loop ()) throw () \ 567 (EV_PX = get_default_loop ()) throw () \
569 : base<ev_ ## cstem, cppstem> (EV_A) \ 568 : base<ev_ ## cstem, cppstem> (EV_A) \
570 { \ 569 { \
571 } 570 }
572 #else 571 #else
573 #define EV_CONSTRUCT(cppstem,cstem) \ 572 #define EV_CONSTRUCT(cppstem,cstem) \
574 () throw () \ 573 () throw () \
575 { \ 574 { \
576 } 575 }
577 #endif 576 #endif
578 577
579 /* using a template here would require quite a bit more lines, 578 /* using a template here would require quite a bit more lines,
580 * so a macro solution was chosen */ 579 * so a macro solution was chosen */
581 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 580 #define EV_BEGIN_WATCHER(cppstem,cstem) \
582 \ 581 \
583 struct cppstem : base<ev_ ## cstem, cppstem> \ 582 struct cppstem : base<ev_ ## cstem, cppstem> \
584 { \ 583 { \
585 void start () throw () \ 584 void start () throw () \
586 { \ 585 { \
587 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 586 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
588 } \ 587 } \
589 \ 588 \
590 void stop () throw () \ 589 void stop () throw () \
591 { \ 590 { \
592 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 591 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
593 } \ 592 } \
594 \ 593 \
595 cppstem EV_CONSTRUCT(cppstem,cstem) \ 594 cppstem EV_CONSTRUCT(cppstem,cstem) \
596 \ 595 \
597 ~cppstem () throw () \ 596 ~cppstem () throw () \
598 { \ 597 { \
599 stop (); \ 598 stop (); \
600 } \ 599 } \
601 \ 600 \
602 using base<ev_ ## cstem, cppstem>::set; \ 601 using base<ev_ ## cstem, cppstem>::set; \
603 \ 602 \
604 private: \ 603 private: \
605 \ 604 \
606 cppstem (const cppstem &o); \ 605 cppstem (const cppstem &o); \
607 \ 606 \
608 cppstem & operator =(const cppstem &o); \ 607 cppstem &operator =(const cppstem &o); \
609 \ 608 \
610 public: 609 public:
611 610
612 #define EV_END_WATCHER(cppstem,cstem) \ 611 #define EV_END_WATCHER(cppstem,cstem) \
613 }; 612 };
695 start (); 694 start ();
696 } 695 }
697 EV_END_WATCHER (sig, signal) 696 EV_END_WATCHER (sig, signal)
698 697
699 EV_BEGIN_WATCHER (child, child) 698 EV_BEGIN_WATCHER (child, child)
700 void set (int pid) throw () 699 void set (int pid, int trace = 0) throw ()
701 { 700 {
702 int active = is_active (); 701 int active = is_active ();
703 if (active) stop (); 702 if (active) stop ();
704 ev_child_set (static_cast<ev_child *>(this), pid); 703 ev_child_set (static_cast<ev_child *>(this), pid, trace);
705 if (active) start (); 704 if (active) start ();
706 } 705 }
707 706
708 void start (int pid) throw () 707 void start (int pid, int trace = 0) throw ()
709 { 708 {
710 set (pid); 709 set (pid, trace);
711 start (); 710 start ();
712 } 711 }
713 EV_END_WATCHER (child, child) 712 EV_END_WATCHER (child, child)
714 713
715 #if EV_STAT_ENABLE 714 #if EV_STAT_ENABLE
748 void set () throw () { } 747 void set () throw () { }
749 EV_END_WATCHER (check, check) 748 EV_END_WATCHER (check, check)
750 749
751 #if EV_EMBED_ENABLE 750 #if EV_EMBED_ENABLE
752 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
753 void start (struct ev_loop *embedded_loop) throw () 760 void start (struct ev_loop *embedded_loop) throw ()
754 { 761 {
755 stop (); 762 set (embedded_loop);
756 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
757 start (); 763 start ();
758 } 764 }
759 765
760 void sweep () 766 void sweep ()
761 { 767 {
768 EV_BEGIN_WATCHER (fork, fork) 774 EV_BEGIN_WATCHER (fork, fork)
769 void set () throw () { } 775 void set () throw () { }
770 EV_END_WATCHER (fork, fork) 776 EV_END_WATCHER (fork, fork)
771 #endif 777 #endif
772 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
773 #undef EV_PX 795 #undef EV_PX
774 #undef EV_PX_ 796 #undef EV_PX_
775 #undef EV_CONSTRUCT 797 #undef EV_CONSTRUCT
776 #undef EV_BEGIN_WATCHER 798 #undef EV_BEGIN_WATCHER
777 #undef EV_END_WATCHER 799 #undef EV_END_WATCHER
778
779} 800}
780 801
781#endif 802#endif
782 803

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines