summaryrefslogtreecommitdiffstats
path: root/ingen
diff options
context:
space:
mode:
Diffstat (limited to 'ingen')
-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
7 files changed, 265 insertions, 335 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