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.1 by pcg, Mon Nov 24 17:28:08 2003 UTC vs.
Revision 1.5 by pcg, Fri Dec 19 06:17:03 2003 UTC

23#include <cassert> 23#include <cassert>
24 24
25#include "rxvtvec.h" 25#include "rxvtvec.h"
26#include "callback.h" 26#include "callback.h"
27 27
28typedef double tstamp; 28#define IOM_IO 1
29#define IOM_TIME 1
30#define IOM_CHECK 1
31#define IOM_IDLE 0
29 32
33#if IOM_IO
34 typedef double tstamp;
30extern tstamp NOW; 35 extern tstamp NOW;
31 36
32struct io_watcher; 37 struct io_watcher;
38#endif
39#if IOM_TIME
33struct time_watcher; 40 struct time_watcher;
41#endif
42#if IOM_CHECK
43 struct check_watcher;
44#endif
45#if IOM_IDLE
46 struct idle_watcher;
47#endif
34 48
35class io_manager { 49class io_manager {
50#if IOM_IO
36 simplevec<io_watcher *> iow; 51 simplevec<io_watcher *> iow;
52#endif
53#if IOM_CHECK
54 simplevec<check_watcher *> cw;
55#endif
56#if IOM_TIME
37 simplevec<time_watcher *> tw; // actually a heap 57 simplevec<time_watcher *> tw;
58#endif
59#if IOM_IDLE
60 simplevec<idle_watcher *> iw;
61#endif
38 62
39 void idle_cb (time_watcher &w); time_watcher *idle; 63 template<class watcher>
64 void reg (watcher *w, simplevec<watcher *> &queue);
65
66 template<class watcher>
67 void unreg (watcher *w, simplevec<watcher *> &queue);
68
40public: 69public:
41 // register a watcher 70 // register a watcher
42 void reg (io_watcher *w); 71#if IOM_IO
43 void unreg (io_watcher *w); 72 void reg (io_watcher *w); void unreg (io_watcher *w);
44 void reg (time_watcher *w); 73#endif
45 void unreg (time_watcher *w); 74#if IOM_TIME
75 void reg (time_watcher *w); void unreg (time_watcher *w);
76#endif
77#if IOM_CHECK
78 void reg (check_watcher *w); void unreg (check_watcher *w);
79#endif
80#if IOM_IDLE
81 void reg (idle_watcher *w); void unreg (idle_watcher *w);
82#endif
46 83
47 void loop (); 84 void loop ();
48 85
49 io_manager (); 86 io_manager ();
50 ~io_manager (); 87 ~io_manager ();
51}; 88};
52 89
53extern io_manager iom; // a singleton, together with it's construction/destruction problems. 90extern io_manager iom; // a singleton, together with it's construction/destruction problems.
54 91
92#if IOM_IO
55enum { EVENT_READ = 1, EVENT_WRITE = 2 }; 93enum { EVENT_READ = 1, EVENT_WRITE = 2 };
56 94
57struct io_watcher : callback2<void, io_watcher &, short> { 95struct io_watcher : callback2<void, io_watcher &, short> {
58 int fd; 96 int fd;
59 short events; 97 short events;
63 : callback2<void, io_watcher &, short>(object,method) 101 : callback2<void, io_watcher &, short>(object,method)
64 { } 102 { }
65 103
66 ~io_watcher (); 104 ~io_watcher ();
67 105
68 void set(int fd_, short events_) { fd = fd_; events = events_; } 106 void set (int fd_, short events_) { fd = fd_; events = events_; }
69 107
70 void set(short events_) { set (fd, events_); } 108 void set (short events_) { set (fd, events_); }
109 void start () { iom.reg (this); }
71 void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); } 110 void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); }
72 void stop () { iom.unreg (this); } 111 void stop () { iom.unreg (this); }
73}; 112};
113#endif
74 114
75#define TSTAMP_CANCEL -1. 115#if IOM_TIME
116enum { TSTAMP_CANCEL = -1 };
76 117
77struct time_watcher : callback1<void, time_watcher &> { 118struct time_watcher : callback1<void, time_watcher &> {
78 tstamp at; 119 tstamp at;
79 120
80 template<class O1, class O2> 121 template<class O1, class O2>
96 { 137 {
97 stop (); 138 stop ();
98 at = when; 139 at = when;
99 } 140 }
100}; 141};
142#endif
143
144#if IOM_CHECK
145// run before checking for new events
146struct check_watcher : callback1<void, check_watcher &> {
147 template<class O1, class O2>
148 check_watcher (O1 *object, void (O2::*method)(check_watcher &))
149 : callback1<void, check_watcher &>(object,method)
150 { }
151
152 ~check_watcher ();
153
154 void start () { iom.reg (this); }
155 void stop () { iom.unreg (this); }
156};
157#endif
158
159#if IOM_IDLE
160// run after checking for any i/o, but before waiting
161struct idle_watcher : callback1<void, idle_watcher &> {
162 template<class O1, class O2>
163 idle_watcher (O1 *object, void (O2::*method)(idle_watcher &))
164 : callback1<void, idle_watcher &>(object,method)
165 { }
166
167 ~idle_watcher ();
168
169 void start () { iom.reg (this); }
170 void stop () { iom.unreg (this); }
171};
172#endif
101 173
102#endif 174#endif
103 175

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines