Rev 1962 | 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: |
||
| 1963 | runge | 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; |
||
| 1592 | runge | 42 | |
| 1963 | runge | 43 | Client(boost::asio::io_service& io_service, SocketId id, SocketId server_id); |
| 44 | virtual ~Client(); |
||
| 1592 | runge | 45 | |
| 1963 | runge | 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; |
||
| 1592 | runge | 52 | |
| 1963 | runge | 53 | SocketId GetServerId(); |
| 54 | SocketId GetId(); |
||
| 1592 | runge | 55 | |
| 56 | protected: |
||
| 1962 | runge | 57 | common::Byteset buffer_; |
| 58 | boost::asio::io_service& io_service_; |
||
| 1963 | runge | 59 | SignalOnNewState signal_on_new_state_; |
| 1592 | runge | 60 | virtual void Read(); |
| 61 | void ReadHandler(const boost::system::error_code& error, size_t size); |
||
| 62 | |||
| 63 | |||
| 1963 | runge | 64 | |
| 1592 | runge | 65 | private: |
| 1963 | runge | 66 | SocketId id_; |
| 67 | SocketId server_id_; |
||
| 1592 | runge | 68 | SignalOnNewData signal_on_new_data_; |
| 69 | }; |
||
| 70 | |||
| 71 | }; // namespace net |
||
| 72 | }; // namespace atom |
||
| 73 | |||
| 74 | #endif // NET_CLIENT_H |