--- deliantra/server/include/cfperl.h 2006/12/14 05:09:32 1.35 +++ deliantra/server/include/cfperl.h 2006/12/14 20:39:54 1.36 @@ -12,6 +12,10 @@ #include #include +#include + +#include "callback.h" + // optimisations/workaround for functions requiring my_perl in scope (anti-bloat) #undef localtime #undef srand48 @@ -326,5 +330,49 @@ char *fgets (char *s, int n, object_thawer &thawer); +struct watcher_base +{ + static struct EventAPI *GEventAPI; +}; + +template +struct watcher : watcher_base +{ + base *pe; + + void start (bool repeat = false) { GEventAPI->start ((pe_watcher *)pe, repeat); } + void stop (bool cancel_events = false) { GEventAPI->stop ((pe_watcher *)pe, cancel_events); } + void now () { GEventAPI->now ((pe_watcher *)pe); } + void suspend () { GEventAPI->suspend ((pe_watcher *)pe); } + void resume () { GEventAPI->resume ((pe_watcher *)pe); } + + void prio (int new_prio) { ((pe_watcher *)pe)->prio = new_prio; } + + ~watcher () + { + cancel (); + } + +private: + void cancel () { GEventAPI->cancel ((pe_watcher *)pe); } // private +}; + +struct iow : watcher, callback +{ + template + iow (O object, M method) + : callback (object, method) + { + alloc (); + } + + iow &fd (int fd); + int poll (); + iow &poll (int events); + +private: + void alloc (); +}; + #endif