--- gvpe/src/iom.h 2003/03/28 04:05:10 1.6 +++ gvpe/src/iom.h 2003/04/02 05:15:00 1.9 @@ -23,13 +23,13 @@ #include +#include "callback.h" #include "slog.h" typedef double tstamp; extern tstamp NOW; -template class callback; struct io_watcher; struct time_watcher; @@ -45,9 +45,9 @@ // register a watcher void reg (int fd, short events, io_watcher *w); - void unreg (const io_watcher *w); + void unreg (io_watcher *w); void reg (time_watcher *w); - void unreg (const time_watcher *w); + void unreg (time_watcher *w); void loop (); @@ -57,53 +57,10 @@ 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, R (object::*meth)(A), A arg) = 0; - }; +struct io_watcher : callback2 { template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)(A), A arg) - { - ((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (arg); - } - }; - - proxy_base *prxy; - -public: - template - callback (O1 *object, R (O2::*method)(A)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A arg) const - { - return prxy->call (obj, meth, arg); - } - - R operator ()(A arg) const - { - return call (arg); - } -}; - -struct io_watcher : callback { - template - io_watcher (O1 *object, void (O2::*method)(short revents)) - : callback(object,method) + io_watcher (O1 *object, void (O2::*method)(int fd, short revents)) + : callback2(object,method) { } ~io_watcher () @@ -116,7 +73,7 @@ iom.reg (fd, events, this); } - void stop () const + void stop () { iom.unreg (this); } @@ -124,13 +81,13 @@ #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) { } @@ -153,7 +110,7 @@ set (when); } - void stop () const + void stop () { iom.unreg (this); }