00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONEXUSIO_H
00020 #define CONEXUSIO_H
00021
00022 #include <boost/shared_ptr.hpp>
00023
00024 #include <conexus/error.h>
00025 #include <conexus/dataserver.h>
00026
00216 namespace Conexus
00217 {
00218
00219
00220 typedef enum IOMETHOD {
00221 BLOCK,
00222 NONBLOCK
00223 };
00224
00242 class Endpoint: public DataServer
00243 {
00244 public:
00245 typedef boost::shared_ptr<Endpoint> pointer;
00246
00250 typedef enum EndpointState {
00251 NOSTATE=0x00,
00252 CLOSED=1<<0,
00253 OPENED=1<<1,
00254 LASTENDPOINTSTATE=OPENED,
00255 UNCHANGED=~0x00,
00256 } EndpointState;
00257
00265 Endpoint(bool close_on_destruction=true);
00266
00271 virtual ~Endpoint();
00272
00276 virtual void open() throw (open_error) = 0;
00277
00280 virtual void close(bool force=false) throw (close_error) = 0;
00281
00291 virtual ssize_t write(const void* data, size_t size, IOMETHOD block=BLOCK) throw (write_error) = 0;
00292
00297 virtual ssize_t write(Data data, IOMETHOD block=BLOCK);
00298
00303 virtual ssize_t write(CData data, IOMETHOD block=BLOCK);
00304
00324 virtual Data read(size_t s = 0) throw (read_error) = 0;
00325
00340 virtual void change_state(unsigned long new_state) throw (state_error);
00341
00342 void set_close_on_destruction(bool value);
00343
00344 bool close_on_destruction() const;
00345
00354 void close_and_reopen(unsigned long state=UNCHANGED);
00355
00356 sigc::signal<void> signal_opened();
00357 sigc::signal<void> signal_closed();
00358 sigc::signal<void, bool, bool> signal_read_write_block_changed();
00359
00360 bool is_open();
00361 bool is_closed();
00362
00363 bool is_read_blocked();
00364 bool is_write_blocked();
00365 virtual void block_read(bool read_block=true);
00366 virtual void block_write(bool write_block=true);
00367 virtual void block_read_write(bool read_block=true, bool write_block=true);
00368
00369 unsigned long state();
00370
00371 virtual const std::string& object_type() { static std::string s("Conexus::Endpoint"); return s; }
00372
00373 protected:
00374 bool m_close_on_destruction;
00375 long unsigned m_state;
00376 bool m_readable;
00377 bool m_writable;
00378 bool m_read_blocked;
00379 bool m_write_blocked;
00380
00381 virtual void set_state_opened();
00382 virtual void set_state_closed();
00383
00384 sigc::signal<void> m_signal_opened;
00385 sigc::signal<void> m_signal_closed;
00386 sigc::signal<void, bool, bool> m_signal_read_write_block_changed;
00387 };
00388
00389 }
00390
00391 Conexus::Endpoint& operator<<(Conexus::Endpoint& io, Conexus::Data d);
00392 Conexus::Endpoint& operator<<(Conexus::Endpoint& io, Conexus::CData d);
00393 Conexus::Endpoint& operator>>(Conexus::Endpoint& io, Conexus::Data d);
00394
00395 #endif