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

Comparing libev/ev++.h (file contents):
Revision 1.38 by root, Mon Jan 28 11:43:37 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,
561 ev_set_syserr_cb (cb); 564 ev_set_syserr_cb (cb);
562 } 565 }
563 566
564 #if EV_MULTIPLICITY 567 #if EV_MULTIPLICITY
565 #define EV_CONSTRUCT(cppstem,cstem) \ 568 #define EV_CONSTRUCT(cppstem,cstem) \
566 (EV_PX = get_default_loop ()) throw () \ 569 (EV_PX = get_default_loop ()) throw () \
567 : base<ev_ ## cstem, cppstem> (EV_A) \ 570 : base<ev_ ## cstem, cppstem> (EV_A) \
568 { \ 571 { \
569 } 572 }
570 #else 573 #else
571 #define EV_CONSTRUCT(cppstem,cstem) \ 574 #define EV_CONSTRUCT(cppstem,cstem) \
572 () throw () \ 575 () throw () \
573 { \ 576 { \
574 } 577 }
575 #endif 578 #endif
576 579
577 /* using a template here would require quite a bit more lines, 580 /* using a template here would require quite a bit more lines,
578 * so a macro solution was chosen */ 581 * so a macro solution was chosen */
579 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 582 #define EV_BEGIN_WATCHER(cppstem,cstem) \
580 \ 583 \
581 struct cppstem : base<ev_ ## cstem, cppstem> \ 584 struct cppstem : base<ev_ ## cstem, cppstem> \
582 { \ 585 { \
583 void start () throw () \ 586 void start () throw () \
584 { \ 587 { \
585 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 588 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
586 } \ 589 } \
587 \ 590 \
588 void stop () throw () \ 591 void stop () throw () \
589 { \ 592 { \
590 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 593 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
591 } \ 594 } \
592 \ 595 \
593 cppstem EV_CONSTRUCT(cppstem,cstem) \ 596 cppstem EV_CONSTRUCT(cppstem,cstem) \
594 \ 597 \
595 ~cppstem () throw () \ 598 ~cppstem () throw () \
596 { \ 599 { \
597 stop (); \ 600 stop (); \
598 } \ 601 } \
599 \ 602 \
600 using base<ev_ ## cstem, cppstem>::set; \ 603 using base<ev_ ## cstem, cppstem>::set; \
601 \ 604 \
602 private: \ 605 private: \
603 \ 606 \
604 cppstem (const cppstem &o); \ 607 cppstem (const cppstem &o); \
605 \ 608 \
606 cppstem & operator =(const cppstem &o); \ 609 cppstem &operator =(const cppstem &o); \
607 \ 610 \
608 public: 611 public:
609 612
610 #define EV_END_WATCHER(cppstem,cstem) \ 613 #define EV_END_WATCHER(cppstem,cstem) \
611 }; 614 };
746 void set () throw () { } 749 void set () throw () { }
747 EV_END_WATCHER (check, check) 750 EV_END_WATCHER (check, check)
748 751
749 #if EV_EMBED_ENABLE 752 #if EV_EMBED_ENABLE
750 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
751 void start (struct ev_loop *embedded_loop) throw () 762 void start (struct ev_loop *embedded_loop) throw ()
752 { 763 {
753 stop (); 764 set (embedded_loop);
754 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
755 start (); 765 start ();
756 } 766 }
757 767
758 void sweep () 768 void sweep ()
759 { 769 {
764 774
765 #if EV_FORK_ENABLE 775 #if EV_FORK_ENABLE
766 EV_BEGIN_WATCHER (fork, fork) 776 EV_BEGIN_WATCHER (fork, fork)
767 void set () throw () { } 777 void set () throw () { }
768 EV_END_WATCHER (fork, fork) 778 EV_END_WATCHER (fork, fork)
779 #endif
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)
769 #endif 795 #endif
770 796
771 #undef EV_PX 797 #undef EV_PX
772 #undef EV_PX_ 798 #undef EV_PX_
773 #undef EV_CONSTRUCT 799 #undef EV_CONSTRUCT

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines