From e9bd50ff9bd8c2b448e39e7bb3fbddbb9c6bed49 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 29 Nov 2022 21:57:48 -0800 Subject: [PATCH] [glass] NT view: clear meta-topic info on disconnect (#4732) --- glass/src/libnt/native/cpp/NetworkTables.cpp | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/glass/src/libnt/native/cpp/NetworkTables.cpp b/glass/src/libnt/native/cpp/NetworkTables.cpp index 6b0a776fd5..226e347201 100644 --- a/glass/src/libnt/native/cpp/NetworkTables.cpp +++ b/glass/src/libnt/native/cpp/NetworkTables.cpp @@ -432,6 +432,27 @@ void NetworkTablesModel::Update() { } } if (event.flags & nt::EventFlags::kUnpublish) { + // meta topic handling + if (wpi::starts_with(info->name, '$')) { + // meta topic handling + if (info->name == "$clients") { + m_clients.clear(); + } else if (info->name == "$serverpub") { + m_server.publishers.clear(); + } else if (info->name == "$serversub") { + m_server.subscribers.clear(); + } else if (wpi::starts_with(info->name, "$clientpub$")) { + auto it = m_clients.find(wpi::drop_front(info->name, 11)); + if (it != m_clients.end()) { + it->second.publishers.clear(); + } + } else if (wpi::starts_with(info->name, "$clientsub$")) { + auto it = m_clients.find(wpi::drop_front(info->name, 11)); + if (it != m_clients.end()) { + it->second.subscribers.clear(); + } + } + } auto it = std::find(m_sortedEntries.begin(), m_sortedEntries.end(), entry.get()); // will be removed completely below