TOBI Interface A  0.1
/home/breidi/Dropbox/libtia/include/tia-private/network/control_connection.h
Go to the documentation of this file.
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 
00039 #ifndef CONTROLCONNECTION_H
00040 #define CONTROLCONNECTION_H
00041 
00042 // Standard
00043 #include <assert.h>
00044 #include <iostream>
00045 
00046 // Boost
00047 #include <boost/thread/condition.hpp>
00048 #include <boost/cstdint.hpp>
00049 
00050 // local
00051 #include "tia-private/config/control_messages.h"
00052 #include "tia/constants.h"
00053 #include "tcp_server.h"
00054 
00055 namespace tia
00056 {
00057 // forward declarations
00058 class ControlMsgEncoder;
00059 class ControlMsgDecoder;
00060 class ControlConnectionServer;
00061 class TiAServer;
00062 class TCPDataServer;
00063 class UDPDataServer;
00064 
00065 //-----------------------------------------------------------------------------
00066 
00073 class ControlConnection : public boost::enable_shared_from_this<ControlConnection>
00074 {
00075 public:
00076 
00080   typedef boost::shared_ptr<ControlConnection> pointer;
00081 
00082   typedef std::pair<int, std::string> ConnectionID;
00083 
00089   static pointer create(boost::asio::io_service& io_service,
00090       const ConnectionID& id,
00091       ControlConnectionServer& ctl_conn_server,
00092       const TCPConnection::pointer& tcp_conn_handle)
00093   {
00094     return pointer(new ControlConnection(io_service, id, ctl_conn_server, tcp_conn_handle));
00095   }
00096 
00097 public:
00101   virtual ~ControlConnection();
00102 
00106   void start();
00107 
00108 private:
00110   ControlConnection(boost::asio::io_service& io_service,
00111       const ConnectionID& id,
00112       ControlConnectionServer& ctl_conn_server,
00113       const TCPConnection::pointer& tcp_conn);
00114 
00115 private:
00119   void handleClient();
00120 
00124   void handle_read(const boost::system::error_code& e,
00125       std::size_t bytes_transferred);
00126 
00130   void handle_write(const boost::system::error_code& e,
00131       std::size_t bytes_transferred);
00132 
00136   void sendMsg(const ControlMsg& msg);
00137 
00141   void close();
00142 
00143 private:
00144   static const size_t MAX_DATA_SIZE = 100 * 1024;
00146   boost::asio::io_service&                 io_service_; 
00147 
00148   ConnectionID                             connection_id_;
00149 
00150   ControlConnectionServer&                 ctl_conn_server_; 
00151 
00153   boost::asio::streambuf*                  input_buffer_; 
00154 
00155   boost::asio::streambuf*                  output_buffer_; 
00156 
00157   TCPConnection::pointer                   tcp_connection_; 
00158 
00160   ControlMsgEncoder*                       msg_encoder_; 
00161 
00162   ControlMsgDecoder*                       msg_decoder_; 
00163 
00164   boost::shared_ptr<ConfigMsg>             config_msg_; 
00165 
00166   enum State
00167   {
00168     State_Connected,
00169     State_AllocatedDataConnection,
00170     State_TransmissionStarted,
00171     State_TransmissionStopped,
00172     State_ConnectionClosed
00173   };
00174 
00175   int                                      state_;                    
00176   int                                      connection_type_;          
00177   boost::asio::ip::tcp::endpoint           tcp_data_server_local_endpoint_;  
00178 };
00179 
00180 //-----------------------------------------------------------------------------
00181 
00182 } // Namespace tobiss
00183 
00184 #endif //CONTROLCONNECTION_H
00185 
00186 // End Of File
 All Data Structures Files Functions Variables Typedefs Enumerations