PIClout data send and receive test
This commit is contained in:
@@ -16,7 +16,7 @@ DispatcherServer::DispatcherServer(PIEthernet::Address addr) : eth(PIEthernet::T
|
||||
|
||||
DispatcherServer::~DispatcherServer() {
|
||||
eth.close();
|
||||
piCoutObj << "server stoped";
|
||||
//piCoutObj << "server stoped";
|
||||
}
|
||||
|
||||
|
||||
@@ -59,23 +59,25 @@ void DispatcherServer::printStatus() {
|
||||
|
||||
void DispatcherServer::disconnectClient(DispatcherClient *client) {
|
||||
if (!clients.contains(client)) {
|
||||
piCoutObj << "INVALID client" << client;
|
||||
//piCoutObj << "INVALID client" << client;
|
||||
return;
|
||||
}
|
||||
piCoutObj << "remove client" << client;
|
||||
//piCoutObj << "remove client" << client;
|
||||
map_mutex.lock();
|
||||
clients.removeOne(client);
|
||||
CloudServer * cs = index_c_servers.value(client, nullptr);
|
||||
if (cs) {
|
||||
PIVector<DispatcherClient *> cscv = cs->getClients();
|
||||
for(auto csc : cscv) {
|
||||
csc->close();
|
||||
clients.removeOne(csc);
|
||||
index_c_clients.removeOne(csc);
|
||||
cs->removeClient(csc);
|
||||
csc->close();
|
||||
csc->deleteLater();
|
||||
}
|
||||
c_servers.remove(cs->serverName());
|
||||
index_c_servers.removeOne(client);
|
||||
delete cs;
|
||||
}
|
||||
CloudServer * cc = index_c_clients.value(client, nullptr);
|
||||
if (cc) {
|
||||
@@ -93,10 +95,16 @@ void DispatcherServer::newConnection(PIEthernet *cl) {
|
||||
CONNECTU(client, disconnectEvent, this, disconnectClient);
|
||||
CONNECTL(client, registerServer, [this](PIString sname, DispatcherClient * c){
|
||||
map_mutex.lock();
|
||||
piCoutObj << "add new Server ->" << sname;
|
||||
CloudServer * cs = new CloudServer(c, sname);
|
||||
c_servers.insert(sname, cs);
|
||||
index_c_servers.insert(c, cs);
|
||||
CloudServer * cs = c_servers.value(sname, nullptr);
|
||||
if (cs) {
|
||||
rm_clients << c;
|
||||
} else {
|
||||
piCoutObj << "add new Server ->" << sname;
|
||||
CloudServer * cs = new CloudServer(c, sname);
|
||||
c_servers.insert(sname, cs);
|
||||
index_c_servers.insert(c, cs);
|
||||
c->authorise(true);
|
||||
}
|
||||
map_mutex.unlock();
|
||||
});
|
||||
CONNECTL(client, registerClient, [this](PIString sname, DispatcherClient * c){
|
||||
@@ -106,12 +114,13 @@ void DispatcherServer::newConnection(PIEthernet *cl) {
|
||||
piCoutObj << "add new Client to Server ->" << sname;
|
||||
cs->addClient(c);
|
||||
index_c_clients.insert(c, cs);
|
||||
c->authorise(true);
|
||||
} else {
|
||||
rm_clients << c;
|
||||
}
|
||||
map_mutex.unlock();
|
||||
});
|
||||
piCoutObj << "add client" << client;
|
||||
//piCoutObj << "add client" << client;
|
||||
client->start();
|
||||
map_mutex.lock();
|
||||
clients.push_back(client);
|
||||
|
||||
Reference in New Issue
Block a user