From 7513e0b53a36e96b9e1fa1884b78077a95da3081 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 16 Dec 2017 17:57:49 +0100 Subject: Add Message struct and remove tons of interface boilerplate --- src/AtomWriter.cpp | 106 ++++++++++++++++++++++----------------------- src/client/ClientStore.cpp | 104 ++++++++++++++++++++------------------------ src/gui/App.cpp | 42 ++++++++---------- src/gui/App.hpp | 3 ++ src/gui/BreadCrumbs.cpp | 12 ++++- src/gui/BreadCrumbs.hpp | 1 + src/gui/ConnectWindow.cpp | 15 ++++++- src/gui/ConnectWindow.hpp | 2 + src/server/Broadcaster.hpp | 71 +++--------------------------- src/server/EventWriter.cpp | 71 ++++++++++++++---------------- src/server/EventWriter.hpp | 62 ++++++++------------------ 11 files changed, 204 insertions(+), 285 deletions(-) (limited to 'src') diff --git a/src/AtomWriter.cpp b/src/AtomWriter.cpp index 54dcd0a2..1615630f 100644 --- a/src/AtomWriter.cpp +++ b/src/AtomWriter.cpp @@ -51,6 +51,8 @@ #include #include +#include + #include "ingen/AtomSink.hpp" #include "ingen/AtomWriter.hpp" #include "ingen/Node.hpp" @@ -82,6 +84,12 @@ AtomWriter::finish_msg() _out.clear(); } +void +AtomWriter::message(const Message& message) +{ + boost::apply_visitor(*this, message); +} + /** @page protocol * @subsection Bundles * @@ -101,7 +109,7 @@ AtomWriter::finish_msg() * @endcode */ void -AtomWriter::bundle_begin() +AtomWriter::operator()(const BundleBegin&) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.ingen_BundleStart); @@ -110,7 +118,7 @@ AtomWriter::bundle_begin() } void -AtomWriter::bundle_end() +AtomWriter::operator()(const BundleEnd&) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.ingen_BundleEnd); @@ -206,20 +214,18 @@ AtomWriter::forge_context(Resource::Graph ctx) * @endcode */ void -AtomWriter::put(const Raul::URI& uri, - const Properties& properties, - Resource::Graph ctx) +AtomWriter::operator()(const Put& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Put); - forge_context(ctx); + forge_context(message.ctx); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(uri); + forge_uri(message.uri); lv2_atom_forge_key(&_forge, _uris.patch_body); LV2_Atom_Forge_Frame body; lv2_atom_forge_object(&_forge, &body, 0, 0); - forge_properties(properties); + forge_properties(message.properties); lv2_atom_forge_pop(&_forge, &body); lv2_atom_forge_pop(&_forge, &msg); @@ -253,27 +259,24 @@ AtomWriter::put(const Raul::URI& uri, * @endcode */ void -AtomWriter::delta(const Raul::URI& uri, - const Properties& remove, - const Properties& add, - Resource::Graph ctx) +AtomWriter::operator()(const Delta& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Patch); - forge_context(ctx); + forge_context(message.ctx); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(uri); + forge_uri(message.uri); lv2_atom_forge_key(&_forge, _uris.patch_remove); LV2_Atom_Forge_Frame remove_obj; lv2_atom_forge_object(&_forge, &remove_obj, 0, 0); - forge_properties(remove); + forge_properties(message.remove); lv2_atom_forge_pop(&_forge, &remove_obj); lv2_atom_forge_key(&_forge, _uris.patch_add); LV2_Atom_Forge_Frame add_obj; lv2_atom_forge_object(&_forge, &add_obj, 0, 0); - forge_properties(add); + forge_properties(message.add); lv2_atom_forge_pop(&_forge, &add_obj); lv2_atom_forge_pop(&_forge, &msg); @@ -304,15 +307,14 @@ AtomWriter::delta(const Raul::URI& uri, * @endcode */ void -AtomWriter::copy(const Raul::URI& old_uri, - const Raul::URI& new_uri) +AtomWriter::operator()(const Copy& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Copy); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(old_uri); + forge_uri(message.old_uri); lv2_atom_forge_key(&_forge, _uris.patch_destination); - forge_uri(new_uri); + forge_uri(message.new_uri); lv2_atom_forge_pop(&_forge, &msg); finish_msg(); } @@ -334,15 +336,14 @@ AtomWriter::copy(const Raul::URI& old_uri, * @endcode */ void -AtomWriter::move(const Raul::Path& old_path, - const Raul::Path& new_path) +AtomWriter::operator()(const Move& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Move); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(path_to_uri(old_path)); + forge_uri(path_to_uri(message.old_path)); lv2_atom_forge_key(&_forge, _uris.patch_destination); - forge_uri(path_to_uri(new_path)); + forge_uri(path_to_uri(message.new_path)); lv2_atom_forge_pop(&_forge, &msg); finish_msg(); } @@ -363,12 +364,12 @@ AtomWriter::move(const Raul::Path& old_path, * @endcode */ void -AtomWriter::del(const Raul::URI& uri) +AtomWriter::operator()(const Del& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Delete); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(uri); + forge_uri(message.uri); lv2_atom_forge_pop(&_forge, &msg); finish_msg(); } @@ -388,21 +389,18 @@ AtomWriter::del(const Raul::URI& uri) * @endcode */ void -AtomWriter::set_property(const Raul::URI& subject, - const Raul::URI& predicate, - const Atom& value, - Resource::Graph ctx) +AtomWriter::operator()(const SetProperty& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Set); - forge_context(ctx); + forge_context(message.ctx); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(subject); + forge_uri(message.subject); lv2_atom_forge_key(&_forge, _uris.patch_property); - lv2_atom_forge_urid(&_forge, _map.map_uri(predicate.c_str())); + lv2_atom_forge_urid(&_forge, _map.map_uri(message.predicate.c_str())); lv2_atom_forge_key(&_forge, _uris.patch_value); - lv2_atom_forge_atom(&_forge, value.size(), value.type()); - lv2_atom_forge_write(&_forge, value.get_body(), value.size()); + lv2_atom_forge_atom(&_forge, message.value.size(), message.value.type()); + lv2_atom_forge_write(&_forge, message.value.get_body(), message.value.size()); lv2_atom_forge_pop(&_forge, &msg); finish_msg(); @@ -421,7 +419,7 @@ AtomWriter::set_property(const Raul::URI& subject, * @endcode */ void -AtomWriter::undo() +AtomWriter::operator()(const Undo&) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.ingen_Undo); @@ -439,7 +437,7 @@ AtomWriter::undo() * @endcode */ void -AtomWriter::redo() +AtomWriter::operator()(const Redo&) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.ingen_Redo); @@ -460,12 +458,12 @@ AtomWriter::redo() * @endcode */ void -AtomWriter::get(const Raul::URI& uri) +AtomWriter::operator()(const Get& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Get); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(uri); + forge_uri(message.subject); lv2_atom_forge_pop(&_forge, &msg); finish_msg(); } @@ -494,15 +492,14 @@ AtomWriter::get(const Raul::URI& uri) * @endcode */ void -AtomWriter::connect(const Raul::Path& tail, - const Raul::Path& head) +AtomWriter::operator()(const Connect& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Put); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(path_to_uri(Raul::Path::lca(tail, head))); + forge_uri(path_to_uri(Raul::Path::lca(message.tail, message.head))); lv2_atom_forge_key(&_forge, _uris.patch_body); - forge_arc(tail, head); + forge_arc(message.tail, message.head); lv2_atom_forge_pop(&_forge, &msg); finish_msg(); } @@ -524,13 +521,12 @@ AtomWriter::connect(const Raul::Path& tail, * @endcode */ void -AtomWriter::disconnect(const Raul::Path& tail, - const Raul::Path& head) +AtomWriter::operator()(const Disconnect& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Delete); lv2_atom_forge_key(&_forge, _uris.patch_body); - forge_arc(tail, head); + forge_arc(message.tail, message.head); lv2_atom_forge_pop(&_forge, &msg); finish_msg(); } @@ -554,20 +550,19 @@ AtomWriter::disconnect(const Raul::Path& tail, * @endcode */ void -AtomWriter::disconnect_all(const Raul::Path& graph, - const Raul::Path& path) +AtomWriter::operator()(const DisconnectAll& message) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Delete); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(path_to_uri(graph)); + forge_uri(path_to_uri(message.graph)); lv2_atom_forge_key(&_forge, _uris.patch_body); LV2_Atom_Forge_Frame arc; lv2_atom_forge_object(&_forge, &arc, 0, _uris.ingen_Arc); lv2_atom_forge_key(&_forge, _uris.ingen_incidentTo); - forge_uri(path_to_uri(path)); + forge_uri(path_to_uri(message.path)); lv2_atom_forge_pop(&_forge, &arc); lv2_atom_forge_pop(&_forge, &msg); @@ -612,28 +607,29 @@ AtomWriter::set_response_id(int32_t id) * following the response. */ void -AtomWriter::response(int32_t id, Status status, const std::string& subject) +AtomWriter::operator()(const Response& response) { - if (!id) { + const auto& subject = response.subject; + if (!response.id) { return; } LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Response); lv2_atom_forge_key(&_forge, _uris.patch_sequenceNumber); - lv2_atom_forge_int(&_forge, id); + lv2_atom_forge_int(&_forge, response.id); if (!subject.empty() && Raul::URI::is_valid(subject)) { lv2_atom_forge_key(&_forge, _uris.patch_subject); lv2_atom_forge_uri(&_forge, subject.c_str(), subject.length()); } lv2_atom_forge_key(&_forge, _uris.patch_body); - lv2_atom_forge_int(&_forge, static_cast(status)); + lv2_atom_forge_int(&_forge, static_cast(response.status)); lv2_atom_forge_pop(&_forge, &msg); finish_msg(); } void -AtomWriter::error(const std::string& msg) +AtomWriter::operator()(const Error&) { } diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index a622068c..a7bd1274 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -14,6 +14,8 @@ along with Ingen. If not, see . */ +#include + #include "ingen/Log.hpp" #include "ingen/client/ArcModel.hpp" #include "ingen/client/BlockModel.hpp" @@ -37,21 +39,10 @@ ClientStore::ClientStore(URIs& uris, , _emitter(emitter) , _plugins(new Plugins()) { - if (!emitter) - return; - -#define CONNECT(signal, method) \ - emitter->signal_##signal().connect( \ - sigc::mem_fun(this, &ClientStore::method)); - - CONNECT(object_deleted, del); - CONNECT(object_moved, move); - CONNECT(put, put); - CONNECT(delta, delta); - CONNECT(connection, connect); - CONNECT(disconnection, disconnect); - CONNECT(disconnect_all, disconnect_all); - CONNECT(property_change, set_property); + if (emitter) { + emitter->signal_message().connect( + sigc::mem_fun(this, &ClientStore::message)); + } } void @@ -207,42 +198,48 @@ ClientStore::add_plugin(SPtr pm) /* ****** Signal Handlers ******** */ void -ClientStore::del(const Raul::URI& uri) +ClientStore::operator()(const Del& del) { - if (uri_is_path(uri)) { - remove_object(uri_to_path(uri)); + if (uri_is_path(del.uri)) { + remove_object(uri_to_path(del.uri)); } else { - Plugins::iterator p = _plugins->find(uri); + Plugins::iterator p = _plugins->find(del.uri); if (p != _plugins->end()) { _plugins->erase(p); - _signal_plugin_deleted.emit(uri); + _signal_plugin_deleted.emit(del.uri); } } } void -ClientStore::copy(const Raul::URI& old_uri, - const Raul::URI& new_uri) +ClientStore::operator()(const Copy&) { _log.error("Client store copy unsupported\n"); } void -ClientStore::move(const Raul::Path& old_path, const Raul::Path& new_path) +ClientStore::operator()(const Move& msg) { - const iterator top = find(old_path); + const iterator top = find(msg.old_path); if (top != end()) { - rename(top, new_path); + rename(top, msg.new_path); } } void -ClientStore::put(const Raul::URI& uri, - const Properties& properties, - Resource::Graph ctx) +ClientStore::message(const Message& msg) +{ + boost::apply_visitor(*this, msg); +} + +void +ClientStore::operator()(const Put& msg) { typedef Properties::const_iterator Iterator; + const auto& uri = msg.uri; + const auto& properties = msg.properties; + bool is_graph, is_block, is_port, is_output; Resource::type(uris(), properties, is_graph, is_block, is_port, is_output); @@ -340,11 +337,9 @@ ClientStore::put(const Raul::URI& uri, } void -ClientStore::delta(const Raul::URI& uri, - const Properties& remove, - const Properties& add, - Resource::Graph ctx) +ClientStore::operator()(const Delta& msg) { + const auto& uri = msg.uri; if (uri == Raul::URI("ingen:/clients/this")) { // Client property, which we don't store (yet?) return; @@ -360,20 +355,20 @@ ClientStore::delta(const Raul::URI& uri, SPtr obj = _object(path); if (obj) { - obj->remove_properties(remove); - obj->add_properties(add); + obj->remove_properties(msg.remove); + obj->add_properties(msg.add); } else { - _log.warn(fmt("Failed to find object `%1%'\n") - % path.c_str()); + _log.warn(fmt("Failed to find object `%1%'\n") % path.c_str()); } } void -ClientStore::set_property(const Raul::URI& subject_uri, - const Raul::URI& predicate, - const Atom& value, - Resource::Graph ctx) +ClientStore::operator()(const SetProperty& msg) { + const auto& subject_uri = msg.subject; + const auto& predicate = msg.predicate; + const auto& value = msg.value; + if (subject_uri == Raul::URI("ingen:/engine")) { _log.info(fmt("Engine property <%1%> = %2%\n") % predicate.c_str() % _uris.forge.str(value, false)); @@ -386,7 +381,7 @@ ClientStore::set_property(const Raul::URI& subject_uri, blinkenlights) but do not store the property. */ subject->on_property(predicate, value); } else { - subject->set_property(predicate, value, ctx); + subject->set_property(predicate, value, msg.ctx); } } else { SPtr plugin = _plugin(subject_uri); @@ -444,33 +439,30 @@ ClientStore::attempt_connection(const Raul::Path& tail_path, } void -ClientStore::connect(const Raul::Path& src_path, - const Raul::Path& dst_path) +ClientStore::operator()(const Connect& msg) { - attempt_connection(src_path, dst_path); + attempt_connection(msg.tail, msg.head); } void -ClientStore::disconnect(const Raul::Path& src_path, - const Raul::Path& dst_path) +ClientStore::operator()(const Disconnect& msg) { - SPtr tail = dynamic_ptr_cast(_object(src_path)); - SPtr head = dynamic_ptr_cast(_object(dst_path)); - SPtr graph = connection_graph(src_path, dst_path); + SPtr tail = dynamic_ptr_cast(_object(msg.tail)); + SPtr head = dynamic_ptr_cast(_object(msg.head)); + SPtr graph = connection_graph(msg.tail, msg.head); if (graph) graph->remove_arc(tail.get(), head.get()); } void -ClientStore::disconnect_all(const Raul::Path& parent_graph, - const Raul::Path& path) +ClientStore::operator()(const DisconnectAll& msg) { - SPtr graph = dynamic_ptr_cast(_object(parent_graph)); - SPtr object = _object(path); + SPtr graph = dynamic_ptr_cast(_object(msg.graph)); + SPtr object = _object(msg.path); if (!graph || !object) { _log.error(fmt("Bad disconnect all notification %1% in %2%\n") - % path % parent_graph); + % msg.path % msg.graph); return; } @@ -479,8 +471,8 @@ ClientStore::disconnect_all(const Raul::Path& parent_graph, SPtr arc = dynamic_ptr_cast(a.second); if (arc->tail()->parent() == object || arc->head()->parent() == object - || arc->tail()->path() == path - || arc->head()->path() == path) { + || arc->tail()->path() == msg.path + || arc->head()->path() == msg.path) { graph->remove_arc(arc->tail().get(), arc->head().get()); } } diff --git a/src/gui/App.cpp b/src/gui/App.cpp index 15bdc796..789ead6d 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -180,32 +180,12 @@ App::attach(SPtr client) stderr, ColorContext::Color::CYAN)); -#define DUMP_CONNECT(signal, method) \ - client->signal_##signal().connect( \ - sigc::mem_fun(*_dumper.get(), &StreamWriter::method)); - - DUMP_CONNECT(object_deleted, del); - DUMP_CONNECT(object_moved, move); - DUMP_CONNECT(put, put); - DUMP_CONNECT(delta, delta); - DUMP_CONNECT(connection, connect); - DUMP_CONNECT(disconnection, disconnect); - DUMP_CONNECT(disconnect_all, disconnect_all); - DUMP_CONNECT(property_change, set_property); - -#undef DUMP_CONNECT + client->signal_message().connect( + sigc::mem_fun(*_dumper.get(), &StreamWriter::message)); } _graph_tree_window->init(*this, *_store); - - _client->signal_response().connect( - sigc::mem_fun(this, &App::response)); - _client->signal_error().connect( - sigc::mem_fun(this, &App::error_message)); - _client->signal_put().connect( - sigc::mem_fun(this, &App::put)); - _client->signal_property_change().connect( - sigc::mem_fun(this, &App::property_change)); + _client->signal_message().connect(sigc::mem_fun(this, &App::message)); } void @@ -237,6 +217,20 @@ App::serialiser() return _world->serialiser(); } +void +App::message(const Message& msg) +{ + if (const Response* const r = boost::get(&msg)) { + response(r->id, r->status, r->subject); + } else if (const Error* const e = boost::get(&msg)) { + error_message(e->message); + } else if (const Put* const p = boost::get(&msg)) { + put(p->uri, p->properties, p->ctx); + } else if (const SetProperty* const s = boost::get(&msg)) { + property_change(s->subject, s->predicate, s->value, s->ctx); + } +} + void App::response(int32_t id, Status status, const std::string& subject) { @@ -269,7 +263,7 @@ App::set_property(const Raul::URI& subject, went as planned here and fire the signal ourselves as if the server feedback came back immediately. */ if (key != uris().ingen_activity) { - _client->signal_property_change().emit(subject, key, value, ctx); + _client->signal_message().emit(SetProperty{subject, key, value, ctx}); } } diff --git a/src/gui/App.hpp b/src/gui/App.hpp index 6dcab171..e226751b 100644 --- a/src/gui/App.hpp +++ b/src/gui/App.hpp @@ -25,6 +25,7 @@ #include #include "ingen/Atom.hpp" +#include "ingen/Message.hpp" #include "ingen/Resource.hpp" #include "ingen/Status.hpp" #include "ingen/World.hpp" @@ -141,6 +142,8 @@ public: protected: explicit App(Ingen::World* world); + void message(const Ingen::Message& msg); + bool animate(); void response(int32_t id, Ingen::Status status, const std::string& subject); diff --git a/src/gui/BreadCrumbs.cpp b/src/gui/BreadCrumbs.cpp index 447b06ba..c62a1e06 100644 --- a/src/gui/BreadCrumbs.cpp +++ b/src/gui/BreadCrumbs.cpp @@ -33,8 +33,8 @@ BreadCrumbs::BreadCrumbs(App& app) , _full_path("/") , _enable_signal(true) { - app.client()->signal_object_deleted().connect( - sigc::mem_fun(this, &BreadCrumbs::object_destroyed)); + app.client()->signal_message().connect( + sigc::mem_fun(this, &BreadCrumbs::message)); set_can_focus(false); } @@ -179,6 +179,14 @@ BreadCrumbs::breadcrumb_clicked(BreadCrumb* crumb) } } +void +BreadCrumbs::message(const Message& msg) +{ + if (const Del* const del = boost::get(&msg)) { + object_destroyed(del->uri); + } +} + void BreadCrumbs::object_destroyed(const Raul::URI& uri) { diff --git a/src/gui/BreadCrumbs.hpp b/src/gui/BreadCrumbs.hpp index e58b2c0f..22bbd7af 100644 --- a/src/gui/BreadCrumbs.hpp +++ b/src/gui/BreadCrumbs.hpp @@ -103,6 +103,7 @@ private: void breadcrumb_clicked(BreadCrumb* crumb); + void message(const Message& msg); void object_destroyed(const Raul::URI& uri); void object_moved(const Raul::Path& old_path, const Raul::Path& new_path); diff --git a/src/gui/ConnectWindow.cpp b/src/gui/ConnectWindow.cpp index 0b4ea298..635df134 100644 --- a/src/gui/ConnectWindow.cpp +++ b/src/gui/ConnectWindow.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include "raul/Process.hpp" @@ -73,6 +74,16 @@ ConnectWindow::ConnectWindow(BaseObjectType* cobject, { } +void +ConnectWindow::message(const Message& msg) +{ + if (const Response* const r = boost::get(&msg)) { + ingen_response(r->id, r->status, r->subject); + } else if (const Error* const e = boost::get(&msg)) { + error(e->message); + } +} + void ConnectWindow::error(const std::string& msg) { @@ -477,8 +488,8 @@ ConnectWindow::gtk_callback() } } else if (_connect_stage == 1) { _attached = false; - _app->client()->signal_response().connect( - sigc::mem_fun(this, &ConnectWindow::ingen_response)); + _app->client()->signal_message().connect( + sigc::mem_fun(this, &ConnectWindow::message)); _ping_id = g_random_int_range(1, std::numeric_limits::max()); _app->interface()->set_response_id(_ping_id); diff --git a/src/gui/ConnectWindow.hpp b/src/gui/ConnectWindow.hpp index 5b68c597..560bd82b 100644 --- a/src/gui/ConnectWindow.hpp +++ b/src/gui/ConnectWindow.hpp @@ -58,6 +58,8 @@ public: private: enum class Mode { CONNECT_REMOTE, LAUNCH_REMOTE, INTERNAL }; + void message(const Message& message); + void error(const std::string& msg); void ingen_response(int32_t id, Status status, const std::string& subject); diff --git a/src/server/Broadcaster.hpp b/src/server/Broadcaster.hpp index fd8d3996..6fcb3e4d 100644 --- a/src/server/Broadcaster.hpp +++ b/src/server/Broadcaster.hpp @@ -88,75 +88,18 @@ public: void send_plugins(const BlockFactory::Plugins& plugin_list); void send_plugins_to(Interface*, const BlockFactory::Plugins& plugin_list); -#define BROADCAST(msg, ...) \ - std::lock_guard lock(_clients_mutex); \ - for (const auto& c : _clients) { \ - if (c != _ignore_client) { \ - c->msg(__VA_ARGS__); \ - } \ - } \ - - void bundle_begin() { BROADCAST(bundle_begin); } - void bundle_end() { BROADCAST(bundle_end); } - - void put(const Raul::URI& uri, - const Properties& properties, - Resource::Graph ctx = Resource::Graph::DEFAULT) { - BROADCAST(put, uri, properties, ctx); - } - - void delta(const Raul::URI& uri, - const Properties& remove, - const Properties& add, - Resource::Graph ctx = Resource::Graph::DEFAULT) { - BROADCAST(delta, uri, remove, add, ctx); - } - - void copy(const Raul::URI& old_uri, - const Raul::URI& new_uri) { - BROADCAST(copy, old_uri, new_uri); - } - - void move(const Raul::Path& old_path, - const Raul::Path& new_path) { - BROADCAST(move, old_path, new_path); - } - - void del(const Raul::URI& uri) { - BROADCAST(del, uri); - } - - void connect(const Raul::Path& tail, - const Raul::Path& head) { - BROADCAST(connect, tail, head); - } - - void disconnect(const Raul::Path& tail, - const Raul::Path& head) { - BROADCAST(disconnect, tail, head); - } - - void disconnect_all(const Raul::Path& graph, - const Raul::Path& path) { - BROADCAST(disconnect_all, graph, path); - } - - void set_property(const Raul::URI& subject, - const Raul::URI& predicate, - const Atom& value, - Resource::Graph ctx = Resource::Graph::DEFAULT) { - BROADCAST(set_property, subject, predicate, value, ctx); + void message(const Message& msg) override { + std::lock_guard lock(_clients_mutex); + for (const auto& c : _clients) { + if (c != _ignore_client) { + c->message(msg); + } + } } Raul::URI uri() const { return Raul::URI("ingen:/broadcaster"); } - void undo() {} ///< N/A - void redo() {} ///< N/A void set_response_id(int32_t id) {} ///< N/A - void get(const Raul::URI& uri) {} ///< N/A - void response(int32_t id, Status status, const std::string& subject) {} ///< N/A - - void error(const std::string& msg) { BROADCAST(error, msg); } private: friend class Transfer; diff --git a/src/server/EventWriter.cpp b/src/server/EventWriter.cpp index 28a8d319..56ba439c 100644 --- a/src/server/EventWriter.cpp +++ b/src/server/EventWriter.cpp @@ -14,6 +14,8 @@ along with Ingen. If not, see . */ +#include + #include "ingen/URIs.hpp" #include "Engine.hpp" @@ -49,7 +51,13 @@ EventWriter::set_response_id(int32_t id) } void -EventWriter::bundle_begin() +EventWriter::message(const Message& msg) +{ + boost::apply_visitor(*this, msg); +} + +void +EventWriter::operator()(const BundleBegin&) { _engine.enqueue_event( new Events::Mark(_engine, _respondee, _request_id, now(), @@ -58,7 +66,7 @@ EventWriter::bundle_begin() } void -EventWriter::bundle_end() +EventWriter::operator()(const BundleEnd&) { _engine.enqueue_event( new Events::Mark(_engine, _respondee, _request_id, now(), @@ -67,102 +75,89 @@ EventWriter::bundle_end() } void -EventWriter::put(const Raul::URI& uri, - const Properties& properties, - const Resource::Graph ctx) +EventWriter::operator()(const Put& msg) { _engine.enqueue_event( new Events::Delta(_engine, _respondee, _request_id, now(), - Events::Delta::Type::PUT, ctx, uri, properties), + Events::Delta::Type::PUT, msg.ctx, msg.uri, msg.properties), _event_mode); } void -EventWriter::delta(const Raul::URI& uri, - const Properties& remove, - const Properties& add, - const Resource::Graph ctx) +EventWriter::operator()(const Delta& msg) { _engine.enqueue_event( new Events::Delta(_engine, _respondee, _request_id, now(), - Events::Delta::Type::PATCH, ctx, uri, add, remove), + Events::Delta::Type::PATCH, msg.ctx, msg.uri, msg.add, msg.remove), _event_mode); } void -EventWriter::copy(const Raul::URI& old_uri, - const Raul::URI& new_uri) +EventWriter::operator()(const Copy& msg) { _engine.enqueue_event( new Events::Copy(_engine, _respondee, _request_id, now(), - old_uri, new_uri), + msg.old_uri, msg.new_uri), _event_mode); } void -EventWriter::move(const Raul::Path& old_path, - const Raul::Path& new_path) +EventWriter::operator()(const Move& msg) { _engine.enqueue_event( new Events::Move(_engine, _respondee, _request_id, now(), - old_path, new_path), + msg.old_path, msg.new_path), _event_mode); } void -EventWriter::del(const Raul::URI& uri) +EventWriter::operator()(const Del& msg) { _engine.enqueue_event( - new Events::Delete(_engine, _respondee, _request_id, now(), uri), + new Events::Delete(_engine, _respondee, _request_id, now(), msg.uri), _event_mode); } void -EventWriter::connect(const Raul::Path& tail_path, - const Raul::Path& head_path) +EventWriter::operator()(const Connect& msg) { _engine.enqueue_event( new Events::Connect(_engine, _respondee, _request_id, now(), - tail_path, head_path), + msg.tail, msg.head), _event_mode); } void -EventWriter::disconnect(const Raul::Path& src, - const Raul::Path& dst) +EventWriter::operator()(const Disconnect& msg) { _engine.enqueue_event( new Events::Disconnect(_engine, _respondee, _request_id, now(), - src, dst), + msg.tail, msg.head), _event_mode); } void -EventWriter::disconnect_all(const Raul::Path& graph, - const Raul::Path& path) +EventWriter::operator()(const DisconnectAll& msg) { _engine.enqueue_event( new Events::DisconnectAll(_engine, _respondee, _request_id, now(), - graph, path), + msg.graph, msg.path), _event_mode); } void -EventWriter::set_property(const Raul::URI& uri, - const Raul::URI& predicate, - const Atom& value, - const Resource::Graph ctx) +EventWriter::operator()(const SetProperty& msg) { _engine.enqueue_event( new Events::Delta(_engine, _respondee, _request_id, now(), - Events::Delta::Type::SET, ctx, - uri, {{predicate, value}}, {}), + Events::Delta::Type::SET, msg.ctx, + msg.subject, {{msg.predicate, msg.value}}, {}), _event_mode); } void -EventWriter::undo() +EventWriter::operator()(const Undo&) { _engine.enqueue_event( new Events::Undo(_engine, _respondee, _request_id, now(), false), @@ -170,7 +165,7 @@ EventWriter::undo() } void -EventWriter::redo() +EventWriter::operator()(const Redo&) { _engine.enqueue_event( new Events::Undo(_engine, _respondee, _request_id, now(), true), @@ -178,10 +173,10 @@ EventWriter::redo() } void -EventWriter::get(const Raul::URI& uri) +EventWriter::operator()(const Get& msg) { _engine.enqueue_event( - new Events::Get(_engine, _respondee, _request_id, now(), uri), + new Events::Get(_engine, _respondee, _request_id, now(), msg.subject), _event_mode); } diff --git a/src/server/EventWriter.hpp b/src/server/EventWriter.hpp index 18e98421..3a5e285e 100644 --- a/src/server/EventWriter.hpp +++ b/src/server/EventWriter.hpp @@ -53,54 +53,28 @@ public: virtual void set_response_id(int32_t id); - virtual void bundle_begin(); - - virtual void bundle_end(); - - virtual void put(const Raul::URI& path, - const Properties& properties, - const Resource::Graph g = Resource::Graph::DEFAULT); - - virtual void delta(const Raul::URI& path, - const Properties& remove, - const Properties& add, - Resource::Graph ctx = Resource::Graph::DEFAULT); - - virtual void copy(const Raul::URI& old_uri, - const Raul::URI& new_uri); - - virtual void move(const Raul::Path& old_path, - const Raul::Path& new_path); - - virtual void connect(const Raul::Path& tail, - const Raul::Path& head); - - virtual void disconnect(const Raul::Path& tail, - const Raul::Path& head); - - virtual void set_property(const Raul::URI& subject_path, - const Raul::URI& predicate, - const Atom& value, - Resource::Graph ctx = Resource::Graph::DEFAULT); - - virtual void del(const Raul::URI& uri); - - virtual void disconnect_all(const Raul::Path& graph, - const Raul::Path& path); - - virtual void undo(); - - virtual void redo(); - - virtual void get(const Raul::URI& uri); - - virtual void response(int32_t id, Status status, const std::string& subject) {} ///< N/A - - virtual void error(const std::string& msg) {} ///< N/A + void message(const Message& msg) override; void set_event_mode(Event::Mode mode) { _event_mode = mode; } Event::Mode get_event_mode() { return _event_mode; } + void operator()(const BundleBegin&); + void operator()(const BundleEnd&); + void operator()(const Connect&); + void operator()(const Copy&); + void operator()(const Del&); + void operator()(const Delta&); + void operator()(const Disconnect&); + void operator()(const DisconnectAll&); + void operator()(const Error&) {} + void operator()(const Get&); + void operator()(const Move&); + void operator()(const Put&); + void operator()(const Redo&); + void operator()(const Response&) {} + void operator()(const SetProperty&); + void operator()(const Undo&); + protected: Engine& _engine; SPtr _respondee; -- cgit v1.2.1