--- gvpe/src/iom.h 2003/03/21 23:17:01 1.4 +++ gvpe/src/iom.h 2003/03/28 04:05:10 1.6 @@ -35,17 +35,19 @@ 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); + void unreg (const io_watcher *w); void reg (time_watcher *w); - void unreg (time_watcher *w); + void unreg (const time_watcher *w); void loop (); @@ -64,13 +66,13 @@ // 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; + virtual R call (void *obj, R (object::*meth)(A), A arg) = 0; }; template struct proxy : proxy_base { - virtual R call (void *obj, void (object::*meth)(A), A arg) + virtual R call (void *obj, R (object::*meth)(A), A arg) { - ((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) + ((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) (arg); } }; @@ -79,20 +81,20 @@ public: template - callback (O1 *object, void (O2::*method)(A)) + callback (O1 *object, R (O2::*method)(A)) { static proxy p; obj = reinterpret_cast(object); - meth = reinterpret_cast(method); + meth = reinterpret_cast(method); prxy = &p; } - R call(A arg) + R call(A arg) const { return prxy->call (obj, meth, arg); } - R operator ()(A arg) + R operator ()(A arg) const { return call (arg); } @@ -104,12 +106,17 @@ : callback(object,method) { } + ~io_watcher () + { + iom.unreg (this); + } + void start (int fd, short events) { iom.reg (fd, events, this); } - void stop () + void stop () const { iom.unreg (this); } @@ -118,13 +125,20 @@ #define TSTAMP_CANCEL -1. struct time_watcher : callback { + bool registered; // already registered? tstamp at; template time_watcher (O1 *object, void (O2::*method)(tstamp &)) : callback(object,method) + , registered(false) { } + ~time_watcher () + { + iom.unreg (this); + } + void set (tstamp when); void trigger (); @@ -139,7 +153,7 @@ set (when); } - void stop () + void stop () const { iom.unreg (this); }