diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2013-07-11 13:58:48 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2013-07-11 13:58:48 -0400 |
commit | 83ed3d7dcc121bb7947d7532c869ccf3e0510b86 (patch) | |
tree | 66adb4caa8b58b90d638b1086c53b0ac785e8534 | |
parent | 058ebf98b928f735ac2dbd5026a4dcf3fba3e67b (diff) |
Use glibmm for modules instead of dlfch.h
-rw-r--r-- | libs/ardour/ardour/ladspa_plugin.h | 9 | ||||
-rw-r--r-- | libs/ardour/ardour/panner_manager.h | 11 | ||||
-rw-r--r-- | libs/ardour/control_protocol_manager.cc | 36 | ||||
-rw-r--r-- | libs/ardour/ladspa_plugin.cc | 40 | ||||
-rw-r--r-- | libs/ardour/panner_manager.cc | 22 | ||||
-rw-r--r-- | libs/ardour/plugin_manager.cc | 18 |
6 files changed, 71 insertions, 65 deletions
diff --git a/libs/ardour/ardour/ladspa_plugin.h b/libs/ardour/ardour/ladspa_plugin.h index 6853a1dc36..62cad017fc 100644 --- a/libs/ardour/ardour/ladspa_plugin.h +++ b/libs/ardour/ardour/ladspa_plugin.h @@ -23,8 +23,8 @@ #include <set> #include <vector> #include <string> -#include <dlfcn.h> +#include <glibmm/module.h> #include "pbd/stateful.h" @@ -39,7 +39,7 @@ class Session; class LadspaPlugin : public ARDOUR::Plugin { public: - LadspaPlugin (void *module, ARDOUR::AudioEngine&, ARDOUR::Session&, uint32_t index, framecnt_t sample_rate); + LadspaPlugin (std::string module_path, ARDOUR::AudioEngine&, ARDOUR::Session&, uint32_t index, framecnt_t sample_rate); LadspaPlugin (const LadspaPlugin &); ~LadspaPlugin (); @@ -122,7 +122,8 @@ class LadspaPlugin : public ARDOUR::Plugin void connect_port (uint32_t port, float *ptr) { _descriptor->connect_port (_handle, port, ptr); } private: - void* _module; + std::string _module_path; + Glib::Module* _module; const LADSPA_Descriptor* _descriptor; LADSPA_Handle _handle; framecnt_t _sample_rate; @@ -134,7 +135,7 @@ class LadspaPlugin : public ARDOUR::Plugin void find_presets (); - void init (void *mod, uint32_t index, framecnt_t rate); + void init (std::string module_path, uint32_t index, framecnt_t rate); void run_in_place (pframes_t nsamples); void latency_compute_run (); int set_state_2X (const XMLNode&, int version); diff --git a/libs/ardour/ardour/panner_manager.h b/libs/ardour/ardour/panner_manager.h index 016ba56ce3..c34d22285d 100644 --- a/libs/ardour/ardour/panner_manager.h +++ b/libs/ardour/ardour/panner_manager.h @@ -20,7 +20,8 @@ #ifndef __ardour_panner_manager_h__ #define __ardour_panner_manager_h__ -#include <dlfcn.h> +#include <glibmm/module.h> + #include "ardour/panner.h" #include "ardour/session_handle.h" @@ -28,15 +29,15 @@ namespace ARDOUR { struct PannerInfo { PanPluginDescriptor descriptor; - void* module; + Glib::Module* module; - PannerInfo (PanPluginDescriptor& d, void* handle) + PannerInfo (PanPluginDescriptor& d, Glib::Module* m) : descriptor (d) - , module (handle) + , module (m) {} ~PannerInfo () { - dlclose (module); + delete module; } }; diff --git a/libs/ardour/control_protocol_manager.cc b/libs/ardour/control_protocol_manager.cc index 2e65a8d6f8..3ccc1f134b 100644 --- a/libs/ardour/control_protocol_manager.cc +++ b/libs/ardour/control_protocol_manager.cc @@ -17,7 +17,7 @@ */ -#include <dlfcn.h> +#include <glibmm/module.h> #include <glibmm/fileutils.h> @@ -29,8 +29,14 @@ #include "ardour/debug.h" #include "ardour/control_protocol_manager.h" + +#ifdef SearchPath +#undef SearchPath +#endif + #include "ardour/control_protocol_search_path.h" + using namespace ARDOUR; using namespace std; using namespace PBD; @@ -179,7 +185,7 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi) cpi.protocol = 0; delete cpi.state; cpi.state = 0; - dlclose (cpi.descriptor->module); + delete (Glib::Module*)cpi.descriptor->module; ProtocolStatusChange (&cpi); @@ -264,7 +270,7 @@ ControlProtocolManager::control_protocol_discover (string path) string_compose(_("Control surface protocol discovered: \"%1\"\n"), cpi->name)); } - dlclose (descriptor->module); + delete (Glib::Module*)descriptor->module; } return 0; @@ -273,31 +279,31 @@ ControlProtocolManager::control_protocol_discover (string path) ControlProtocolDescriptor* ControlProtocolManager::get_descriptor (string path) { - void *module; + Glib::Module* module = new Glib::Module(path); ControlProtocolDescriptor *descriptor = 0; ControlProtocolDescriptor* (*dfunc)(void); - const char *errstr; + void* func = 0; - if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) { - error << string_compose(_("ControlProtocolManager: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg; + if (!(*module)) { + error << string_compose(_("ControlProtocolManager: cannot load module \"%1\" (%2)"), path, Glib::Module::get_last_error()) << endmsg; + delete module; return 0; } - - dfunc = (ControlProtocolDescriptor* (*)(void)) dlsym (module, "protocol_descriptor"); - - if ((errstr = dlerror()) != 0) { + if (!module->get_symbol("protocol_descriptor", func)) { error << string_compose(_("ControlProtocolManager: module \"%1\" has no descriptor function."), path) << endmsg; - error << errstr << endmsg; - dlclose (module); + error << Glib::Module::get_last_error() << endmsg; + delete module; return 0; } + dfunc = (ControlProtocolDescriptor* (*)(void))func; descriptor = dfunc(); + if (descriptor) { - descriptor->module = module; + descriptor->module = (void*)module; } else { - dlclose (module); + delete module; } return descriptor; diff --git a/libs/ardour/ladspa_plugin.cc b/libs/ardour/ladspa_plugin.cc index cebff59771..b306269276 100644 --- a/libs/ardour/ladspa_plugin.cc +++ b/libs/ardour/ladspa_plugin.cc @@ -51,16 +51,16 @@ using namespace std; using namespace ARDOUR; using namespace PBD; -LadspaPlugin::LadspaPlugin (void *mod, AudioEngine& e, Session& session, uint32_t index, framecnt_t rate) +LadspaPlugin::LadspaPlugin (string module_path, AudioEngine& e, Session& session, uint32_t index, framecnt_t rate) : Plugin (e, session) { - init (mod, index, rate); + init (module_path, index, rate); } LadspaPlugin::LadspaPlugin (const LadspaPlugin &other) : Plugin (other) { - init (other._module, other._index, other._sample_rate); + init (other._module_path, other._index, other._sample_rate); for (uint32_t i = 0; i < parameter_count(); ++i) { _control_data[i] = other._shadow_data[i]; @@ -69,25 +69,32 @@ LadspaPlugin::LadspaPlugin (const LadspaPlugin &other) } void -LadspaPlugin::init (void *mod, uint32_t index, framecnt_t rate) +LadspaPlugin::init (string module_path, uint32_t index, framecnt_t rate) { + void* func; LADSPA_Descriptor_Function dfunc; uint32_t i, port_cnt; - const char *errstr; - _module = mod; + _module_path = module_path; + _module = new Glib::Module(_module_path); _control_data = 0; _shadow_data = 0; _latency_control_port = 0; _was_activated = false; - dfunc = (LADSPA_Descriptor_Function) dlsym (_module, "ladspa_descriptor"); + if (!(*_module)) { + error << _("LADSPA: Unable to open module: ") << Glib::Module::get_last_error() << endmsg; + delete _module; + throw failed_constructor(); + } - if ((errstr = dlerror()) != NULL) { + if (!_module->get_symbol("ladspa_descriptor", func)) { error << _("LADSPA: module has no descriptor function.") << endmsg; throw failed_constructor(); } + dfunc = (LADSPA_Descriptor_Function)func; + if ((_descriptor = dfunc (index)) == 0) { error << _("LADSPA: plugin has gone away since discovery!") << endmsg; throw failed_constructor(); @@ -141,9 +148,8 @@ LadspaPlugin::~LadspaPlugin () deactivate (); cleanup (); - /* XXX who should close a plugin? */ - - // dlclose (module); + // glib has internal reference counting on modules so this is ok + delete _module; delete [] _control_data; delete [] _shadow_data; @@ -700,17 +706,7 @@ PluginPtr LadspaPluginInfo::load (Session& session) { try { - PluginPtr plugin; - void *module; - - if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) { - error << string_compose(_("LADSPA: cannot load module from \"%1\""), path) << endmsg; - error << dlerror() << endmsg; - return PluginPtr ((Plugin*) 0); - } else { - plugin.reset (new LadspaPlugin (module, session.engine(), session, index, session.frame_rate())); - } - + PluginPtr plugin (new LadspaPlugin (path, session.engine(), session, index, session.frame_rate())); plugin->set_info(PluginInfoPtr(new LadspaPluginInfo(*this))); return plugin; } diff --git a/libs/ardour/panner_manager.cc b/libs/ardour/panner_manager.cc index c3601d41de..e77104dd33 100644 --- a/libs/ardour/panner_manager.cc +++ b/libs/ardour/panner_manager.cc @@ -106,31 +106,33 @@ PannerManager::panner_discover (string path) PannerInfo* PannerManager::get_descriptor (string path) { - void *module; + Glib::Module* module = new Glib::Module(path); PannerInfo* info = 0; PanPluginDescriptor *descriptor = 0; PanPluginDescriptor* (*dfunc)(void); - const char *errstr; + void* func = 0; - if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) { - error << string_compose(_("PannerManager: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg; + if (!module) { + error << string_compose(_("PannerManager: cannot load module \"%1\" (%2)"), path, + Glib::Module::get_last_error()) << endmsg; + delete module; return 0; } - dfunc = (PanPluginDescriptor* (*)(void)) dlsym (module, "panner_descriptor"); - - if ((errstr = dlerror()) != 0) { + if (!module->get_symbol("panner_descriptor", func)) { error << string_compose(_("PannerManager: module \"%1\" has no descriptor function."), path) << endmsg; - error << errstr << endmsg; - dlclose (module); + error << Glib::Module::get_last_error() << endmsg; + delete module; return 0; } + dfunc = (PanPluginDescriptor* (*)(void))func; descriptor = dfunc(); + if (descriptor) { info = new PannerInfo (*descriptor, module); } else { - dlclose (module); + delete module; } return info; diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index 90522a7e06..a3a7fb48da 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -26,7 +26,6 @@ #include <sys/types.h> #include <cstdio> #include <lrdf.h> -#include <dlfcn.h> #include <cstdlib> #include <fstream> @@ -365,25 +364,26 @@ PluginManager::add_lrdf_data (const string &path) int PluginManager::ladspa_discover (string path) { - void *module; + Glib::Module module(path); const LADSPA_Descriptor *descriptor; LADSPA_Descriptor_Function dfunc; - const char *errstr; + void* func = 0; - if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) { - error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg; + if (!module) { + error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), + path, Glib::Module::get_last_error()) << endmsg; return -1; } - dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor"); - if ((errstr = dlerror()) != 0) { + if (!module.get_symbol("ladspa_descriptor", func)) { error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg; - error << errstr << endmsg; - dlclose (module); + error << Glib::Module::get_last_error() << endmsg; return -1; } + dfunc = (LADSPA_Descriptor_Function)func; + for (uint32_t i = 0; ; ++i) { if ((descriptor = dfunc (i)) == 0) { break; |