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.13 by root, Sun May 30 19:12:42 2004 UTC vs.
Revision 1.15 by root, Thu Sep 2 07:44:40 2004 UTC

79 if ((*this)[pos] = w) 79 if ((*this)[pos] = w)
80 w->active = pos + 1; 80 w->active = pos + 1;
81 } 81 }
82}; 82};
83 83
84// only used as a namespace, and for initialisation purposes
84class io_manager { 85class io_manager {
85#if IOM_IO
86 io_manager_vec<io_watcher> iow;
87#endif
88#if IOM_CHECK
89 io_manager_vec<check_watcher> cw;
90#endif
91#if IOM_TIME
92 io_manager_vec<time_watcher> tw;
93#endif
94#if IOM_IDLE
95 io_manager_vec<idle_watcher> iw;
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
102
103 template<class watcher> 86 template<class watcher>
104 void reg (watcher *w, io_manager_vec<watcher> &queue); 87 static void reg (watcher &w, io_manager_vec<watcher> &queue);
105 88
106 template<class watcher> 89 template<class watcher>
107 void unreg (watcher *w, io_manager_vec<watcher> &queue); 90 static void unreg (watcher &w, io_manager_vec<watcher> &queue);
108 91
109public: 92public:
110 // register a watcher 93 // register a watcher
111#if IOM_IO 94#if IOM_IO
112 void reg (io_watcher *w); void unreg (io_watcher *w); 95 static void reg (io_watcher &w); static void unreg (io_watcher &w);
113#endif 96#endif
114#if IOM_TIME 97#if IOM_TIME
115 void reg (time_watcher *w); void unreg (time_watcher *w); 98 static void reg (time_watcher &w); static void unreg (time_watcher &w);
116#endif 99#endif
117#if IOM_CHECK 100#if IOM_CHECK
118 void reg (check_watcher *w); void unreg (check_watcher *w); 101 static void reg (check_watcher &w); static void unreg (check_watcher &w);
119#endif 102#endif
120#if IOM_IDLE 103#if IOM_IDLE
121 void reg (idle_watcher *w); void unreg (idle_watcher *w); 104 static void reg (idle_watcher &w); static void unreg (idle_watcher &w);
122#endif 105#endif
123#if IOM_SIG 106#if IOM_SIG
124 void reg (sig_watcher *w); void unreg (sig_watcher *w); 107 static void reg (sig_watcher &w); static void unreg (sig_watcher &w);
125#endif 108#endif
126 109
127 void loop (); 110 static void loop ();
128
129 io_manager ();
130 ~io_manager ();
131}; 111};
132
133extern io_manager iom; // a singleton, together with it's construction/destruction problems.
134 112
135struct watcher { 113struct watcher {
136 int active; /* 0 == inactive, else index into respective vector */ 114 int active; /* 0 == inactive, else index into respective vector */
137 115
138 watcher () : active (0) { } 116 watcher () : active (0) { }
146 short events; 124 short events;
147 125
148 void set (int fd_, short events_) { fd = fd_; events = events_; } 126 void set (int fd_, short events_) { fd = fd_; events = events_; }
149 127
150 void set (short events_) { set (fd, events_); } 128 void set (short events_) { set (fd, events_); }
151 void start () { iom.reg (this); } 129 void start () { io_manager::reg (*this); }
152 void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); } 130 void start (int fd_, short events_) { set (fd_, events_); io_manager::reg (*this); }
153 void stop () { iom.unreg (this); } 131 void stop () { io_manager::unreg (*this); }
154 132
155 template<class O1, class O2> 133 template<class O1, class O2>
156 io_watcher (O1 *object, void (O2::*method) (io_watcher &, short)) 134 io_watcher (O1 *object, void (O2::*method) (io_watcher &, short))
157 : callback2<void, io_watcher &, short> (object,method) 135 : callback2<void, io_watcher &, short> (object,method)
158 { } 136 { }
166 144
167 void trigger (); 145 void trigger ();
168 146
169 void set (tstamp when) { at = when; } 147 void set (tstamp when) { at = when; }
170 void operator () () { trigger (); } 148 void operator () () { trigger (); }
171 void start () { iom.reg (this); } 149 void start () { io_manager::reg (*this); }
172 void start (tstamp when) { set (when); iom.reg (this); } 150 void start (tstamp when) { set (when); io_manager::reg (*this); }
173 void stop () { iom.unreg (this); } 151 void stop () { io_manager::unreg (*this); }
174 152
175 template<class O1, class O2> 153 template<class O1, class O2>
176 time_watcher (O1 *object, void (O2::*method) (time_watcher &)) 154 time_watcher (O1 *object, void (O2::*method) (time_watcher &))
177 : callback1<void, time_watcher &> (object,method), at (0) 155 : callback1<void, time_watcher &> (object,method), at (0)
178 { } 156 { }
181#endif 159#endif
182 160
183#if IOM_CHECK 161#if IOM_CHECK
184// run before checking for new events 162// run before checking for new events
185struct check_watcher : watcher, callback1<void, check_watcher &> { 163struct check_watcher : watcher, callback1<void, check_watcher &> {
186 void start () { iom.reg (this); } 164 void start () { io_manager::reg (*this); }
187 void stop () { iom.unreg (this); } 165 void stop () { io_manager::unreg (*this); }
188 166
189 template<class O1, class O2> 167 template<class O1, class O2>
190 check_watcher (O1 *object, void (O2::*method) (check_watcher &)) 168 check_watcher (O1 *object, void (O2::*method) (check_watcher &))
191 : callback1<void, check_watcher &> (object,method) 169 : callback1<void, check_watcher &> (object,method)
192 { } 170 { }
195#endif 173#endif
196 174
197#if IOM_IDLE 175#if IOM_IDLE
198// run after checking for any i/o, but before waiting 176// run after checking for any i/o, but before waiting
199struct idle_watcher : watcher, callback1<void, idle_watcher &> { 177struct idle_watcher : watcher, callback1<void, idle_watcher &> {
200 void start () { iom.reg (this); } 178 void start () { io_manager::reg (*this); }
201 void stop () { iom.unreg (this); } 179 void stop () { io_manager::unreg (*this); }
202 180
203 template<class O1, class O2> 181 template<class O1, class O2>
204 idle_watcher (O1 *object, void (O2::*method) (idle_watcher &)) 182 idle_watcher (O1 *object, void (O2::*method) (idle_watcher &))
205 : callback1<void, idle_watcher &> (object,method) 183 : callback1<void, idle_watcher &> (object,method)
206 { } 184 { }
211#if IOM_SIG 189#if IOM_SIG
212struct sig_watcher : watcher, callback1<void, sig_watcher &> { 190struct sig_watcher : watcher, callback1<void, sig_watcher &> {
213 int signum; 191 int signum;
214 192
215 void start (int signum); 193 void start (int signum);
216 void stop () { iom.unreg (this); } 194 void stop () { io_manager::unreg (*this); }
217 195
218 template<class O1, class O2> 196 template<class O1, class O2>
219 sig_watcher (O1 *object, void (O2::*method) (sig_watcher &)) 197 sig_watcher (O1 *object, void (O2::*method) (sig_watcher &))
220 : callback1<void, sig_watcher &> (object,method), signum (-1) 198 : callback1<void, sig_watcher &> (object,method), signum (-1)
221 { } 199 { }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines