62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
#include "cloudserver.h"
|
|
|
|
CloudServer::CloudServer(DispatcherClient * c, const PIString & sname) : server(c) {
|
|
setName(sname);
|
|
server_name = sname;
|
|
CONNECTL(c, dataReadedServer, ([this](uint id, PIByteArray & ba){
|
|
DispatcherClient * cl = index_clients.value(id, nullptr);
|
|
if (cl) cl->sendData(ba);
|
|
}));
|
|
}
|
|
|
|
|
|
CloudServer::~CloudServer() {
|
|
for (auto c :clients) {
|
|
c->close();
|
|
}
|
|
}
|
|
|
|
|
|
PIString CloudServer::serverName() const {
|
|
return server_name;
|
|
}
|
|
|
|
|
|
void CloudServer::addClient(DispatcherClient * c) {
|
|
clients << c;
|
|
index_clients.insert(c->clientId(), c);
|
|
c->sendConnected(1);
|
|
server->sendConnected(c->clientId());
|
|
CONNECTL(c, dataReaded, ([this, c](PIByteArray & ba){
|
|
// piCoutObj << c->clientId() << "dataReaded";
|
|
if (clients.contains(c)) {
|
|
server->sendDataToClient(ba, c->clientId());
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
void CloudServer::removeClient(DispatcherClient * c) {
|
|
clients.removeOne(c);
|
|
index_clients.removeOne(c->clientId());
|
|
}
|
|
|
|
|
|
PIVector<DispatcherClient *> CloudServer::getClients() {
|
|
return clients;
|
|
}
|
|
|
|
|
|
void CloudServer::printStatus() {
|
|
piCout << " " << "Clients for" << server->address() << server_name << ":";
|
|
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());
|
|
// }
|
|
}
|
|
|
|
|