4 #include <sigc++/sigc++.h>
14 Common interface for all I/O objects.
16 A derived class must call set_events(P_NONE) before it is destroyed to avoid
17 leaving stale pointers in an EventDispatcher.
22 /** Emitted when there is data available for reading. If all data is not
23 read, the signal is emitted again immediately. */
24 sigc::signal<void> signal_data_available;
26 /** Emitted when there is no more data to be read. */
27 sigc::signal<void> signal_end_of_file;
29 /** Emitted when there is a nonlinearity in I/O (such as a file being
30 seeked) and any data buffered by upper layers needs to be flushed. */
31 sigc::signal<void> signal_flush_required;
33 /** Emitted when the I/O object has closed. */
34 sigc::signal<void> signal_closed;
36 /** Emitted when the mask of interesting events changes. Mainly for use by
38 sigc::signal<void, PollEvent> signal_events_changed;
40 /** Emitted when the object is deleted. Mainly for use by
42 sigc::signal<void> signal_deleted;
52 Base &operator=(const Base &);
56 /** Sets blocking mode. When blocking is enabled, most operations won't
57 return until they can make progress. When blocking is disabled, these
58 operations may return immediately with a return code indicating that nothing
61 Blocking is enabled by default. */
62 virtual void set_block(bool) { }
64 /** Returns the current mode flags. */
65 Mode get_mode() const { return mode; }
68 virtual unsigned do_write(const char *, unsigned) = 0;
69 virtual unsigned do_read(char *, unsigned) = 0;
72 /** Writes data from a buffer. Subject to blocking. Returns the number of
73 bytes written, which may be zero for a non-blockin operation. */
74 unsigned write(const char *b, unsigned c) { return do_write(b, c); }
76 /** Writes a string. This is identical to calling
77 write(s.data(), s.size()). */
78 unsigned write(const std::string &s) { return do_write(s.data(), s.size()); }
80 /** Writes a single character. This is identical to calling
82 virtual unsigned put(char c) { return do_write(&c, 1); }
84 /** Reads data into a buffer. Subject to blocking. Returns the number of
85 bytes read, which may be zero for a non-blocking operation. */
86 unsigned read(char *b, unsigned c) { return do_read(b, c); }
88 /** Reads characters up to the next linefeed or end-of-file. The linefeed
89 is not included in the line. Returns true if a line was successfully read,
91 virtual bool getline(std::string &);
93 /** Reads a single character. Returns -1 if no character was available due
94 to end-of-file or non-blocking operation. */
97 /** Returns the end-of-file flag. */
98 bool eof() const { return eof_flag; }
101 void set_events(PollEvent);
104 /** Returns a mask of the currently interesting events. Used by
106 PollEvent get_events() const { return events; }
108 /** Returns a handle for polling. Should throw if the object does not have
110 virtual const Handle &get_event_handle() = 0;
112 /** Notifies the object of an event. Used by EventDispatcher. */
113 void event(PollEvent);
116 virtual void on_event(PollEvent) { }