summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/World.cpp')
-rw-r--r--src/World.cpp311
1 files changed, 199 insertions, 112 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 41e69826..7e643002 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -14,36 +14,35 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ingen/World.hpp"
-
-#include "ingen/Atom.hpp"
-#include "ingen/Configuration.hpp"
-#include "ingen/DataAccess.hpp"
-#include "ingen/EngineBase.hpp"
-#include "ingen/FilePath.hpp"
-#include "ingen/Forge.hpp"
-#include "ingen/InstanceAccess.hpp"
-#include "ingen/LV2Features.hpp"
-#include "ingen/Library.hpp"
-#include "ingen/Log.hpp"
-#include "ingen/Module.hpp"
-#include "ingen/Parser.hpp"
-#include "ingen/Serialiser.hpp"
-#include "ingen/URI.hpp"
-#include "ingen/URIMap.hpp"
-#include "ingen/URIs.hpp"
-#include "ingen/ingen.h"
-#include "ingen/runtime_paths.hpp"
-#include "lilv/lilv.h"
-#include "lv2/log/log.h"
-#include "lv2/urid/urid.h"
-#include "sord/sordmm.hpp"
+#include <ingen/World.hpp>
+
+#include <ingen/Atom.hpp>
+#include <ingen/Configuration.hpp>
+#include <ingen/DataAccess.hpp>
+#include <ingen/EngineBase.hpp>
+#include <ingen/Forge.hpp>
+#include <ingen/InstanceAccess.hpp>
+#include <ingen/LV2Features.hpp>
+#include <ingen/Library.hpp>
+#include <ingen/Log.hpp>
+#include <ingen/Module.hpp>
+#include <ingen/Parser.hpp>
+#include <ingen/Serialiser.hpp>
+#include <ingen/URI.hpp>
+#include <ingen/URIMap.hpp>
+#include <ingen/URIs.hpp>
+#include <ingen/ingen.h>
+#include <ingen/runtime_paths.hpp>
+#include <lilv/lilv.h>
+#include <lv2/log/log.h>
+#include <lv2/urid/urid.h>
+#include <sord/sordmm.hpp>
#include <cstdint>
+#include <filesystem>
#include <list>
#include <map>
#include <memory>
-#include <sstream>
#include <string>
#include <utility>
@@ -68,38 +67,38 @@ ingen_load_library(Log& log, const string& name)
const auto path = ingen_module_path(name);
if (path.empty()) {
log.error("Failed to find %1% (%2%)\n",
- name, Library::get_last_error());
+ name,
+ Library::get_last_error());
return nullptr;
}
- UPtr<Library> library = make_unique<Library>(path);
+ log.info("Loading module %1%\n", path);
+
+ std::unique_ptr<Library> library = std::make_unique<Library>(path);
if (*library) {
return library;
}
log.error("Unable to load %1% from %2% (%3%)\n",
- name, path, Library::get_last_error());
+ name,
+ path,
+ Library::get_last_error());
return nullptr;
}
-class World::Impl {
+class World::Impl
+{
public:
- Impl(LV2_URID_Map* map,
- LV2_URID_Unmap* unmap,
- LV2_Log_Log* lv2_log)
- : argc(nullptr)
- , argv(nullptr)
- , lv2_features(nullptr)
- , rdf_world(new Sord::World())
- , lilv_world(lilv_world_new(), lilv_world_free)
- , uri_map(log, map, unmap)
- , forge(uri_map)
- , uris(forge, &uri_map, lilv_world.get())
- , lv2_log()
- , conf(forge)
- , log(lv2_log, uris)
+ Impl(LV2_URID_Map* map, LV2_URID_Unmap* unmap, LV2_Log_Log* log_feature)
+ : lv2_features(new LV2Features())
+ , rdf_world(new Sord::World())
+ , lilv_world(lilv_world_new(), lilv_world_free)
+ , uri_map(log, map, unmap)
+ , forge(uri_map)
+ , uris(forge, &uri_map, lilv_world.get())
+ , conf(forge)
+ , log(log_feature, uris)
{
- lv2_features = new LV2Features();
lv2_features->add_feature(uri_map.urid_map_feature());
lv2_features->add_feature(uri_map.urid_unmap_feature());
lv2_features->add_feature(std::make_shared<InstanceAccess>());
@@ -108,25 +107,28 @@ public:
lilv_world_load_all(lilv_world.get());
// Set up RDF namespaces
- rdf_world->add_prefix("atom", "http://lv2plug.in/ns/ext/atom#");
- rdf_world->add_prefix("doap", "http://usefulinc.com/ns/doap#");
+ rdf_world->add_prefix("atom", "http://lv2plug.in/ns/ext/atom#");
+ rdf_world->add_prefix("doap", "http://usefulinc.com/ns/doap#");
rdf_world->add_prefix("ingen", INGEN_NS);
- rdf_world->add_prefix("lv2", "http://lv2plug.in/ns/lv2core#");
- rdf_world->add_prefix("midi", "http://lv2plug.in/ns/ext/midi#");
- rdf_world->add_prefix("owl", "http://www.w3.org/2002/07/owl#");
+ rdf_world->add_prefix("lv2", "http://lv2plug.in/ns/lv2core#");
+ rdf_world->add_prefix("midi", "http://lv2plug.in/ns/ext/midi#");
+ rdf_world->add_prefix("owl", "http://www.w3.org/2002/07/owl#");
rdf_world->add_prefix("patch", "http://lv2plug.in/ns/ext/patch#");
- rdf_world->add_prefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
- rdf_world->add_prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
- rdf_world->add_prefix("xsd", "http://www.w3.org/2001/XMLSchema#");
+ rdf_world->add_prefix("rdf",
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ rdf_world->add_prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
+ rdf_world->add_prefix("xsd", "http://www.w3.org/2001/XMLSchema#");
// Load internal 'plugin' information into lilv world
- LilvNode* rdf_type = lilv_new_uri(
- lilv_world.get(), "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
- LilvNode* ingen_Plugin = lilv_new_uri(
- lilv_world.get(), INGEN__Plugin);
- LilvNodes* internals = lilv_world_find_nodes(
- lilv_world.get(), nullptr, rdf_type, ingen_Plugin);
- LILV_FOREACH(nodes, i, internals) {
+ LilvNode* rdf_type =
+ lilv_new_uri(lilv_world.get(),
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
+ LilvNode* ingen_Plugin = lilv_new_uri(lilv_world.get(), INGEN__Plugin);
+ LilvNodes* internals = lilv_world_find_nodes(lilv_world.get(),
+ nullptr,
+ rdf_type,
+ ingen_Plugin);
+ LILV_FOREACH (nodes, i, internals) {
const LilvNode* internal = lilv_nodes_get(internals, i);
lilv_world_load_resource(lilv_world.get(), internal);
}
@@ -164,44 +166,45 @@ public:
}
Impl(const Impl&) = delete;
- Impl(Impl&&) = delete;
+ Impl(Impl&&) = delete;
Impl& operator=(const Impl&) = delete;
Impl& operator=(Impl&&) = delete;
using Modules = std::map<std::string, Module*>;
Modules modules;
- using InterfaceFactories = std::map<const std::string, World::InterfaceFactory>;
+ using InterfaceFactories =
+ std::map<const std::string, World::InterfaceFactory>;
InterfaceFactories interface_factories;
using ScriptRunner = bool (*)(World& world, const char* filename);
using ScriptRunners = std::map<const std::string, ScriptRunner>;
ScriptRunners script_runners;
- using LilvWorldUPtr = std::unique_ptr<LilvWorld, decltype(&lilv_world_free)>;
-
- int* argc;
- char*** argv;
- LV2Features* lv2_features;
- UPtr<Sord::World> rdf_world;
- LilvWorldUPtr lilv_world;
- URIMap uri_map;
- Forge forge;
- URIs uris;
- LV2_Log_Log* lv2_log;
- Configuration conf;
- Log log;
- SPtr<Interface> interface;
- SPtr<EngineBase> engine;
- SPtr<Serialiser> serialiser;
- SPtr<Parser> parser;
- SPtr<Store> store;
- std::mutex rdf_mutex;
- std::string jack_uuid;
+ using LilvWorldUPtr =
+ std::unique_ptr<LilvWorld, decltype(&lilv_world_free)>;
+
+ int* argc{nullptr};
+ char*** argv{nullptr};
+ LV2Features* lv2_features;
+ std::unique_ptr<Sord::World> rdf_world;
+ LilvWorldUPtr lilv_world;
+ URIMap uri_map;
+ Forge forge;
+ URIs uris;
+ Configuration conf;
+ Log log;
+ std::shared_ptr<Interface> interface;
+ std::shared_ptr<EngineBase> engine;
+ std::shared_ptr<Serialiser> serialiser;
+ std::shared_ptr<Parser> parser;
+ std::shared_ptr<Store> store;
+ std::mutex rdf_mutex;
+ std::string jack_uuid;
};
World::World(LV2_URID_Map* map, LV2_URID_Unmap* unmap, LV2_Log_Log* log)
- : _impl(new Impl(map, unmap, log))
+ : _impl(new Impl(map, unmap, log))
{
_impl->serialiser = std::make_shared<Serialiser>(*this);
_impl->parser = std::make_shared<Parser>();
@@ -230,30 +233,108 @@ World::load_configuration(int& argc, char**& argv)
_impl->log.set_trace(_impl->conf.option("trace").get<int32_t>());
}
-void World::set_engine(const SPtr<EngineBase>& e) { _impl->engine = e; }
-void World::set_interface(const SPtr<Interface>& i) { _impl->interface = i; }
-void World::set_store(const SPtr<Store>& s) { _impl->store = s; }
+void
+World::set_engine(const std::shared_ptr<EngineBase>& e)
+{
+ _impl->engine = e;
+}
-SPtr<EngineBase> World::engine() { return _impl->engine; }
-SPtr<Interface> World::interface() { return _impl->interface; }
-SPtr<Parser> World::parser() { return _impl->parser; }
-SPtr<Serialiser> World::serialiser() { return _impl->serialiser; }
-SPtr<Store> World::store() { return _impl->store; }
+void
+World::set_interface(const std::shared_ptr<Interface>& i)
+{
+ _impl->interface = i;
+}
-int& World::argc() { return *_impl->argc; }
-char**& World::argv() { return *_impl->argv; }
-Configuration& World::conf() { return _impl->conf; }
-Log& World::log() { return _impl->log; }
+void
+World::set_store(const std::shared_ptr<Store>& s)
+{
+ _impl->store = s;
+}
-std::mutex& World::rdf_mutex() { return _impl->rdf_mutex; }
+std::shared_ptr<EngineBase>
+World::engine()
+{
+ return _impl->engine;
+}
+std::shared_ptr<Interface>
+World::interface()
+{
+ return _impl->interface;
+}
+std::shared_ptr<Parser>
+World::parser()
+{
+ return _impl->parser;
+}
+std::shared_ptr<Serialiser>
+World::serialiser()
+{
+ return _impl->serialiser;
+}
+std::shared_ptr<Store>
+World::store()
+{
+ return _impl->store;
+}
-Sord::World* World::rdf_world() { return _impl->rdf_world.get(); }
-LilvWorld* World::lilv_world() { return _impl->lilv_world.get(); }
+int&
+World::argc()
+{
+ return *_impl->argc;
+}
+char**&
+World::argv()
+{
+ return *_impl->argv;
+}
+Configuration&
+World::conf()
+{
+ return _impl->conf;
+}
+Log&
+World::log()
+{
+ return _impl->log;
+}
+
+std::mutex&
+World::rdf_mutex()
+{
+ return _impl->rdf_mutex;
+}
+
+Sord::World*
+World::rdf_world()
+{
+ return _impl->rdf_world.get();
+}
+LilvWorld*
+World::lilv_world()
+{
+ return _impl->lilv_world.get();
+}
-LV2Features& World::lv2_features() { return *_impl->lv2_features; }
-Forge& World::forge() { return _impl->forge; }
-URIs& World::uris() { return _impl->uris; }
-URIMap& World::uri_map() { return _impl->uri_map; }
+LV2Features&
+World::lv2_features()
+{
+ return *_impl->lv2_features;
+}
+Forge&
+World::forge()
+{
+ return _impl->forge;
+}
+URIs&
+World::uris()
+{
+ return _impl->uris;
+}
+URIMap&
+World::uri_map()
+{
+ return _impl->uri_map;
+}
bool
World::load_module(const char* name)
@@ -262,11 +343,14 @@ World::load_module(const char* name)
if (i != _impl->modules.end()) {
return true;
}
- log().info("Loading %1% module\n", name);
+
std::unique_ptr<ingen::Library> lib = ingen_load_library(log(), name);
+
ingen::Module* (*module_load)() =
- lib ? (ingen::Module* (*)())lib->get_function("ingen_module_load")
- : nullptr;
+ lib ? reinterpret_cast<ingen::Module* (*)()>(
+ lib->get_function("ingen_module_load"))
+ : nullptr;
+
if (module_load) {
Module* module = module_load();
if (module) {
@@ -278,7 +362,8 @@ World::load_module(const char* name)
}
log().error("Failed to load module `%1%' (%2%)\n",
- name, lib->get_last_error());
+ name,
+ lib->get_last_error());
return false;
}
@@ -297,14 +382,15 @@ World::run_module(const char* name)
/** Get an interface for a remote engine at `engine_uri`
*/
-SPtr<Interface>
-World::new_interface(const URI& engine_uri, const SPtr<Interface>& respondee)
+std::shared_ptr<Interface>
+World::new_interface(const URI& engine_uri,
+ const std::shared_ptr<Interface>& respondee)
{
- const Impl::InterfaceFactories::const_iterator i =
- _impl->interface_factories.find(std::string(engine_uri.scheme()));
+ const auto i =
+ _impl->interface_factories.find(std::string{engine_uri.scheme()});
if (i == _impl->interface_factories.end()) {
log().warn("Unknown URI scheme `%1%'\n", engine_uri.scheme());
- return SPtr<Interface>();
+ return nullptr;
}
return i->second(*this, engine_uri, respondee);
@@ -314,7 +400,7 @@ World::new_interface(const URI& engine_uri, const SPtr<Interface>& respondee)
bool
World::run(const std::string& mime_type, const std::string& filename)
{
- const Impl::ScriptRunners::const_iterator i = _impl->script_runners.find(mime_type);
+ const auto i = _impl->script_runners.find(mime_type);
if (i == _impl->script_runners.end()) {
log().warn("Unknown script MIME type `%1%'\n", mime_type);
return false;
@@ -324,7 +410,8 @@ World::run(const std::string& mime_type, const std::string& filename)
}
void
-World::add_interface_factory(const std::string& scheme, InterfaceFactory factory)
+World::add_interface_factory(const std::string& scheme,
+ InterfaceFactory factory)
{
_impl->interface_factories.emplace(scheme, factory);
}