map and cloud fix, add cloud debug
This commit is contained in:
@@ -28,7 +28,7 @@ void DispatcherServer::start() {
|
||||
|
||||
|
||||
void DispatcherServer::picoutStatus() {
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
piCout << PICoutManipulators::NewLine;
|
||||
piCout << "Connections:";
|
||||
for (auto c: clients) {
|
||||
@@ -40,16 +40,12 @@ void DispatcherServer::picoutStatus() {
|
||||
piCout << " " << it.key();
|
||||
it.value()->printStatus();
|
||||
}
|
||||
map_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void DispatcherServer::cleanClients() {
|
||||
map_mutex.lock();
|
||||
for (auto c: rmrf_clients) {
|
||||
delete c;
|
||||
}
|
||||
rmrf_clients.clear();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
piDeleteAllAndClear(rmrf_clients);
|
||||
for (auto c: clients) {
|
||||
if (!index_c_servers.contains(c) && !index_c_clients.contains(c)) {
|
||||
if (!rm_clients.contains(c)) rm_clients << c;
|
||||
@@ -88,12 +84,11 @@ void DispatcherServer::cleanClients() {
|
||||
index_c_clients.remove(c);
|
||||
rm_clients.removeAll(c);
|
||||
}
|
||||
map_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void DispatcherServer::updateConnectionsTile(TileList * tl) {
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
tl->content.clear();
|
||||
for (auto c: clients) {
|
||||
PIString role = "Invalid";
|
||||
@@ -118,12 +113,11 @@ void DispatcherServer::updateConnectionsTile(TileList * tl) {
|
||||
for (auto c: rmrf_clients) {
|
||||
tl->content << TileList::Row("[NULL]" + c->address(), PIScreenTypes::CellFormat());
|
||||
}
|
||||
map_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void DispatcherServer::updateServersTile(TileList * tl, PISet<const DispatcherClient *> servers) {
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
tl->content.clear();
|
||||
auto mi = c_servers.makeIterator();
|
||||
while (mi.next()) {
|
||||
@@ -132,12 +126,11 @@ void DispatcherServer::updateServersTile(TileList * tl, PISet<const DispatcherCl
|
||||
PIScreenTypes::CellFormat());
|
||||
if (servers.contains(mi.value()->getConnection())) tl->selected << (tl->content.size_s() - 1);
|
||||
}
|
||||
map_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void DispatcherServer::updateClientsTile(TileList * tl, PISet<const DispatcherClient *> servers) {
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
tl->content.clear();
|
||||
auto mi = c_servers.makeIterator();
|
||||
while (mi.next()) {
|
||||
@@ -146,26 +139,23 @@ void DispatcherServer::updateClientsTile(TileList * tl, PISet<const DispatcherCl
|
||||
tl->content << TileList::Row(c->address(), PIScreenTypes::CellFormat());
|
||||
}
|
||||
}
|
||||
map_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
const DispatcherClient * DispatcherServer::getConnection(int index) {
|
||||
PIMutexLocker locker(map_mutex);
|
||||
const DispatcherClient * ret = nullptr;
|
||||
map_mutex.lock();
|
||||
if (index >= 0 && index < clients.size_s()) ret = clients[index];
|
||||
map_mutex.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
const DispatcherClient * DispatcherServer::getServer(int index) {
|
||||
PIMutexLocker locker(map_mutex);
|
||||
const DispatcherClient * ret = nullptr;
|
||||
map_mutex.lock();
|
||||
if (index >= 0 && index < clients.size_s()) {
|
||||
if (index_c_servers.contains(clients[index])) ret = clients[index];
|
||||
}
|
||||
map_mutex.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -173,14 +163,13 @@ const DispatcherClient * DispatcherServer::getServer(int index) {
|
||||
PISet<const DispatcherClient *> DispatcherServer::getServers(PISet<int> ids) {
|
||||
PISet<const DispatcherClient *> ret;
|
||||
if (ids.isEmpty()) return ret;
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
int i = 0;
|
||||
auto mi = c_servers.makeIterator();
|
||||
while (mi.next()) {
|
||||
if (ids.contains(i)) ret << mi.value()->getConnection();
|
||||
i++;
|
||||
}
|
||||
map_mutex.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -196,7 +185,7 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
||||
return;
|
||||
}
|
||||
piCoutObj << "remove ..." << client->clientId();
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
clients.removeAll(client);
|
||||
rm_clients.removeAll(client);
|
||||
CloudServer * cs = index_c_servers.value(client, nullptr);
|
||||
@@ -221,8 +210,7 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
||||
index_c_clients.remove(client);
|
||||
}
|
||||
// client->close();
|
||||
rmrf_clients << client;
|
||||
map_mutex.unlock();
|
||||
if (!rmrf_clients.contains(client)) rmrf_clients << client;
|
||||
piCoutObj << "remove done" << client->clientId();
|
||||
}
|
||||
|
||||
@@ -235,7 +223,7 @@ void DispatcherServer::newConnection(PIEthernet * cl) {
|
||||
DispatcherClient * client = new DispatcherClient(cl, client_gid++);
|
||||
CONNECTU(client, disconnectEvent, this, disconnectClient);
|
||||
CONNECTL(client, registerServer, [this](const PIByteArray & sname, DispatcherClient * c) {
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
CloudServer * cs = c_servers.value(sname, nullptr);
|
||||
if (cs) {
|
||||
rm_clients << c;
|
||||
@@ -247,10 +235,9 @@ void DispatcherServer::newConnection(PIEthernet * cl) {
|
||||
index_c_servers.insert(c, cs);
|
||||
c->authorise(true);
|
||||
}
|
||||
map_mutex.unlock();
|
||||
});
|
||||
CONNECTL(client, registerClient, [this](const PIByteArray & sname, DispatcherClient * c) {
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
CloudServer * cs = c_servers.value(sname, nullptr);
|
||||
if (cs) {
|
||||
piCoutObj << "add new Client to Server ->" << sname.toHex();
|
||||
@@ -261,11 +248,9 @@ void DispatcherServer::newConnection(PIEthernet * cl) {
|
||||
rm_clients << c;
|
||||
piCoutObj << "Client can't connect to Server ->" << sname.toHex();
|
||||
}
|
||||
map_mutex.unlock();
|
||||
});
|
||||
// piCoutObj << "add client" << client;
|
||||
map_mutex.lock();
|
||||
PIMutexLocker locker(map_mutex);
|
||||
clients.push_back(client);
|
||||
map_mutex.unlock();
|
||||
client->start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user