endpoint.h

00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
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

Generated on Sun Aug 6 12:16:57 2006 by  doxygen 1.4.6