diff options
Diffstat (limited to 'ingen')
-rw-r--r-- | ingen/AtomForge.hpp | 41 | ||||
-rw-r--r-- | ingen/AtomWriter.hpp | 2 | ||||
-rw-r--r-- | ingen/Configuration.hpp | 9 | ||||
-rw-r--r-- | ingen/FilePath.hpp | 6 | ||||
-rw-r--r-- | ingen/Forge.hpp | 15 | ||||
-rw-r--r-- | ingen/Parser.hpp | 7 | ||||
-rw-r--r-- | ingen/Serialiser.hpp | 7 | ||||
-rw-r--r-- | ingen/SocketReader.hpp | 22 | ||||
-rw-r--r-- | ingen/SocketWriter.hpp | 3 | ||||
-rw-r--r-- | ingen/StreamWriter.hpp | 3 | ||||
-rw-r--r-- | ingen/TurtleWriter.hpp | 19 | ||||
-rw-r--r-- | ingen/URI.hpp | 114 | ||||
-rw-r--r-- | ingen/URIMap.hpp | 2 | ||||
-rw-r--r-- | ingen/URIs.hpp | 11 | ||||
-rw-r--r-- | ingen/World.hpp | 7 | ||||
-rw-r--r-- | ingen/client/PluginModel.hpp | 9 | ||||
-rw-r--r-- | ingen/client/SocketClient.hpp | 12 | ||||
-rw-r--r-- | ingen/filesystem.hpp | 2 | ||||
-rw-r--r-- | ingen/paths.hpp | 6 |
19 files changed, 99 insertions, 198 deletions
diff --git a/ingen/AtomForge.hpp b/ingen/AtomForge.hpp index acb24fac..241233ea 100644 --- a/ingen/AtomForge.hpp +++ b/ingen/AtomForge.hpp @@ -21,8 +21,8 @@ #include "lv2/atom/atom.h" #include "lv2/atom/forge.h" #include "lv2/atom/util.h" -#include "sord/sordmm.hpp" -#include "sratom/sratom.h" +#include "serd/serd.hpp" +#include "sratom/sratom.hpp" #include <cassert> #include <cstdint> @@ -31,14 +31,19 @@ namespace ingen { -/// An atom forge that writes to an automatically-resized memory buffer +/** An atom forge that writes to an automatically-resized memory buffer. + * + * Can be used to easily forge a complete atom from a node using read(), or + * manually to forge more complex atoms using clear(), atom(), and the + * LV2_Atom_Forge interface. + */ class AtomForge : public LV2_Atom_Forge { public: - explicit AtomForge(LV2_URID_Map& map) + explicit AtomForge(serd::World& world, LV2_URID_Map& map) : _size{0} , _capacity{8 * sizeof(LV2_Atom)} - , _sratom{sratom_new(&map)} + , _forger{world, map} , _buf{(LV2_Atom*)calloc(8, sizeof(LV2_Atom))} { lv2_atom_forge_init(this, &map); @@ -46,14 +51,15 @@ public: } /// Forge an atom from `node` in `model` - void read(Sord::World& world, SordModel* model, const SordNode* node) + const LV2_Atom* read(serd::Model& model, + const serd::Node& node, + const sratom::Flags flags = {}) { - sratom_read(_sratom.get(), this, world.c_obj(), model, node); + clear(); + _forger.read(serd::make_uri("file:///"), *this, model, node, flags); + return atom(); } - /// Return the top-level atom that has been forged - const LV2_Atom* atom() const { return _buf.get(); } - /// Clear the atom buffer and reset the forge void clear() { @@ -62,14 +68,11 @@ public: *_buf = {0U, 0U}; } - /// Return the internal atom serialiser - Sratom& sratom() { return *_sratom; } + /// Return the top-level atom that has been forged + const LV2_Atom* atom() const { return _buf.get(); } private: - struct SratomDeleter { void operator()(Sratom* s) { sratom_free(s); } }; - using AtomPtr = UPtr<LV2_Atom, FreeDeleter<LV2_Atom>>; - using SratomPtr = UPtr<Sratom, SratomDeleter>; /// Append some data and return a reference to its start intptr_t append(const void* buf, uint32_t len) { @@ -110,10 +113,10 @@ private: return ((AtomForge*)handle)->deref(ref); } - size_t _size; ///< Current atom size - size_t _capacity; ///< Allocated size of atom buffer - SratomPtr _sratom; ///< Atom serialiser - AtomPtr _buf; ///< Atom buffer + size_t _size; ///< Current atom size + size_t _capacity; ///< Allocated size of atom buffer + sratom::Forger _forger; ///< Atom forger + AtomPtr _buf; ///< Atom buffer }; } // namespace ingen diff --git a/ingen/AtomWriter.hpp b/ingen/AtomWriter.hpp index f9052d93..565fbdba 100644 --- a/ingen/AtomWriter.hpp +++ b/ingen/AtomWriter.hpp @@ -43,7 +43,7 @@ class INGEN_API AtomWriter : public Interface public: using result_type = void; ///< For boost::apply_visitor - AtomWriter(URIMap& map, URIs& uris, AtomSink& sink); + AtomWriter(serd::World& world, URIMap& map, URIs& uris, AtomSink& sink); URI uri() const override { return URI("ingen:/clients/atom_writer"); } diff --git a/ingen/Configuration.hpp b/ingen/Configuration.hpp index 6c0343b1..20fc79f5 100644 --- a/ingen/Configuration.hpp +++ b/ingen/Configuration.hpp @@ -22,6 +22,7 @@ #include "ingen/ingen.h" #include "lv2/urid/urid.h" #include "raul/Exception.hpp" +#include "serd/serd.hpp" #include <cstdio> #include <list> @@ -86,7 +87,7 @@ public: void parse(int argc, char **argv); /** Load a specific file. */ - bool load(const FilePath& path); + bool load(serd::World& world, const FilePath& path); /** Save configuration to a file. * @@ -103,7 +104,8 @@ public: * * @return The absolute path of the saved configuration file. */ - FilePath save(URIMap& uri_map, + FilePath save(serd::World& world, + URIMap& uri_map, const std::string& app, const FilePath& filename, unsigned scopes); @@ -114,7 +116,8 @@ public: * will be loaded before the user's, e.g. ~/.config/appname/filename, * so the user options will override the system options. */ - std::list<FilePath> load_default(const std::string& app, + std::list<FilePath> load_default(serd::World& world, + const std::string& app, const FilePath& filename); const Atom& option(const std::string& long_name) const; diff --git a/ingen/FilePath.hpp b/ingen/FilePath.hpp index 98893dfc..8d5c6882 100644 --- a/ingen/FilePath.hpp +++ b/ingen/FilePath.hpp @@ -19,7 +19,7 @@ #include "ingen/ingen.h" -#include <boost/utility/string_view.hpp> +#include "serd/serd.hpp" #include <ostream> #include <string> @@ -57,7 +57,7 @@ public: FilePath(string_type&& str) : _str(std::move(str)) {} FilePath(const string_type& str) : _str(str) {} FilePath(const value_type* str) : _str(str) {} - FilePath(const boost::basic_string_view<value_type>& sv) + FilePath(const serd::StringView& sv) : _str(sv.data(), sv.length()) {} @@ -73,7 +73,7 @@ public: FilePath& operator+=(const string_type& str); FilePath& operator+=(const value_type* str); FilePath& operator+=(value_type chr); - FilePath& operator+=(boost::basic_string_view<value_type> sv); + FilePath& operator+=(serd::StringView sv); void clear() noexcept { _str.clear(); } diff --git a/ingen/Forge.hpp b/ingen/Forge.hpp index b414a6ab..53cae153 100644 --- a/ingen/Forge.hpp +++ b/ingen/Forge.hpp @@ -19,7 +19,9 @@ #include "ingen/Atom.hpp" #include "ingen/ingen.h" +#include "lv2/atom/atom.h" #include "lv2/atom/forge.h" +#include "serd/serd.hpp" #include <cstdint> #include <cstring> @@ -59,8 +61,12 @@ public: return Atom(size, type, val); } + Atom alloc(const LV2_Atom* atom) { + return Atom(atom->size, atom->type, LV2_ATOM_BODY_CONST(atom)); + } + Atom alloc(const char* v) { - const size_t len = strlen(v); + const auto len = strlen(v); return Atom(len + 1, String, v); } @@ -68,12 +74,11 @@ public: return Atom(v.length() + 1, String, v.c_str()); } - Atom alloc_uri(const char* v) { - const size_t len = strlen(v); - return Atom(len + 1, URI, v); + Atom alloc(serd::StringView v) { + return Atom(v.length() + 1, String, v.c_str()); } - Atom alloc_uri(const std::string& v) { + Atom alloc_uri(serd::StringView v) { return Atom(v.length() + 1, URI, v.c_str()); } diff --git a/ingen/Parser.hpp b/ingen/Parser.hpp index 45d087cd..697e96c8 100644 --- a/ingen/Parser.hpp +++ b/ingen/Parser.hpp @@ -30,8 +30,6 @@ #include <string> #include <utility> -namespace Sord { class World; } - namespace ingen { class Interface; @@ -63,9 +61,8 @@ public: }; /** Find all resources of a given type listed in a manifest file. */ - virtual std::set<ResourceRecord> find_resources(Sord::World& world, - const URI& manifest_uri, - const URI& type_uri); + virtual std::set<ResourceRecord> find_resources(const URI& manifest_uri, + const URI& type_uri); /** Parse a graph from RDF into a Interface (engine or client). * diff --git a/ingen/Serialiser.hpp b/ingen/Serialiser.hpp index 1ac5c151..522d0bdb 100644 --- a/ingen/Serialiser.hpp +++ b/ingen/Serialiser.hpp @@ -21,7 +21,7 @@ #include "ingen/Properties.hpp" #include "ingen/ingen.h" #include "ingen/types.hpp" -#include "sord/sordmm.hpp" +#include "serd/serd.hpp" #include <string> @@ -30,6 +30,7 @@ namespace Raul { class Path; } namespace ingen { class Arc; +class FilePath; class Node; class URI; class World; @@ -84,8 +85,8 @@ public: * * @throw std::logic_error */ - virtual void serialise_arc(const Sord::Node& parent, - const SPtr<const Arc>& arc); + virtual void serialise_arc(const serd::Optional<serd::Node>& parent, + const SPtr<const Arc>& arc); /** Finish serialization. * diff --git a/ingen/SocketReader.hpp b/ingen/SocketReader.hpp index 3c3c5f3c..8afcafb7 100644 --- a/ingen/SocketReader.hpp +++ b/ingen/SocketReader.hpp @@ -19,8 +19,6 @@ #include "ingen/ingen.h" #include "ingen/types.hpp" -#include "serd/serd.h" -#include "sord/sord.h" #include <thread> @@ -47,29 +45,11 @@ protected: private: void run(); - static SerdStatus set_base_uri(SocketReader* iface, - const SerdNode* uri_node); - - static SerdStatus set_prefix(SocketReader* iface, - const SerdNode* name, - const SerdNode* uri_node); - - static SerdStatus write_statement(SocketReader* iface, - SerdStatementFlags flags, - const SerdNode* graph, - const SerdNode* subject, - const SerdNode* predicate, - const SerdNode* object, - const SerdNode* object_datatype, - const SerdNode* object_lang); - World& _world; Interface& _iface; - SerdEnv* _env; - SordInserter* _inserter; - SordNode* _msg_node; SPtr<Raul::Socket> _socket; bool _exit_flag; + std::thread _thread; }; diff --git a/ingen/SocketWriter.hpp b/ingen/SocketWriter.hpp index 2424fe24..b3852940 100644 --- a/ingen/SocketWriter.hpp +++ b/ingen/SocketWriter.hpp @@ -39,7 +39,8 @@ class URIs; class INGEN_API SocketWriter : public TurtleWriter { public: - SocketWriter(URIMap& map, + SocketWriter(serd::World& world, + URIMap& map, URIs& uris, const URI& uri, SPtr<Raul::Socket> sock); diff --git a/ingen/StreamWriter.hpp b/ingen/StreamWriter.hpp index 56603b92..15ef42c1 100644 --- a/ingen/StreamWriter.hpp +++ b/ingen/StreamWriter.hpp @@ -34,7 +34,8 @@ class URIs; class INGEN_API StreamWriter : public TurtleWriter { public: - StreamWriter(URIMap& map, + StreamWriter(serd::World& world, + URIMap& map, URIs& uris, const URI& uri, FILE* stream, diff --git a/ingen/TurtleWriter.hpp b/ingen/TurtleWriter.hpp index 9c88be2e..09c01d26 100644 --- a/ingen/TurtleWriter.hpp +++ b/ingen/TurtleWriter.hpp @@ -23,7 +23,7 @@ #include "ingen/ingen.h" #include "lv2/atom/atom.h" #include "serd/serd.h" -#include "sratom/sratom.h" +#include "sratom/sratom.hpp" #include <cstddef> #include <cstdint> @@ -41,7 +41,7 @@ class URIs; class INGEN_API TurtleWriter : public AtomWriter, public AtomSink { public: - TurtleWriter(URIMap& map, URIs& uris, URI uri); + TurtleWriter(serd::World& world, URIMap& map, URIs& uris, const URI& uri); ~TurtleWriter() override; @@ -54,14 +54,13 @@ public: URI uri() const override { return _uri; } protected: - URIMap& _map; - Sratom* _sratom; - SerdNode _base; - SerdURI _base_uri; - SerdEnv* _env; - SerdWriter* _writer; - URI _uri; - bool _wrote_prefixes; + URIMap& _map; + sratom::Streamer _streamer; + serd::Node _base; + serd::Env _env; + serd::Writer _writer; + URI _uri; + bool _wrote_prefixes; }; } // namespace ingen diff --git a/ingen/URI.hpp b/ingen/URI.hpp index cbbfd46a..489b6219 100644 --- a/ingen/URI.hpp +++ b/ingen/URI.hpp @@ -19,8 +19,7 @@ #include "ingen/FilePath.hpp" #include "ingen/ingen.h" -#include "serd/serd.h" -#include "sord/sordmm.hpp" +#include "serd/serd.hpp" #include <boost/utility/string_view.hpp> @@ -31,130 +30,45 @@ namespace ingen { -class INGEN_API URI +class INGEN_API URI : public serd::Node { public: - using Chunk = boost::string_view; + using Slice = serd::StringView; - URI(); explicit URI(const std::string& str); explicit URI(const char* str); - URI(const std::string& str, const URI& base); - URI(const Sord::Node& node); - URI(SerdNode node); + URI(const serd::NodeView& node); + URI(const serd::Node& node); explicit URI(const FilePath& path); - URI(const URI& uri); - URI& operator=(const URI& uri); - - URI(URI&& uri) noexcept; - URI& operator=(URI&& uri) noexcept; - - ~URI(); - URI make_relative(const URI& base) const; - bool empty() const { return !_node.buf; } - - std::string string() const { return std::string(c_str(), _node.n_bytes); } - size_t length() const { return _node.n_bytes; } - const char* c_str() const { return (const char*)_node.buf; } + std::string string() const { return std::string(*this); } + std::string str() const { return std::string(*this); } FilePath file_path() const { return scheme() == "file" ? FilePath(path()) : FilePath(); } - operator std::string() const { return string(); } - - const char* begin() const { return (const char*)_node.buf; } - const char* end() const { return (const char*)_node.buf + _node.n_bytes; } - - Chunk scheme() const { return make_chunk(_uri.scheme); } - Chunk authority() const { return make_chunk(_uri.authority); } - Chunk path() const { return make_chunk(_uri.path); } - Chunk query() const { return make_chunk(_uri.query); } - Chunk fragment() const { return make_chunk(_uri.fragment); } + Slice scheme() const { return serd::URI{*this}.scheme(); } + Slice authority() const { return serd::URI{*this}.authority(); } + Slice path() const { return serd::URI{*this}.path(); } + Slice query() const { return serd::URI{*this}.query(); } + Slice fragment() const { return serd::URI{*this}.fragment(); } static bool is_valid(const char* str) { - return serd_uri_string_has_scheme((const uint8_t*)str); + return serd_uri_string_has_scheme(str); } static bool is_valid(const std::string& str) { return is_valid(str.c_str()); } - -private: - URI(SerdNode node, SerdURI uri); - - static Chunk make_chunk(const SerdChunk& chunk) { - return Chunk((const char*)chunk.buf, chunk.len); - } - - SerdURI _uri; - SerdNode _node; }; -inline bool operator==(const URI& lhs, const URI& rhs) -{ - return lhs.string() == rhs.string(); -} - inline bool operator==(const URI& lhs, const std::string& rhs) { - return lhs.string() == rhs; -} - -inline bool operator==(const URI& lhs, const char* rhs) -{ - return lhs.string() == rhs; -} - -inline bool operator==(const URI& lhs, const Sord::Node& rhs) -{ - return rhs.type() == Sord::Node::URI && lhs.string() == rhs.to_string(); -} - -inline bool operator==(const Sord::Node& lhs, const URI& rhs) -{ - return rhs == lhs; -} - -inline bool operator!=(const URI& lhs, const URI& rhs) -{ - return lhs.string() != rhs.string(); -} - -inline bool operator!=(const URI& lhs, const std::string& rhs) -{ - return lhs.string() != rhs; -} - -inline bool operator!=(const URI& lhs, const char* rhs) -{ - return lhs.string() != rhs; -} - -inline bool operator!=(const URI& lhs, const Sord::Node& rhs) -{ - return !(lhs == rhs); -} - -inline bool operator!=(const Sord::Node& lhs, const URI& rhs) -{ - return !(lhs == rhs); -} - -inline bool operator<(const URI& lhs, const URI& rhs) -{ - return lhs.string() < rhs.string(); -} - -template <typename Char, typename Traits> -inline std::basic_ostream<Char, Traits>& -operator<<(std::basic_ostream<Char, Traits>& os, const URI& uri) -{ - return os << uri.string(); + return lhs.c_str() == rhs; } } // namespace ingen diff --git a/ingen/URIMap.hpp b/ingen/URIMap.hpp index a3b9f219..3ca22557 100644 --- a/ingen/URIMap.hpp +++ b/ingen/URIMap.hpp @@ -18,6 +18,7 @@ #define INGEN_URIMAP_HPP #include "ingen/LV2Features.hpp" +#include "ingen/URI.hpp" #include "ingen/ingen.h" #include "ingen/types.hpp" #include "lv2/core/lv2.h" @@ -45,6 +46,7 @@ public: uint32_t map_uri(const char* uri); uint32_t map_uri(const std::string& uri) { return map_uri(uri.c_str()); } + uint32_t map_uri(const URI& uri) { return map_uri(uri.c_str()); } const char* unmap_uri(uint32_t urid) const; class Feature : public LV2Features::Feature { diff --git a/ingen/URIs.hpp b/ingen/URIs.hpp index eb657473..f8bf65a9 100644 --- a/ingen/URIs.hpp +++ b/ingen/URIs.hpp @@ -47,17 +47,12 @@ public: LilvWorld* lworld, const char* str); - Quark(const Quark& copy); - - ~Quark(); - operator LV2_URID() const { return urid.get<LV2_URID>(); } explicit operator Atom() const { return urid; } - operator const LilvNode*() const { return lnode; } + operator const LilvNode*() const { return cobj(); } - Atom urid; - Atom uri; - LilvNode* lnode; + Atom urid; + Atom uri; }; ingen::Forge& forge; diff --git a/ingen/World.hpp b/ingen/World.hpp index a2906525..62d160b1 100644 --- a/ingen/World.hpp +++ b/ingen/World.hpp @@ -28,7 +28,7 @@ typedef struct LilvWorldImpl LilvWorld; -namespace Sord { class World; } +namespace serd { class World; class Env; } namespace ingen { @@ -49,7 +49,7 @@ class URIs; * * This is the root to which all components of Ingen are connected. It * contains all necessary shared data (including the world for libraries like - * Sord and Lilv) and holds references to components. + * Serd and Lilv) and holds references to components. * * Some functionality in Ingen is implemented in dynamically loaded modules, * which are loaded using this interface. When loaded, those modules add @@ -126,7 +126,8 @@ public: /** Lock for rdf_world() or lilv_world(). */ virtual std::mutex& rdf_mutex(); - virtual Sord::World* rdf_world(); + virtual serd::World& rdf_world(); + virtual serd::Env& env(); virtual LilvWorld* lilv_world(); virtual LV2Features& lv2_features(); diff --git a/ingen/client/PluginModel.hpp b/ingen/client/PluginModel.hpp index 5f43b3c4..c2d291f0 100644 --- a/ingen/client/PluginModel.hpp +++ b/ingen/client/PluginModel.hpp @@ -25,7 +25,7 @@ #include "ingen/types.hpp" #include "lilv/lilv.h" #include "raul/Symbol.hpp" -#include "sord/sordmm.hpp" +#include "serd/serd.hpp" #include <cstdint> #include <map> @@ -88,12 +88,6 @@ public: std::string documentation(bool html) const; std::string port_documentation(uint32_t index, bool html) const; - static void set_rdf_world(Sord::World& world) { - _rdf_world = &world; - } - - static Sord::World* rdf_world() { return _rdf_world; } - // Signals INGEN_SIGNAL(changed, void); INGEN_SIGNAL(property, void, const URI&, const Atom&); @@ -111,7 +105,6 @@ protected: private: std::string get_documentation(const LilvNode* subject, bool html) const; - static Sord::World* _rdf_world; static LilvWorld* _lilv_world; static const LilvPlugins* _lilv_plugins; diff --git a/ingen/client/SocketClient.hpp b/ingen/client/SocketClient.hpp index 092ef9d2..b3656d92 100644 --- a/ingen/client/SocketClient.hpp +++ b/ingen/client/SocketClient.hpp @@ -33,9 +33,13 @@ public: const URI& uri, SPtr<Raul::Socket> sock, SPtr<Interface> respondee) - : SocketWriter(world.uri_map(), world.uris(), uri, sock) - , _respondee(respondee) - , _reader(world, *respondee.get(), sock) + : SocketWriter(world.rdf_world(), + world.uri_map(), + world.uris(), + uri, + sock) + , _respondee(respondee) + , _reader(world, *respondee.get(), sock) {} SPtr<Interface> respondee() const override { @@ -56,7 +60,7 @@ public: : Raul::Socket::Type::TCP); SPtr<Raul::Socket> sock(new Raul::Socket(type)); - if (!sock->connect(uri)) { + if (!sock->connect(uri.str())) { world.log().error("Failed to connect <%1%> (%2%)\n", sock->uri(), strerror(errno)); return SPtr<Interface>(); diff --git a/ingen/filesystem.hpp b/ingen/filesystem.hpp index 5156eb79..8be6b1f4 100644 --- a/ingen/filesystem.hpp +++ b/ingen/filesystem.hpp @@ -27,6 +27,8 @@ # include <io.h> # define F_OK 0 # define mkdir(path, flags) _mkdir(path) +#else +# include <unistd.h> #endif #include <cerrno> diff --git a/ingen/paths.hpp b/ingen/paths.hpp index 05496114..fa6c9aff 100644 --- a/ingen/paths.hpp +++ b/ingen/paths.hpp @@ -29,12 +29,12 @@ inline URI main_uri() { return URI("ingen:/main"); } inline bool uri_is_path(const URI& uri) { - const size_t root_len = main_uri().string().length(); + const size_t root_len = main_uri().length(); if (uri == main_uri()) { return true; } else { - return uri.string().substr(0, root_len + 1) == - main_uri().string() + "/"; + return uri.str().substr(0, root_len + 1) == + main_uri().str() + "/"; } } |