--- gvpe/src/iom.h 2003/03/21 23:17:01 1.4 +++ gvpe/src/iom.h 2003/04/02 05:15:00 1.9 @@ -23,24 +23,26 @@ #include +#include "callback.h" #include "slog.h" typedef double tstamp; extern tstamp NOW; -template class callback; struct io_watcher; struct time_watcher; class io_manager { vector pfs; - vector iow; + vector iow; vector tw; // actually a heap void idle_cb (tstamp &ts); time_watcher *idle; public: + void reschedule_time_watchers (); + // register a watcher void reg (int fd, short events, io_watcher *w); void unreg (io_watcher *w); @@ -55,54 +57,16 @@ extern io_manager iom; -template -class callback { - struct object { }; - - void *obj; - R (object::*meth)(A arg); - - // a proxy is a kind of recipe on how to call a specific class method - struct proxy_base { - virtual R call (void *obj, void (object::*meth)(A), A arg) = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, void (object::*meth)(A), A arg) - { - ((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (arg); - } - }; - - proxy_base *prxy; - -public: +struct io_watcher : callback2 { template - callback (O1 *object, void (O2::*method)(A)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A arg) - { - return prxy->call (obj, meth, arg); - } + io_watcher (O1 *object, void (O2::*method)(int fd, short revents)) + : callback2(object,method) + { } - R operator ()(A arg) + ~io_watcher () { - return call (arg); + iom.unreg (this); } -}; - -struct io_watcher : callback { - template - io_watcher (O1 *object, void (O2::*method)(short revents)) - : callback(object,method) - { } void start (int fd, short events) { @@ -117,14 +81,21 @@ #define TSTAMP_CANCEL -1. -struct time_watcher : callback { +struct time_watcher : callback1 { + bool registered; // already registered? tstamp at; template time_watcher (O1 *object, void (O2::*method)(tstamp &)) - : callback(object,method) + : callback1(object,method) + , registered(false) { } + ~time_watcher () + { + iom.unreg (this); + } + void set (tstamp when); void trigger ();