Rev 1595 | Rev 1597 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1595 | Rev 1596 | ||
|---|---|---|---|
| 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 "Manager.h" |
21 | #include "Manager.h" |
| - | 22 | ||
| - | 23 | #include <iostream> |
|
| 22 | 24 | ||
| 23 | #include <boost/lexical_cast.hpp> |
25 | #include <boost/lexical_cast.hpp> |
| 24 | #include <boost/bind.hpp> |
26 | #include <boost/bind.hpp> |
| 25 | #include <boost/cast.hpp> |
27 | #include <boost/cast.hpp> |
| 26 | 28 | ||
| Line 96... | Line 98... | ||
| 96 | } |
98 | } |
| 97 | 99 | ||
| 98 | this->signal_on_new_state_(client_id, server_id, client_state); |
100 | this->signal_on_new_state_(client_id, server_id, client_state); |
| 99 | } |
101 | } |
| 100 | 102 | ||
| 101 | void Manager::SlotOnNewData(ClientId client_id, ServerId server_id, |
103 | void Manager::SlotOnNewData(ClientId client_id, ServerId server_id, type::Byteset data) |
| 102 | { |
104 | { |
| 103 | this->signal_on_new_data_(client_id, server_id, data); |
105 | this->signal_on_new_data_(client_id, server_id, data); |
| 104 | } |
106 | } |
| 105 | 107 | ||
| 106 | ServerId Manager::GetFreeServerId() |
108 | ServerId Manager::GetFreeServerId() |
| Line 115... | Line 117... | ||
| 115 | } |
117 | } |
| 116 | 118 | ||
| 117 | server_id++; |
119 | server_id++; |
| 118 | } |
120 | } |
| 119 | 121 | ||
| 120 | return |
122 | return server_id; |
| 121 | } |
123 | } |
| 122 | 124 | ||
| 123 | ClientId Manager::GetFreeClientId() |
125 | ClientId Manager::GetFreeClientId() |
| 124 | { |
126 | { |
| 125 | ClientId client_id = 1; |
127 | ClientId client_id = 1; |
| Line 207... | Line 209... | ||
| 207 | this->mutex_clients_.unlock(); |
209 | this->mutex_clients_.unlock(); |
| 208 | 210 | ||
| 209 | return client->GetId(); |
211 | return client->GetId(); |
| 210 | } |
212 | } |
| 211 | 213 | ||
| 212 | void Manager::SendToAll(ServerId server_id, |
214 | void Manager::SendToAll(ServerId server_id, type::Byteset data) |
| 213 | { |
215 | { |
| 214 | this->io_service_.post(boost::bind(&Manager::SendToAllHandler, this, server_id, data)); |
216 | this->io_service_.post(boost::bind(&Manager::SendToAllHandler, this, server_id, data)); |
| 215 | } |
217 | } |
| 216 | 218 | ||
| 217 | void Manager::SendTo(ClientId client_id, |
219 | void Manager::SendTo(ClientId client_id, type::Byteset data) |
| 218 | { |
220 | { |
| 219 | this->io_service_.post(boost::bind(&Manager::SendToHandler, this, client_id, data)); |
221 | this->io_service_.post(boost::bind(&Manager::SendToHandler, this, client_id, data)); |
| 220 | } |
222 | } |
| 221 | 223 | ||
| 222 | void Manager::StopServer(ServerId server_id) |
224 | void Manager::StopServer(ServerId server_id) |
| Line 227... | Line 229... | ||
| 227 | void Manager::Disconnect(ClientId client_id) |
229 | void Manager::Disconnect(ClientId client_id) |
| 228 | { |
230 | { |
| 229 | this->io_service_.post(boost::bind(&Manager::DisconnectHandler, this, client_id)); |
231 | this->io_service_.post(boost::bind(&Manager::DisconnectHandler, this, client_id)); |
| 230 | } |
232 | } |
| 231 | 233 | ||
| 232 | void Manager::SendToAllHandler(ServerId server_id, |
234 | void Manager::SendToAllHandler(ServerId server_id, type::Byteset data) |
| 233 | { |
235 | { |
| 234 | this->mutex_clients_.lock(); |
236 | this->mutex_clients_.lock(); |
| 235 | 237 | ||
| 236 | for (ClientList::iterator it = this->clients_.begin(); it != this->clients_.end(); it++) |
238 | for (ClientList::iterator it = this->clients_.begin(); it != this->clients_.end(); it++) |
| 237 | { |
239 | { |
| Line 242... | Line 244... | ||
| 242 | } |
244 | } |
| 243 | 245 | ||
| 244 | this->mutex_clients_.unlock(); |
246 | this->mutex_clients_.unlock(); |
| 245 | } |
247 | } |
| 246 | 248 | ||
| 247 | void Manager::SendToHandler(ClientId client_id, |
249 | void Manager::SendToHandler(ClientId client_id, type::Byteset data) |
| 248 | { |
250 | { |
| 249 | this->mutex_clients_.lock(); |
251 | this->mutex_clients_.lock(); |
| 250 | 252 | ||
| 251 | ClientList::iterator it = this->clients_.find(client_id); |
253 | ClientList::iterator it = this->clients_.find(client_id); |
| 252 | 254 | ||