Subversion Repositories HomeAutomation

Rev

Rev 1962 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  *
  3.  *  Copyright (C) 2010  Mattias Runge
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License along
  16.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  17.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  *
  19.  */
  20.  
  21. #ifndef NET_CLIENT_H
  22. #define NET_CLIENT_H
  23.  
  24. #include <boost/asio.hpp>
  25. #include <boost/signals2.hpp>
  26. #include <boost/shared_ptr.hpp>
  27. #include <boost/array.hpp>
  28.  
  29. #include "common/Byteset.h"
  30.  
  31. #include "types.h"
  32.  
  33. namespace atom {
  34. namespace net {
  35.  
  36. class Client
  37. {
  38. public:
  39.   typedef boost::shared_ptr<Client>                                           Pointer;
  40.   typedef boost::signals2::signal<void(SocketId, SocketId, ClientState)>      SignalOnNewState;
  41.   typedef boost::signals2::signal<void(SocketId, SocketId, common::Byteset)>  SignalOnNewData;
  42.  
  43.   Client(boost::asio::io_service& io_service, SocketId id, SocketId server_id);
  44.   virtual ~Client();
  45.  
  46.   void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data);
  47.  
  48.   virtual void Connect(std::string address, unsigned int port_or_baud) = 0;
  49.   void Disconnect();
  50.   virtual void Stop();
  51.   virtual void Send(common::Byteset data) = 0;
  52.  
  53.   SocketId GetServerId();
  54.   SocketId GetId();
  55.    
  56. protected:
  57.     common::Byteset           buffer_;
  58.     boost::asio::io_service&  io_service_;
  59.     SignalOnNewState          signal_on_new_state_;
  60.     virtual void Read();
  61.     void ReadHandler(const boost::system::error_code& error, size_t size);
  62.    
  63.    
  64.    
  65. private:
  66.     SocketId        id_;
  67.     SocketId        server_id_;
  68.     SignalOnNewData signal_on_new_data_;
  69. };
  70.  
  71. }; // namespace net
  72. }; // namespace atom
  73.  
  74. #endif // NET_CLIENT_H
  75.