summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-02-09 21:37:31 +0000
committerDavid Robillard <d@drobilla.net>2015-02-09 21:37:31 +0000
commit9cde188fcb8cc7ff30f28ec898d72ce1575496ca (patch)
tree61fa3c3b5bb85428501868a6d2764b655db35ba2
parent971a4e484757c083c9daa68a4a3e235a549ab523 (diff)
downloadingen-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
-rw-r--r--ingen/EngineBase.hpp5
-rw-r--r--src/gui/App.cpp2
-rw-r--r--src/server/Broadcaster.cpp30
-rw-r--r--src/server/Broadcaster.hpp33
-rw-r--r--src/server/Engine.cpp12
-rw-r--r--src/server/Engine.hpp5
-rw-r--r--src/server/SocketServer.hpp4
-rw-r--r--src/server/events/Delta.cpp2
-rw-r--r--src/server/ingen_lv2.cpp2
-rw-r--r--tests/ingen_test.cpp3
10 files changed, 38 insertions, 60 deletions
diff --git a/ingen/EngineBase.hpp b/ingen/EngineBase.hpp
index ec6cee89..1b44e89d 100644
--- a/ingen/EngineBase.hpp
+++ b/ingen/EngineBase.hpp
@@ -99,13 +99,12 @@ public:
/**
Register a client to receive updates about engine changes.
*/
- virtual void register_client(const Raul::URI& uri,
- SPtr<Interface> client) = 0;
+ virtual void register_client(SPtr<Interface> client) = 0;
/**
Unregister a client.
*/
- virtual bool unregister_client(const Raul::URI& uri) = 0;
+ virtual bool unregister_client(SPtr<Interface> client) = 0;
};
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;
}
diff --git a/tests/ingen_test.cpp b/tests/ingen_test.cpp
index 28b60da7..13ae62f7 100644
--- a/tests/ingen_test.cpp
+++ b/tests/ingen_test.cpp
@@ -191,8 +191,7 @@ main(int argc, char** argv)
SPtr<Interface> client(new TestClient(world->log()));
world->interface()->set_respondee(client);
- world->engine()->register_client(Raul::URI("ingen:/clients/test"),
- client);
+ world->engine()->register_client(client);
SerdURI cmds_base;
SerdNode cmds_file_uri = serd_node_new_file_uri(