ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/iom.h
(Generate patch)

Comparing gvpe/src/iom.h (file contents):
Revision 1.7 by pcg, Fri Mar 28 05:40:54 2003 UTC vs.
Revision 1.8 by pcg, Wed Apr 2 03:06:22 2003 UTC

21 21
22#include <vector> 22#include <vector>
23 23
24#include <sys/poll.h> 24#include <sys/poll.h>
25 25
26#include "callback.h"
26#include "slog.h" 27#include "slog.h"
27 28
28typedef double tstamp; 29typedef double tstamp;
29 30
30extern tstamp NOW; 31extern tstamp NOW;
31 32
32template<class R, class A> class callback;
33struct io_watcher; 33struct io_watcher;
34struct time_watcher; 34struct time_watcher;
35 35
36class io_manager { 36class io_manager {
37 vector<pollfd> pfs; 37 vector<pollfd> pfs;
54 io_manager (); 54 io_manager ();
55 ~io_manager (); 55 ~io_manager ();
56}; 56};
57 57
58extern io_manager iom; 58extern io_manager iom;
59
60template<class R, class A>
61class callback {
62 struct object { };
63
64 void *obj;
65 R (object::*meth)(A arg);
66
67 // a proxy is a kind of recipe on how to call a specific class method
68 struct proxy_base {
69 virtual R call (void *obj, R (object::*meth)(A), A arg) = 0;
70 };
71 template<class O1, class O2>
72 struct proxy : proxy_base {
73 virtual R call (void *obj, R (object::*meth)(A), A arg)
74 {
75 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A)>(meth)))
76 (arg);
77 }
78 };
79
80 proxy_base *prxy;
81
82public:
83 template<class O1, class O2>
84 callback (O1 *object, R (O2::*method)(A))
85 {
86 static proxy<O1,O2> p;
87 obj = reinterpret_cast<void *>(object);
88 meth = reinterpret_cast<R (object::*)(A)>(method);
89 prxy = &p;
90 }
91
92 R call(A arg) const
93 {
94 return prxy->call (obj, meth, arg);
95 }
96
97 R operator ()(A arg) const
98 {
99 return call (arg);
100 }
101};
102 59
103struct io_watcher : callback<void, short> { 60struct io_watcher : callback<void, short> {
104 template<class O1, class O2> 61 template<class O1, class O2>
105 io_watcher (O1 *object, void (O2::*method)(short revents)) 62 io_watcher (O1 *object, void (O2::*method)(short revents))
106 : callback<void, short>(object,method) 63 : callback<void, short>(object,method)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines