summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/AtomSink.hpp34
-rw-r--r--src/shared/AtomWriter.cpp48
-rw-r--r--src/shared/AtomWriter.hpp89
-rw-r--r--src/shared/LV2Atom.cpp4
-rw-r--r--src/shared/URIs.cpp2
5 files changed, 47 insertions, 130 deletions
diff --git a/src/shared/AtomSink.hpp b/src/shared/AtomSink.hpp
deleted file mode 100644
index 5bc5aef6..00000000
--- a/src/shared/AtomSink.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/* This file is part of Ingen.
- * Copyright 2012 David Robillard <http://drobilla.net>
- *
- * Ingen is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) 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 General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef INGEN_ATOMSINK_HPP
-#define INGEN_ATOMSINK_HPP
-
-namespace Ingen {
-namespace Shared {
-
-class AtomSink
-{
-public:
- virtual void write(const LV2_Atom* msg) = 0;
-};
-
-} // namespace Shared
-} // namespace Ingen
-
-#endif // INGEN_ATOMSINK_HPP
-
diff --git a/src/shared/AtomWriter.cpp b/src/shared/AtomWriter.cpp
index a5317bfb..c86ac96f 100644
--- a/src/shared/AtomWriter.cpp
+++ b/src/shared/AtomWriter.cpp
@@ -15,19 +15,50 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "ingen/shared/AtomSink.hpp"
+#include "ingen/shared/AtomWriter.hpp"
#include "raul/Path.hpp"
-
-#include "AtomWriter.hpp"
+#include "serd/serd.h"
namespace Ingen {
namespace Shared {
-AtomWriter::AtomWriter(LV2URIMap& map, URIs& uris)
+static LV2_Atom_Forge_Ref
+forge_sink(LV2_Atom_Forge_Sink_Handle handle,
+ const void* buf,
+ uint32_t size)
+{
+ SerdChunk* chunk = (SerdChunk*)handle;
+ const LV2_Atom_Forge_Ref ref = chunk->len + 1;
+ serd_chunk_sink(buf, size, chunk);
+ return ref;
+}
+
+static LV2_Atom*
+forge_deref(LV2_Atom_Forge_Sink_Handle handle, LV2_Atom_Forge_Ref ref)
+{
+ SerdChunk* chunk = (SerdChunk*)handle;
+ return (LV2_Atom*)(chunk->buf + ref - 1);
+}
+
+
+AtomWriter::AtomWriter(LV2URIMap& map, URIs& uris, AtomSink& sink)
: _map(map)
, _uris(uris)
- , _id(-1)
+ , _sink(sink)
+ , _id(1)
{
+ _out.buf = NULL;
+ _out.len = 0;
lv2_atom_forge_init(&_forge, &map.urid_map_feature()->urid_map);
+ lv2_atom_forge_set_sink(&_forge, forge_sink, forge_deref, &_out);
+}
+
+void
+AtomWriter::finish_msg()
+{
+ _sink.write((LV2_Atom*)_out.buf);
+ _out.len = 0;
}
int32_t
@@ -55,6 +86,11 @@ AtomWriter::put(const Raul::URI& uri,
const Resource::Properties& properties,
Resource::Graph ctx)
{
+ LV2_Atom_Forge_Frame msg;
+ lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Put);
+ // ...
+ lv2_atom_forge_pop(&_forge, &msg);
+ finish_msg();
}
void
@@ -92,6 +128,8 @@ AtomWriter::connect(const Raul::Path& src,
lv2_atom_forge_pop(&_forge, &body);
lv2_atom_forge_pop(&_forge, &msg);
+
+ finish_msg();
}
void
@@ -126,6 +164,7 @@ AtomWriter::get(const Raul::URI& uri)
lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0);
lv2_atom_forge_uri(&_forge, uri.c_str(), uri.length());
lv2_atom_forge_pop(&_forge, &msg);
+ finish_msg();
}
void
@@ -136,6 +175,7 @@ AtomWriter::response(int32_t id, Status status)
lv2_atom_forge_property_head(&_forge, _uris.patch_request, 0);
lv2_atom_forge_int32(&_forge, id);
lv2_atom_forge_pop(&_forge, &msg);
+ finish_msg();
}
void
diff --git a/src/shared/AtomWriter.hpp b/src/shared/AtomWriter.hpp
deleted file mode 100644
index 2983848c..00000000
--- a/src/shared/AtomWriter.hpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/* This file is part of Ingen.
- * Copyright 2012 David Robillard <http://drobilla.net>
- *
- * Ingen is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) 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 General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef INGEN_SHARED_ATOM_WRITER_HPP
-#define INGEN_SHARED_ATOM_WRITER_HPP
-
-#include "ingen/Interface.hpp"
-#include "ingen/shared/LV2URIMap.hpp"
-#include "ingen/shared/URIs.hpp"
-#include "lv2/lv2plug.in/ns/ext/atom/forge.h"
-
-namespace Ingen {
-namespace Shared {
-
-/** An Interface that writes LV2 atoms. */
-class AtomWriter : public Interface
-{
-public:
- AtomWriter(LV2URIMap& map, URIs& uris);
- ~AtomWriter() {}
-
- Raul::URI uri() const { return "http://drobilla.net/ns/ingen#AtomWriter"; }
-
- void bundle_begin();
-
- void bundle_end();
-
- void put(const Raul::URI& uri,
- const Resource::Properties& properties,
- Resource::Graph ctx = Resource::DEFAULT);
-
- void delta(const Raul::URI& uri,
- const Resource::Properties& remove,
- const Resource::Properties& add);
-
- void move(const Raul::Path& old_path,
- const Raul::Path& new_path);
-
- void del(const Raul::URI& uri);
-
- void connect(const Raul::Path& src_port_path,
- const Raul::Path& dst_port_path);
-
- void disconnect(const Raul::URI& src,
- const Raul::URI& dst);
-
- 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 Raul::Atom& value);
-
- void set_response_id(int32_t id);
-
- void get(const Raul::URI& uri);
-
- void response(int32_t id, Status status);
-
- void error(const std::string& msg);
-
-private:
- int32_t next_id();
-
- LV2URIMap& _map;
- URIs& _uris;
- LV2_Atom_Forge _forge;
- int32_t _id;
-};
-
-} // namespace Shared
-} // namespace Ingen
-
-#endif // INGEN_SHARED_ATOM_WRITER_HPP
-
diff --git a/src/shared/LV2Atom.cpp b/src/shared/LV2Atom.cpp
index 63686bf5..ccd5f352 100644
--- a/src/shared/LV2Atom.cpp
+++ b/src/shared/LV2Atom.cpp
@@ -43,7 +43,7 @@ to_atom(Raul::Forge* forge,
} else if (object->type == uris.atom_Bool.id) {
atom = forge->make((bool)(int32_t*)(object + 1));
return true;
- } else if (object->type == uris.atom_Int32.id) {
+ } else if (object->type == uris.atom_Int.id) {
atom = forge->make((int32_t*)(object + 1));
return true;
} else if (object->type == uris.atom_Float.id) {
@@ -67,7 +67,7 @@ from_atom(const Shared::URIs& uris, const Raul::Atom& atom, LV2_Atom* object)
*(float*)(object + 1) = atom.get_float();
break;
case Raul::Atom::INT:
- object->type = uris.atom_Int32.id;
+ object->type = uris.atom_Int.id;
object->size = sizeof(int32_t);
*(int32_t*)(object + 1) = atom.get_int32();
break;
diff --git a/src/shared/URIs.cpp b/src/shared/URIs.cpp
index 3ca8a69d..73718fab 100644
--- a/src/shared/URIs.cpp
+++ b/src/shared/URIs.cpp
@@ -52,7 +52,7 @@ URIs::URIs(Raul::Forge& f, LV2URIMap* map)
: forge(f)
, atom_Bool (map, LV2_ATOM__Bool)
, atom_Float (map, LV2_ATOM__Float)
- , atom_Int32 (map, LV2_ATOM__Int32)
+ , atom_Int (map, LV2_ATOM__Int)
, atom_MessagePort (map, LV2_ATOM__MessagePort)
, atom_String (map, LV2_ATOM__String)
, atom_ValuePort (map, LV2_ATOM__ValuePort)