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

Comparing rxvt-unicode/src/iom.h (file contents):
Revision 1.9 by pcg, Thu Jan 29 23:26:01 2004 UTC vs.
Revision 1.12 by pcg, Fri Apr 2 14:30:06 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;
55struct check_watcher; 58struct check_watcher;
56#endif 59#endif
57#if IOM_IDLE 60#if IOM_IDLE
58struct idle_watcher; 61struct idle_watcher;
59#endif 62#endif
63#if IOM_SIG
64struct sig_watcher;
65#endif
60 66
61template<class watcher> 67template<class watcher>
62struct io_manager_vec : protected vector<watcher *> { 68struct io_manager_vec : vector<watcher *> {
63 friend class io_manager;
64protected:
65#if IOM_CHECK 69#if IOM_CHECK
66 bool activity; 70 bool activity;
67#endif 71#endif
68 72
69 void erase_unordered (unsigned int pos) 73 void erase_unordered (unsigned int pos)
88 io_manager_vec<time_watcher> tw; 92 io_manager_vec<time_watcher> tw;
89#endif 93#endif
90#if IOM_IDLE 94#if IOM_IDLE
91 io_manager_vec<idle_watcher> iw; 95 io_manager_vec<idle_watcher> iw;
92#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
93 102
94 template<class watcher> 103 template<class watcher>
95 void reg (watcher *w, io_manager_vec<watcher> &queue); 104 void reg (watcher *w, io_manager_vec<watcher> &queue);
96 105
97 template<class watcher> 106 template<class watcher>
109 void reg (check_watcher *w); void unreg (check_watcher *w); 118 void reg (check_watcher *w); void unreg (check_watcher *w);
110#endif 119#endif
111#if IOM_IDLE 120#if IOM_IDLE
112 void reg (idle_watcher *w); void unreg (idle_watcher *w); 121 void reg (idle_watcher *w); void unreg (idle_watcher *w);
113#endif 122#endif
123#if IOM_SIG
124 void reg (sig_watcher *w); void unreg (sig_watcher *w);
125#endif
114 126
115 void loop (); 127 void loop ();
116 128
117 io_manager (); 129 io_manager ();
118 ~io_manager (); 130 ~io_manager ();
121extern 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.
122 134
123struct watcher { 135struct watcher {
124 int active; /* 0 == inactive, else index into respective vector */ 136 int active; /* 0 == inactive, else index into respective vector */
125 137
126 watcher() : active(0) { } 138 watcher () : active (0) { }
127}; 139};
128 140
129#if IOM_IO 141#if IOM_IO
130enum { EVENT_READ = 1, EVENT_WRITE = 2 }; 142enum { EVENT_READ = 1, EVENT_WRITE = 2 };
131 143
139 void start () { iom.reg (this); } 151 void start () { iom.reg (this); }
140 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); }
141 void stop () { iom.unreg (this); } 153 void stop () { iom.unreg (this); }
142 154
143 template<class O1, class O2> 155 template<class O1, class O2>
144 io_watcher (O1 *object, void (O2::*method)(io_watcher &, short)) 156 io_watcher (O1 *object, void (O2::*method) (io_watcher &, short))
145 : callback2<void, io_watcher &, short>(object,method) 157 : callback2<void, io_watcher &, short> (object,method)
146 { } 158 { }
147 ~io_watcher () { stop (); } 159 ~io_watcher () { stop (); }
148}; 160};
149#endif 161#endif
150 162
153 tstamp at; 165 tstamp at;
154 166
155 void trigger (); 167 void trigger ();
156 168
157 void set (tstamp when) { at = when; } 169 void set (tstamp when) { at = when; }
158 void operator ()() { trigger (); } 170 void operator () () { trigger (); }
159 void start () { iom.reg (this); } 171 void start () { iom.reg (this); }
160 void start (tstamp when) { set (when); iom.reg (this); } 172 void start (tstamp when) { set (when); iom.reg (this); }
161 void stop () { iom.unreg (this); } 173 void stop () { iom.unreg (this); }
162 174
163 template<class O1, class O2> 175 template<class O1, class O2>
164 time_watcher (O1 *object, void (O2::*method)(time_watcher &)) 176 time_watcher (O1 *object, void (O2::*method) (time_watcher &))
165 : callback1<void, time_watcher &>(object,method), at(0) 177 : callback1<void, time_watcher &> (object,method), at (0)
166 { } 178 { }
167 ~time_watcher () { stop (); } 179 ~time_watcher () { stop (); }
168}; 180};
169#endif 181#endif
170 182
173struct check_watcher : watcher, callback1<void, check_watcher &> { 185struct check_watcher : watcher, callback1<void, check_watcher &> {
174 void start () { iom.reg (this); } 186 void start () { iom.reg (this); }
175 void stop () { iom.unreg (this); } 187 void stop () { iom.unreg (this); }
176 188
177 template<class O1, class O2> 189 template<class O1, class O2>
178 check_watcher (O1 *object, void (O2::*method)(check_watcher &)) 190 check_watcher (O1 *object, void (O2::*method) (check_watcher &))
179 : callback1<void, check_watcher &>(object,method) 191 : callback1<void, check_watcher &> (object,method)
180 { } 192 { }
181 ~check_watcher () { stop (); } 193 ~check_watcher () { stop (); }
182}; 194};
183#endif 195#endif
184 196
187struct idle_watcher : watcher, callback1<void, idle_watcher &> { 199struct idle_watcher : watcher, callback1<void, idle_watcher &> {
188 void start () { iom.reg (this); } 200 void start () { iom.reg (this); }
189 void stop () { iom.unreg (this); } 201 void stop () { iom.unreg (this); }
190 202
191 template<class O1, class O2> 203 template<class O1, class O2>
192 idle_watcher (O1 *object, void (O2::*method)(idle_watcher &)) 204 idle_watcher (O1 *object, void (O2::*method) (idle_watcher &))
193 : callback1<void, idle_watcher &>(object,method) 205 : callback1<void, idle_watcher &> (object,method)
194 { } 206 { }
195 ~idle_watcher () { stop (); } 207 ~idle_watcher () { stop (); }
196}; 208};
197#endif 209#endif
198 210
199#endif 211#if IOM_SIG
212struct sig_watcher : watcher, callback1<void, sig_watcher &> {
213 int signum;
200 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