--- rxvt-unicode/src/iom.h 2004/02/13 12:16:21 1.11 +++ rxvt-unicode/src/iom.h 2004/09/02 07:44:40 1.15 @@ -40,6 +40,9 @@ #ifndef IOM_IDLE # define IOM_IDLE 0 #endif +#ifndef IOM_SIG +# define IOM_SIG 0 +#endif typedef double tstamp; extern tstamp NOW; @@ -57,6 +60,9 @@ #if IOM_IDLE struct idle_watcher; #endif +#if IOM_SIG +struct sig_watcher; +#endif template struct io_manager_vec : vector { @@ -66,58 +72,44 @@ void erase_unordered (unsigned int pos) { - watcher *w = (*this)[size () - 1]; - pop_back (); + watcher *w = (*this)[this->size () - 1]; + this->pop_back (); - if (size ()) + if (this->size ()) if ((*this)[pos] = w) w->active = pos + 1; } }; +// only used as a namespace, and for initialisation purposes class io_manager { -#if IOM_IO - io_manager_vec iow; -#endif -#if IOM_CHECK - io_manager_vec cw; -#endif -#if IOM_TIME - io_manager_vec tw; -#endif -#if IOM_IDLE - io_manager_vec iw; -#endif - template - void reg (watcher *w, io_manager_vec &queue); + static void reg (watcher &w, io_manager_vec &queue); template - void unreg (watcher *w, io_manager_vec &queue); + static void unreg (watcher &w, io_manager_vec &queue); public: // register a watcher #if IOM_IO - void reg (io_watcher *w); void unreg (io_watcher *w); + static void reg (io_watcher &w); static void unreg (io_watcher &w); #endif #if IOM_TIME - void reg (time_watcher *w); void unreg (time_watcher *w); + static void reg (time_watcher &w); static void unreg (time_watcher &w); #endif #if IOM_CHECK - void reg (check_watcher *w); void unreg (check_watcher *w); + static void reg (check_watcher &w); static void unreg (check_watcher &w); #endif #if IOM_IDLE - void reg (idle_watcher *w); void unreg (idle_watcher *w); + 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 - void loop (); - - io_manager (); - ~io_manager (); + static void loop (); }; -extern io_manager iom; // a singleton, together with it's construction/destruction problems. - struct watcher { int active; /* 0 == inactive, else index into respective vector */ @@ -134,9 +126,9 @@ void set (int fd_, short events_) { fd = fd_; events = events_; } void set (short events_) { set (fd, events_); } - void start () { iom.reg (this); } - void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); } - void stop () { iom.unreg (this); } + void start () { io_manager::reg (*this); } + void start (int fd_, short events_) { set (fd_, events_); io_manager::reg (*this); } + void stop () { io_manager::unreg (*this); } template io_watcher (O1 *object, void (O2::*method) (io_watcher &, short)) @@ -154,9 +146,9 @@ void set (tstamp when) { at = when; } void operator () () { trigger (); } - void start () { iom.reg (this); } - void start (tstamp when) { set (when); iom.reg (this); } - void stop () { iom.unreg (this); } + void start () { io_manager::reg (*this); } + void start (tstamp when) { set (when); io_manager::reg (*this); } + void stop () { io_manager::unreg (*this); } template time_watcher (O1 *object, void (O2::*method) (time_watcher &)) @@ -169,8 +161,8 @@ #if IOM_CHECK // run before checking for new events struct check_watcher : watcher, callback1 { - void start () { iom.reg (this); } - void stop () { iom.unreg (this); } + void start () { io_manager::reg (*this); } + void stop () { io_manager::unreg (*this); } template check_watcher (O1 *object, void (O2::*method) (check_watcher &)) @@ -183,8 +175,8 @@ #if IOM_IDLE // run after checking for any i/o, but before waiting struct idle_watcher : watcher, callback1 { - void start () { iom.reg (this); } - void stop () { iom.unreg (this); } + void start () { io_manager::reg (*this); } + void stop () { io_manager::unreg (*this); } template idle_watcher (O1 *object, void (O2::*method) (idle_watcher &)) @@ -194,5 +186,20 @@ }; #endif +#if IOM_SIG +struct sig_watcher : watcher, callback1 { + int signum; + + void start (int signum); + void stop () { io_manager::unreg (*this); } + + template + sig_watcher (O1 *object, void (O2::*method) (sig_watcher &)) + : callback1 (object,method), signum (-1) + { } + ~sig_watcher () { stop (); } +}; +#endif + #endif