ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/iom.h
(Generate patch)

Comparing rxvt-unicode/src/iom.h (file contents):
Revision 1.30 by root, Thu Oct 25 10:44:14 2007 UTC vs.
Revision 1.31 by root, Thu Oct 25 12:42:00 2007 UTC

45#ifdef IOM_LIBEVENT 45#ifdef IOM_LIBEVENT
46# include <sys/time.h> 46# include <sys/time.h>
47# include IOM_LIBEVENT 47# include IOM_LIBEVENT
48# undef IOM_IO 48# undef IOM_IO
49# define IOM_IO 1 49# define IOM_IO 1
50# undef IOM_TIME
51# define IOM_TIME 1
52# undef IOM_IDLE // NYI
53# undef IOM_SIG // NYI
54# undef IOM_CHILD // NYI
50#endif 55#endif
51 56
52struct watcher; 57struct watcher;
53#if IOM_IO 58#if IOM_IO
54struct io_watcher; 59struct io_watcher;
139void iom_io_c_callback (int fd, short events, void *data); 144void iom_io_c_callback (int fd, short events, void *data);
140 145
141struct io_watcher : watcher, callback<void (io_watcher &, short)> { 146struct io_watcher : watcher, callback<void (io_watcher &, short)> {
142 struct event ev; 147 struct event ev;
143 int fd; 148 int fd;
149 short events;
144 150
145 void set (int fd_, short events_) { fd = fd_; event_set (&ev, fd_, events_, iom_io_c_callback, (void *)this); } 151 void set (int fd_, short events_);
146
147 void set (short events_) { set (fd, events_); } 152 void set (short events_) { set (fd, events_); }
148 void start () { event_add (&ev, 0); active = 1; } 153 void start () { if (!active) event_add (&ev, 0); active = 1; }
149 void start (int fd_, short events_) { set (fd_, events_); start (); } 154 void start (int fd_, short events_) { set (fd_, events_); start (); }
150 void stop () { if (active) event_del (&ev); active = 0; } 155 void stop () { if (active) event_del (&ev); active = 0; }
151 156
152 template<class O, class M> 157 template<class O, class M>
153 io_watcher (O object, M method) 158 io_watcher (O object, M method)
186 struct event ev; 191 struct event ev;
187 tstamp at; 192 tstamp at;
188 193
189 void trigger (); 194 void trigger ();
190 195
191 void set (tstamp when) { at = when; } 196 void set (tstamp when)
197 {
198 at = when;
199 if (active)
200 start ();
201 }
192 void operator () () { trigger (); } 202 void operator () () { trigger (); }
193 void start () 203 void start ();
194 {
195 struct timeval tv;
196 tv.tv_sec = (long)at;
197 tv.tv_usec = (long)((at - (tstamp)tv.tv_sec) * 1000000.);
198 evtimer_add (&ev, &tv);
199 active = 1;
200 }
201 void start (tstamp when) { set (when); start (); } 204 void start (tstamp when) { at = when; start (); }
202 void stop () { if (active) evtimer_del (&ev); active = 0; } 205 void stop () { if (active) evtimer_del (&ev); active = 0; }
203 206
204 template<class O, class M> 207 template<class O, class M>
205 time_watcher (O object, M method) 208 time_watcher (O object, M method)
206 : callback<void (time_watcher &)> (object, method), at (0) 209 : callback<void (time_watcher &)> (object, method), at (0)
207 { 210 { }
208 evtimer_set (&ev, iom_time_c_callback, (void *)this);
209 }
210 ~time_watcher () { stop (); } 211 ~time_watcher () { stop (); }
211}; 212};
212#else 213#else
213struct time_watcher : watcher, callback<void (time_watcher &)> { 214struct time_watcher : watcher, callback<void (time_watcher &)> {
214 tstamp at; 215 tstamp at;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines