--- rxvt-unicode/src/iom.h 2006/05/31 00:32:56 1.28 +++ rxvt-unicode/src/iom.h 2007/10/25 12:42:00 1.31 @@ -41,6 +41,19 @@ // TSTAMP_MAX must still fit into a positive struct timeval #define TSTAMP_MAX (double)(1UL<<31) +//#define IOM_LIBEVENT "event.h" *NOT* a supported feature +#ifdef IOM_LIBEVENT +# include +# include IOM_LIBEVENT +# undef IOM_IO +# define IOM_IO 1 +# undef IOM_TIME +# define IOM_TIME 1 +# undef IOM_IDLE // NYI +# undef IOM_SIG // NYI +# undef IOM_CHILD // NYI +#endif + struct watcher; #if IOM_IO struct io_watcher; @@ -92,21 +105,23 @@ #endif // register a watcher +#ifndef IOM_LIBEVENT #if IOM_IO static void reg (io_watcher &w); static void unreg (io_watcher &w); #endif #if IOM_TIME static void reg (time_watcher &w); static void unreg (time_watcher &w); #endif +#if IOM_SIG + static void reg (sig_watcher &w); static void unreg (sig_watcher &w); +#endif #if IOM_CHECK static void reg (check_watcher &w); static void unreg (check_watcher &w); #endif +#endif #if IOM_IDLE static void reg (idle_watcher &w); static void unreg (idle_watcher &w); #endif -#if IOM_SIG - static void reg (sig_watcher &w); static void unreg (sig_watcher &w); -#endif #if IOM_CHILD static void reg (child_watcher &w); static void unreg (child_watcher &w); #endif @@ -123,6 +138,29 @@ }; #if IOM_IO +#ifdef IOM_LIBEVENT +enum { EVENT_UNDEF = -1, EVENT_NONE = 0, EVENT_READ = EV_READ, EVENT_WRITE = EV_WRITE }; + +void iom_io_c_callback (int fd, short events, void *data); + +struct io_watcher : watcher, callback { + struct event ev; + int fd; + short events; + + void set (int fd_, short events_); + void set (short events_) { set (fd, events_); } + void start () { if (!active) event_add (&ev, 0); active = 1; } + void start (int fd_, short events_) { set (fd_, events_); start (); } + void stop () { if (active) event_del (&ev); active = 0; } + + template + io_watcher (O object, M method) + : callback (object, method) + { } + ~io_watcher () { stop (); } +}; +#else enum { EVENT_UNDEF = -1, EVENT_NONE = 0, EVENT_READ = 1, EVENT_WRITE = 2 }; struct io_watcher : watcher, callback { @@ -133,18 +171,46 @@ void set (short events_) { set (fd, events_); } void start () { io_manager::reg (*this); } - void start (int fd_, short events_) { set (fd_, events_); io_manager::reg (*this); } + void start (int fd_, short events_) { set (fd_, events_); start (); } void stop () { io_manager::unreg (*this); } - template - io_watcher (O1 *object, void (O2::*method) (io_watcher &, short)) + template + io_watcher (O object, M method) : callback (object, method) { } ~io_watcher () { stop (); } }; #endif +#endif #if IOM_TIME +#ifdef IOM_LIBEVENT +void iom_time_c_callback (int fd, short events, void *data); + +struct time_watcher : watcher, callback { + struct event ev; + tstamp at; + + void trigger (); + + void set (tstamp when) + { + at = when; + if (active) + start (); + } + void operator () () { trigger (); } + void start (); + void start (tstamp when) { at = when; start (); } + void stop () { if (active) evtimer_del (&ev); active = 0; } + + template + time_watcher (O object, M method) + : callback (object, method), at (0) + { } + ~time_watcher () { stop (); } +}; +#else struct time_watcher : watcher, callback { tstamp at; @@ -153,16 +219,17 @@ void set (tstamp when) { at = when; } void operator () () { trigger (); } void start () { io_manager::reg (*this); } - void start (tstamp when) { set (when); io_manager::reg (*this); } + void start (tstamp when) { set (when); start (); } void stop () { io_manager::unreg (*this); } - template - time_watcher (O1 *object, void (O2::*method) (time_watcher &)) + template + time_watcher (O object, M method) : callback (object, method), at (0) { } ~time_watcher () { stop (); } }; #endif +#endif #if IOM_CHECK // run before checking for new events @@ -170,8 +237,8 @@ void start () { io_manager::reg (*this); } void stop () { io_manager::unreg (*this); } - template - check_watcher (O1 *object, void (O2::*method) (check_watcher &)) + template + check_watcher (O object, M method) : callback (object, method) { } ~check_watcher () { stop (); } @@ -184,8 +251,8 @@ void start () { io_manager::reg (*this); } void stop () { io_manager::unreg (*this); } - template - idle_watcher (O1 *object, void (O2::*method) (idle_watcher &)) + template + idle_watcher (O object, M method) : callback (object, method) { } ~idle_watcher () { stop (); } @@ -199,8 +266,8 @@ void start (int signum); void stop () { io_manager::unreg (*this); } - template - sig_watcher (O1 *object, void (O2::*method) (sig_watcher &)) + template + sig_watcher (O object, M method) : callback (object, method), signum (0) { } ~sig_watcher () { stop (); } @@ -214,8 +281,8 @@ void start (int pid) { this->pid = pid; io_manager::reg (*this); } void stop () { io_manager::unreg (*this); } - template - child_watcher (O1 *object, void (O2::*method) (child_watcher &, int status)) + template + child_watcher (O object, M method) : callback (object, method), pid (0) { } ~child_watcher () { stop (); }