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.4 by root, Sun Nov 11 16:58:25 2007 UTC

91 91
92 #endif 92 #endif
93 93
94 /* using a template here would require quite a bit more lines, 94 /* using a template here would require quite a bit more lines,
95 * so a macro solution was chosen */ 95 * so a macro solution was chosen */
96 #define EV_DECLARE_WATCHER(cppstem,cstem) \ 96 #define EV_BEGIN_WATCHER(cppstem,cstem) \
97 \ 97 \
98 extern "C" void cb_ ## cppstem (struct ev_ ## cstem *w, int revents); \ 98 static void cb_ ## cppstem (struct ev_ ## cstem *w, int revents); \
99 \ 99 \
100 struct cppstem : ev_ ## cstem, callback<cppstem> \ 100 struct cppstem : ev_ ## cstem, callback<cppstem> \
101 { \ 101 { \
102 EV_CONSTRUCT (cppstem) \ 102 EV_CONSTRUCT (cppstem) \
103 { \ 103 { \
125 } \ 125 } \
126 \ 126 \
127 void operator ()(int events = EV_UNDEF) \ 127 void operator ()(int events = EV_UNDEF) \
128 { \ 128 { \
129 return call (this, events); \ 129 return call (this, events); \
130 } \
131 \
132 ~cppstem () \
133 { \
134 stop (); \
130 } \ 135 } \
131 \ 136 \
132 private: \ 137 private: \
133 \ 138 \
134 cppstem (const cppstem &o) \ 139 cppstem (const cppstem &o) \
136 { /* disabled */ } \ 141 { /* disabled */ } \
137 void operator =(const cppstem &o) { /* disabled */ } \ 142 void operator =(const cppstem &o) { /* disabled */ } \
138 \ 143 \
139 public: 144 public:
140 145
146 #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 }
153
141 EV_DECLARE_WATCHER (io, io) 154 EV_BEGIN_WATCHER (io, io)
142 void set (int fd, int events) 155 void set (int fd, int events)
143 { 156 {
144 int active = is_active (); 157 int active = is_active ();
145 if (active) stop (); 158 if (active) stop ();
146 ev_io_set (static_cast<ev_io *>(this), fd, events); 159 ev_io_set (static_cast<ev_io *>(this), fd, events);
158 void start (int fd, int events) 171 void start (int fd, int events)
159 { 172 {
160 set (fd, events); 173 set (fd, events);
161 start (); 174 start ();
162 } 175 }
163 }; 176 EV_END_WATCHER (io, io)
164 177
165 EV_DECLARE_WATCHER (timer, timer) 178 EV_BEGIN_WATCHER (timer, timer)
166 void set (ev_tstamp after, ev_tstamp repeat = 0.) 179 void set (ev_tstamp after, ev_tstamp repeat = 0.)
167 { 180 {
168 int active = is_active (); 181 int active = is_active ();
169 if (active) stop (); 182 if (active) stop ();
170 ev_timer_set (static_cast<ev_timer *>(this), after, repeat); 183 ev_timer_set (static_cast<ev_timer *>(this), after, repeat);
179 192
180 void again () 193 void again ()
181 { 194 {
182 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 195 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
183 } 196 }
184 }; 197 EV_END_WATCHER (timer, timer)
185 198
199 #if EV_PERIODICS
186 EV_DECLARE_WATCHER (periodic, periodic) 200 EV_BEGIN_WATCHER (periodic, periodic)
187 void set (ev_tstamp at, ev_tstamp interval = 0.) 201 void set (ev_tstamp at, ev_tstamp interval = 0.)
188 { 202 {
189 int active = is_active (); 203 int active = is_active ();
190 if (active) stop (); 204 if (active) stop ();
191 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); 205 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0);
200 214
201 void again () 215 void again ()
202 { 216 {
203 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 217 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
204 } 218 }
205 }; 219 EV_END_WATCHER (periodic, periodic)
220 #endif
206 221
222 EV_BEGIN_WATCHER (idle, idle)
207 EV_DECLARE_WATCHER (idle, idle) 223 EV_END_WATCHER (idle, idle)
208 };
209 224
225 EV_BEGIN_WATCHER (prepare, prepare)
210 EV_DECLARE_WATCHER (prepare, prepare) 226 EV_END_WATCHER (prepare, prepare)
211 };
212 227
228 EV_BEGIN_WATCHER (check, check)
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)
247 262
248 #undef EV_CONSTRUCT 263 #undef EV_CONSTRUCT
249 #undef EV_DECLARE_WATCHER 264 #undef EV_BEGIN_WATCHER
250} 265}
251 266
252#endif 267#endif
253 268

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines