--- rxvt-unicode/src/iom.h 2003/11/24 17:28:08 1.1 +++ rxvt-unicode/src/iom.h 2003/12/19 06:17:03 1.5 @@ -25,24 +25,61 @@ #include "rxvtvec.h" #include "callback.h" -typedef double tstamp; +#define IOM_IO 1 +#define IOM_TIME 1 +#define IOM_CHECK 1 +#define IOM_IDLE 0 + +#if IOM_IO + typedef double tstamp; + extern tstamp NOW; -extern tstamp NOW; - -struct io_watcher; -struct time_watcher; + struct io_watcher; +#endif +#if IOM_TIME + struct time_watcher; +#endif +#if IOM_CHECK + struct check_watcher; +#endif +#if IOM_IDLE + struct idle_watcher; +#endif class io_manager { - simplevec iow; - simplevec tw; // actually a heap +#if IOM_IO + simplevec iow; +#endif +#if IOM_CHECK + simplevec cw; +#endif +#if IOM_TIME + simplevec tw; +#endif +#if IOM_IDLE + simplevec iw; +#endif + + template + void reg (watcher *w, simplevec &queue); + + template + void unreg (watcher *w, simplevec &queue); - void idle_cb (time_watcher &w); time_watcher *idle; public: // register a watcher - void reg (io_watcher *w); - void unreg (io_watcher *w); - void reg (time_watcher *w); - void unreg (time_watcher *w); +#if IOM_IO + void reg (io_watcher *w); void unreg (io_watcher *w); +#endif +#if IOM_TIME + void reg (time_watcher *w); void unreg (time_watcher *w); +#endif +#if IOM_CHECK + void reg (check_watcher *w); void unreg (check_watcher *w); +#endif +#if IOM_IDLE + void reg (idle_watcher *w); void unreg (idle_watcher *w); +#endif void loop (); @@ -52,6 +89,7 @@ extern io_manager iom; // a singleton, together with it's construction/destruction problems. +#if IOM_IO enum { EVENT_READ = 1, EVENT_WRITE = 2 }; struct io_watcher : callback2 { @@ -65,14 +103,17 @@ ~io_watcher (); - void set(int fd_, short events_) { fd = fd_; events = events_; } + void set (int fd_, short events_) { fd = fd_; events = events_; } - void set(short events_) { set (fd, 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); } }; +#endif -#define TSTAMP_CANCEL -1. +#if IOM_TIME +enum { TSTAMP_CANCEL = -1 }; struct time_watcher : callback1 { tstamp at; @@ -98,6 +139,37 @@ at = when; } }; +#endif + +#if IOM_CHECK +// run before checking for new events +struct check_watcher : callback1 { + template + check_watcher (O1 *object, void (O2::*method)(check_watcher &)) + : callback1(object,method) + { } + + ~check_watcher (); + + void start () { iom.reg (this); } + void stop () { iom.unreg (this); } +}; +#endif + +#if IOM_IDLE +// run after checking for any i/o, but before waiting +struct idle_watcher : callback1 { + template + idle_watcher (O1 *object, void (O2::*method)(idle_watcher &)) + : callback1(object,method) + { } + + ~idle_watcher (); + + void start () { iom.reg (this); } + void stop () { iom.unreg (this); } +}; +#endif #endif