Rev 1592 | Rev 1594 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1592 | Rev 1593 | ||
|---|---|---|---|
| Line 58... | Line 58... | ||
| 58 | { |
58 | { |
| 59 | this->signal_on_new_state_.connect(slot_on_new_state); |
59 | this->signal_on_new_state_.connect(slot_on_new_state); |
| 60 | this->signal_on_new_data_.connect(slot_on_new_data); |
60 | this->signal_on_new_data_.connect(slot_on_new_data); |
| 61 | } |
61 | } |
| 62 | 62 | ||
| 63 | void Manager::SlotOnNewState(ClientId client_id, ClientState client_state) |
63 | void Manager::SlotOnNewState(ClientId client_id, ServerId server_id, ClientState client_state) |
| 64 | { |
64 | { |
| 65 | if (client_state == CLIENT_STATE_DISCONNECTED) |
65 | if (client_state == CLIENT_STATE_DISCONNECTED) |
| 66 | { |
66 | { |
| 67 | this->clients_.erase(client_id); |
67 | this->clients_.erase(client_id); |
| 68 | } |
68 | } |
| Line 72... | Line 72... | ||
| 72 | 72 | ||
| 73 | if (it != this->clients_.end()) |
73 | if (it != this->clients_.end()) |
| 74 | { |
74 | { |
| 75 | TcpClient::Pointer client = TcpClient::Pointer(new TcpClient(this->io_service_, this->GetFreeClientId(), it->second->GetServerId())); |
75 | TcpClient::Pointer client = TcpClient::Pointer(new TcpClient(this->io_service_, this->GetFreeClientId(), it->second->GetServerId())); |
| 76 | 76 | ||
| 77 | client->ConnectSlots(Client::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, |
77 | client->ConnectSlots(Client::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(Manager::instance_), |
| 78 | Client::SignalOnNewData::slot_type(&Manager::SlotOnNewData, this, _1, |
78 | Client::SignalOnNewData::slot_type(&Manager::SlotOnNewData, this, _1, _2, _3).track(Manager::instance_)); |
| 79 | 79 | ||
| 80 | client->Accept(((TcpClient*)(it->second.get()))->ReleaseAcceptor()); |
80 | client->Accept(((TcpClient*)(it->second.get()))->ReleaseAcceptor()); |
| 81 | 81 | ||
| 82 | this->clients_[client->GetId()] = client; |
82 | this->clients_[client->GetId()] = client; |
| 83 | 83 | ||
| 84 | this->signal_on_new_state_(client_id, CLIENT_STATE_CONNECTED); |
84 | this->signal_on_new_state_(client_id, server_id, CLIENT_STATE_CONNECTED); |
| 85 | return; |
85 | return; |
| 86 | } |
86 | } |
| 87 | else |
87 | else |
| 88 | { |
88 | { |
| 89 | throw std::runtime_error("Accepted unknown client!"); |
89 | throw std::runtime_error("Accepted unknown client!"); |
| 90 | } |
90 | } |
| 91 | } |
91 | } |
| 92 | 92 | ||
| 93 | this->signal_on_new_state_(client_id, client_state); |
93 | this->signal_on_new_state_(client_id, server_id, client_state); |
| 94 | } |
94 | } |
| 95 | 95 | ||
| 96 | void Manager::SlotOnNewData(ClientId client_id, Buffer data) |
96 | void Manager::SlotOnNewData(ClientId client_id, ServerId server_id, Buffer data) |
| 97 | { |
97 | { |
| 98 | this->signal_on_new_data_(client_id, data); |
98 | this->signal_on_new_data_(client_id, server_id, data); |
| 99 | } |
99 | } |
| 100 | 100 | ||
| 101 | ServerId Manager::GetFreeServerId() |
101 | ServerId Manager::GetFreeServerId() |
| 102 | { |
102 | { |
| 103 | ServerId server_id = 1; |
103 | ServerId server_id = 1; |
| Line 135... | Line 135... | ||
| 135 | return 0; |
135 | return 0; |
| 136 | } |
136 | } |
| 137 | 137 | ||
| 138 | TcpClient::Pointer client = TcpClient::Pointer(new TcpClient(this->io_service_, this->GetFreeClientId(), this->GetFreeServerId())); |
138 | TcpClient::Pointer client = TcpClient::Pointer(new TcpClient(this->io_service_, this->GetFreeClientId(), this->GetFreeServerId())); |
| 139 | 139 | ||
| 140 | client->ConnectSlots(Client::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, |
140 | client->ConnectSlots(Client::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(Manager::instance_), |
| 141 | Client::SignalOnNewData::slot_type(&Manager::SlotOnNewData, this, _1, |
141 | Client::SignalOnNewData::slot_type(&Manager::SlotOnNewData, this, _1, _2, _3).track(Manager::instance_)); |
| 142 | 142 | ||
| 143 | TcpClient::AcceptorPointer acceptor = TcpClient::AcceptorPointer(new boost::asio::ip::tcp::acceptor(this->io_service_, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))); |
143 | TcpClient::AcceptorPointer acceptor = TcpClient::AcceptorPointer(new boost::asio::ip::tcp::acceptor(this->io_service_, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))); |
| 144 | 144 | ||
| 145 | client->Accept(acceptor); |
145 | client->Accept(acceptor); |
| 146 | 146 | ||
| Line 175... | Line 175... | ||
| 175 | throw std::runtime_error("Invalid protocol specified!"); |
175 | throw std::runtime_error("Invalid protocol specified!"); |
| 176 | return 0; |
176 | return 0; |
| 177 | } |
177 | } |
| 178 | } |
178 | } |
| 179 | 179 | ||
| 180 | client->ConnectSlots(Client::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, |
180 | client->ConnectSlots(Client::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(Manager::instance_), |
| 181 | Client::SignalOnNewData::slot_type(&Manager::SlotOnNewData, this, _1, |
181 | Client::SignalOnNewData::slot_type(&Manager::SlotOnNewData, this, _1, _2, _3).track(Manager::instance_)); |
| 182 | 182 | ||
| 183 | try |
183 | try |
| 184 | { |
184 | { |
| 185 | client->Connect(address, port_or_baud); |
185 | client->Connect(address, port_or_baud); |
| 186 | } |
186 | } |