--- gvpe/src/iom.h 2003/03/21 21:17:02 1.2 +++ gvpe/src/iom.h 2003/03/26 01:58:46 1.5 @@ -35,15 +35,17 @@ class io_manager { vector pfs; - vector iow; + vector iow; vector tw; // actually a heap + + void idle_cb (tstamp &ts); time_watcher *idle; public: // 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 (); @@ -62,13 +64,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); } }; @@ -77,22 +79,22 @@ 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); } - void stop () + R operator ()(A arg) const { - iom.unreg (this); + return call (arg); } }; @@ -107,8 +109,14 @@ iom.reg (fd, events, this); } + void stop () const + { + iom.unreg (this); + } }; +#define TSTAMP_CANCEL -1. + struct time_watcher : callback { tstamp at; @@ -118,16 +126,29 @@ { } void set (tstamp when); + void trigger (); - void trigger () + void operator ()() { - call (at); + trigger (); } + void start (); void start (tstamp when) { set (when); } + + void stop () const + { + iom.unreg (this); + } + + void reset (tstamp when = TSTAMP_CANCEL) + { + stop (); + at = when; + } }; #endif