From 789e5555ab4c44a1ae779eccf6ccf8340602cf22 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Thu, 26 Jan 2023 20:46:30 +0100 Subject: Websockets: Notify other clients of changes --- connectionregistry.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 connectionregistry.h (limited to 'connectionregistry.h') diff --git a/connectionregistry.h b/connectionregistry.h new file mode 100644 index 0000000..2b14553 --- /dev/null +++ b/connectionregistry.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +class ConnectionRegistry +{ +public: + using connection = std::shared_ptr>; + + ConnectionRegistry() = default; + ~ConnectionRegistry() = default; + + void setId(connection c, const std::string& id); + + // used via RegistryGuard + void addConnection(connection c); + void delConnection(connection c); + + // map connection to id + std::unordered_map m_connections; + // map id to list of related connections, used for iteration over connections to notify about changes + std::unordered_map> m_ids; + + std::unordered_set::iterator begin(const std::string& id); + std::unordered_set::iterator end(const std::string& id); + + void dump(); + + class RegistryGuard + { + public: + RegistryGuard(ConnectionRegistry& registry, connection c); + ~RegistryGuard(); + private: + ConnectionRegistry& m_registry; + connection m_connection; + }; + +}; + -- cgit v1.2.3