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.42 by root, Mon Nov 3 14:27:06 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,
77# undef ERROR // some systems stupidly #define ERROR
76 ERROR = EV_ERROR, 78 ERROR = EV_ERROR,
77 }; 79 };
78 80
79 enum 81 enum
80 { 82 {
81 AUTO = EVFLAG_AUTO, 83 AUTO = EVFLAG_AUTO,
82 NOENV = EVFLAG_NOENV, 84 NOENV = EVFLAG_NOENV,
83 FORKCHECK = EVFLAG_FORKCHECK, 85 FORKCHECK = EVFLAG_FORKCHECK,
86
84 SELECT = EVBACKEND_SELECT, 87 SELECT = EVBACKEND_SELECT,
85 POLL = EVBACKEND_POLL, 88 POLL = EVBACKEND_POLL,
86 EPOLL = EVBACKEND_EPOLL, 89 EPOLL = EVBACKEND_EPOLL,
87 KQUEUE = EVBACKEND_KQUEUE, 90 KQUEUE = EVBACKEND_KQUEUE,
88 DEVPOLL = EVBACKEND_DEVPOLL, 91 DEVPOLL = EVBACKEND_DEVPOLL,
89 PORT = EVBACKEND_PORT 92 PORT = EVBACKEND_PORT
90 }; 93 };
91 94
92 enum 95 enum
93 { 96 {
94 NONBLOCK = EVLOOP_NONBLOCK, 97 NONBLOCK = EVLOOP_NONBLOCK,
95 ONESHOT = EVLOOP_ONESHOT 98 ONESHOT = EVLOOP_ONESHOT
96 }; 99 };
97 100
98 enum how_t 101 enum how_t
99 { 102 {
100 ONE = EVUNLOOP_ONE, 103 ONE = EVUNLOOP_ONE,
130# define EV_AX_ 133# define EV_AX_
131#endif 134#endif
132 135
133 struct loop_ref 136 struct loop_ref
134 { 137 {
135
136 loop_ref (EV_P) throw () 138 loop_ref (EV_P) throw ()
137#if EV_MULTIPLICITY 139#if EV_MULTIPLICITY
138 : EV_AX (EV_A) 140 : EV_AX (EV_A)
139#endif 141#endif
140 { 142 {
157 return false; 159 return false;
158#endif 160#endif
159 } 161 }
160 162
161#if EV_MULTIPLICITY 163#if EV_MULTIPLICITY
162 bool operator== (struct ev_loop *other) const throw () 164 bool operator == (struct ev_loop *other) const throw ()
163 { 165 {
164 return this->EV_AX == other; 166 return this->EV_AX == other;
165 } 167 }
166 168
167 bool operator!= (struct ev_loop *other) const throw () 169 bool operator != (struct ev_loop *other) const throw ()
168 { 170 {
169 return ! (*this == other); 171 return ! (*this == other);
170 } 172 }
171 173
172 bool operator== (const struct ev_loop *other) const throw () 174 bool operator == (const struct ev_loop *other) const throw ()
173 { 175 {
174 return this->EV_AX == other; 176 return this->EV_AX == other;
175 } 177 }
176 178
177 bool operator!= (const struct ev_loop *other) const throw () 179 bool operator != (const struct ev_loop *other) const throw ()
178 { 180 {
179 return (*this == other); 181 return (*this == other);
180 } 182 }
181 183
182 operator struct ev_loop * () const throw () 184 operator struct ev_loop * () const throw ()
365 }; 367 };
366#endif 368#endif
367 369
368 struct default_loop : loop_ref 370 struct default_loop : loop_ref
369 { 371 {
370
371 default_loop (unsigned int flags = AUTO) throw (bad_loop) 372 default_loop (unsigned int flags = AUTO) throw (bad_loop)
372#if EV_MULTIPLICITY 373#if EV_MULTIPLICITY
373 : loop_ref (ev_default_loop (flags)) 374 : loop_ref (ev_default_loop (flags))
374#endif 375#endif
375 { 376 {
563 ev_set_syserr_cb (cb); 564 ev_set_syserr_cb (cb);
564 } 565 }
565 566
566 #if EV_MULTIPLICITY 567 #if EV_MULTIPLICITY
567 #define EV_CONSTRUCT(cppstem,cstem) \ 568 #define EV_CONSTRUCT(cppstem,cstem) \
568 (EV_PX = get_default_loop ()) throw () \ 569 (EV_PX = get_default_loop ()) throw () \
569 : base<ev_ ## cstem, cppstem> (EV_A) \ 570 : base<ev_ ## cstem, cppstem> (EV_A) \
570 { \ 571 { \
571 } 572 }
572 #else 573 #else
573 #define EV_CONSTRUCT(cppstem,cstem) \ 574 #define EV_CONSTRUCT(cppstem,cstem) \
574 () throw () \ 575 () throw () \
575 { \ 576 { \
576 } 577 }
577 #endif 578 #endif
578 579
579 /* using a template here would require quite a bit more lines, 580 /* using a template here would require quite a bit more lines,
580 * so a macro solution was chosen */ 581 * so a macro solution was chosen */
581 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 582 #define EV_BEGIN_WATCHER(cppstem,cstem) \
582 \ 583 \
583 struct cppstem : base<ev_ ## cstem, cppstem> \ 584 struct cppstem : base<ev_ ## cstem, cppstem> \
584 { \ 585 { \
585 void start () throw () \ 586 void start () throw () \
586 { \ 587 { \
587 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 588 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
588 } \ 589 } \
589 \ 590 \
590 void stop () throw () \ 591 void stop () throw () \
591 { \ 592 { \
592 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 593 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
593 } \ 594 } \
594 \ 595 \
595 cppstem EV_CONSTRUCT(cppstem,cstem) \ 596 cppstem EV_CONSTRUCT(cppstem,cstem) \
596 \ 597 \
597 ~cppstem () throw () \ 598 ~cppstem () throw () \
598 { \ 599 { \
599 stop (); \ 600 stop (); \
600 } \ 601 } \
601 \ 602 \
602 using base<ev_ ## cstem, cppstem>::set; \ 603 using base<ev_ ## cstem, cppstem>::set; \
603 \ 604 \
604 private: \ 605 private: \
605 \ 606 \
606 cppstem (const cppstem &o); \ 607 cppstem (const cppstem &o); \
607 \ 608 \
608 cppstem & operator =(const cppstem &o); \ 609 cppstem &operator =(const cppstem &o); \
609 \ 610 \
610 public: 611 public:
611 612
612 #define EV_END_WATCHER(cppstem,cstem) \ 613 #define EV_END_WATCHER(cppstem,cstem) \
613 }; 614 };
695 start (); 696 start ();
696 } 697 }
697 EV_END_WATCHER (sig, signal) 698 EV_END_WATCHER (sig, signal)
698 699
699 EV_BEGIN_WATCHER (child, child) 700 EV_BEGIN_WATCHER (child, child)
700 void set (int pid) throw () 701 void set (int pid, int trace = 0) throw ()
701 { 702 {
702 int active = is_active (); 703 int active = is_active ();
703 if (active) stop (); 704 if (active) stop ();
704 ev_child_set (static_cast<ev_child *>(this), pid); 705 ev_child_set (static_cast<ev_child *>(this), pid, trace);
705 if (active) start (); 706 if (active) start ();
706 } 707 }
707 708
708 void start (int pid) throw () 709 void start (int pid, int trace = 0) throw ()
709 { 710 {
710 set (pid); 711 set (pid, trace);
711 start (); 712 start ();
712 } 713 }
713 EV_END_WATCHER (child, child) 714 EV_END_WATCHER (child, child)
714 715
715 #if EV_STAT_ENABLE 716 #if EV_STAT_ENABLE
748 void set () throw () { } 749 void set () throw () { }
749 EV_END_WATCHER (check, check) 750 EV_END_WATCHER (check, check)
750 751
751 #if EV_EMBED_ENABLE 752 #if EV_EMBED_ENABLE
752 EV_BEGIN_WATCHER (embed, embed) 753 EV_BEGIN_WATCHER (embed, embed)
754 void set (struct ev_loop *embedded_loop) throw ()
755 {
756 int active = is_active ();
757 if (active) stop ();
758 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
759 if (active) start ();
760 }
761
753 void start (struct ev_loop *embedded_loop) throw () 762 void start (struct ev_loop *embedded_loop) throw ()
754 { 763 {
755 stop (); 764 set (embedded_loop);
756 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
757 start (); 765 start ();
758 } 766 }
759 767
760 void sweep () 768 void sweep ()
761 { 769 {
768 EV_BEGIN_WATCHER (fork, fork) 776 EV_BEGIN_WATCHER (fork, fork)
769 void set () throw () { } 777 void set () throw () { }
770 EV_END_WATCHER (fork, fork) 778 EV_END_WATCHER (fork, fork)
771 #endif 779 #endif
772 780
781 #if EV_ASYNC_ENABLE
782 EV_BEGIN_WATCHER (async, async)
783 void set () throw () { }
784
785 void send () throw ()
786 {
787 ev_async_send (EV_A_ static_cast<ev_async *>(this));
788 }
789
790 bool async_pending () throw ()
791 {
792 return ev_async_pending (static_cast<ev_async *>(this));
793 }
794 EV_END_WATCHER (async, async)
795 #endif
796
773 #undef EV_PX 797 #undef EV_PX
774 #undef EV_PX_ 798 #undef EV_PX_
775 #undef EV_CONSTRUCT 799 #undef EV_CONSTRUCT
776 #undef EV_BEGIN_WATCHER 800 #undef EV_BEGIN_WATCHER
777 #undef EV_END_WATCHER 801 #undef EV_END_WATCHER
778
779} 802}
780 803
781#endif 804#endif
782 805

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines