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.3 by pcg, Sat Nov 29 18:42:07 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#undef IOM_CHECK
29 31
32#if IOM_IO
33 typedef double tstamp;
30extern tstamp NOW; 34 extern tstamp NOW;
31 35
32struct io_watcher; 36 struct io_watcher;
37#endif
38#if IOM_TIME
33struct time_watcher; 39 struct time_watcher;
40#endif
41#if IOM_CHECK
42 struct check_watcher;
43#endif
34 44
35class io_manager { 45class io_manager {
46#if IOM_IO
36 simplevec<io_watcher *> iow; 47 simplevec<io_watcher *> iow;
48#endif
49#if IOM_CHECK
50 simplevec<check_watcher *> cw;
51#endif
52#if IOM_TIME
37 simplevec<time_watcher *> tw; // actually a heap 53 simplevec<time_watcher *> tw;
54#endif
38 55
39 void idle_cb (time_watcher &w); time_watcher *idle; 56 template<class watcher>
57 void reg (watcher *w, simplevec<watcher *> &queue);
58
59 template<class watcher>
60 void unreg (watcher *w, simplevec<watcher *> &queue);
61
40public: 62public:
41 // register a watcher 63 // register a watcher
42 void reg (io_watcher *w); 64#if IOM_IO
43 void unreg (io_watcher *w); 65 void reg (io_watcher *w); void unreg (io_watcher *w);
44 void reg (time_watcher *w); 66#endif
45 void unreg (time_watcher *w); 67#if IOM_TIME
68 void reg (time_watcher *w); void unreg (time_watcher *w);
69#endif
70#if IOM_CHECK
71 void reg (check_watcher *w); void unreg (check_watcher *w);
72#endif
46 73
47 void loop (); 74 void loop ();
48 75
49 io_manager (); 76 io_manager ();
50 ~io_manager (); 77 ~io_manager ();
51}; 78};
52 79
53extern io_manager iom; // a singleton, together with it's construction/destruction problems. 80extern io_manager iom; // a singleton, together with it's construction/destruction problems.
54 81
82#if IOM_IO
55enum { EVENT_READ = 1, EVENT_WRITE = 2 }; 83enum { EVENT_READ = 1, EVENT_WRITE = 2 };
56 84
57struct io_watcher : callback2<void, io_watcher &, short> { 85struct io_watcher : callback2<void, io_watcher &, short> {
58 int fd; 86 int fd;
59 short events; 87 short events;
69 97
70 void set(short events_) { set (fd, events_); } 98 void set(short events_) { set (fd, events_); }
71 void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); } 99 void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); }
72 void stop () { iom.unreg (this); } 100 void stop () { iom.unreg (this); }
73}; 101};
102#endif
74 103
75#define TSTAMP_CANCEL -1. 104#if IOM_TIME
105enum { TSTAMP_CANCEL = -1 };
76 106
77struct time_watcher : callback1<void, time_watcher &> { 107struct time_watcher : callback1<void, time_watcher &> {
78 tstamp at; 108 tstamp at;
79 109
80 template<class O1, class O2> 110 template<class O1, class O2>
96 { 126 {
97 stop (); 127 stop ();
98 at = when; 128 at = when;
99 } 129 }
100}; 130};
131#endif
132
133#if IOM_CHECK
134// run before checking for new events
135struct check_watcher : callback1<void, check_watcher &> {
136 template<class O1, class O2>
137 check_watcher (O1 *object, void (O2::*method)(check_watcher &))
138 : callback1<void, check_watcher &>(object,method)
139 { }
140
141 ~check_watcher ();
142
143 void start () { iom.reg (this); }
144 void stop () { iom.unreg (this); }
145};
146#endif
101 147
102#endif 148#endif
103 149

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines