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/enums.h>
00025 #include <conexus/error.h>
00026 #include <conexus/dataserver.h>
00027
00222 namespace Conexus
00223 {
00224
00242 class Endpoint: public DataServer
00243 {
00246 public:
00247
00249 typedef boost::shared_ptr<Endpoint> pointer;
00250
00254 typedef enum EndpointState {
00255 NOSTATE=0x00,
00256 CLOSED=1<<0,
00257 OPENED=1<<1,
00258 LASTENDPOINTSTATE=OPENED,
00259 UNCHANGED=~0x00,
00260 } EndpointState;
00261
00269 Endpoint(bool close_on_destruction=true);
00270
00275 virtual ~Endpoint();
00276
00280 virtual void open() throw (open_error) = 0;
00281
00284 virtual void close(bool force=false) throw (close_error) = 0;
00285
00296 virtual ssize_t write(const void* data, size_t size, IOMethod block=BLOCK) throw (write_error) = 0;
00297
00302 virtual ssize_t write(const Data& data, IOMethod block=BLOCK);
00303
00323 virtual Data read(size_t s = 0) throw (read_error) = 0;
00324
00339 virtual void change_state(long new_state) throw (state_error);
00340
00345 long state();
00346
00348 void set_close_on_destruction(bool value);
00349
00351 bool close_on_destruction() const;
00352
00361 void close_and_reopen(long state=UNCHANGED);
00362
00364 sigc::signal<void> signal_opened();
00365
00367 sigc::signal<void> signal_closed();
00368
00370 sigc::signal<void, bool, bool> signal_read_write_stop_changed();
00371
00373 bool is_open();
00374
00376 bool is_closed();
00377
00379 bool is_read_stopped();
00380
00382 bool is_write_stopped();
00383
00390 virtual void stop_read(bool read_stop=true);
00391
00398 virtual void stop_write(bool write_stop=true);
00399
00404 virtual void stop_read_write(bool read_stop=true, bool write_stop=true);
00405
00407 virtual const std::string& object_type() { static std::string s("Conexus::Endpoint"); return s; }
00408
00409 protected:
00410 bool m_close_on_destruction;
00411 long m_state;
00412 bool m_readable;
00413 bool m_writable;
00414 bool m_read_stopped;
00415 bool m_write_stopped;
00416
00417 virtual void set_state_opened();
00418 virtual void set_state_closed();
00419
00420 sigc::signal<void> m_signal_opened;
00421 sigc::signal<void> m_signal_closed;
00422 sigc::signal<void, bool, bool> m_signal_read_write_stop_changed;
00423 };
00424
00425 }
00426
00427 Conexus::Endpoint& operator<<(Conexus::Endpoint& io, const Conexus::Data& d);
00428 Conexus::Endpoint& operator>>(Conexus::Endpoint& io, Conexus::Data& d);
00429
00430 #endif