Rev 1599 | Rev 1939 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1599 | Rev 1608 | ||
|---|---|---|---|
| Line 17... | Line 17... | ||
| 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> |
|
| 22 | 24 | ||
| 23 | #include <boost/bind.hpp> |
25 | #include <boost/bind.hpp> |
| 24 | #include <boost/lexical_cast.hpp> |
26 | #include <boost/lexical_cast.hpp> |
| 25 | 27 | ||
| 26 | namespace atom { |
28 | namespace atom { |
| Line 31... | Line 33... | ||
| 31 | this->server_id_ = server_id; |
33 | this->server_id_ = server_id; |
| 32 | this->id_ = id; |
34 | this->id_ = id; |
| 33 | } |
35 | } |
| 34 | 36 | ||
| 35 | Client::~Client() |
37 | Client::~Client() |
| 36 | { |
38 | { |
| 37 | this->Stop(); |
39 | this->Stop(); |
| 38 | } |
40 | } |
| 39 | 41 | ||
| 40 | void Client::ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data) |
42 | void Client::ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data) |
| 41 | { |
43 | { |
| 42 | this->signal_on_new_state_.connect(slot_on_new_state); |
44 | this->signal_on_new_state_.connect(slot_on_new_state); |
| 43 | this->signal_on_new_data_.connect(slot_on_new_data); |
45 | this->signal_on_new_data_.connect(slot_on_new_data); |
| 44 | } |
46 | } |
| 45 | 47 | ||
| 46 | ClientId Client::GetId() |
48 | ClientId Client::GetId() |
| 47 | { |
49 | { |
| 48 | return this->id_; |
50 | return this->id_; |
| 49 | } |
51 | } |
| 50 | 52 | ||
| 51 | ServerId Client::GetServerId() |
53 | ServerId Client::GetServerId() |
| 52 | { |
54 | { |
| 53 | return this->server_id_; |
55 | return this->server_id_; |
| 54 | } |
56 | } |
| 55 | 57 | ||
| 56 | void Client::Read() |
58 | void Client::Read() |
| 57 | { |
59 | { |
| 58 | this->buffer_.Clear(); |
60 | this->buffer_.Clear(); |
| 59 | } |
61 | } |
| 60 | 62 | ||
| 61 | void Client::ReadHandler(const boost::system::error_code& error, size_t size) |
63 | void Client::ReadHandler(const boost::system::error_code& error, size_t size) |
| 62 | { |
64 | { |
| 63 | if (error) |
65 | if (error) |
| 64 | { |
66 | { |
| 65 |
|
67 | this->Disconnect(); |
| 66 | } |
68 | } |
| 67 | else if (size == 0) |
69 | else if (size == 0) |
| 68 | { |
70 | { |
| 69 | this->Disconnect(); |
71 | this->Disconnect(); |
| 70 | } |
72 | } |
| 71 | else |
73 | else |
| 72 | { |
74 | { |
| 73 | this->buffer_.SetSize(size); |
75 | this->buffer_.SetSize(size); |
| 74 | 76 | ||
| 75 | this->signal_on_new_data_(this->id_, this->server_id_, this->buffer_); |
77 | this->signal_on_new_data_(this->id_, this->server_id_, this->buffer_); |
| 76 | 78 | ||
| 77 | this->Read(); |
79 | this->Read(); |
| 78 | } |
80 | } |
| 79 | } |
81 | } |
| 80 | 82 | ||
| 81 | void Client::Stop() |
83 | void Client::Stop() |
| 82 | { |
84 | { |
| 83 | } |
85 | } |
| 84 | 86 | ||
| 85 | void Client::Disconnect() |
87 | void Client::Disconnect() |
| - | 88 | { |
|
| - | 89 | if (this->id_ != 0) |
|
| 86 | { |
90 | { |
| 87 | this->Stop(); |
91 | this->Stop(); |
| 88 | this->signal_on_new_state_(this->id_, this->server_id_, CLIENT_STATE_DISCONNECTED); |
92 | this->signal_on_new_state_(this->id_, this->server_id_, CLIENT_STATE_DISCONNECTED); |
| - | 93 | ||
| - | 94 | this->id_ = 0; |
|
| - | 95 | } |
|
| 89 | } |
96 | } |
| 90 | 97 | ||
| 91 | }; // namespace net |
98 | }; // namespace net |
| 92 | }; // namespace atom |
99 | }; // namespace atom |