diff options
author | David Robillard <d@drobilla.net> | 2015-02-09 21:37:31 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2015-02-09 21:37:31 +0000 |
commit | 9cde188fcb8cc7ff30f28ec898d72ce1575496ca (patch) | |
tree | 61fa3c3b5bb85428501868a6d2764b655db35ba2 /src | |
parent | 971a4e484757c083c9daa68a4a3e235a549ab523 (diff) | |
download | ingen-9cde188fcb8cc7ff30f28ec898d72ce1575496ca.tar.gz ingen-9cde188fcb8cc7ff30f28ec898d72ce1575496ca.tar.bz2 ingen-9cde188fcb8cc7ff30f28ec898d72ce1575496ca.zip |
Fix broadcasting to several clients.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5550 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/App.cpp | 2 | ||||
-rw-r--r-- | src/server/Broadcaster.cpp | 30 | ||||
-rw-r--r-- | src/server/Broadcaster.hpp | 33 | ||||
-rw-r--r-- | src/server/Engine.cpp | 12 | ||||
-rw-r--r-- | src/server/Engine.hpp | 5 | ||||
-rw-r--r-- | src/server/SocketServer.hpp | 4 | ||||
-rw-r--r-- | src/server/events/Delta.cpp | 2 | ||||
-rw-r--r-- | src/server/ingen_lv2.cpp | 2 |
8 files changed, 35 insertions, 55 deletions
diff --git a/src/gui/App.cpp b/src/gui/App.cpp index a524220e..3deda1a2 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -148,7 +148,7 @@ App::attach(SPtr<SigClientInterface> client) assert(!_loader); if (_world->engine()) { - _world->engine()->register_client(client->uri(), client); + _world->engine()->register_client(client); } _client = client; diff --git a/src/server/Broadcaster.cpp b/src/server/Broadcaster.cpp index 02ca9518..5f13096b 100644 --- a/src/server/Broadcaster.cpp +++ b/src/server/Broadcaster.cpp @@ -40,11 +40,10 @@ Broadcaster::~Broadcaster() /** Register a client to receive messages over the notification band. */ void -Broadcaster::register_client(const Raul::URI& uri, - SPtr<Interface> client) +Broadcaster::register_client(SPtr<Interface> client) { std::lock_guard<std::mutex> lock(_clients_mutex); - _clients[uri] = client; + _clients.insert(client); } /** Remove a client from the list of registered clients. @@ -52,16 +51,16 @@ Broadcaster::register_client(const Raul::URI& uri, * @return true if client was found and removed. */ bool -Broadcaster::unregister_client(const Raul::URI& uri) +Broadcaster::unregister_client(SPtr<Interface> client) { std::lock_guard<std::mutex> lock(_clients_mutex); - const size_t erased = _clients.erase(uri); - _broadcastees.erase(uri); + const size_t erased = _clients.erase(client); + _broadcastees.erase(client); return (erased > 0); } void -Broadcaster::set_broadcast(const Raul::URI& client, bool broadcast) +Broadcaster::set_broadcast(SPtr<Interface> client, bool broadcast) { if (broadcast) { _broadcastees.insert(client); @@ -71,27 +70,12 @@ Broadcaster::set_broadcast(const Raul::URI& client, bool broadcast) _must_broadcast.store(!_broadcastees.empty()); } -/** Looks up the client with the given source `uri` (which is used as the - * unique identifier for registered clients). - */ -SPtr<Interface> -Broadcaster::client(const Raul::URI& uri) -{ - std::lock_guard<std::mutex> lock(_clients_mutex); - Clients::iterator i = _clients.find(uri); - if (i != _clients.end()) { - return (*i).second; - } else { - return SPtr<Interface>(); - } -} - void Broadcaster::send_plugins(const BlockFactory::Plugins& plugins) { std::lock_guard<std::mutex> lock(_clients_mutex); for (const auto& c : _clients) { - send_plugins_to(c.second.get(), plugins); + send_plugins_to(c.get(), plugins); } } diff --git a/src/server/Broadcaster.hpp b/src/server/Broadcaster.hpp index e33594a4..b610f2a2 100644 --- a/src/server/Broadcaster.hpp +++ b/src/server/Broadcaster.hpp @@ -14,12 +14,11 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef INGEN_ENGINE_CLIENTBROADCASTER_HPP -#define INGEN_ENGINE_CLIENTBROADCASTER_HPP +#ifndef INGEN_ENGINE_BROADCASTER_HPP +#define INGEN_ENGINE_BROADCASTER_HPP #include <atomic> #include <list> -#include <map> #include <mutex> #include <set> #include <string> @@ -45,10 +44,10 @@ public: Broadcaster(); ~Broadcaster(); - void register_client(const Raul::URI& uri, SPtr<Interface> client); - bool unregister_client(const Raul::URI& uri); + void register_client(SPtr<Interface> client); + bool unregister_client(SPtr<Interface> client); - void set_broadcast(const Raul::URI& client, bool broadcast); + void set_broadcast(SPtr<Interface> client, bool broadcast); /** Ignore a client when broadcasting. * @@ -86,16 +85,14 @@ public: Broadcaster& broadcaster; }; - SPtr<Interface> client(const Raul::URI& uri); - void send_plugins(const BlockFactory::Plugins& plugin_list); void send_plugins_to(Interface*, const BlockFactory::Plugins& plugin_list); #define BROADCAST(msg, ...) \ std::lock_guard<std::mutex> lock(_clients_mutex); \ for (const auto& c : _clients) { \ - if (c.second != _ignore_client) { \ - c.second->msg(__VA_ARGS__); \ + if (c != _ignore_client) { \ + c->msg(__VA_ARGS__); \ } \ } \ @@ -160,17 +157,17 @@ public: private: friend class Transfer; - typedef std::map< Raul::URI, SPtr<Interface> > Clients; + typedef std::set<SPtr<Interface>> Clients; - std::mutex _clients_mutex; - Clients _clients; - std::set<Raul::URI> _broadcastees; - std::atomic<bool> _must_broadcast; - unsigned _bundle_depth; - SPtr<Interface> _ignore_client; + std::mutex _clients_mutex; + Clients _clients; + std::set< SPtr<Interface> > _broadcastees; + std::atomic<bool> _must_broadcast; + unsigned _bundle_depth; + SPtr<Interface> _ignore_client; }; } // namespace Server } // namespace Ingen -#endif // INGEN_ENGINE_CLIENTBROADCASTER_HPP +#endif // INGEN_ENGINE_BROADCASTER_HPP diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index c905eed2..b932e2ba 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -386,17 +386,17 @@ Engine::process_events() } void -Engine::register_client(const Raul::URI& uri, SPtr<Interface> client) +Engine::register_client(SPtr<Interface> client) { - log().info(fmt("Registering client <%1%>\n") % uri.c_str()); - _broadcaster->register_client(uri, client); + log().info(fmt("Registering client <%1%>\n") % client->uri().c_str()); + _broadcaster->register_client(client); } bool -Engine::unregister_client(const Raul::URI& uri) +Engine::unregister_client(SPtr<Interface> client) { - log().info(fmt("Unregistering client <%1%>\n") % uri.c_str()); - return _broadcaster->unregister_client(uri); + log().info(fmt("Unregistering client <%1%>\n") % client->uri().c_str()); + return _broadcaster->unregister_client(client); } } // namespace Server diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp index ecc90c9b..1d8b0051 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -75,9 +75,8 @@ public: virtual unsigned run(uint32_t sample_count); virtual void quit(); virtual bool main_iteration(); - virtual void register_client(const Raul::URI& uri, - SPtr<Interface> client); - virtual bool unregister_client(const Raul::URI& uri); + virtual void register_client(SPtr<Interface> client); + virtual bool unregister_client(SPtr<Interface> client); void listen(); diff --git a/src/server/SocketServer.hpp b/src/server/SocketServer.hpp index 5ebcaa6f..a1811334 100644 --- a/src/server/SocketServer.hpp +++ b/src/server/SocketServer.hpp @@ -43,11 +43,11 @@ public: sock)) { set_respondee(_writer); - engine.register_client(_writer->uri(), _writer); + engine.register_client(_writer); } ~SocketServer() { - _engine.unregister_client(_writer->uri()); + _engine.unregister_client(_writer); } private: diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index 02f53410..03a7ccd5 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -269,7 +269,7 @@ Delta::pre_process() } } else if (is_client && key == uris.ingen_broadcast) { _engine.broadcaster()->set_broadcast( - _request_client->uri(), value.get<int32_t>()); + _request_client, value.get<int32_t>()); } if (_status != Status::NOT_PREPARED) { diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index 065f42ac..23e65108 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -604,7 +604,7 @@ ingen_instantiate(const LV2_Descriptor* descriptor, Since we are not yet rolling, it won't be drained, causing a deadlock. */ SPtr<Interface> client(&driver->writer(), NullDeleter<Interface>); interface->set_respondee(client); - engine->register_client(Raul::URI("ingen:/clients/lv2"), client); + engine->register_client(client); return (LV2_Handle)plugin; } |