Rev 1599 | Rev 1962 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1592 | runge | 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> |
||
| 1593 | runge | 26 | #include <boost/shared_ptr.hpp> |
| 1592 | runge | 27 | #include <boost/array.hpp> |
| 28 | |||
| 1642 | runge | 29 | #include "common/Byteset.h" |
| 1596 | runge | 30 | |
| 1595 | runge | 31 | #include "types.h" |
| 1592 | runge | 32 | |
| 33 | namespace atom { |
||
| 34 | namespace net { |
||
| 35 | |||
| 36 | class Client |
||
| 37 | { |
||
| 38 | public: |
||
| 39 | typedef boost::shared_ptr<Client> Pointer; |
||
| 40 | |||
| 1593 | runge | 41 | typedef boost::signals2::signal<void(ClientId, ServerId, ClientState)> SignalOnNewState; |
| 1642 | runge | 42 | typedef boost::signals2::signal<void(ClientId, ServerId, common::Byteset)> SignalOnNewData; |
| 1592 | runge | 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; |
||
| 1599 | runge | 50 | void Disconnect(); |
| 51 | virtual void Stop(); |
||
| 1642 | runge | 52 | virtual void Send(common::Byteset data) = 0; |
| 1592 | runge | 53 | |
| 54 | ServerId GetServerId(); |
||
| 55 | ClientId GetId(); |
||
| 56 | |||
| 57 | protected: |
||
| 1642 | runge | 58 | common::Byteset buffer_; |
| 1592 | runge | 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: |
||
| 1593 | runge | 66 | ClientId id_; |
| 1592 | runge | 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 |