summaryrefslogtreecommitdiffstats
path: root/src/server
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 /src/server
parent2b88ebdcb7a438a8419ab6a815742b115b2dce03 (diff)
downloadingen-7513e0b53a36e96b9e1fa1884b78077a95da3081.tar.gz
ingen-7513e0b53a36e96b9e1fa1884b78077a95da3081.tar.bz2
ingen-7513e0b53a36e96b9e1fa1884b78077a95da3081.zip
Add Message struct and remove tons of interface boilerplate
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Broadcaster.hpp71
-rw-r--r--src/server/EventWriter.cpp71
-rw-r--r--src/server/EventWriter.hpp62
3 files changed, 58 insertions, 146 deletions
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;