summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-12-16 17:57:49 +0100
committerDavid Robillard <d@drobilla.net>2017-12-16 18:05:19 +0100
commit7513e0b53a36e96b9e1fa1884b78077a95da3081 (patch)
treefc96befa9b2c2f5255ada0d589c524e22626c16d
parent2b88ebdcb7a438a8419ab6a815742b115b2dce03 (diff)
downloadingen-7513e0b53a36e96b9e1fa1884b78077a95da3081.tar.gz
ingen-7513e0b53a36e96b9e1fa1884b78077a95da3081.tar.bz2
ingen-7513e0b53a36e96b9e1fa1884b78077a95da3081.zip
Add Message struct and remove tons of interface boilerplate
-rw-r--r--ingen/AtomWriter.hpp62
-rw-r--r--ingen/Interface.hpp103
-rw-r--r--ingen/Message.hpp148
-rw-r--r--ingen/Tee.hpp77
-rw-r--r--ingen/client/ClientStore.hpp56
-rw-r--r--ingen/client/SigClientInterface.hpp73
-rw-r--r--ingen/client/ThreadedSigClientInterface.hpp81
-rw-r--r--src/AtomWriter.cpp106
-rw-r--r--src/client/ClientStore.cpp104
-rw-r--r--src/gui/App.cpp42
-rw-r--r--src/gui/App.hpp3
-rw-r--r--src/gui/BreadCrumbs.cpp12
-rw-r--r--src/gui/BreadCrumbs.hpp1
-rw-r--r--src/gui/ConnectWindow.cpp15
-rw-r--r--src/gui/ConnectWindow.hpp2
-rw-r--r--src/server/Broadcaster.hpp71
-rw-r--r--src/server/EventWriter.cpp71
-rw-r--r--src/server/EventWriter.hpp62
-rw-r--r--tests/TestClient.hpp67
-rw-r--r--wscript1
20 files changed, 485 insertions, 672 deletions
diff --git a/ingen/AtomWriter.hpp b/ingen/AtomWriter.hpp
index e7a02049..21fcb933 100644
--- a/ingen/AtomWriter.hpp
+++ b/ingen/AtomWriter.hpp
@@ -42,52 +42,26 @@ public:
return Raul::URI("ingen:/clients/atom_writer");
}
- void bundle_begin();
-
- void bundle_end();
-
- void put(const Raul::URI& uri,
- const Properties& properties,
- Resource::Graph ctx = Resource::Graph::DEFAULT);
-
- void delta(const Raul::URI& uri,
- const Properties& remove,
- const Properties& add,
- Resource::Graph ctx = Resource::Graph::DEFAULT);
-
- void copy(const Raul::URI& old_uri,
- const Raul::URI& new_uri);
-
- void move(const Raul::Path& old_path,
- const Raul::Path& new_path);
-
- void del(const Raul::URI& uri);
-
- void connect(const Raul::Path& tail,
- const Raul::Path& head);
-
- void disconnect(const Raul::Path& tail,
- const Raul::Path& head);
-
- void disconnect_all(const Raul::Path& graph,
- const Raul::Path& path);
-
- void set_property(const Raul::URI& subject,
- const Raul::URI& predicate,
- const Atom& value,
- Resource::Graph ctx = Resource::Graph::DEFAULT);
-
- void undo();
-
- void redo();
-
void set_response_id(int32_t id);
- void get(const Raul::URI& uri);
-
- void response(int32_t id, Status status, const std::string& subject);
-
- void error(const std::string& msg);
+ void message(const Message& message) override;
+
+ 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&);
private:
void forge_uri(const Raul::URI& uri);
diff --git a/ingen/Interface.hpp b/ingen/Interface.hpp
index f83cd6f2..68f21304 100644
--- a/ingen/Interface.hpp
+++ b/ingen/Interface.hpp
@@ -23,6 +23,7 @@
#include <string>
+#include "ingen/Message.hpp"
#include "ingen/Resource.hpp"
#include "ingen/Status.hpp"
#include "ingen/ingen.h"
@@ -53,66 +54,82 @@ public:
virtual void set_respondee(SPtr<Interface> respondee) {}
- /** Begin a transaction.
- *
- * This does not guarantee strict atomicity, but the events in a bundle will be
- * considered one operation, and they will all be undone at once.
+ /** Set the ID to use to respond to the next message.
+ * Setting the ID to 0 will disable responses.
*/
- virtual void bundle_begin() = 0;
+ virtual void set_response_id(int32_t id) = 0;
- /** End a transaction. */
- virtual void bundle_end() = 0;
+ virtual void message(const Message& message) = 0;
- virtual void put(const Raul::URI& uri,
- const Properties& properties,
- Resource::Graph ctx = Resource::Graph::DEFAULT) = 0;
+ inline void bundle_begin() { message(BundleBegin{}); }
- virtual void delta(const Raul::URI& uri,
- const Properties& remove,
- const Properties& add,
- Resource::Graph ctx = Resource::Graph::DEFAULT) = 0;
+ inline void bundle_end() { message(BundleEnd{}); }
- virtual void copy(const Raul::URI& old_uri,
- const Raul::URI& new_uri) = 0;
+ inline void put(const Raul::URI& uri,
+ const Properties& properties,
+ Resource::Graph ctx = Resource::Graph::DEFAULT)
+ {
+ message(Put{uri, properties, ctx});
+ }
- virtual void move(const Raul::Path& old_path,
- const Raul::Path& new_path) = 0;
+ inline void delta(const Raul::URI& uri,
+ const Properties& remove,
+ const Properties& add,
+ Resource::Graph ctx = Resource::Graph::DEFAULT)
+ {
+ message(Delta{uri, remove, add, ctx});
+ }
- virtual void del(const Raul::URI& uri) = 0;
+ inline void copy(const Raul::URI& old_uri, const Raul::URI& new_uri)
+ {
+ message(Copy{old_uri, new_uri});
+ }
+
+ inline void move(const Raul::Path& old_path, const Raul::Path& new_path)
+ {
+ message(Move{old_path, new_path});
+ }
- virtual void connect(const Raul::Path& tail,
- const Raul::Path& head) = 0;
+ inline void del(const Raul::URI& uri) { message(Del{uri}); }
- virtual void disconnect(const Raul::Path& tail,
- const Raul::Path& head) = 0;
+ inline void connect(const Raul::Path& tail, const Raul::Path& head)
+ {
+ message(Connect{tail, head});
+ }
- virtual void disconnect_all(const Raul::Path& graph,
- const Raul::Path& path) = 0;
+ inline void disconnect(const Raul::Path& tail, const Raul::Path& head)
+ {
+ message(Disconnect{tail, head});
+ }
- virtual void set_property(const Raul::URI& subject,
- const Raul::URI& predicate,
- const Atom& value,
- Resource::Graph ctx = Resource::Graph::DEFAULT) = 0;
+ inline void disconnect_all(const Raul::Path& graph, const Raul::Path& path)
+ {
+ message(DisconnectAll{graph, path});
+ }
- virtual void undo() = 0;
+ inline void set_property(const Raul::URI& subject,
+ const Raul::URI& predicate,
+ const Atom& value,
+ Resource::Graph ctx = Resource::Graph::DEFAULT)
+ {
+ message(SetProperty{subject, predicate, value, ctx});
+ }
- virtual void redo() = 0;
+ inline void undo() { message(Undo{}); }
- /** Set the ID to use to respond to the next message.
- * Setting the ID to 0 will disable responses.
- */
- virtual void set_response_id(int32_t id) = 0;
+ inline void redo() { message(Redo{}); }
- // Requests
- virtual void get(const Raul::URI& uri) = 0;
+ inline void get(const Raul::URI& uri) { message(Get{uri}); }
- // Response
- virtual void response(int32_t id,
- Status status,
- const std::string& subject) = 0;
+ inline void response(int32_t id,
+ Status status,
+ const std::string& subject) {
+ message(Response{id, status, subject});
+ }
- // Non-response error
- virtual void error(const std::string& msg) = 0;
+ inline void error(const std::string& error_message) {
+ message(Error{error_message});
+ }
};
} // namespace Ingen
diff --git a/ingen/Message.hpp b/ingen/Message.hpp
new file mode 100644
index 00000000..d4118dcb
--- /dev/null
+++ b/ingen/Message.hpp
@@ -0,0 +1,148 @@
+/*
+ This file is part of Ingen.
+ Copyright 2007-2017 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/>.
+*/
+
+#ifndef INGEN_MESSAGE_HPP
+#define INGEN_MESSAGE_HPP
+
+#include <string>
+
+#include <boost/variant.hpp>
+
+#include "ingen/Resource.hpp"
+#include "ingen/Status.hpp"
+#include "ingen/ingen.h"
+#include "ingen/types.hpp"
+#include "raul/Path.hpp"
+
+namespace Raul {
+class Atom;
+class Path;
+class URI;
+}
+
+namespace Ingen {
+
+struct BundleBegin
+{
+};
+
+struct BundleEnd
+{
+};
+
+struct Connect
+{
+ Raul::Path tail;
+ Raul::Path head;
+};
+
+struct Copy
+{
+ Raul::URI old_uri;
+ Raul::URI new_uri;
+};
+
+struct Del
+{
+ Raul::URI uri;
+};
+
+struct Delta
+{
+ Raul::URI uri;
+ Properties remove;
+ Properties add;
+ Resource::Graph ctx;
+};
+
+struct Disconnect
+{
+ Raul::Path tail;
+ Raul::Path head;
+};
+
+struct DisconnectAll
+{
+ Raul::Path graph;
+ Raul::Path path;
+};
+
+struct Error
+{
+ std::string message;
+};
+
+struct Get
+{
+ Raul::URI subject;
+};
+
+struct Move
+{
+ Raul::Path old_path;
+ Raul::Path new_path;
+};
+
+struct Put
+{
+ Raul::URI uri;
+ Properties properties;
+ Resource::Graph ctx;
+};
+
+struct Redo
+{
+};
+
+struct Response
+{
+ int32_t id;
+ Status status;
+ std::string subject;
+};
+
+struct SetProperty
+{
+ Raul::URI subject;
+ Raul::URI predicate;
+ Atom value;
+ Resource::Graph ctx;
+};
+
+struct Undo
+{
+};
+
+using Message = boost::variant<BundleBegin,
+ BundleEnd,
+ Connect,
+ Copy,
+ Del,
+ Delta,
+ Disconnect,
+ DisconnectAll,
+ Error,
+ Get,
+ Move,
+ Put,
+ Redo,
+ Response,
+ SetProperty,
+ Undo>;
+
+} // namespace Ingen
+
+#endif // INGEN_MESSAGE_HPP
diff --git a/ingen/Tee.hpp b/ingen/Tee.hpp
index 02596e03..12cccc91 100644
--- a/ingen/Tee.hpp
+++ b/ingen/Tee.hpp
@@ -54,77 +54,20 @@ public:
(*_sinks.begin())->set_respondee(respondee);
}
-#define BROADCAST(msg, ...) \
- std::lock_guard<std::mutex> lock(_sinks_mutex); \
- for (const auto& s : _sinks) { \
- s->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 set_response_id(int32_t id) {
+ std::lock_guard<std::mutex> lock(_sinks_mutex);
+ for (const auto& s : _sinks) {
+ s->set_response_id(id);
+ }
}
- void undo() { BROADCAST(undo); }
- void redo() { BROADCAST(redo); }
-
- void set_response_id(int32_t id) { BROADCAST(set_response_id, id); }
-
- void get(const Raul::URI& uri) { BROADCAST(get, uri); }
-
- void response(int32_t id, Status status, const std::string& subject) {
- BROADCAST(response, id, status, subject);
+ void message(const Message& message) override {
+ std::lock_guard<std::mutex> lock(_sinks_mutex);
+ for (const auto& s : _sinks) {
+ s->message(message);
+ }
}
- void error(const std::string& msg) { BROADCAST(error, msg); }
-
-#undef BROADCAST
-
Raul::URI uri() const { return Raul::URI("ingen:/tee"); }
const Sinks& sinks() const { return _sinks; }
Sinks& sinks() { return _sinks; }
diff --git a/ingen/client/ClientStore.hpp b/ingen/client/ClientStore.hpp
index 1887bed3..899273dc 100644
--- a/ingen/client/ClientStore.hpp
+++ b/ingen/client/ClientStore.hpp
@@ -73,43 +73,26 @@ public:
URIs& uris() { return _uris; }
- void put(const Raul::URI& uri,
- const Properties& properties,
- Resource::Graph ctx = Resource::Graph::DEFAULT);
+ void message(const Message& msg) override;
+
+ 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&) {}
- void delta(const Raul::URI& uri,
- const Properties& remove,
- const Properties& add,
- Resource::Graph ctx = Resource::Graph::DEFAULT);
-
- void copy(const Raul::URI& old_uri,
- const Raul::URI& new_uri);
-
- void move(const Raul::Path& old_path,
- const Raul::Path& new_path);
-
- void set_property(const Raul::URI& subject_path,
- const Raul::URI& predicate,
- const Atom& value,
- Resource::Graph ctx = Resource::Graph::DEFAULT);
-
- void connect(const Raul::Path& tail,
- const Raul::Path& head);
-
- void disconnect(const Raul::Path& tail,
- const Raul::Path& head);
-
- void disconnect_all(const Raul::Path& graph,
- const Raul::Path& path);
-
- void del(const Raul::URI& uri);
-
- void undo() {}
- void redo() {}
void set_response_id(int32_t id) {}
- void get(const Raul::URI& uri) {}
- void response(int32_t id, Status status, const std::string& subject) {}
- void error(const std::string& msg) {}
INGEN_SIGNAL(new_object, void, SPtr<ObjectModel>);
INGEN_SIGNAL(new_plugin, void, SPtr<PluginModel>);
@@ -129,9 +112,6 @@ private:
SPtr<GraphModel> connection_graph(const Raul::Path& tail_path,
const Raul::Path& head_path);
- void bundle_begin() {}
- void bundle_end() {}
-
// Slots for SigClientInterface signals
bool attempt_connection(const Raul::Path& tail_path,
const Raul::Path& head_path);
diff --git a/ingen/client/SigClientInterface.hpp b/ingen/client/SigClientInterface.hpp
index 7e903fab..2934e8b1 100644
--- a/ingen/client/SigClientInterface.hpp
+++ b/ingen/client/SigClientInterface.hpp
@@ -48,80 +48,17 @@ public:
Raul::URI uri() const { return Raul::URI("ingen:/clients/sig"); }
- INGEN_SIGNAL(response, void, int32_t, Status, std::string)
- INGEN_SIGNAL(bundle_begin, void)
- INGEN_SIGNAL(bundle_end, void)
- INGEN_SIGNAL(error, void, std::string)
- INGEN_SIGNAL(put, void, Raul::URI, Properties, Resource::Graph)
- INGEN_SIGNAL(delta, void, Raul::URI, Properties, Properties, Resource::Graph)
- INGEN_SIGNAL(object_copied, void, Raul::URI, Raul::URI)
- INGEN_SIGNAL(object_moved, void, Raul::Path, Raul::Path)
- INGEN_SIGNAL(object_deleted, void, Raul::URI)
- INGEN_SIGNAL(connection, void, Raul::Path, Raul::Path)
- INGEN_SIGNAL(disconnection, void, Raul::Path, Raul::Path)
- INGEN_SIGNAL(disconnect_all, void, Raul::Path, Raul::Path)
- INGEN_SIGNAL(property_change, void, Raul::URI, Raul::URI, Atom, Resource::Graph)
+ INGEN_SIGNAL(message, void, Message)
/** Fire pending signals. Only does anything on derived classes (that may queue) */
virtual bool emit_signals() { return false; }
protected:
-
- // ClientInterface hooks that fire the above signals
-
-#define EMIT(name, ...) { _signal_ ## name (__VA_ARGS__); }
-
- void bundle_begin()
- { EMIT(bundle_begin); }
-
- void bundle_end()
- { EMIT(bundle_end); }
-
- void response(int32_t id, Status status, const std::string& subject)
- { EMIT(response, id, status, subject); }
-
- void error(const std::string& msg)
- { EMIT(error, msg); }
-
- void put(const Raul::URI& uri,
- const Properties& properties,
- Resource::Graph ctx = Resource::Graph::DEFAULT)
- { EMIT(put, uri, properties, ctx); }
-
- void delta(const Raul::URI& uri,
- const Properties& remove,
- const Properties& add,
- Resource::Graph ctx = Resource::Graph::DEFAULT)
- { EMIT(delta, uri, remove, add, ctx); }
-
- void connect(const Raul::Path& tail, const Raul::Path& head)
- { EMIT(connection, tail, head); }
-
- void del(const Raul::URI& uri)
- { EMIT(object_deleted, uri); }
-
- void copy(const Raul::URI& old_uri, const Raul::URI& new_uri)
- { EMIT(object_copied, old_uri, new_uri); }
-
- void move(const Raul::Path& old_path, const Raul::Path& new_path)
- { EMIT(object_moved, old_path, new_path); }
-
- void disconnect(const Raul::Path& tail, const Raul::Path& head)
- { EMIT(disconnection, tail, head); }
-
- void disconnect_all(const Raul::Path& graph, const Raul::Path& path)
- { EMIT(disconnect_all, graph, path); }
-
- void set_property(const Raul::URI& subject,
- const Raul::URI& key,
- const Atom& value,
- Resource::Graph ctx = Resource::Graph::DEFAULT)
- { EMIT(property_change, subject, key, value, ctx); }
-
- void undo() {}
- void redo() {}
void set_response_id(int32_t id) {}
- void get(const Raul::URI& uri) {}
+
+ void message(const Message& msg) override {
+ _signal_message(msg);
+ }
};
} // namespace Client
diff --git a/ingen/client/ThreadedSigClientInterface.hpp b/ingen/client/ThreadedSigClientInterface.hpp
index 96c47374..8fa36c90 100644
--- a/ingen/client/ThreadedSigClientInterface.hpp
+++ b/ingen/client/ThreadedSigClientInterface.hpp
@@ -52,66 +52,15 @@ class INGEN_API ThreadedSigClientInterface : public SigClientInterface
{
public:
ThreadedSigClientInterface()
- : response_slot(_signal_response.make_slot())
- , error_slot(_signal_error.make_slot())
- , put_slot(_signal_put.make_slot())
- , connection_slot(_signal_connection.make_slot())
- , object_deleted_slot(_signal_object_deleted.make_slot())
- , object_moved_slot(_signal_object_moved.make_slot())
- , object_copied_slot(_signal_object_copied.make_slot())
- , disconnection_slot(_signal_disconnection.make_slot())
- , disconnect_all_slot(_signal_disconnect_all.make_slot())
- , property_change_slot(_signal_property_change.make_slot())
+ : message_slot(_signal_message.make_slot())
{}
virtual Raul::URI uri() const { return Raul::URI("ingen:/clients/sig_queue"); }
- void bundle_begin()
- { push_sig(bundle_begin_slot); }
-
- void bundle_end()
- { push_sig(bundle_end_slot); }
-
- void response(int32_t id, Status status, const std::string& subject)
- { push_sig(sigc::bind(response_slot, id, status, subject)); }
-
- void error(const std::string& msg)
- { push_sig(sigc::bind(error_slot, msg)); }
-
- void put(const Raul::URI& path,
- const Properties& properties,
- Resource::Graph ctx = Resource::Graph::DEFAULT)
- { push_sig(sigc::bind(put_slot, path, properties, ctx)); }
-
- void delta(const Raul::URI& path,
- const Properties& remove,
- const Properties& add,
- Resource::Graph ctx = Resource::Graph::DEFAULT)
- { push_sig(sigc::bind(delta_slot, path, remove, add, ctx)); }
-
- void connect(const Raul::Path& tail, const Raul::Path& head)
- { push_sig(sigc::bind(connection_slot, tail, head)); }
-
- void del(const Raul::URI& uri)
- { push_sig(sigc::bind(object_deleted_slot, uri)); }
-
- void move(const Raul::Path& old_path, const Raul::Path& new_path)
- { push_sig(sigc::bind(object_moved_slot, old_path, new_path)); }
-
- void copy(const Raul::URI& old_uri, const Raul::URI& new_uri)
- { push_sig(sigc::bind(object_copied_slot, old_uri, new_uri)); }
-
- void disconnect(const Raul::Path& tail, const Raul::Path& head)
- { push_sig(sigc::bind(disconnection_slot, tail, head)); }
-
- void disconnect_all(const Raul::Path& graph, const Raul::Path& path)
- { push_sig(sigc::bind(disconnect_all_slot, graph, path)); }
-
- void set_property(const Raul::URI& subject,
- const Raul::URI& key,
- const Atom& value,
- Resource::Graph ctx = Resource::Graph::DEFAULT)
- { push_sig(sigc::bind(property_change_slot, subject, key, value, ctx)); }
+ void message(const Message& msg) override {
+ std::lock_guard<std::mutex> lock(_mutex);
+ _sigs.push_back(sigc::bind(message_slot, msg));
+ }
/** Process all queued events - Called from GTK thread to emit signals. */
bool emit_signals() {
@@ -131,11 +80,6 @@ public:
}
private:
- void push_sig(Closure ev) {
- std::lock_guard<std::mutex> lock(_mutex);
- _sigs.push_back(ev);
- }
-
std::mutex _mutex;
std::vector<Closure> _sigs;
@@ -143,20 +87,7 @@ private:
using Path = Raul::Path;
using URI = Raul::URI;
- sigc::slot<void> bundle_begin_slot;
- sigc::slot<void> bundle_end_slot;
- sigc::slot<void, int32_t, Status, std::string> response_slot;
- sigc::slot<void, std::string> error_slot;
- sigc::slot<void, URI, URI, Raul::Symbol> new_plugin_slot;
- sigc::slot<void, URI, Properties, Graph> put_slot;
- sigc::slot<void, URI, Properties, Properties, Graph> delta_slot;
- sigc::slot<void, Path, Path> connection_slot;
- sigc::slot<void, URI> object_deleted_slot;
- sigc::slot<void, Path, Path> object_moved_slot;
- sigc::slot<void, URI, URI> object_copied_slot;
- sigc::slot<void, Path, Path> disconnection_slot;
- sigc::slot<void, Path, Path> disconnect_all_slot;
- sigc::slot<void, URI, URI, Atom, Graph> property_change_slot;
+ sigc::slot<void, Message> message_slot;
};
} // namespace Client
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 <cstdlib>
#include <string>
+#include <boost/variant.hpp>
+
#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<int>(status));
+ lv2_atom_forge_int(&_forge, static_cast<int>(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 <http://www.gnu.org/licenses/>.
*/
+#include <boost/variant.hpp>
+
#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<PluginModel> 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<ObjectModel> 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<PluginModel> 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<PortModel> tail = dynamic_ptr_cast<PortModel>(_object(src_path));
- SPtr<PortModel> head = dynamic_ptr_cast<PortModel>(_object(dst_path));
- SPtr<GraphModel> graph = connection_graph(src_path, dst_path);
+ SPtr<PortModel> tail = dynamic_ptr_cast<PortModel>(_object(msg.tail));
+ SPtr<PortModel> head = dynamic_ptr_cast<PortModel>(_object(msg.head));
+ SPtr<GraphModel> 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<GraphModel> graph = dynamic_ptr_cast<GraphModel>(_object(parent_graph));
- SPtr<ObjectModel> object = _object(path);
+ SPtr<GraphModel> graph = dynamic_ptr_cast<GraphModel>(_object(msg.graph));
+ SPtr<ObjectModel> 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<ArcModel> arc = dynamic_ptr_cast<ArcModel>(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<SigClientInterface> 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
@@ -238,6 +218,20 @@ App::serialiser()
}
void
+App::message(const Message& msg)
+{
+ if (const Response* const r = boost::get<Response>(&msg)) {
+ response(r->id, r->status, r->subject);
+ } else if (const Error* const e = boost::get<Error>(&msg)) {
+ error_message(e->message);
+ } else if (const Put* const p = boost::get<Put>(&msg)) {
+ put(p->uri, p->properties, p->ctx);
+ } else if (const SetProperty* const s = boost::get<SetProperty>(&msg)) {
+ property_change(s->subject, s->predicate, s->value, s->ctx);
+ }
+}
+
+void
App::response(int32_t id, Status status, const std::string& subject)
{
if (status != Status::SUCCESS) {
@@ -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 <gtkmm/window.h>
#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);
}
@@ -180,6 +180,14 @@ BreadCrumbs::breadcrumb_clicked(BreadCrumb* crumb)
}
void
+BreadCrumbs::message(const Message& msg)
+{
+ if (const Del* const del = boost::get<Del>(&msg)) {
+ object_destroyed(del->uri);
+ }
+}
+
+void
BreadCrumbs::object_destroyed(const Raul::URI& uri)
{
for (auto i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) {
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 <sstream>
#include <string>
+#include <boost/variant.hpp>
#include <gtkmm/stock.h>
#include "raul/Process.hpp"
@@ -74,6 +75,16 @@ ConnectWindow::ConnectWindow(BaseObjectType* cobject,
}
void
+ConnectWindow::message(const Message& msg)
+{
+ if (const Response* const r = boost::get<Response>(&msg)) {
+ ingen_response(r->id, r->status, r->subject);
+ } else if (const Error* const e = boost::get<Error>(&msg)) {
+ error(e->message);
+ }
+}
+
+void
ConnectWindow::error(const std::string& msg)
{
if (!is_visible()) {
@@ -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<int32_t>::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<std::mutex> 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<std::mutex> 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 <http://www.gnu.org/licenses/>.
*/
+#include <boost/variant.hpp>
+
#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<Interface> _respondee;
diff --git a/tests/TestClient.hpp b/tests/TestClient.hpp
index 968e4423..90fc212b 100644
--- a/tests/TestClient.hpp
+++ b/tests/TestClient.hpp
@@ -17,6 +17,8 @@
#ifndef INGEN_TESTCLIENT_HPP
#define INGEN_TESTCLIENT_HPP
+#include <boost/variant.hpp>
+
#include "ingen/Interface.hpp"
using namespace Ingen;
@@ -29,62 +31,23 @@ public:
Raul::URI uri() const { return Raul::URI("ingen:testClient"); }
- void bundle_begin() {}
-
- void bundle_end() {}
-
- void put(const Raul::URI& uri,
- const Properties& properties,
- Resource::Graph ctx = Resource::Graph::DEFAULT) {}
-
- void delta(const Raul::URI& uri,
- const Properties& remove,
- const Properties& add,
- Resource::Graph ctx = Resource::Graph::DEFAULT) {}
-
- void copy(const Raul::URI& old_uri,
- const Raul::URI& new_uri) {}
-
- void move(const Raul::Path& old_path,
- const Raul::Path& new_path) {}
-
- void del(const Raul::URI& uri) {}
-
- void connect(const Raul::Path& tail,
- const Raul::Path& head) {}
-
- void disconnect(const Raul::Path& tail,
- const Raul::Path& head) {}
-
- void disconnect_all(const Raul::Path& parent_patch_path,
- const Raul::Path& path) {}
-
- void set_property(const Raul::URI& subject,
- const Raul::URI& predicate,
- const Atom& value,
- Resource::Graph ctx = Resource::Graph::DEFAULT) {}
-
- void set_response_id(int32_t id) {}
-
- void get(const Raul::URI& uri) {}
-
- void undo() {}
-
- void redo() {}
-
- void response(int32_t id, Status status, const std::string& subject) {
- if (status != Status::SUCCESS) {
- _log.error(fmt("error on message %1%: %2% (%3%)\n")
- % id % ingen_status_string(status) % subject);
+ void set_response_id(int32_t id) override {}
+
+ void message(const Message& msg) override {
+ if (const Response* const response = boost::get<Response>(&msg)) {
+ if (response->status != Status::SUCCESS) {
+ _log.error(fmt("error on message %1%: %2% (%3%)\n")
+ % response->id
+ % ingen_status_string(response->status)
+ % response->subject);
+ exit(EXIT_FAILURE);
+ }
+ } else if (const Error* const error = boost::get<Error>(&msg)) {
+ _log.error(fmt("error: %1%\n") % error->message);
exit(EXIT_FAILURE);
}
}
- void error(const std::string& msg) {
- _log.error(fmt("error: %1%\n") % msg);
- exit(EXIT_FAILURE);
- }
-
private:
Log& _log;
};
diff --git a/wscript b/wscript
index bd587592..2044e25b 100644
--- a/wscript
+++ b/wscript
@@ -63,6 +63,7 @@ def configure(conf):
conf.check_cxx(header_name='boost/intrusive/slist.hpp')
conf.check_cxx(header_name='boost/intrusive_ptr.hpp')
conf.check_cxx(header_name='boost/optional.hpp')
+ conf.check_cxx(header_name='boost/variant.hpp')
conf.check_cxx(msg='Checking for thread_local keyword',
mandatory=False,
fragment='thread_local int i = 0; int main() {}',