… | |
… | |
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 | { |
… | |
… | |
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 | }; |
… | |
… | |
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 | |