… | |
… | |
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) |
136 | loop_ref (EV_P) throw () |
137 | #if EV_MULTIPLICITY |
137 | #if EV_MULTIPLICITY |
138 | throw (bad_loop) : EV_AX (EV_A) |
138 | : EV_AX (EV_A) |
139 | { |
139 | #endif |
140 | if (!EV_AX) |
|
|
141 | throw bad_loop (); |
|
|
142 | } |
140 | { |
143 | #else |
|
|
144 | throw () |
|
|
145 | { |
141 | } |
146 | } |
|
|
147 | #endif |
|
|
148 | |
142 | |
149 | bool operator == (const loop_ref &other) const throw () |
143 | bool operator == (const loop_ref &other) const throw () |
150 | { |
144 | { |
151 | #if EV_MULTIPLICITY |
145 | #if EV_MULTIPLICITY |
152 | return EV_AX == other.EV_AX; |
146 | return EV_AX == other.EV_AX; |
… | |
… | |
163 | return false; |
157 | return false; |
164 | #endif |
158 | #endif |
165 | } |
159 | } |
166 | |
160 | |
167 | #if EV_MULTIPLICITY |
161 | #if EV_MULTIPLICITY |
168 | bool operator== (struct ev_loop *other) const throw () |
162 | bool operator == (struct ev_loop *other) const throw () |
169 | { |
163 | { |
170 | return this->EV_AX == other; |
164 | return this->EV_AX == other; |
171 | } |
165 | } |
172 | |
166 | |
173 | bool operator!= (struct ev_loop *other) const throw () |
167 | bool operator != (struct ev_loop *other) const throw () |
174 | { |
168 | { |
175 | return ! (*this == other); |
169 | return ! (*this == other); |
176 | } |
170 | } |
177 | |
171 | |
178 | bool operator== (const struct ev_loop *other) const throw () |
172 | bool operator == (const struct ev_loop *other) const throw () |
179 | { |
173 | { |
180 | return this->EV_AX == other; |
174 | return this->EV_AX == other; |
181 | } |
175 | } |
182 | |
176 | |
183 | bool operator!= (const struct ev_loop *other) const throw () |
177 | bool operator != (const struct ev_loop *other) const throw () |
184 | { |
178 | { |
185 | return (*this == other); |
179 | return (*this == other); |
186 | } |
180 | } |
187 | |
181 | |
188 | operator struct ev_loop * () const throw () |
182 | operator struct ev_loop * () const throw () |
… | |
… | |
344 | #endif |
338 | #endif |
345 | |
339 | |
346 | }; |
340 | }; |
347 | |
341 | |
348 | #if EV_MULTIPLICITY |
342 | #if EV_MULTIPLICITY |
349 | struct dynamic_loop: loop_ref |
343 | struct dynamic_loop : loop_ref |
350 | { |
344 | { |
351 | |
345 | |
352 | dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) |
346 | dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) |
353 | : loop_ref (ev_loop_new (flags)) |
347 | : loop_ref (ev_loop_new (flags)) |
354 | { |
348 | { |
|
|
349 | if (!EV_AX) |
|
|
350 | throw bad_loop (); |
355 | } |
351 | } |
356 | |
352 | |
357 | ~dynamic_loop () throw () |
353 | ~dynamic_loop () throw () |
358 | { |
354 | { |
359 | ev_loop_destroy (EV_AX); |
355 | ev_loop_destroy (EV_AX); |
… | |
… | |
367 | dynamic_loop & operator= (const dynamic_loop &); |
363 | dynamic_loop & operator= (const dynamic_loop &); |
368 | |
364 | |
369 | }; |
365 | }; |
370 | #endif |
366 | #endif |
371 | |
367 | |
372 | struct default_loop: loop_ref |
368 | struct default_loop : loop_ref |
373 | { |
369 | { |
374 | |
|
|
375 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
370 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
376 | #if EV_MULTIPLICITY |
371 | #if EV_MULTIPLICITY |
377 | : loop_ref (ev_default_loop (flags)) |
372 | : loop_ref (ev_default_loop (flags)) |
378 | #endif |
373 | #endif |
379 | { |
374 | { |
|
|
375 | if ( |
380 | #if !EV_MULTIPLICITY |
376 | #if EV_MULTIPLICITY |
|
|
377 | !EV_AX |
|
|
378 | #else |
381 | if (!ev_default_loop (flags)) |
379 | !ev_default_loop (flags) |
|
|
380 | #endif |
|
|
381 | ) |
382 | throw bad_loop (); |
382 | throw bad_loop (); |
383 | #endif |
|
|
384 | } |
383 | } |
385 | |
384 | |
386 | ~default_loop () throw () |
385 | ~default_loop () throw () |
387 | { |
386 | { |
388 | ev_default_destroy (); |
387 | ev_default_destroy (); |
… | |
… | |
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 | |