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.18 by pcg, Sun Mar 21 12:50:05 2004 UTC vs.
Revision 1.19 by pcg, Fri Apr 2 14:42:45 2004 UTC

38# define IOM_CHECK 0 38# define IOM_CHECK 0
39#endif 39#endif
40#ifndef IOM_IDLE 40#ifndef IOM_IDLE
41# define IOM_IDLE 0 41# define IOM_IDLE 0
42#endif 42#endif
43#ifndef IOM_SIG
44# define IOM_SIG 0
45#endif
43 46
44typedef double tstamp; 47typedef double tstamp;
45extern tstamp NOW; 48extern tstamp NOW;
46 49
47struct watcher; 50struct watcher;
54#if IOM_CHECK 57#if IOM_CHECK
55struct check_watcher; 58struct check_watcher;
56#endif 59#endif
57#if IOM_IDLE 60#if IOM_IDLE
58struct idle_watcher; 61struct idle_watcher;
62#endif
63#if IOM_SIG
64struct sig_watcher;
59#endif 65#endif
60 66
61template<class watcher> 67template<class watcher>
62struct io_manager_vec : vector<watcher *> { 68struct io_manager_vec : vector<watcher *> {
63#if IOM_CHECK 69#if IOM_CHECK
86 io_manager_vec<time_watcher> tw; 92 io_manager_vec<time_watcher> tw;
87#endif 93#endif
88#if IOM_IDLE 94#if IOM_IDLE
89 io_manager_vec<idle_watcher> iw; 95 io_manager_vec<idle_watcher> iw;
90#endif 96#endif
97#if IOM_SIG
98 typedef io_manager_vec<sig_watcher> sig_vec;
99 vector<sig_vec *> sw;
100 static void sighandler (int signum);
101#endif
91 102
92 template<class watcher> 103 template<class watcher>
93 void reg (watcher *w, io_manager_vec<watcher> &queue); 104 void reg (watcher *w, io_manager_vec<watcher> &queue);
94 105
95 template<class watcher> 106 template<class watcher>
107 void reg (check_watcher *w); void unreg (check_watcher *w); 118 void reg (check_watcher *w); void unreg (check_watcher *w);
108#endif 119#endif
109#if IOM_IDLE 120#if IOM_IDLE
110 void reg (idle_watcher *w); void unreg (idle_watcher *w); 121 void reg (idle_watcher *w); void unreg (idle_watcher *w);
111#endif 122#endif
123#if IOM_SIG
124 void reg (sig_watcher *w); void unreg (sig_watcher *w);
125#endif
112 126
113 void loop (); 127 void loop ();
114 128
115 io_manager (); 129 io_manager ();
116 ~io_manager (); 130 ~io_manager ();
119extern io_manager iom; // a singleton, together with it's construction/destruction problems. 133extern io_manager iom; // a singleton, together with it's construction/destruction problems.
120 134
121struct watcher { 135struct watcher {
122 int active; /* 0 == inactive, else index into respective vector */ 136 int active; /* 0 == inactive, else index into respective vector */
123 137
124 watcher() : active(0) { } 138 watcher () : active (0) { }
125}; 139};
126 140
127#if IOM_IO 141#if IOM_IO
128enum { EVENT_READ = 1, EVENT_WRITE = 2 }; 142enum { EVENT_READ = 1, EVENT_WRITE = 2 };
129 143
137 void start () { iom.reg (this); } 151 void start () { iom.reg (this); }
138 void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); } 152 void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); }
139 void stop () { iom.unreg (this); } 153 void stop () { iom.unreg (this); }
140 154
141 template<class O1, class O2> 155 template<class O1, class O2>
142 io_watcher (O1 *object, void (O2::*method)(io_watcher &, short)) 156 io_watcher (O1 *object, void (O2::*method) (io_watcher &, short))
143 : callback2<void, io_watcher &, short>(object,method) 157 : callback2<void, io_watcher &, short> (object,method)
144 { } 158 { }
145 ~io_watcher () { stop (); } 159 ~io_watcher () { stop (); }
146}; 160};
147#endif 161#endif
148 162
151 tstamp at; 165 tstamp at;
152 166
153 void trigger (); 167 void trigger ();
154 168
155 void set (tstamp when) { at = when; } 169 void set (tstamp when) { at = when; }
156 void operator ()() { trigger (); } 170 void operator () () { trigger (); }
157 void start () { iom.reg (this); } 171 void start () { iom.reg (this); }
158 void start (tstamp when) { set (when); iom.reg (this); } 172 void start (tstamp when) { set (when); iom.reg (this); }
159 void stop () { iom.unreg (this); } 173 void stop () { iom.unreg (this); }
160 174
161 template<class O1, class O2> 175 template<class O1, class O2>
162 time_watcher (O1 *object, void (O2::*method)(time_watcher &)) 176 time_watcher (O1 *object, void (O2::*method) (time_watcher &))
163 : callback1<void, time_watcher &>(object,method), at(0) 177 : callback1<void, time_watcher &> (object,method), at (0)
164 { } 178 { }
165 ~time_watcher () { stop (); } 179 ~time_watcher () { stop (); }
166}; 180};
167#endif 181#endif
168 182
171struct check_watcher : watcher, callback1<void, check_watcher &> { 185struct check_watcher : watcher, callback1<void, check_watcher &> {
172 void start () { iom.reg (this); } 186 void start () { iom.reg (this); }
173 void stop () { iom.unreg (this); } 187 void stop () { iom.unreg (this); }
174 188
175 template<class O1, class O2> 189 template<class O1, class O2>
176 check_watcher (O1 *object, void (O2::*method)(check_watcher &)) 190 check_watcher (O1 *object, void (O2::*method) (check_watcher &))
177 : callback1<void, check_watcher &>(object,method) 191 : callback1<void, check_watcher &> (object,method)
178 { } 192 { }
179 ~check_watcher () { stop (); } 193 ~check_watcher () { stop (); }
180}; 194};
181#endif 195#endif
182 196
185struct idle_watcher : watcher, callback1<void, idle_watcher &> { 199struct idle_watcher : watcher, callback1<void, idle_watcher &> {
186 void start () { iom.reg (this); } 200 void start () { iom.reg (this); }
187 void stop () { iom.unreg (this); } 201 void stop () { iom.unreg (this); }
188 202
189 template<class O1, class O2> 203 template<class O1, class O2>
190 idle_watcher (O1 *object, void (O2::*method)(idle_watcher &)) 204 idle_watcher (O1 *object, void (O2::*method) (idle_watcher &))
191 : callback1<void, idle_watcher &>(object,method) 205 : callback1<void, idle_watcher &> (object,method)
192 { } 206 { }
193 ~idle_watcher () { stop (); } 207 ~idle_watcher () { stop (); }
194}; 208};
195#endif 209#endif
196 210
197#endif 211#if IOM_SIG
212struct sig_watcher : watcher, callback1<void, sig_watcher &> {
213 int signum;
198 214
215 void start (int signum);
216 void stop () { iom.unreg (this); }
217
218 template<class O1, class O2>
219 sig_watcher (O1 *object, void (O2::*method) (sig_watcher &))
220 : callback1<void, sig_watcher &> (object,method), signum (-1)
221 { }
222 ~sig_watcher () { stop (); }
223};
224#endif
225
226#endif
227

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines