summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/Module.cpp33
-rw-r--r--src/shared/World.cpp65
-rw-r--r--src/shared/wscript45
3 files changed, 66 insertions, 77 deletions
diff --git a/src/shared/Module.cpp b/src/shared/Module.cpp
deleted file mode 100644
index 9ef8f0d6..00000000
--- a/src/shared/Module.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- This file is part of Ingen.
- Copyright 2007-2012 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/>.
-*/
-
-#include <glibmm/module.h>
-
-#include "raul/log.hpp"
-#include "raul/SharedPtr.hpp"
-
-#include "ingen/shared/Module.hpp"
-
-namespace Ingen {
-namespace Shared {
-
-Module::~Module()
-{
- Raul::info("[Module] ")(Raul::fmt("Unloading %1%\n") % library->get_name());
-}
-
-} // namespace Shared
-} // namespace Ingen
diff --git a/src/shared/World.cpp b/src/shared/World.cpp
index b71ea8c8..608a8409 100644
--- a/src/shared/World.cpp
+++ b/src/shared/World.cpp
@@ -50,7 +50,7 @@ namespace Shared {
*
* \param name The base name of the module, e.g. "ingen_serialisation"
*/
-static SharedPtr<Glib::Module>
+Glib::Module*
ingen_load_module(const string& name)
{
Glib::Module* module = NULL;
@@ -61,15 +61,14 @@ ingen_load_module(const string& name)
if (module_path_found) {
string dir;
istringstream iss(module_path);
- while (getline(iss, dir, ':')) {
+ while (getline(iss, dir, G_SEARCHPATH_SEPARATOR)) {
string filename = Shared::module_path(name, dir);
if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
- module = new Glib::Module(filename, Glib::MODULE_BIND_LAZY);
+ module = new Glib::Module(filename);
if (*module) {
LOG(Raul::info)(Raul::fmt("Loading %1%\n") % filename);
- return SharedPtr<Glib::Module>(module);
+ return module;
} else {
- delete module;
Raul::error << Glib::Module::get_last_error() << endl;
}
}
@@ -77,23 +76,20 @@ ingen_load_module(const string& name)
}
// Try default directory if not found
- module = new Glib::Module(Shared::module_path(name), Glib::MODULE_BIND_LAZY);
+ module = new Glib::Module(Shared::module_path(name));
- // FIXME: SEGV on exit without this
- module->make_resident();
-
- if (*module) {
+ if (module) {
LOG(Raul::info)(Raul::fmt("Loading %1%\n") % Shared::module_path(name));
- return SharedPtr<Glib::Module>(module);
+ return module;
} else if (!module_path_found) {
LOG(Raul::error)(Raul::fmt("Unable to find %1% (%2%)\n")
% name % Glib::Module::get_last_error());
- return SharedPtr<Glib::Module>();
+ return NULL;
} else {
LOG(Raul::error)(Raul::fmt("Unable to load %1% from %2% (%3%)\n")
% name % module_path % Glib::Module::get_last_error());
LOG(Raul::error)("Is Ingen installed?\n");
- return SharedPtr<Glib::Module>();
+ return NULL;
}
}
@@ -131,28 +127,39 @@ public:
rdf_world->add_prefix("xsd", "http://www.w3.org/2001/XMLSchema#");
}
- virtual ~Impl()
+ ~Impl()
{
serialiser.reset();
parser.reset();
-
+ interface.reset();
engine.reset();
store.reset();
- modules.clear();
interface_factories.clear();
script_runners.clear();
- lilv_world_free(lilv_world);
-
delete rdf_world;
delete lv2_features;
delete uris;
delete forge;
delete uri_map;
+
+ lilv_world_free(lilv_world);
+
+
+ for (Modules::iterator i = modules.begin(); i != modules.end(); ++i) {
+ // Keep a reference to the library
+ Glib::Module* lib = i->second->library;
+
+ // Destroy the Ingen module
+ delete i->second;
+
+ // Now all references to library code should be done, close it
+ delete lib;
+ }
}
- typedef std::map< const std::string, SharedPtr<Module> > Modules;
+ typedef std::map<const std::string, Module*> Modules;
Modules modules;
typedef std::map<const std::string, World::InterfaceFactory> InterfaceFactories;
@@ -189,7 +196,6 @@ World::World(int& argc,
World::~World()
{
- unload_modules();
delete _impl;
}
@@ -225,18 +231,21 @@ World::load_module(const char* name)
LOG(Raul::info)(Raul::fmt("Module `%1%' already loaded\n") % name);
return true;
}
- SharedPtr<Glib::Module> lib = ingen_load_module(name);
+ Glib::Module* lib = ingen_load_module(name);
Ingen::Shared::Module* (*module_load)() = NULL;
if (lib && lib->get_symbol("ingen_module_load", (void*&)module_load)) {
Module* module = module_load();
- module->library = lib;
- module->load(this);
- _impl->modules.insert(make_pair(string(name), module));
- return true;
- } else {
- LOG(Raul::error)(Raul::fmt("Failed to load module `%1%'\n") % name);
- return false;
+ if (module) {
+ module->library = lib;
+ module->load(this);
+ _impl->modules.insert(make_pair(string(name), module));
+ return true;
+ }
}
+
+ LOG(Raul::error)(Raul::fmt("Failed to load module `%1%'\n") % name);
+ delete lib;
+ return false;
}
bool
diff --git a/src/shared/wscript b/src/shared/wscript
index 15e6097e..751951e1 100644
--- a/src/shared/wscript
+++ b/src/shared/wscript
@@ -1,8 +1,25 @@
#!/usr/bin/env python
from waflib.extras import autowaf as autowaf
+sources = [
+ 'AtomReader.cpp',
+ 'AtomWriter.cpp',
+ 'Builder.cpp',
+ 'ClashAvoider.cpp',
+ 'Configuration.cpp',
+ 'Forge.cpp',
+ 'LV2Features.cpp',
+ 'ResourceImpl.cpp',
+ 'Store.cpp',
+ 'URIMap.cpp',
+ 'URIs.cpp',
+ 'World.cpp',
+ 'runtime_paths.cpp',
+]
+
def build(bld):
obj = bld(features = 'cxx cxxshlib',
+ source = sources,
export_includes = ['../..'],
includes = ['../..'],
name = 'libingen_shared',
@@ -12,19 +29,15 @@ def build(bld):
lib = ['dl'])
autowaf.use_lib(bld, obj, 'GLIBMM LV2 LILV RAUL SORD LV2_MIDI')
- obj.source = '''
- AtomReader.cpp
- AtomWriter.cpp
- Builder.cpp
- ClashAvoider.cpp
- Configuration.cpp
- Forge.cpp
- LV2Features.cpp
- Module.cpp
- ResourceImpl.cpp
- Store.cpp
- URIMap.cpp
- URIs.cpp
- World.cpp
- runtime_paths.cpp
- '''
+ if bld.env['BUILD_TESTS']:
+ obj = bld(features = 'cxx cxxshlib',
+ source = sources,
+ export_includes = ['../..'],
+ includes = ['../..'],
+ name = 'libingen_shared_profiled',
+ target = 'ingen_shared_profiled',
+ install_path = '',
+ lib = ['dl'] + bld.env['INGEN_TEST_LIBS'],
+ cxxflags = bld.env['INGEN_TEST_CXXFLAGS'])
+ autowaf.use_lib(bld, obj, 'GLIBMM LV2 LILV RAUL SORD LV2_MIDI')
+