… | |
… | |
57 | #if IOM_IDLE |
57 | #if IOM_IDLE |
58 | struct idle_watcher; |
58 | struct idle_watcher; |
59 | #endif |
59 | #endif |
60 | |
60 | |
61 | template<class watcher> |
61 | template<class watcher> |
62 | struct io_manager_vec : protected vector<watcher *> { |
62 | struct io_manager_vec : vector<watcher *> { |
63 | friend class io_manager; |
63 | #if IOM_CHECK |
64 | protected: |
64 | bool activity; |
|
|
65 | #endif |
|
|
66 | |
65 | void erase_unordered (unsigned int pos) |
67 | void erase_unordered (unsigned int pos) |
66 | { |
68 | { |
67 | watcher *w = (*this)[size () - 1]; |
69 | watcher *w = (*this)[size () - 1]; |
68 | pop_back (); |
70 | pop_back (); |
69 | |
71 | |
… | |
… | |
117 | extern io_manager iom; // a singleton, together with it's construction/destruction problems. |
119 | extern io_manager iom; // a singleton, together with it's construction/destruction problems. |
118 | |
120 | |
119 | struct watcher { |
121 | struct watcher { |
120 | int active; /* 0 == inactive, else index into respective vector */ |
122 | int active; /* 0 == inactive, else index into respective vector */ |
121 | |
123 | |
122 | watcher() : active(0) { } |
124 | watcher () : active (0) { } |
123 | }; |
125 | }; |
124 | |
126 | |
125 | #if IOM_IO |
127 | #if IOM_IO |
126 | enum { EVENT_READ = 1, EVENT_WRITE = 2 }; |
128 | enum { EVENT_READ = 1, EVENT_WRITE = 2 }; |
127 | |
129 | |
… | |
… | |
135 | void start () { iom.reg (this); } |
137 | void start () { iom.reg (this); } |
136 | void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); } |
138 | void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); } |
137 | void stop () { iom.unreg (this); } |
139 | void stop () { iom.unreg (this); } |
138 | |
140 | |
139 | template<class O1, class O2> |
141 | template<class O1, class O2> |
140 | io_watcher (O1 *object, void (O2::*method)(io_watcher &, short)) |
142 | io_watcher (O1 *object, void (O2::*method) (io_watcher &, short)) |
141 | : callback2<void, io_watcher &, short>(object,method) |
143 | : callback2<void, io_watcher &, short> (object,method) |
142 | { } |
144 | { } |
143 | ~io_watcher () { stop (); } |
145 | ~io_watcher () { stop (); } |
144 | }; |
146 | }; |
145 | #endif |
147 | #endif |
146 | |
148 | |
… | |
… | |
149 | tstamp at; |
151 | tstamp at; |
150 | |
152 | |
151 | void trigger (); |
153 | void trigger (); |
152 | |
154 | |
153 | void set (tstamp when) { at = when; } |
155 | void set (tstamp when) { at = when; } |
154 | void operator ()() { trigger (); } |
156 | void operator () () { trigger (); } |
155 | void start () { iom.reg (this); } |
157 | void start () { iom.reg (this); } |
156 | void start (tstamp when) { set (when); iom.reg (this); } |
158 | void start (tstamp when) { set (when); iom.reg (this); } |
157 | void stop () { iom.unreg (this); } |
159 | void stop () { iom.unreg (this); } |
158 | |
160 | |
159 | template<class O1, class O2> |
161 | template<class O1, class O2> |
160 | time_watcher (O1 *object, void (O2::*method)(time_watcher &)) |
162 | time_watcher (O1 *object, void (O2::*method) (time_watcher &)) |
161 | : callback1<void, time_watcher &>(object,method), at(0) |
163 | : callback1<void, time_watcher &> (object,method), at (0) |
162 | { } |
164 | { } |
163 | ~time_watcher () { stop (); } |
165 | ~time_watcher () { stop (); } |
164 | }; |
166 | }; |
165 | #endif |
167 | #endif |
166 | |
168 | |
… | |
… | |
169 | struct check_watcher : watcher, callback1<void, check_watcher &> { |
171 | struct check_watcher : watcher, callback1<void, check_watcher &> { |
170 | void start () { iom.reg (this); } |
172 | void start () { iom.reg (this); } |
171 | void stop () { iom.unreg (this); } |
173 | void stop () { iom.unreg (this); } |
172 | |
174 | |
173 | template<class O1, class O2> |
175 | template<class O1, class O2> |
174 | check_watcher (O1 *object, void (O2::*method)(check_watcher &)) |
176 | check_watcher (O1 *object, void (O2::*method) (check_watcher &)) |
175 | : callback1<void, check_watcher &>(object,method) |
177 | : callback1<void, check_watcher &> (object,method) |
176 | { } |
178 | { } |
177 | ~check_watcher () { stop (); } |
179 | ~check_watcher () { stop (); } |
178 | }; |
180 | }; |
179 | #endif |
181 | #endif |
180 | |
182 | |
… | |
… | |
183 | struct idle_watcher : watcher, callback1<void, idle_watcher &> { |
185 | struct idle_watcher : watcher, callback1<void, idle_watcher &> { |
184 | void start () { iom.reg (this); } |
186 | void start () { iom.reg (this); } |
185 | void stop () { iom.unreg (this); } |
187 | void stop () { iom.unreg (this); } |
186 | |
188 | |
187 | template<class O1, class O2> |
189 | template<class O1, class O2> |
188 | idle_watcher (O1 *object, void (O2::*method)(idle_watcher &)) |
190 | idle_watcher (O1 *object, void (O2::*method) (idle_watcher &)) |
189 | : callback1<void, idle_watcher &>(object,method) |
191 | : callback1<void, idle_watcher &> (object,method) |
190 | { } |
192 | { } |
191 | ~idle_watcher () { stop (); } |
193 | ~idle_watcher () { stop (); } |
192 | }; |
194 | }; |
193 | #endif |
195 | #endif |
194 | |
196 | |