Subversion Repositories HomeAutomation

Rev

Rev 1592 | Rev 1596 | 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 "Types.h"
  30.  
  31. namespace atom {
  32. namespace net {
  33.  
  34. class Client
  35. {
  36. public:
  37.     typedef boost::shared_ptr<Client> Pointer;
  38.  
  39.     typedef boost::signals2::signal<void(ClientId, ServerId, ClientState)> SignalOnNewState;
  40.     typedef boost::signals2::signal<void(ClientId, ServerId, Buffer)> SignalOnNewData;
  41.  
  42.     Client(boost::asio::io_service& io_service, ClientId id, ServerId server_id);
  43.     virtual ~Client();
  44.  
  45.     void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data);
  46.    
  47.     virtual void Connect(std::string address, unsigned int port_or_baud) = 0;
  48.     virtual void Disconnect();
  49.     virtual void Send(Buffer data) = 0;
  50.  
  51.     ServerId GetServerId();
  52.     ClientId GetId();
  53.    
  54. protected:
  55.     Buffer buffer_;
  56.    
  57.     virtual void Read();
  58.     void ReadHandler(const boost::system::error_code& error, size_t size);
  59.    
  60.     SignalOnNewState signal_on_new_state_;
  61.    
  62. private:
  63.     ClientId id_;
  64.     ServerId server_id_;
  65.    
  66.     SignalOnNewData signal_on_new_data_;
  67. };
  68.  
  69. }; // namespace net
  70. }; // namespace atom
  71.  
  72. #endif // NET_CLIENT_H
  73.