Rev 1593 | Rev 1595 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1593 | Rev 1594 | ||
|---|---|---|---|
| 1 | /* |
1 | /* |
| 2 | * |
2 | * |
| 3 | * Copyright (C) 2010 Mattias Runge |
3 | * Copyright (C) 2010 Mattias Runge |
| 4 | * |
4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
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 |
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 |
7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
8 | * (at your option) any later version. |
| 9 | * |
9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
13 | * GNU General Public License for more details. |
| 14 | * |
14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
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., |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
18 | * |
| 19 | */ |
19 | */ |
| 20 | 20 | ||
| 21 | #include "Client.h" |
21 | #include "Client.h" |
| 22 | - | ||
| 23 | #include <iostream> |
- | |
| 24 | 22 | ||
| 25 | #include <boost/bind.hpp> |
23 | #include <boost/bind.hpp> |
| 26 | #include <boost/lexical_cast.hpp> |
24 | #include <boost/lexical_cast.hpp> |
| 27 | 25 | ||
| 28 | namespace atom { |
26 | namespace atom { |
| 29 | namespace net { |
27 | namespace net { |
| 30 | 28 | ||
| 31 | Client::Client(boost::asio::io_service& io_service, ClientId id, ServerId server_id) |
29 | Client::Client(boost::asio::io_service& io_service, ClientId id, ServerId server_id) |
| 32 | { |
30 | { |
| 33 | this->server_id_ = server_id; |
31 | this->server_id_ = server_id; |
| 34 | this->id_ = id; |
32 | this->id_ = id; |
| 35 | } |
33 | } |
| 36 | 34 | ||
| 37 | Client::~Client() |
35 | Client::~Client() |
| 38 | { |
36 | { |
| 39 | } |
37 | } |
| 40 | 38 | ||
| 41 | void Client::ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data) |
39 | void Client::ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data) |
| 42 | { |
40 | { |
| 43 | this->signal_on_new_state_.connect(slot_on_new_state); |
41 | this->signal_on_new_state_.connect(slot_on_new_state); |
| 44 | this->signal_on_new_data_.connect(slot_on_new_data); |
42 | this->signal_on_new_data_.connect(slot_on_new_data); |
| 45 | } |
43 | } |
| 46 | 44 | ||
| 47 | ClientId Client::GetId() |
45 | ClientId Client::GetId() |
| 48 | { |
46 | { |
| 49 | return this->id_; |
47 | return this->id_; |
| 50 | } |
48 | } |
| 51 | 49 | ||
| 52 | ServerId Client::GetServerId() |
50 | ServerId Client::GetServerId() |
| 53 | { |
51 | { |
| 54 | return this->server_id_; |
52 | return this->server_id_; |
| 55 | } |
53 | } |
| 56 | 54 | ||
| 57 | void Client::Read() |
55 | void Client::Read() |
| 58 | { |
56 | { |
| 59 | this->buffer_.assign(0); |
57 | this->buffer_.assign(0); |
| 60 | } |
58 | } |
| 61 | 59 | ||
| 62 | void Client::ReadHandler(const boost::system::error_code& error, size_t size) |
60 | void Client::ReadHandler(const boost::system::error_code& error, size_t size) |
| 63 | { |
61 | { |
| 64 | if (error) |
62 | if (error) |
| 65 | { |
63 | { |
| 66 | this->Disconnect(); |
64 | this->Disconnect(); |
| 67 | } |
65 | } |
| 68 | else if (size == 0) |
66 | else if (size == 0) |
| 69 | { |
67 | { |
| 70 | this->Disconnect(); |
68 | this->Disconnect(); |
| 71 | } |
69 | } |
| 72 | else |
70 | else |
| 73 | { |
71 | { |
| 74 | this->signal_on_new_data_(this->id_, this->server_id_, this->buffer_); |
72 | this->signal_on_new_data_(this->id_, this->server_id_, this->buffer_); |
| 75 | 73 | ||
| 76 | this->Read(); |
74 | this->Read(); |
| 77 | } |
75 | } |
| 78 | } |
76 | } |
| 79 | 77 | ||
| 80 | void Client::Disconnect() |
78 | void Client::Disconnect() |
| 81 | { |
79 | { |
| 82 | this->signal_on_new_state_(this->id_, this->server_id_, CLIENT_STATE_DISCONNECTED); |
80 | this->signal_on_new_state_(this->id_, this->server_id_, CLIENT_STATE_DISCONNECTED); |
| 83 | } |
81 | } |
| 84 | 82 | ||
| 85 | }; // namespace net |
83 | }; // namespace net |
| 86 | }; // namespace atom |
84 | }; // namespace atom |
| 87 | 85 | ||