PICloud change protocol > server_uuid

This commit is contained in:
2021-04-12 11:35:34 +03:00
parent f75ce1e8e0
commit dbd2267a8c
12 changed files with 56 additions and 33 deletions

View File

@@ -1,8 +1,8 @@
#include "cloudserver.h"
CloudServer::CloudServer(DispatcherClient * c, const PIString & sname) : server(c) {
setName(sname);
server_name = sname;
CloudServer::CloudServer(DispatcherClient * c, const PIByteArray & sname) : server(c) {
setName(sname.toHex());
server_uuid = sname;
CONNECTL(c, dataReadedServer, ([this](uint id, PIByteArray & ba){
DispatcherClient * cl = index_clients.value(id, nullptr);
if (cl) cl->sendData(ba);
@@ -17,8 +17,8 @@ CloudServer::~CloudServer() {
}
PIString CloudServer::serverName() const {
return server_name;
PIByteArray CloudServer::serverUUID() const {
return server_uuid;
}
@@ -49,7 +49,7 @@ PIVector<DispatcherClient *> CloudServer::getClients() {
void CloudServer::printStatus() {
piCout << " " << "Clients for" << server->address() << server_name << ":";
piCout << " " << "Clients for" << server->address() << server_uuid.toHex() << ":";
for (auto c: clients) {
piCout << " " << c->address() << c->clientId();
}

View File

@@ -7,9 +7,9 @@
class CloudServer : public PIObject {
PIOBJECT(CloudServer)
public:
CloudServer(DispatcherClient * c, const PIString & sname);
CloudServer(DispatcherClient * c, const PIByteArray & sname);
~CloudServer();
PIString serverName() const;
PIByteArray serverUUID() const;
void addClient(DispatcherClient * c);
void removeClient(DispatcherClient * c);
PIVector<DispatcherClient*> getClients();
@@ -20,7 +20,7 @@ private:
DispatcherClient * server;
PIVector<DispatcherClient*> clients;
PIMap<uint, DispatcherClient*> index_clients;
PIString server_name;
PIByteArray server_uuid;
};
#endif // CLOUDSERVER_H

View File

@@ -101,7 +101,7 @@ void DispatcherClient::readed(PIByteArray & ba) {
switch (hdr.first) {
case PICloud::TCP::Connect: {
tcp.setRole(hdr.second);
PIString sn = tcp.parseConnect_d(ba);
PIByteArray sn = tcp.parseConnect_d(ba);
if (hdr.second == PICloud::TCP::Server) registerServer(sn, this);
if (hdr.second == PICloud::TCP::Client) registerClient(sn, this);
return;}

View File

@@ -23,8 +23,8 @@ public:
PIString address();
uint clientId() const {return client_id;}
EVENT1(disconnectEvent, DispatcherClient *, client)
EVENT2(registerServer, PIString, sname, DispatcherClient *, client)
EVENT2(registerClient, PIString, sname, DispatcherClient *, client)
EVENT2(registerServer, const PIByteArray &, sname, DispatcherClient *, client)
EVENT2(registerClient, const PIByteArray &, sname, DispatcherClient *, client)
EVENT1(dataReaded, PIByteArray &, ba)
EVENT2(dataReadedServer, uint, id, PIByteArray &, ba)

View File

@@ -70,12 +70,12 @@ void DispatcherServer::updateConnectionsTile(TileList * tl) {
case PICloud::TCP::Client : {
role = "Client";
CloudServer * cs = index_c_clients.value(c, nullptr);
if (cs) role += " \"" + cs->serverName() + "\"";
if (cs) role += " \"" + cs->serverUUID().toHex().left(8) + "...\"";
} break;
case PICloud::TCP::Server : {
role = "Server";
CloudServer * cs = index_c_servers.value(c, nullptr);
if (cs) role += " \"" + cs->serverName() + "\"";
if (cs) role += " \"" + cs->serverUUID().toHex().left(8) + "...\"";
} break;
default:
break;
@@ -91,7 +91,7 @@ void DispatcherServer::updateServersTile(TileList * tl, PISet<const DispatcherCl
tl->content.clear();
auto mi = c_servers.makeIterator();
while (mi.next()) {
tl->content << TileList::Row(mi.value()->serverName() + " - " + PIString::fromNumber(mi.value()->getClients().size()), PIScreenTypes::CellFormat());
tl->content << TileList::Row(mi.value()->serverUUID().toHex().left(8) + "... - " + PIString::fromNumber(mi.value()->getClients().size()), PIScreenTypes::CellFormat());
if (servers.contains(mi.value()->getConnection())) tl->selected << (tl->content.size_s() - 1);
}
map_mutex.unlock();
@@ -167,7 +167,7 @@ void DispatcherServer::disconnectClient(DispatcherClient *client) {
csc->close();
csc->deleteLater();
}
c_servers.remove(cs->serverName());
c_servers.remove(cs->serverUUID());
index_c_servers.removeOne(client);
delete cs;
}
@@ -185,13 +185,13 @@ void DispatcherServer::disconnectClient(DispatcherClient *client) {
void DispatcherServer::newConnection(PIEthernet *cl) {
DispatcherClient * client = new DispatcherClient(cl, client_gid++);
CONNECTU(client, disconnectEvent, this, disconnectClient);
CONNECTL(client, registerServer, [this](PIString sname, DispatcherClient * c){
CONNECTL(client, registerServer, [this](const PIByteArray & sname, DispatcherClient * c){
map_mutex.lock();
CloudServer * cs = c_servers.value(sname, nullptr);
if (cs) {
rm_clients << c;
} else {
piCoutObj << "add new Server ->" << sname;
piCoutObj << "add new Server ->" << sname.toHex();
CloudServer * cs = new CloudServer(c, sname);
c_servers.insert(sname, cs);
index_c_servers.insert(c, cs);
@@ -199,11 +199,11 @@ void DispatcherServer::newConnection(PIEthernet *cl) {
}
map_mutex.unlock();
});
CONNECTL(client, registerClient, [this](PIString sname, DispatcherClient * c){
CONNECTL(client, registerClient, [this](const PIByteArray & sname, DispatcherClient * c){
map_mutex.lock();
CloudServer * cs = c_servers.value(sname, nullptr);
if (cs) {
piCoutObj << "add new Client to Server ->" << sname;
piCoutObj << "add new Client to Server ->" << sname.toHex();
cs->addClient(c);
index_c_clients.insert(c, cs);
c->authorise(true);

View File

@@ -28,7 +28,7 @@ private:
PIEthernet eth;
PIVector<DispatcherClient*> clients;
PIMap<PIString, CloudServer *> c_servers;
PIMap<PIByteArray, CloudServer *> c_servers;
PIMap<const DispatcherClient *, CloudServer *> index_c_servers;
PIMap<const DispatcherClient *, CloudServer *> index_c_clients;
PIVector<DispatcherClient*> rm_clients;