… | |
… | |
23 | |
23 | |
24 | #include <sys/poll.h> |
24 | #include <sys/poll.h> |
25 | |
25 | |
26 | #include "slog.h" |
26 | #include "slog.h" |
27 | |
27 | |
28 | typedef double timestamp; |
28 | typedef double tstamp; |
29 | |
29 | |
30 | extern timestamp NOW; |
30 | extern tstamp NOW; |
31 | |
31 | |
32 | template<class R, class A> class callback; |
32 | template<class R, class A> class callback; |
33 | struct io_watcher; |
33 | struct io_watcher; |
34 | struct time_watcher; |
34 | struct time_watcher; |
35 | |
35 | |
… | |
… | |
87 | |
87 | |
88 | R call(A arg) |
88 | R call(A arg) |
89 | { |
89 | { |
90 | return prxy->call (obj, meth, arg); |
90 | return prxy->call (obj, meth, arg); |
91 | } |
91 | } |
92 | }; |
|
|
93 | |
92 | |
94 | struct io_watcher : callback<void, short> { |
93 | void stop () |
95 | template<class O1, class O2> |
|
|
96 | io_watcher (int fd, short events, O1 *object, void (O2::*method)(short revents)) |
|
|
97 | : callback<void, short>(object,method) |
|
|
98 | { |
|
|
99 | iom.reg (fd, events, this); |
|
|
100 | } |
|
|
101 | |
|
|
102 | ~io_watcher () |
|
|
103 | { |
94 | { |
104 | iom.unreg (this); |
95 | iom.unreg (this); |
105 | } |
96 | } |
106 | }; |
97 | }; |
107 | |
98 | |
108 | struct time_watcher : callback<void, timestamp &> { |
99 | struct io_watcher : callback<void, short> { |
109 | timestamp at; |
100 | template<class O1, class O2> |
|
|
101 | io_watcher (O1 *object, void (O2::*method)(short revents)) |
|
|
102 | : callback<void, short>(object,method) |
|
|
103 | { } |
110 | |
104 | |
111 | void set (timestamp when); |
105 | void start (int fd, short events) |
|
|
106 | { |
|
|
107 | iom.reg (fd, events, this); |
|
|
108 | } |
|
|
109 | |
|
|
110 | }; |
|
|
111 | |
|
|
112 | struct time_watcher : callback<void, tstamp &> { |
|
|
113 | tstamp at; |
112 | |
114 | |
113 | template<class O1, class O2> |
115 | template<class O1, class O2> |
114 | time_watcher (timestamp when, O1 *object, void (O2::*method)(timestamp &)) |
116 | time_watcher (O1 *object, void (O2::*method)(tstamp &)) |
115 | : callback<void, timestamp &>(object,method) |
117 | : callback<void, tstamp &>(object,method) |
116 | , at(when) |
118 | { } |
|
|
119 | |
|
|
120 | void set (tstamp when); |
|
|
121 | |
|
|
122 | void trigger () |
117 | { |
123 | { |
118 | iom.reg (this); |
124 | call (at); |
119 | } |
125 | } |
120 | |
126 | |
121 | ~time_watcher () |
127 | void start (tstamp when) |
122 | { |
128 | { |
123 | iom.unreg (this); |
129 | set (when); |
124 | } |
130 | } |
125 | }; |
131 | }; |
126 | |
132 | |
127 | #endif |
133 | #endif |
128 | |
134 | |