summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-10-24 22:13:22 +0000
committerDavid Robillard <d@drobilla.net>2015-10-24 22:13:22 +0000
commite4d549a7d7322103904ac8ba8d5a4711c6901870 (patch)
tree48f837795ccf77cbb8a5005eeabe8866ed588503
parent732bfb33105b4a534bc17caae9a50a1ccfcd7570 (diff)
downloadingen-e4d549a7d7322103904ac8ba8d5a4711c6901870.tar.gz
ingen-e4d549a7d7322103904ac8ba8d5a4711c6901870.tar.bz2
ingen-e4d549a7d7322103904ac8ba8d5a4711c6901870.zip
Set prefixes on the wire to reduce traffic
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5779 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--ingen/SocketWriter.hpp5
-rw-r--r--src/SocketWriter.cpp29
2 files changed, 31 insertions, 3 deletions
diff --git a/ingen/SocketWriter.hpp b/ingen/SocketWriter.hpp
index 85264f30..bb5c332b 100644
--- a/ingen/SocketWriter.hpp
+++ b/ingen/SocketWriter.hpp
@@ -46,8 +46,9 @@ public:
void bundle_end();
- int fd() { return _socket->fd(); }
- Raul::URI uri() const { return _uri; }
+ int fd() { return _socket->fd(); }
+ Raul::URI uri() const { return _uri; }
+ SerdWriter* writer() { return _writer; }
protected:
URIMap& _map;
diff --git a/src/SocketWriter.cpp b/src/SocketWriter.cpp
index 23c28394..3ef9f2a2 100644
--- a/src/SocketWriter.cpp
+++ b/src/SocketWriter.cpp
@@ -25,6 +25,8 @@
# define MSG_NOSIGNAL 0
#endif
+#define USTR(s) ((const uint8_t*)(s))
+
namespace Ingen {
static size_t
@@ -38,6 +40,14 @@ socket_sink(const void* buf, size_t len, void* stream)
return ret;
}
+static SerdStatus
+write_prefix(void* handle, const SerdNode* name, const SerdNode* uri)
+{
+ SocketWriter* writer = (SocketWriter*)handle;
+ serd_writer_set_prefix(writer->writer(), name, uri);
+ return SERD_SUCCESS;
+}
+
SocketWriter::SocketWriter(URIMap& map,
URIs& uris,
const Raul::URI& uri,
@@ -53,7 +63,20 @@ SocketWriter::SocketWriter(URIMap& map,
serd_uri_parse(_base.buf, &_base_uri);
- _env = serd_env_new(&_base);
+ // Set up serialisation environment
+ _env = serd_env_new(&_base);
+ serd_env_set_prefix_from_strings(_env, USTR("atom"), USTR("http://lv2plug.in/ns/ext/atom#"));
+ serd_env_set_prefix_from_strings(_env, USTR("patch"), USTR("http://lv2plug.in/ns/ext/patch#"));
+ serd_env_set_prefix_from_strings(_env, USTR("doap"), USTR("http://usefulinc.com/ns/doap#"));
+ serd_env_set_prefix_from_strings(_env, USTR("ingen"), USTR(INGEN_NS));
+ serd_env_set_prefix_from_strings(_env, USTR("lv2"), USTR("http://lv2plug.in/ns/lv2core#"));
+ serd_env_set_prefix_from_strings(_env, USTR("midi"), USTR("http://lv2plug.in/ns/ext/midi#"));
+ serd_env_set_prefix_from_strings(_env, USTR("owl"), USTR("http://www.w3.org/2002/07/owl#"));
+ serd_env_set_prefix_from_strings(_env, USTR("rdf"), USTR("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
+ serd_env_set_prefix_from_strings(_env, USTR("rdfs"), USTR("http://www.w3.org/2000/01/rdf-schema#"));
+ serd_env_set_prefix_from_strings(_env, USTR("xsd"), USTR("http://www.w3.org/2001/XMLSchema#"));
+
+ // Make a Turtle writer that writes directly to the socket
_writer = serd_writer_new(
SERD_TURTLE,
(SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED),
@@ -62,6 +85,10 @@ SocketWriter::SocketWriter(URIMap& map,
socket_sink,
this);
+ // Write namespace prefixes to reduce traffic
+ serd_env_foreach(_env, write_prefix, this);
+
+ // Configure sratom to write directly to the writer (and thus the socket)
sratom_set_sink(_sratom,
(const char*)_base.buf,
(SerdStatementSink)serd_writer_write_statement,