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

Comparing libev/ev++.h (file contents):
Revision 1.2 by root, Sun Nov 11 00:05:59 2007 UTC vs.
Revision 1.7 by root, Sat Nov 24 09:48:37 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)); \
125 } \ 121 } \
126 \ 122 \
127 void operator ()(int events = EV_UNDEF) \ 123 void operator ()(int events = EV_UNDEF) \
128 { \ 124 { \
129 return call (this, events); \ 125 return call (this, events); \
126 } \
127 \
128 ~cppstem () \
129 { \
130 stop (); \
130 } \ 131 } \
131 \ 132 \
132 private: \ 133 private: \
133 \ 134 \
134 cppstem (const cppstem &o) \ 135 cppstem (const cppstem &o) \
135 : callback<cppstem> (this, (void (cppstem::*)(cppstem &, int))0) \ 136 : callback<cppstem> (this, (void (cppstem::*)(cppstem &, int))0) \
136 { /* disabled */ } \ 137 { /* disabled */ } \
138 \
137 void operator =(const cppstem &o) { /* disabled */ } \ 139 void operator =(const cppstem &o) { /* disabled */ } \
138 \ 140 \
141 static void thunk (EV_P_ struct ev_ ## cstem *w, int revents) \
142 { \
143 (*static_cast<cppstem *>(w))(revents); \
144 } \
145 \
139 public: 146 public:
140 147
148 #define EV_END_WATCHER(cppstem,cstem) \
149 };
150
141 EV_DECLARE_WATCHER (io, io) 151 EV_BEGIN_WATCHER (io, io)
142 void set (int fd, int events) 152 void set (int fd, int events)
143 { 153 {
144 int active = is_active (); 154 int active = is_active ();
145 if (active) stop (); 155 if (active) stop ();
146 ev_io_set (static_cast<ev_io *>(this), fd, events); 156 ev_io_set (static_cast<ev_io *>(this), fd, events);
158 void start (int fd, int events) 168 void start (int fd, int events)
159 { 169 {
160 set (fd, events); 170 set (fd, events);
161 start (); 171 start ();
162 } 172 }
163 }; 173 EV_END_WATCHER (io, io)
164 174
165 EV_DECLARE_WATCHER (timer, timer) 175 EV_BEGIN_WATCHER (timer, timer)
166 void set (ev_tstamp after, ev_tstamp repeat = 0.) 176 void set (ev_tstamp after, ev_tstamp repeat = 0.)
167 { 177 {
168 int active = is_active (); 178 int active = is_active ();
169 if (active) stop (); 179 if (active) stop ();
170 ev_timer_set (static_cast<ev_timer *>(this), after, repeat); 180 ev_timer_set (static_cast<ev_timer *>(this), after, repeat);
179 189
180 void again () 190 void again ()
181 { 191 {
182 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 192 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
183 } 193 }
184 }; 194 EV_END_WATCHER (timer, timer)
185 195
196 #if EV_PERIODICS
186 EV_DECLARE_WATCHER (periodic, periodic) 197 EV_BEGIN_WATCHER (periodic, periodic)
187 void set (ev_tstamp at, ev_tstamp interval = 0.) 198 void set (ev_tstamp at, ev_tstamp interval = 0.)
188 { 199 {
189 int active = is_active (); 200 int active = is_active ();
190 if (active) stop (); 201 if (active) stop ();
191 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); 202 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0);
200 211
201 void again () 212 void again ()
202 { 213 {
203 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 214 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
204 } 215 }
205 }; 216 EV_END_WATCHER (periodic, periodic)
217 #endif
206 218
219 EV_BEGIN_WATCHER (idle, idle)
220 void set () { }
207 EV_DECLARE_WATCHER (idle, idle) 221 EV_END_WATCHER (idle, idle)
208 };
209 222
223 EV_BEGIN_WATCHER (prepare, prepare)
224 void set () { }
210 EV_DECLARE_WATCHER (prepare, prepare) 225 EV_END_WATCHER (prepare, prepare)
211 };
212 226
227 EV_BEGIN_WATCHER (check, check)
228 void set () { }
213 EV_DECLARE_WATCHER (check, check) 229 EV_END_WATCHER (check, check)
214 };
215 230
216 EV_DECLARE_WATCHER (sig, signal) 231 EV_BEGIN_WATCHER (sig, signal)
217 void set (int signum) 232 void set (int signum)
218 { 233 {
219 int active = is_active (); 234 int active = is_active ();
220 if (active) stop (); 235 if (active) stop ();
221 ev_signal_set (static_cast<ev_signal *>(this), signum); 236 ev_signal_set (static_cast<ev_signal *>(this), signum);
225 void start (int signum) 240 void start (int signum)
226 { 241 {
227 set (signum); 242 set (signum);
228 start (); 243 start ();
229 } 244 }
230 }; 245 EV_END_WATCHER (sig, signal)
231 246
232 EV_DECLARE_WATCHER (child, child) 247 EV_BEGIN_WATCHER (child, child)
233 void set (int pid) 248 void set (int pid)
234 { 249 {
235 int active = is_active (); 250 int active = is_active ();
236 if (active) stop (); 251 if (active) stop ();
237 ev_child_set (static_cast<ev_child *>(this), pid); 252 ev_child_set (static_cast<ev_child *>(this), pid);
241 void start (int pid) 256 void start (int pid)
242 { 257 {
243 set (pid); 258 set (pid);
244 start (); 259 start ();
245 } 260 }
246 }; 261 EV_END_WATCHER (child, child)
262
263 #if EV_MULTIPLICITY
264
265 EV_BEGIN_WATCHER (embed, embed)
266 void set (struct ev_loop *loop)
267 {
268 int active = is_active ();
269 if (active) stop ();
270 ev_embed_set (static_cast<ev_embed *>(this), loop);
271 if (active) start ();
272 }
273
274 void start (struct ev_loop *embedded_loop)
275 {
276 set (embedded_loop);
277 start ();
278 }
279
280 void sweep ()
281 {
282 ev_embed_sweep (EV_A_ static_cast<ev_embed *>(this));
283 }
284 EV_END_WATCHER (embed, embed)
285
286 #endif
247 287
248 #undef EV_CONSTRUCT 288 #undef EV_CONSTRUCT
289 #undef EV_BEGIN_WATCHER
249 #undef EV_DECLARE_WATCHER 290 #undef EV_END_WATCHER
250} 291}
251 292
252#endif 293#endif
253 294

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines