… | |
… | |
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 (bad_loop) |
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 | { |
141 | #if EV_MULTIPLICITY |
|
|
142 | if (!EV_AX) |
|
|
143 | throw bad_loop (); |
|
|
144 | #endif |
|
|
145 | } |
141 | } |
146 | |
142 | |
147 | bool operator == (const loop_ref &other) const throw () |
143 | bool operator == (const loop_ref &other) const throw () |
148 | { |
144 | { |
149 | #if EV_MULTIPLICITY |
145 | #if EV_MULTIPLICITY |
… | |
… | |
161 | return false; |
157 | return false; |
162 | #endif |
158 | #endif |
163 | } |
159 | } |
164 | |
160 | |
165 | #if EV_MULTIPLICITY |
161 | #if EV_MULTIPLICITY |
166 | bool operator== (struct ev_loop *other) const throw () |
162 | bool operator == (struct ev_loop *other) const throw () |
167 | { |
163 | { |
168 | return this->EV_AX == other; |
164 | return this->EV_AX == other; |
169 | } |
165 | } |
170 | |
166 | |
171 | bool operator!= (struct ev_loop *other) const throw () |
167 | bool operator != (struct ev_loop *other) const throw () |
172 | { |
168 | { |
173 | return ! (*this == other); |
169 | return ! (*this == other); |
174 | } |
170 | } |
175 | |
171 | |
176 | bool operator== (const struct ev_loop *other) const throw () |
172 | bool operator == (const struct ev_loop *other) const throw () |
177 | { |
173 | { |
178 | return this->EV_AX == other; |
174 | return this->EV_AX == other; |
179 | } |
175 | } |
180 | |
176 | |
181 | bool operator!= (const struct ev_loop *other) const throw () |
177 | bool operator != (const struct ev_loop *other) const throw () |
182 | { |
178 | { |
183 | return (*this == other); |
179 | return (*this == other); |
184 | } |
180 | } |
185 | |
181 | |
186 | operator struct ev_loop * () const throw () |
182 | operator struct ev_loop * () const throw () |
… | |
… | |
342 | #endif |
338 | #endif |
343 | |
339 | |
344 | }; |
340 | }; |
345 | |
341 | |
346 | #if EV_MULTIPLICITY |
342 | #if EV_MULTIPLICITY |
347 | struct dynamic_loop: loop_ref |
343 | struct dynamic_loop : loop_ref |
348 | { |
344 | { |
349 | |
345 | |
350 | dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) |
346 | dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) |
351 | : loop_ref (ev_loop_new (flags)) |
347 | : loop_ref (ev_loop_new (flags)) |
352 | { |
348 | { |
|
|
349 | if (!EV_AX) |
|
|
350 | throw bad_loop (); |
353 | } |
351 | } |
354 | |
352 | |
355 | ~dynamic_loop () throw () |
353 | ~dynamic_loop () throw () |
356 | { |
354 | { |
357 | ev_loop_destroy (EV_AX); |
355 | ev_loop_destroy (EV_AX); |
… | |
… | |
365 | dynamic_loop & operator= (const dynamic_loop &); |
363 | dynamic_loop & operator= (const dynamic_loop &); |
366 | |
364 | |
367 | }; |
365 | }; |
368 | #endif |
366 | #endif |
369 | |
367 | |
370 | struct default_loop: loop_ref |
368 | struct default_loop : loop_ref |
371 | { |
369 | { |
372 | |
|
|
373 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
370 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
374 | #if EV_MULTIPLICITY |
371 | #if EV_MULTIPLICITY |
375 | : loop_ref (ev_default_loop (flags)) |
372 | : loop_ref (ev_default_loop (flags)) |
376 | #endif |
373 | #endif |
377 | { |
374 | { |
|
|
375 | if ( |
378 | #ifndef EV_MULTIPLICITY |
376 | #if EV_MULTIPLICITY |
|
|
377 | !EV_AX |
|
|
378 | #else |
379 | if (!ev_default_loop (flags)) |
379 | !ev_default_loop (flags) |
|
|
380 | #endif |
|
|
381 | ) |
380 | throw bad_loop (); |
382 | throw bad_loop (); |
381 | #endif |
|
|
382 | } |
383 | } |
383 | |
384 | |
384 | ~default_loop () throw () |
385 | ~default_loop () throw () |
385 | { |
386 | { |
386 | ev_default_destroy (); |
387 | ev_default_destroy (); |
… | |
… | |
561 | ev_set_syserr_cb (cb); |
562 | ev_set_syserr_cb (cb); |
562 | } |
563 | } |
563 | |
564 | |
564 | #if EV_MULTIPLICITY |
565 | #if EV_MULTIPLICITY |
565 | #define EV_CONSTRUCT(cppstem,cstem) \ |
566 | #define EV_CONSTRUCT(cppstem,cstem) \ |
566 | (EV_PX = get_default_loop ()) throw () \ |
567 | (EV_PX = get_default_loop ()) throw () \ |
567 | : base<ev_ ## cstem, cppstem> (EV_A) \ |
568 | : base<ev_ ## cstem, cppstem> (EV_A) \ |
568 | { \ |
569 | { \ |
569 | } |
570 | } |
570 | #else |
571 | #else |
571 | #define EV_CONSTRUCT(cppstem,cstem) \ |
572 | #define EV_CONSTRUCT(cppstem,cstem) \ |
572 | () throw () \ |
573 | () throw () \ |
573 | { \ |
574 | { \ |
574 | } |
575 | } |
575 | #endif |
576 | #endif |
576 | |
577 | |
577 | /* using a template here would require quite a bit more lines, |
578 | /* using a template here would require quite a bit more lines, |
578 | * so a macro solution was chosen */ |
579 | * so a macro solution was chosen */ |
579 | #define EV_BEGIN_WATCHER(cppstem,cstem) \ |
580 | #define EV_BEGIN_WATCHER(cppstem,cstem) \ |
580 | \ |
581 | \ |
581 | struct cppstem : base<ev_ ## cstem, cppstem> \ |
582 | struct cppstem : base<ev_ ## cstem, cppstem> \ |
582 | { \ |
583 | { \ |
583 | void start () throw () \ |
584 | void start () throw () \ |
584 | { \ |
585 | { \ |
585 | ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
586 | ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
586 | } \ |
587 | } \ |
587 | \ |
588 | \ |
588 | void stop () throw () \ |
589 | void stop () throw () \ |
589 | { \ |
590 | { \ |
590 | ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
591 | ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
591 | } \ |
592 | } \ |
592 | \ |
593 | \ |
593 | cppstem EV_CONSTRUCT(cppstem,cstem) \ |
594 | cppstem EV_CONSTRUCT(cppstem,cstem) \ |
594 | \ |
595 | \ |
595 | ~cppstem () throw () \ |
596 | ~cppstem () throw () \ |
596 | { \ |
597 | { \ |
597 | stop (); \ |
598 | stop (); \ |
598 | } \ |
599 | } \ |
599 | \ |
600 | \ |
600 | using base<ev_ ## cstem, cppstem>::set; \ |
601 | using base<ev_ ## cstem, cppstem>::set; \ |
601 | \ |
602 | \ |
602 | private: \ |
603 | private: \ |
603 | \ |
604 | \ |
604 | cppstem (const cppstem &o); \ |
605 | cppstem (const cppstem &o); \ |
605 | \ |
606 | \ |
606 | cppstem & operator =(const cppstem &o); \ |
607 | cppstem &operator =(const cppstem &o); \ |
607 | \ |
608 | \ |
608 | public: |
609 | public: |
609 | |
610 | |
610 | #define EV_END_WATCHER(cppstem,cstem) \ |
611 | #define EV_END_WATCHER(cppstem,cstem) \ |
611 | }; |
612 | }; |
… | |
… | |
693 | start (); |
694 | start (); |
694 | } |
695 | } |
695 | EV_END_WATCHER (sig, signal) |
696 | EV_END_WATCHER (sig, signal) |
696 | |
697 | |
697 | EV_BEGIN_WATCHER (child, child) |
698 | EV_BEGIN_WATCHER (child, child) |
698 | void set (int pid) throw () |
699 | void set (int pid, int trace = 0) throw () |
699 | { |
700 | { |
700 | int active = is_active (); |
701 | int active = is_active (); |
701 | if (active) stop (); |
702 | if (active) stop (); |
702 | ev_child_set (static_cast<ev_child *>(this), pid); |
703 | ev_child_set (static_cast<ev_child *>(this), pid, trace); |
703 | if (active) start (); |
704 | if (active) start (); |
704 | } |
705 | } |
705 | |
706 | |
706 | void start (int pid) throw () |
707 | void start (int pid, int trace = 0) throw () |
707 | { |
708 | { |
708 | set (pid); |
709 | set (pid, trace); |
709 | start (); |
710 | start (); |
710 | } |
711 | } |
711 | EV_END_WATCHER (child, child) |
712 | EV_END_WATCHER (child, child) |
712 | |
713 | |
713 | #if EV_STAT_ENABLE |
714 | #if EV_STAT_ENABLE |
… | |
… | |
746 | void set () throw () { } |
747 | void set () throw () { } |
747 | EV_END_WATCHER (check, check) |
748 | EV_END_WATCHER (check, check) |
748 | |
749 | |
749 | #if EV_EMBED_ENABLE |
750 | #if EV_EMBED_ENABLE |
750 | 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 | |
751 | void start (struct ev_loop *embedded_loop) throw () |
760 | void start (struct ev_loop *embedded_loop) throw () |
752 | { |
761 | { |
753 | stop (); |
762 | set (embedded_loop); |
754 | ev_embed_set (static_cast<ev_embed *>(this), embedded_loop); |
|
|
755 | start (); |
763 | start (); |
756 | } |
764 | } |
757 | |
765 | |
758 | void sweep () |
766 | void sweep () |
759 | { |
767 | { |
… | |
… | |
766 | EV_BEGIN_WATCHER (fork, fork) |
774 | EV_BEGIN_WATCHER (fork, fork) |
767 | void set () throw () { } |
775 | void set () throw () { } |
768 | EV_END_WATCHER (fork, fork) |
776 | EV_END_WATCHER (fork, fork) |
769 | #endif |
777 | #endif |
770 | |
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 | |
771 | #undef EV_PX |
795 | #undef EV_PX |
772 | #undef EV_PX_ |
796 | #undef EV_PX_ |
773 | #undef EV_CONSTRUCT |
797 | #undef EV_CONSTRUCT |
774 | #undef EV_BEGIN_WATCHER |
798 | #undef EV_BEGIN_WATCHER |
775 | #undef EV_END_WATCHER |
799 | #undef EV_END_WATCHER |
776 | |
|
|
777 | } |
800 | } |
778 | |
801 | |
779 | #undef EV_THROW |
|
|
780 | |
|
|
781 | #endif |
802 | #endif |
782 | |
803 | |