diff options
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/Broadcaster.hpp | 16 | ||||
-rw-r--r-- | src/server/EventWriter.cpp | 8 | ||||
-rw-r--r-- | src/server/events/Delta.cpp | 23 | ||||
-rw-r--r-- | src/server/events/Delta.hpp | 10 |
4 files changed, 44 insertions, 13 deletions
diff --git a/src/server/Broadcaster.hpp b/src/server/Broadcaster.hpp index 069a0499..b9e37c44 100644 --- a/src/server/Broadcaster.hpp +++ b/src/server/Broadcaster.hpp @@ -50,6 +50,14 @@ public: void set_broadcast(const Raul::URI& client, bool broadcast); + /** Ignore a client when broadcasting. + * + * This is used to prevent feeding back updates to the client that + * initiated a property set in the first place. + */ + void set_ignore_client(SPtr<Interface> client) { _ignore_client = client; } + void clear_ignore_client() { _ignore_client.reset(); } + /** Return true iff there are any clients with broadcasting enabled. * * This is used in the audio thread to decide whether or not notifications @@ -85,8 +93,11 @@ public: #define BROADCAST(msg, ...) \ std::lock_guard<std::mutex> lock(_clients_mutex); \ - for (const auto& c : _clients) \ - c.second->msg(__VA_ARGS__) + for (const auto& c : _clients) { \ + if (c.second != _ignore_client) { \ + c.second->msg(__VA_ARGS__); \ + } \ + } \ void bundle_begin() { BROADCAST(bundle_begin); } void bundle_end() { BROADCAST(bundle_end); } @@ -151,6 +162,7 @@ private: std::set<Raul::URI> _broadcastees; std::atomic<bool> _must_broadcast; unsigned _bundle_depth; + SPtr<Interface> _ignore_client; }; } // namespace Server diff --git a/src/server/EventWriter.cpp b/src/server/EventWriter.cpp index 96814ed2..60096d85 100644 --- a/src/server/EventWriter.cpp +++ b/src/server/EventWriter.cpp @@ -54,7 +54,7 @@ EventWriter::put(const Raul::URI& uri, { _engine.enqueue_event( new Events::Delta(_engine, _respondee, _request_id, now(), - true, ctx, uri, properties)); + Events::Delta::Type::PUT, ctx, uri, properties)); } void @@ -64,7 +64,8 @@ EventWriter::delta(const Raul::URI& uri, { _engine.enqueue_event( new Events::Delta(_engine, _respondee, _request_id, now(), - false, Resource::Graph::DEFAULT, uri, add, remove)); + Events::Delta::Type::PATCH, Resource::Graph::DEFAULT, + uri, add, remove)); } void @@ -124,7 +125,8 @@ EventWriter::set_property(const Raul::URI& uri, add.insert(make_pair(predicate, value)); _engine.enqueue_event( new Events::Delta(_engine, _respondee, _request_id, now(), - false, Resource::Graph::DEFAULT, uri, add, remove)); + Events::Delta::Type::SET, Resource::Graph::DEFAULT, + uri, add, remove)); } void diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index 90baaa52..6fd14fd5 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -48,7 +48,7 @@ Delta::Delta(Engine& engine, SPtr<Interface> client, int32_t id, SampleCount timestamp, - bool create, + Type type, Resource::Graph context, const Raul::URI& subject, const Properties& properties, @@ -62,7 +62,7 @@ Delta::Delta(Engine& engine, , _graph(NULL) , _compiled_graph(NULL) , _context(context) - , _create(create) + , _type(type) , _poly_lock(engine.store()->lock(), Glib::NOT_LOCK) { if (context != Resource::Graph::DEFAULT) { @@ -113,7 +113,7 @@ Delta::pre_process() ? static_cast<Ingen::Resource*>(_engine.store()->get(Node::uri_to_path(_subject))) : static_cast<Ingen::Resource*>(_engine.block_factory()->plugin(_subject)); - if (!_object && !is_client && (!is_graph_object || !_create)) { + if (!_object && !is_client && (!is_graph_object || _type != Type::PUT)) { return Event::pre_process_done(Status::NOT_FOUND, _subject); } @@ -163,7 +163,7 @@ Delta::pre_process() } // Remove all added properties if this is a put - if (_create && _object) { + if (_type == Type::PUT && _object) { for (const auto& p : _properties) { _object->remove_property(p.first, p.second); } @@ -381,11 +381,22 @@ Delta::post_process() _create_event->post_process(); } else { respond(); - if (_create) { + _engine.broadcaster()->set_ignore_client(_request_client); + switch (_type) { + case Type::SET: + _engine.broadcaster()->set_property( + _subject, + (*_properties.begin()).first, + (*_properties.begin()).second); + break; + case Type::PUT: _engine.broadcaster()->put(_subject, _properties, _context); - } else { + break; + case Type::PATCH: _engine.broadcaster()->delta(_subject, _remove, _properties); + break; } + _engine.broadcaster()->clear_ignore_client(); } } else { respond(); diff --git a/src/server/events/Delta.hpp b/src/server/events/Delta.hpp index 451b8e62..a8e8ed0b 100644 --- a/src/server/events/Delta.hpp +++ b/src/server/events/Delta.hpp @@ -69,11 +69,17 @@ class SetPortValue; class Delta : public Event { public: + enum class Type { + SET, + PUT, + PATCH + }; + Delta(Engine& engine, SPtr<Interface> client, int32_t id, SampleCount timestamp, - bool create, + Type type, Resource::Graph context, const Raul::URI& subject, const Resource::Properties& properties, @@ -109,7 +115,7 @@ private: CompiledGraph* _compiled_graph; Resource::Graph _context; ControlBindings::Key _binding; - bool _create; + Type _type; SPtr<ControlBindings::Bindings> _old_bindings; |