TOBI Interface A  0.1
/home/breidi/Dropbox/libtia/include/tia-private/newtia/network_impl/boost_tcp_socket_impl.h
00001 /*
00002     This file is part of the TOBI Interface A (TiA) library.
00003 
00004     Commercial Usage
00005     Licensees holding valid Graz University of Technology Commercial
00006     licenses may use this file in accordance with the Graz University
00007     of Technology Commercial License Agreement provided with the
00008     Software or, alternatively, in accordance with the terms contained in
00009     a written agreement between you and Graz University of Technology.
00010 
00011     --------------------------------------------------
00012 
00013     GNU Lesser General Public License Usage
00014     Alternatively, this file may be used under the terms of the GNU Lesser
00015     General Public License version 3.0 as published by the Free Software
00016     Foundation and appearing in the file lgpl.txt included in the
00017     packaging of this file.  Please review the following information to
00018     ensure the GNU General Public License version 3.0 requirements will be
00019     met: http://www.gnu.org/copyleft/lgpl.html.
00020 
00021     In case of GNU Lesser General Public License Usage ,the TiA library
00022     is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025     GNU General Public License for more details.
00026 
00027     You should have received a copy of the GNU Lesser General Public License
00028     along with the TiA library. If not, see <http://www.gnu.org/licenses/>.
00029 
00030     Copyright 2010 Graz University of Technology
00031     Contact: TiA@tobi-project.org
00032 */
00033 
00034 #ifndef BOOST_TCP_SOCKET_IMPL_H
00035 #define BOOST_TCP_SOCKET_IMPL_H
00036 
00037 #include "tia-private/newtia/network/socket.h"
00038 
00039 #include <boost/asio.hpp>
00040 
00041 //namespace tobiss
00042 //{
00043 //class TCPConnection;
00044 //}
00045 
00046 namespace tia
00047 {
00048 
00049 //-----------------------------------------------------------------------------
00050 class BoostTCPSocketImpl : public Socket
00051 {
00052   public:
00053     BoostTCPSocketImpl (boost::asio::io_service& io_service,
00054                         boost::asio::ip::tcp::endpoint const& endpoint, unsigned buffer_size);
00055 
00056     BoostTCPSocketImpl (boost::shared_ptr<boost::asio::ip::tcp::socket> boost_socket);
00057 
00058     virtual ~BoostTCPSocketImpl ();
00059 
00060     virtual void setReceiveBufferSize (unsigned size);
00061     virtual std::string readUntil (char delimiter);
00062     virtual std::string readUntil (std::string delimiter);
00063     virtual std::string readString (unsigned length);
00064     virtual char readCharacter ();
00065     virtual void waitForData ();
00066     virtual void sendString (std::string const& str) throw (TiALostConnection);
00067 
00068     virtual size_t readBytes (char* data, size_t bytes_to_read);
00069     virtual size_t getAvailableData (char* data, size_t max_size);
00070 
00071 
00072     virtual std::string getRemoteEndPointAsString();
00073     virtual std::string getLocalEndPointAsString();
00074 
00075 
00076   private:
00077     boost::shared_ptr<boost::asio::ip::tcp::socket>    socket_;
00078     boost::asio::streambuf                             stream_buffer_;
00079     std::istream                                       input_stream_;
00080     std::string                                        str_buffer_;
00081     boost::system::error_code                          error_;
00082 
00083     std::string remote_endpoint_str_;
00084     std::string local_endpoint_str_;
00085 };
00086 
00087 }
00088 
00089 #endif // BOOST_TCP_SOCKET_IMPL_H
 All Data Structures Files Functions Variables Typedefs Enumerations