4 #include <sigc++/sigc++.h>
13 Common interface for all I/O objects.
15 A derived class must call set_events(P_NONE) before it is destroyed to avoid
16 leaving stale pointers in an EventDispatcher.
21 /** Emitted when there is data available for reading. If all data is not
22 read, the signal is emitted again immediately. */
23 sigc::signal<void> signal_data_available;
25 /** Emitted when there is no more data to be read. */
26 sigc::signal<void> signal_end_of_file;
28 /** Emitted when there is a nonlinearity in I/O (such as a file being
29 seeked) and any data buffered by upper layers needs to be flushed. */
30 sigc::signal<void> signal_flush_required;
32 /** Emitted when the I/O object has closed. */
33 sigc::signal<void> signal_closed;
35 /** Emitted when the mask of interesting events changes. Mainly for use by
37 sigc::signal<void, PollEvent> signal_events_changed;
39 /** Emitted when the object is deleted. Mainly for use by
41 sigc::signal<void> signal_deleted;
51 Base &operator=(const Base &);
55 /** Sets blocking mode. When blocking is enabled, most operations won't
56 return until they can make progress. When blocking is disabled, these
57 operations may return immediately with a return code indicating that nothing
60 Blocking is enabled by default. */
61 virtual void set_block(bool) { }
63 /** Returns the current mode flags. */
64 Mode get_mode() const { return mode; }
67 virtual unsigned do_write(const char *, unsigned) =0;
68 virtual unsigned do_read(char *, unsigned) =0;
71 /** Writes data from a buffer. Subject to blocking. Returns the number of
72 bytes written, which may be zero for a non-blockin operation. */
73 unsigned write(const char *b, unsigned c) { return do_write(b, c); }
75 /** Writes a string. This is identical to calling
76 write(s.data(), s.size()). */
77 unsigned write(const std::string &s) { return do_write(s.data(), s.size()); }
79 /** Writes a single character. This is identical to calling
81 virtual unsigned put(char c) { return do_write(&c, 1); }
83 /** Reads data into a buffer. Subject to blocking. Returns the number of
84 bytes read, which may be zero for a non-blocking operation. */
85 unsigned read(char *b, unsigned c) { return do_read(b, c); }
87 /** Reads characters up to the next linefeed or end-of-file. The linefeed
88 is not included in the line. Returns true if a line was successfully read,
90 virtual bool getline(std::string &);
92 /** Reads a single character. Returns -1 if no character was available due
93 to end-of-file or non-blocking operation. */
96 /** Returns the end-of-file flag. */
97 bool eof() const { return eof_flag; }
100 void set_events(PollEvent);
103 /** Returns a mask of the currently interesting events. Used by
105 PollEvent get_events() const { return events; }
107 /** Returns a handle for polling. Should throw if the object does not have
109 virtual Handle get_event_handle() =0;
111 /** Notifies the object of an event. Used by EventDispatcher. */
112 void event(PollEvent);
115 virtual void on_event(PollEvent) { }