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.4 by pcg, Fri Mar 21 23:17:01 2003 UTC vs.
Revision 1.7 by pcg, Fri Mar 28 05:40:54 2003 UTC

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;
38 vector<io_watcher *> iow; 38 vector<const io_watcher *> iow;
39 vector<time_watcher *> tw; // actually a heap 39 vector<time_watcher *> tw; // actually a heap
40 40
41 void idle_cb (tstamp &ts); time_watcher *idle; 41 void idle_cb (tstamp &ts); time_watcher *idle;
42public: 42public:
43
44 void reschedule_time_watchers ();
43 45
44 // register a watcher 46 // register a watcher
45 void reg (int fd, short events, io_watcher *w); 47 void reg (int fd, short events, io_watcher *w);
46 void unreg (io_watcher *w); 48 void unreg (io_watcher *w);
47 void reg (time_watcher *w); 49 void reg (time_watcher *w);
62 void *obj; 64 void *obj;
63 R (object::*meth)(A arg); 65 R (object::*meth)(A arg);
64 66
65 // a proxy is a kind of recipe on how to call a specific class method 67 // a proxy is a kind of recipe on how to call a specific class method
66 struct proxy_base { 68 struct proxy_base {
67 virtual R call (void *obj, void (object::*meth)(A), A arg) = 0; 69 virtual R call (void *obj, R (object::*meth)(A), A arg) = 0;
68 }; 70 };
69 template<class O1, class O2> 71 template<class O1, class O2>
70 struct proxy : proxy_base { 72 struct proxy : proxy_base {
71 virtual R call (void *obj, void (object::*meth)(A), A arg) 73 virtual R call (void *obj, R (object::*meth)(A), A arg)
72 { 74 {
73 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<void (O2::*)(A)>(meth))) 75 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A)>(meth)))
74 (arg); 76 (arg);
75 } 77 }
76 }; 78 };
77 79
78 proxy_base *prxy; 80 proxy_base *prxy;
79 81
80public: 82public:
81 template<class O1, class O2> 83 template<class O1, class O2>
82 callback (O1 *object, void (O2::*method)(A)) 84 callback (O1 *object, R (O2::*method)(A))
83 { 85 {
84 static proxy<O1,O2> p; 86 static proxy<O1,O2> p;
85 obj = reinterpret_cast<void *>(object); 87 obj = reinterpret_cast<void *>(object);
86 meth = reinterpret_cast<void (object::*)(A)>(method); 88 meth = reinterpret_cast<R (object::*)(A)>(method);
87 prxy = &p; 89 prxy = &p;
88 } 90 }
89 91
90 R call(A arg) 92 R call(A arg) const
91 { 93 {
92 return prxy->call (obj, meth, arg); 94 return prxy->call (obj, meth, arg);
93 } 95 }
94 96
95 R operator ()(A arg) 97 R operator ()(A arg) const
96 { 98 {
97 return call (arg); 99 return call (arg);
98 } 100 }
99}; 101};
100 102
101struct io_watcher : callback<void, short> { 103struct io_watcher : callback<void, short> {
102 template<class O1, class O2> 104 template<class O1, class O2>
103 io_watcher (O1 *object, void (O2::*method)(short revents)) 105 io_watcher (O1 *object, void (O2::*method)(short revents))
104 : callback<void, short>(object,method) 106 : callback<void, short>(object,method)
105 { } 107 { }
108
109 ~io_watcher ()
110 {
111 iom.unreg (this);
112 }
106 113
107 void start (int fd, short events) 114 void start (int fd, short events)
108 { 115 {
109 iom.reg (fd, events, this); 116 iom.reg (fd, events, this);
110 } 117 }
116}; 123};
117 124
118#define TSTAMP_CANCEL -1. 125#define TSTAMP_CANCEL -1.
119 126
120struct time_watcher : callback<void, tstamp &> { 127struct time_watcher : callback<void, tstamp &> {
128 bool registered; // already registered?
121 tstamp at; 129 tstamp at;
122 130
123 template<class O1, class O2> 131 template<class O1, class O2>
124 time_watcher (O1 *object, void (O2::*method)(tstamp &)) 132 time_watcher (O1 *object, void (O2::*method)(tstamp &))
125 : callback<void, tstamp &>(object,method) 133 : callback<void, tstamp &>(object,method)
134 , registered(false)
126 { } 135 { }
136
137 ~time_watcher ()
138 {
139 iom.unreg (this);
140 }
127 141
128 void set (tstamp when); 142 void set (tstamp when);
129 void trigger (); 143 void trigger ();
130 144
131 void operator ()() 145 void operator ()()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines