summaryrefslogtreecommitdiffstats
path: root/ingen
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-09-18 04:42:31 -0400
committerDavid Robillard <d@drobilla.net>2016-09-18 04:42:31 -0400
commitce6dc3d549bc58515d5d55db1d0a009a92887f3c (patch)
tree2cde2929903e30ec6272a79bd0877dd435aa83c2 /ingen
parent758543f6dbb56755d3239c0ed68f1083384f0e96 (diff)
downloadingen-ce6dc3d549bc58515d5d55db1d0a009a92887f3c.tar.gz
ingen-ce6dc3d549bc58515d5d55db1d0a009a92887f3c.tar.bz2
ingen-ce6dc3d549bc58515d5d55db1d0a009a92887f3c.zip
Add fancy communication logging
Diffstat (limited to 'ingen')
-rw-r--r--ingen/ColorContext.hpp37
-rw-r--r--ingen/StreamWriter.hpp47
-rw-r--r--ingen/Tee.hpp137
3 files changed, 221 insertions, 0 deletions
diff --git a/ingen/ColorContext.hpp b/ingen/ColorContext.hpp
new file mode 100644
index 00000000..81e0e062
--- /dev/null
+++ b/ingen/ColorContext.hpp
@@ -0,0 +1,37 @@
+/*
+ This file is part of Ingen.
+ Copyright 2007-2016 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_COLORCONTEXT_HPP
+#define INGEN_COLORCONTEXT_HPP
+
+#include <cstdio>
+
+namespace Ingen {
+
+class ColorContext {
+public:
+ enum class Color { RED = 31, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
+
+ ColorContext(FILE* stream, Color color);
+ ~ColorContext();
+
+private:
+ FILE* _stream;
+};
+
+} // namespace Ingen
+
+#endif // INGEN_COLORCONTEXT_HPP
diff --git a/ingen/StreamWriter.hpp b/ingen/StreamWriter.hpp
new file mode 100644
index 00000000..7a62382c
--- /dev/null
+++ b/ingen/StreamWriter.hpp
@@ -0,0 +1,47 @@
+/*
+ This file is part of Ingen.
+ Copyright 2012-2016 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_STREAMWRITER_HPP
+#define INGEN_STREAMWRITER_HPP
+
+#include <cstdio>
+
+#include "ingen/ColorContext.hpp"
+#include "ingen/TurtleWriter.hpp"
+
+namespace Ingen {
+
+/** An Interface that writes Turtle messages to a stream.
+ */
+class INGEN_API StreamWriter : public TurtleWriter
+{
+public:
+ StreamWriter(URIMap& map,
+ URIs& uris,
+ const Raul::URI& uri,
+ FILE* stream,
+ ColorContext::Color color);
+
+ size_t text_sink(const void* buf, size_t len) override;
+
+protected:
+ FILE* _stream;
+ ColorContext::Color _color;
+};
+
+} // namespace Ingen
+
+#endif // INGEN_STREAMWRITER_HPP
diff --git a/ingen/Tee.hpp b/ingen/Tee.hpp
new file mode 100644
index 00000000..1577f6dd
--- /dev/null
+++ b/ingen/Tee.hpp
@@ -0,0 +1,137 @@
+/*
+ This file is part of Ingen.
+ Copyright 2007-2016 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_ENGINE_TEE_HPP
+#define INGEN_ENGINE_TEE_HPP
+
+#include <mutex>
+#include <set>
+#include <string>
+
+#include "ingen/Interface.hpp"
+#include "ingen/types.hpp"
+
+namespace Ingen {
+
+/** Interface that forwards all calls to several sinks. */
+class Tee : public Interface
+{
+public:
+ typedef std::set< SPtr<Interface> > Sinks;
+
+ Tee(const Sinks& sinks = {})
+ : _sinks(sinks)
+ {}
+
+ void add_sink(SPtr<Interface> sink) {
+ std::lock_guard<std::mutex> lock(_sinks_mutex);
+ _sinks.insert(sink);
+ }
+
+ bool remove_sink(SPtr<Interface> sink) {
+ std::lock_guard<std::mutex> lock(_sinks_mutex);
+ return (_sinks.erase(sink) > 0);
+ }
+
+ virtual SPtr<Interface> respondee() const {
+ return (*_sinks.begin())->respondee();
+ }
+
+ virtual void set_respondee(SPtr<Interface> respondee) {
+ (*_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 Resource::Properties& properties,
+ Resource::Graph ctx=Resource::Graph::DEFAULT) {
+ BROADCAST(put, uri, properties);
+ }
+
+ void delta(const Raul::URI& uri,
+ const Resource::Properties& remove,
+ const Resource::Properties& add) {
+ BROADCAST(delta, uri, remove, add);
+ }
+
+ 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) {
+ BROADCAST(set_property, subject, predicate, value);
+ }
+
+ 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 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; }
+
+private:
+ std::mutex _sinks_mutex;
+ Sinks _sinks;
+};
+
+} // namespace Ingen
+
+#endif // INGEN_ENGINE_TEE_HPP