ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev++.h
(Generate patch)

Comparing libev/ev++.h (file contents):
Revision 1.3 by root, Sun Nov 11 01:07:35 2007 UTC vs.
Revision 1.8 by root, Tue Nov 27 08:20:41 2007 UTC

1#ifndef EVPP_H__ 1#ifndef EVPP_H__
2#define EVPP_H__ 2#define EVPP_H__
3 3
4/* work in progress, don't use unless you know what you are doing */ 4#include "ev.h"
5 5
6namespace ev { 6namespace ev {
7 7
8 template<class watcher> 8 template<class watcher>
9 class callback 9 class callback
41 void call (watcher *w, int e) const 41 void call (watcher *w, int e) const
42 { 42 {
43 return prxy->call (obj, meth, *w, e); 43 return prxy->call (obj, meth, *w, e);
44 } 44 }
45 }; 45 };
46
47 #include "ev.h"
48 46
49 enum { 47 enum {
50 UNDEF = EV_UNDEF, 48 UNDEF = EV_UNDEF,
51 NONE = EV_NONE, 49 NONE = EV_NONE,
52 READ = EV_READ, 50 READ = EV_READ,
91 89
92 #endif 90 #endif
93 91
94 /* using a template here would require quite a bit more lines, 92 /* using a template here would require quite a bit more lines,
95 * so a macro solution was chosen */ 93 * so a macro solution was chosen */
96 #define EV_DECLARE_WATCHER(cppstem,cstem) \ 94 #define EV_BEGIN_WATCHER(cppstem,cstem) \
97 \
98 extern "C" void cb_ ## cppstem (struct ev_ ## cstem *w, int revents); \
99 \ 95 \
100 struct cppstem : ev_ ## cstem, callback<cppstem> \ 96 struct cppstem : ev_ ## cstem, callback<cppstem> \
101 { \ 97 { \
102 EV_CONSTRUCT (cppstem) \ 98 EV_CONSTRUCT (cppstem) \
103 { \ 99 { \
104 ev_init (static_cast<ev_ ## cstem *>(this), cb_ ## cppstem); \ 100 ev_init (static_cast<ev_ ## cstem *>(this), thunk); \
105 } \ 101 } \
106 \ 102 \
107 bool is_active () const \ 103 bool is_active () const \
108 { \ 104 { \
109 return ev_is_active (static_cast<const ev_ ## cstem *>(this)); \ 105 return ev_is_active (static_cast<const ev_ ## cstem *>(this)); \
137 private: \ 133 private: \
138 \ 134 \
139 cppstem (const cppstem &o) \ 135 cppstem (const cppstem &o) \
140 : callback<cppstem> (this, (void (cppstem::*)(cppstem &, int))0) \ 136 : callback<cppstem> (this, (void (cppstem::*)(cppstem &, int))0) \
141 { /* disabled */ } \ 137 { /* disabled */ } \
138 \
142 void operator =(const cppstem &o) { /* disabled */ } \ 139 void operator =(const cppstem &o) { /* disabled */ } \
143 \ 140 \
141 static void thunk (EV_P_ struct ev_ ## cstem *w, int revents) \
142 { \
143 (*static_cast<cppstem *>(w))(revents); \
144 } \
145 \
144 public: 146 public:
145 147
148 #define EV_END_WATCHER(cppstem,cstem) \
149 };
150
146 EV_DECLARE_WATCHER (io, io) 151 EV_BEGIN_WATCHER (io, io)
147 void set (int fd, int events) 152 void set (int fd, int events)
148 { 153 {
149 int active = is_active (); 154 int active = is_active ();
150 if (active) stop (); 155 if (active) stop ();
151 ev_io_set (static_cast<ev_io *>(this), fd, events); 156 ev_io_set (static_cast<ev_io *>(this), fd, events);
163 void start (int fd, int events) 168 void start (int fd, int events)
164 { 169 {
165 set (fd, events); 170 set (fd, events);
166 start (); 171 start ();
167 } 172 }
168 }; 173 EV_END_WATCHER (io, io)
169 174
170 EV_DECLARE_WATCHER (timer, timer) 175 EV_BEGIN_WATCHER (timer, timer)
171 void set (ev_tstamp after, ev_tstamp repeat = 0.) 176 void set (ev_tstamp after, ev_tstamp repeat = 0.)
172 { 177 {
173 int active = is_active (); 178 int active = is_active ();
174 if (active) stop (); 179 if (active) stop ();
175 ev_timer_set (static_cast<ev_timer *>(this), after, repeat); 180 ev_timer_set (static_cast<ev_timer *>(this), after, repeat);
184 189
185 void again () 190 void again ()
186 { 191 {
187 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 192 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
188 } 193 }
189 }; 194 EV_END_WATCHER (timer, timer)
190 195
191 #if EV_PERIODICS 196 #if EV_PERIODIC_ENABLE
192 EV_DECLARE_WATCHER (periodic, periodic) 197 EV_BEGIN_WATCHER (periodic, periodic)
193 void set (ev_tstamp at, ev_tstamp interval = 0.) 198 void set (ev_tstamp at, ev_tstamp interval = 0.)
194 { 199 {
195 int active = is_active (); 200 int active = is_active ();
196 if (active) stop (); 201 if (active) stop ();
197 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); 202 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0);
206 211
207 void again () 212 void again ()
208 { 213 {
209 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 214 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
210 } 215 }
211 }; 216 EV_END_WATCHER (periodic, periodic)
212 #endif 217 #endif
213 218
214 EV_DECLARE_WATCHER (idle, idle)
215 };
216
217 EV_DECLARE_WATCHER (prepare, prepare)
218 };
219
220 EV_DECLARE_WATCHER (check, check)
221 };
222
223 EV_DECLARE_WATCHER (sig, signal) 219 EV_BEGIN_WATCHER (sig, signal)
224 void set (int signum) 220 void set (int signum)
225 { 221 {
226 int active = is_active (); 222 int active = is_active ();
227 if (active) stop (); 223 if (active) stop ();
228 ev_signal_set (static_cast<ev_signal *>(this), signum); 224 ev_signal_set (static_cast<ev_signal *>(this), signum);
232 void start (int signum) 228 void start (int signum)
233 { 229 {
234 set (signum); 230 set (signum);
235 start (); 231 start ();
236 } 232 }
237 }; 233 EV_END_WATCHER (sig, signal)
238 234
239 EV_DECLARE_WATCHER (child, child) 235 EV_BEGIN_WATCHER (child, child)
240 void set (int pid) 236 void set (int pid)
241 { 237 {
242 int active = is_active (); 238 int active = is_active ();
243 if (active) stop (); 239 if (active) stop ();
244 ev_child_set (static_cast<ev_child *>(this), pid); 240 ev_child_set (static_cast<ev_child *>(this), pid);
248 void start (int pid) 244 void start (int pid)
249 { 245 {
250 set (pid); 246 set (pid);
251 start (); 247 start ();
252 } 248 }
253 }; 249 EV_END_WATCHER (child, child)
250
251 #if EV_STAT_ENABLE
252 EV_BEGIN_WATCHER (stat, stat)
253 void set (const char *path, ev_tstamp interval = 0.)
254 {
255 int active = is_active ();
256 if (active) stop ();
257 ev_stat_set (static_cast<ev_stat *>(this), path, interval);
258 if (active) start ();
259 }
260
261 void start (const char *path, ev_tstamp interval = 0.)
262 {
263 set (path, interval);
264 start ();
265 }
266
267 void update ()
268 {
269 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
270 }
271 EV_END_WATCHER (stat, stat)
272 #endif
273
274 EV_BEGIN_WATCHER (idle, idle)
275 void set () { }
276 EV_END_WATCHER (idle, idle)
277
278 EV_BEGIN_WATCHER (prepare, prepare)
279 void set () { }
280 EV_END_WATCHER (prepare, prepare)
281
282 EV_BEGIN_WATCHER (check, check)
283 void set () { }
284 EV_END_WATCHER (check, check)
285
286 #if EV_EMBED_ENABLE
287 EV_BEGIN_WATCHER (embed, embed)
288 void set (struct ev_loop *loop)
289 {
290 int active = is_active ();
291 if (active) stop ();
292 ev_embed_set (static_cast<ev_embed *>(this), loop);
293 if (active) start ();
294 }
295
296 void start (struct ev_loop *embedded_loop)
297 {
298 set (embedded_loop);
299 start ();
300 }
301
302 void sweep ()
303 {
304 ev_embed_sweep (EV_A_ static_cast<ev_embed *>(this));
305 }
306 EV_END_WATCHER (embed, embed)
307 #endif
254 308
255 #undef EV_CONSTRUCT 309 #undef EV_CONSTRUCT
310 #undef EV_BEGIN_WATCHER
256 #undef EV_DECLARE_WATCHER 311 #undef EV_END_WATCHER
257} 312}
258 313
259#endif 314#endif
260 315

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines