PICloud many important fixes
This commit is contained in:
@@ -5,7 +5,9 @@ CloudServer::CloudServer(DispatcherClient * c, const PIByteArray & sname) : serv
|
||||
server_uuid = sname;
|
||||
CONNECTL(c, dataReadedServer, ([this](uint id, PIByteArray & ba){
|
||||
last_ping.reset();
|
||||
mutex_clients.lock();
|
||||
DispatcherClient * cl = index_clients.value(id, nullptr);
|
||||
mutex_clients.unlock();
|
||||
if (cl) cl->sendData(ba);
|
||||
}));
|
||||
CONNECTL(c, pingReceived, [this]() {last_ping.reset();});
|
||||
@@ -27,9 +29,11 @@ PIByteArray CloudServer::serverUUID() const {
|
||||
|
||||
void CloudServer::addClient(DispatcherClient * c) {
|
||||
last_ping.reset();
|
||||
mutex_clients.lock();
|
||||
clients << c;
|
||||
uint cid = c->clientId();
|
||||
index_clients.insert(cid, c);
|
||||
mutex_clients.unlock();
|
||||
c->sendConnected(1);
|
||||
server->sendConnected(cid);
|
||||
CONNECTL(c, dataReaded, ([this, cid](PIByteArray & ba){
|
||||
@@ -41,14 +45,19 @@ void CloudServer::addClient(DispatcherClient * c) {
|
||||
|
||||
void CloudServer::removeClient(DispatcherClient * c) {
|
||||
last_ping.reset();
|
||||
mutex_clients.lock();
|
||||
clients.removeOne(c);
|
||||
index_clients.remove(c->clientId());
|
||||
mutex_clients.unlock();
|
||||
server->sendDisconnected(c->clientId());
|
||||
}
|
||||
|
||||
|
||||
PIVector<DispatcherClient *> CloudServer::getClients() {
|
||||
return clients;
|
||||
mutex_clients.lock();
|
||||
PIVector<DispatcherClient *> cl = clients;
|
||||
mutex_clients.unlock();
|
||||
return cl;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,14 +67,12 @@ double CloudServer::lastPing() {
|
||||
|
||||
|
||||
void CloudServer::printStatus() {
|
||||
mutex_clients.lock();
|
||||
piCout << " " << "Clients for" << server->address() << server_uuid.toHex() << ":";
|
||||
for (auto c: clients) {
|
||||
piCout << " " << c->address() << c->clientId();
|
||||
}
|
||||
// for (auto c: clients) {
|
||||
// c->sendData(PIByteArray::fromHex("000000"));
|
||||
// server->sendDataToClient(PIByteArray::fromHex("000000"), c->clientId());
|
||||
// }
|
||||
mutex_clients.unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user