Subversion Repositories HomeAutomation

Rev

Rev 1596 | Rev 1959 | Go to most recent revision | 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 "type/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.  
  41.     typedef boost::signals2::signal<void(ClientId, ServerId, ClientState)> SignalOnNewState;
  42.     typedef boost::signals2::signal<void(ClientId, ServerId, type::Byteset)> SignalOnNewData;
  43.  
  44.     Client(boost::asio::io_service& io_service, ClientId id, ServerId server_id);
  45.     virtual ~Client();
  46.  
  47.     void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data);
  48.    
  49.     virtual void Connect(std::string address, unsigned int port_or_baud) = 0;
  50.     void Disconnect();
  51.     virtual void Stop();
  52.     virtual void Send(type::Byteset data) = 0;
  53.  
  54.     ServerId GetServerId();
  55.     ClientId GetId();
  56.    
  57. protected:
  58.     type::Byteset buffer_;
  59.    
  60.     virtual void Read();
  61.     void ReadHandler(const boost::system::error_code& error, size_t size);
  62.    
  63.     SignalOnNewState signal_on_new_state_;
  64.    
  65. private:
  66.     ClientId id_;
  67.     ServerId server_id_;
  68.    
  69.     SignalOnNewData signal_on_new_data_;
  70. };
  71.  
  72. }; // namespace net
  73. }; // namespace atom
  74.  
  75. #endif // NET_CLIENT_H
  76.