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

Comparing libev/ev++.h (file contents):
Revision 1.4 by root, Sun Nov 11 16:58:25 2007 UTC vs.
Revision 1.9 by root, Tue Nov 27 10:59:10 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
42 { 42 {
43 return prxy->call (obj, meth, *w, e); 43 return prxy->call (obj, meth, *w, e);
44 } 44 }
45 }; 45 };
46 46
47 #include "ev.h"
48
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,
53 WRITE = EV_WRITE, 51 WRITE = EV_WRITE,
54 TIMEOUT = EV_TIMEOUT, 52 TIMEOUT = EV_TIMEOUT,
55 PERIODIC = EV_PERIODIC, 53 PERIODIC = EV_PERIODIC,
56 SIGNAL = EV_SIGNAL, 54 SIGNAL = EV_SIGNAL,
55 CHILD = EV_CHILD,
56 STAT = EV_STAT,
57 IDLE = EV_IDLE, 57 IDLE = EV_IDLE,
58 CHECK = EV_CHECK, 58 CHECK = EV_CHECK,
59 PREPARE = EV_PREPARE, 59 PREPARE = EV_PREPARE,
60 CHILD = EV_CHILD, 60 FORK = EV_FORK,
61 EMBED = EV_EMBED,
61 ERROR = EV_ERROR, 62 ERROR = EV_ERROR,
62 }; 63 };
63 64
64 typedef ev_tstamp tstamp; 65 typedef ev_tstamp tstamp;
65 66
93 94
94 /* using a template here would require quite a bit more lines, 95 /* using a template here would require quite a bit more lines,
95 * so a macro solution was chosen */ 96 * so a macro solution was chosen */
96 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 97 #define EV_BEGIN_WATCHER(cppstem,cstem) \
97 \ 98 \
98 static void cb_ ## cppstem (struct ev_ ## cstem *w, int revents); \
99 \
100 struct cppstem : ev_ ## cstem, callback<cppstem> \ 99 struct cppstem : ev_ ## cstem, callback<cppstem> \
101 { \ 100 { \
102 EV_CONSTRUCT (cppstem) \ 101 EV_CONSTRUCT (cppstem) \
103 { \ 102 { \
104 ev_init (static_cast<ev_ ## cstem *>(this), cb_ ## cppstem); \ 103 ev_init (static_cast<ev_ ## cstem *>(this), thunk); \
105 } \ 104 } \
106 \ 105 \
107 bool is_active () const \ 106 bool is_active () const \
108 { \ 107 { \
109 return ev_is_active (static_cast<const ev_ ## cstem *>(this)); \ 108 return ev_is_active (static_cast<const ev_ ## cstem *>(this)); \
137 private: \ 136 private: \
138 \ 137 \
139 cppstem (const cppstem &o) \ 138 cppstem (const cppstem &o) \
140 : callback<cppstem> (this, (void (cppstem::*)(cppstem &, int))0) \ 139 : callback<cppstem> (this, (void (cppstem::*)(cppstem &, int))0) \
141 { /* disabled */ } \ 140 { /* disabled */ } \
141 \
142 void operator =(const cppstem &o) { /* disabled */ } \ 142 void operator =(const cppstem &o) { /* disabled */ } \
143 \ 143 \
144 static void thunk (EV_P_ struct ev_ ## cstem *w, int revents) \
145 { \
146 (*static_cast<cppstem *>(w))(revents); \
147 } \
148 \
144 public: 149 public:
145 150
146 #define EV_END_WATCHER(cppstem,cstem) \ 151 #define EV_END_WATCHER(cppstem,cstem) \
147 }; \
148 \
149 static void cb_ ## cppstem (struct ev_ ## cstem *w, int revents) \
150 { \
151 (*static_cast<cppstem *>(w))(revents); \
152 } 152 };
153 153
154 EV_BEGIN_WATCHER (io, io) 154 EV_BEGIN_WATCHER (io, io)
155 void set (int fd, int events) 155 void set (int fd, int events)
156 { 156 {
157 int active = is_active (); 157 int active = is_active ();
194 { 194 {
195 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 195 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
196 } 196 }
197 EV_END_WATCHER (timer, timer) 197 EV_END_WATCHER (timer, timer)
198 198
199 #if EV_PERIODICS 199 #if EV_PERIODIC_ENABLE
200 EV_BEGIN_WATCHER (periodic, periodic) 200 EV_BEGIN_WATCHER (periodic, periodic)
201 void set (ev_tstamp at, ev_tstamp interval = 0.) 201 void set (ev_tstamp at, ev_tstamp interval = 0.)
202 { 202 {
203 int active = is_active (); 203 int active = is_active ();
204 if (active) stop (); 204 if (active) stop ();
217 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 217 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
218 } 218 }
219 EV_END_WATCHER (periodic, periodic) 219 EV_END_WATCHER (periodic, periodic)
220 #endif 220 #endif
221 221
222 EV_BEGIN_WATCHER (idle, idle)
223 EV_END_WATCHER (idle, idle)
224
225 EV_BEGIN_WATCHER (prepare, prepare)
226 EV_END_WATCHER (prepare, prepare)
227
228 EV_BEGIN_WATCHER (check, check)
229 EV_END_WATCHER (check, check)
230
231 EV_BEGIN_WATCHER (sig, signal) 222 EV_BEGIN_WATCHER (sig, signal)
232 void set (int signum) 223 void set (int signum)
233 { 224 {
234 int active = is_active (); 225 int active = is_active ();
235 if (active) stop (); 226 if (active) stop ();
258 set (pid); 249 set (pid);
259 start (); 250 start ();
260 } 251 }
261 EV_END_WATCHER (child, child) 252 EV_END_WATCHER (child, child)
262 253
254 #if EV_STAT_ENABLE
255 EV_BEGIN_WATCHER (stat, stat)
256 void set (const char *path, ev_tstamp interval = 0.)
257 {
258 int active = is_active ();
259 if (active) stop ();
260 ev_stat_set (static_cast<ev_stat *>(this), path, interval);
261 if (active) start ();
262 }
263
264 void start (const char *path, ev_tstamp interval = 0.)
265 {
266 set (path, interval);
267 start ();
268 }
269
270 void update ()
271 {
272 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
273 }
274 EV_END_WATCHER (stat, stat)
275 #endif
276
277 EV_BEGIN_WATCHER (idle, idle)
278 void set () { }
279 EV_END_WATCHER (idle, idle)
280
281 EV_BEGIN_WATCHER (prepare, prepare)
282 void set () { }
283 EV_END_WATCHER (prepare, prepare)
284
285 EV_BEGIN_WATCHER (check, check)
286 void set () { }
287 EV_END_WATCHER (check, check)
288
289 #if EV_EMBED_ENABLE
290 EV_BEGIN_WATCHER (embed, embed)
291 void set (struct ev_loop *loop)
292 {
293 int active = is_active ();
294 if (active) stop ();
295 ev_embed_set (static_cast<ev_embed *>(this), loop);
296 if (active) start ();
297 }
298
299 void start (struct ev_loop *embedded_loop)
300 {
301 set (embedded_loop);
302 start ();
303 }
304
305 void sweep ()
306 {
307 ev_embed_sweep (EV_A_ static_cast<ev_embed *>(this));
308 }
309 EV_END_WATCHER (embed, embed)
310 #endif
311
263 #undef EV_CONSTRUCT 312 #undef EV_CONSTRUCT
264 #undef EV_BEGIN_WATCHER 313 #undef EV_BEGIN_WATCHER
314 #undef EV_END_WATCHER
265} 315}
266 316
267#endif 317#endif
268 318

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines