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

Comparing libev/ev++.h (file contents):
Revision 1.5 by root, Wed Nov 14 04:45:07 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,
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_BEGIN_WATCHER(cppstem,cstem) \ 94 #define EV_BEGIN_WATCHER(cppstem,cstem) \
97 \ 95 \
98 static void cb_ ## cppstem (EV_P_ struct ev_ ## cstem *w, int revents); \
99 \
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
146 #define EV_END_WATCHER(cppstem,cstem) \ 148 #define EV_END_WATCHER(cppstem,cstem) \
147 }; \
148 \
149 static void cb_ ## cppstem (EV_P_ struct ev_ ## cstem *w, int revents) \
150 { \
151 (*static_cast<cppstem *>(w))(revents); \
152 } 149 };
153 150
154 EV_BEGIN_WATCHER (io, io) 151 EV_BEGIN_WATCHER (io, io)
155 void set (int fd, int events) 152 void set (int fd, int events)
156 { 153 {
157 int active = is_active (); 154 int active = is_active ();
194 { 191 {
195 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 192 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
196 } 193 }
197 EV_END_WATCHER (timer, timer) 194 EV_END_WATCHER (timer, timer)
198 195
199 #if EV_PERIODICS 196 #if EV_PERIODIC_ENABLE
200 EV_BEGIN_WATCHER (periodic, periodic) 197 EV_BEGIN_WATCHER (periodic, periodic)
201 void set (ev_tstamp at, ev_tstamp interval = 0.) 198 void set (ev_tstamp at, ev_tstamp interval = 0.)
202 { 199 {
203 int active = is_active (); 200 int active = is_active ();
204 if (active) stop (); 201 if (active) stop ();
217 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 214 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
218 } 215 }
219 EV_END_WATCHER (periodic, periodic) 216 EV_END_WATCHER (periodic, periodic)
220 #endif 217 #endif
221 218
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) 219 EV_BEGIN_WATCHER (sig, signal)
232 void set (int signum) 220 void set (int signum)
233 { 221 {
234 int active = is_active (); 222 int active = is_active ();
235 if (active) stop (); 223 if (active) stop ();
258 set (pid); 246 set (pid);
259 start (); 247 start ();
260 } 248 }
261 EV_END_WATCHER (child, child) 249 EV_END_WATCHER (child, child)
262 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
308
263 #undef EV_CONSTRUCT 309 #undef EV_CONSTRUCT
264 #undef EV_BEGIN_WATCHER 310 #undef EV_BEGIN_WATCHER
311 #undef EV_END_WATCHER
265} 312}
266 313
267#endif 314#endif
268 315

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines