summaryrefslogtreecommitdiffstats
path: root/src/server/ClientUpdate.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-10-30 17:02:07 +0000
committerDavid Robillard <d@drobilla.net>2015-10-30 17:02:07 +0000
commit8510f80faad7a719a97cf14b1a82a1cc2141282b (patch)
tree11ab0ede29a4a2e29d1e689f6b2cb23ee0da47f1 /src/server/ClientUpdate.cpp
parent2fe35cd17f96a1d393fda203ccaa234b0aa69b16 (diff)
downloadingen-8510f80faad7a719a97cf14b1a82a1cc2141282b.tar.gz
ingen-8510f80faad7a719a97cf14b1a82a1cc2141282b.tar.bz2
ingen-8510f80faad7a719a97cf14b1a82a1cc2141282b.zip
Update clients when plugins are unloaded/reloaded
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5808 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/server/ClientUpdate.cpp')
-rw-r--r--src/server/ClientUpdate.cpp155
1 files changed, 155 insertions, 0 deletions
diff --git a/src/server/ClientUpdate.cpp b/src/server/ClientUpdate.cpp
new file mode 100644
index 00000000..217d3a32
--- /dev/null
+++ b/src/server/ClientUpdate.cpp
@@ -0,0 +1,155 @@
+/*
+ This file is part of Ingen.
+ Copyright 2007-2015 David Robillard <http://drobilla.net/>
+
+ Ingen is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or any later version.
+
+ Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with Ingen. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "ingen/Interface.hpp"
+#include "ingen/URIs.hpp"
+
+#include "BlockImpl.hpp"
+#include "BufferFactory.hpp"
+#include "ClientUpdate.hpp"
+#include "GraphImpl.hpp"
+#include "PortImpl.hpp"
+
+namespace Ingen {
+namespace Server {
+
+void
+ClientUpdate::put(const Raul::URI& uri,
+ const Resource::Properties& props,
+ Resource::Graph ctx)
+{
+ const ClientUpdate::Put put = { uri, props, ctx };
+ puts.push_back(put);
+}
+
+void
+ClientUpdate::put_port(const PortImpl* port)
+{
+ const URIs& uris = port->bufs().uris();
+ if (port->is_a(PortType::CONTROL) || port->is_a(PortType::CV)) {
+ Resource::Properties props = port->properties();
+ props.erase(uris.ingen_value);
+ props.insert(std::make_pair(uris.ingen_value, port->value()));
+ put(port->uri(), props);
+ } else {
+ put(port->uri(), port->properties());
+ }
+}
+
+void
+ClientUpdate::put_block(const BlockImpl* block)
+{
+ const PluginImpl* const plugin = block->plugin_impl();
+ const URIs& uris = plugin->uris();
+
+ if (uris.ingen_Graph == plugin->type()) {
+ put_graph((const GraphImpl*)block);
+ } else {
+ put(block->uri(), block->properties());
+ for (size_t j = 0; j < block->num_ports(); ++j) {
+ put_port(block->port_impl(j));
+ }
+ }
+}
+
+void
+ClientUpdate::put_graph(const GraphImpl* graph)
+{
+ put(graph->uri(),
+ graph->properties(Resource::Graph::INTERNAL),
+ Resource::Graph::INTERNAL);
+
+ put(graph->uri(),
+ graph->properties(Resource::Graph::EXTERNAL),
+ Resource::Graph::EXTERNAL);
+
+ // Enqueue blocks
+ for (const auto& b : graph->blocks()) {
+ put_block(&b);
+ }
+
+ // Enqueue ports
+ for (uint32_t i = 0; i < graph->num_ports_non_rt(); ++i) {
+ put_port(graph->port_impl(i));
+ }
+
+ // Enqueue arcs
+ for (const auto& a : graph->arcs()) {
+ const SPtr<const Arc> arc = a.second;
+ const Connect connect = { arc->tail_path(), arc->head_path() };
+ connects.push_back(connect);
+ }
+}
+
+void
+ClientUpdate::put_plugin(PluginImpl* plugin)
+{
+ put(plugin->uri(), plugin->properties());
+
+ for (const auto& p : plugin->presets()) {
+ put_preset(plugin->uris(), plugin->uri(), p.first, p.second);
+ }
+}
+
+void
+ClientUpdate::put_preset(const URIs& uris,
+ const Raul::URI& plugin,
+ const Raul::URI& preset,
+ const std::string& label)
+{
+ Resource::Properties props{
+ { uris.rdf_type, uris.pset_Preset.urid },
+ { uris.rdfs_label, uris.forge.alloc(label) },
+ { uris.lv2_appliesTo, uris.forge.make_urid(plugin) }};
+ put(preset, props);
+}
+
+void
+ClientUpdate::del(const Raul::URI& subject)
+{
+ dels.push_back(subject);
+}
+
+/** Returns true if a is closer to the root than b. */
+static inline bool
+put_higher_than(const ClientUpdate::Put& a, const ClientUpdate::Put& b)
+{
+ return (std::count(a.uri.begin(), a.uri.end(), '/') <
+ std::count(b.uri.begin(), b.uri.end(), '/'));
+}
+
+void
+ClientUpdate::send(Interface* dest)
+{
+ // Send deletions
+ for (const Raul::URI& subject : dels) {
+ dest->del(subject);
+ }
+
+ // Send puts in increasing depth order so parents are sent first
+ std::stable_sort(puts.begin(), puts.end(), put_higher_than);
+ for (const ClientUpdate::Put& put : puts) {
+ dest->put(put.uri, put.properties, put.ctx);
+ }
+
+ // Send connections
+ for (const ClientUpdate::Connect& connect : connects) {
+ dest->connect(connect.tail, connect.head);
+ }
+}
+
+} // namespace Server
+} // namespace Ingen