connection.hxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Gerd v. Egidy                                   *
00003  *   gve@intra2net.com                                                     *
00004  *                                                                         *
00005  *   This library is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License version   *
00007  *   2.1 as published by the Free Software Foundation.                     *
00008  *                                                                         *
00009  *   This library 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 Lesser 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 program; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00018  ***************************************************************************/
00019 #ifndef __LIBT2N_CONNECTION
00020 #define __LIBT2N_CONNECTION
00021 
00022 #include <string>
00023 #include <vector>
00024 #include <list>
00025 #include <iostream>
00026 
00027 #include <boost/function.hpp>
00028 
00029 #include <netinet/in.h>
00030 
00031 #include "types.hxx"
00032 
00033 namespace libt2n
00034 {
00035 
00038 class connection
00039 {
00040     private:
00041         bool closed;
00042 
00044         std::vector<std::list<boost::function<void ()> > > callbacks;
00045 
00046     protected:
00047         connection()
00048             : callbacks(__events_end), closed(false)
00049             { }
00050 
00051         std::string buffer;
00052 
00053         typedef uint32_t packet_size_indicator;
00054 
00055         packet_size_indicator bytes_available();
00056 
00057         virtual void real_write(const std::string& data)=0;
00058 
00059         virtual std::ostream* get_logstream(log_level_values level)=0;
00060 
00061         void do_callbacks(callback_event_type event);
00062 
00063         void reopen(void);
00064         void remove_incomplete_packets();
00065 
00066     public:
00067         virtual ~connection();
00068 
00070         bool is_closed()
00071             { return closed; }
00072 
00074         virtual void close();
00075 
00085         virtual bool fill_buffer(long long usec_timeout=-1,long long* usec_timeout_remaining=NULL)=0;
00086 
00087         bool get_packet(std::string& data);
00088 
00089         unsigned int peek_packet(std::string& data);
00090 
00092         bool packet_available()
00093             { return bytes_available(); }
00094 
00095         void write(const std::string& data);
00096 
00097         void add_callback(callback_event_type event, const boost::function<void ()>& func);
00098 
00099         std::list<boost::function<void ()> > get_callback_list(callback_event_type event);
00100 };
00101 
00102 }
00103 
00104 #endif

Generated on Fri Sep 26 15:36:59 2008 for libt2n by  doxygen 1.5.6