OpenLightingProject / ola

The Open Lighting Architecture - The Travel Adaptor for the Lighting Industry
https://www.openlighting.org/ola/
Other
644 stars 204 forks source link

Dynamic plugin loading via dlopen()? #603

Open bk138 opened 9 years ago

bk138 commented 9 years ago

Hi there, I'm currently packaing OLA for OpenWRT (https://github.com/bk138/packages/commits/ola) and while everything works fine, I ran into a minor issue WRT plugins: It seems all plugin .so's are linked to the olad binary at build time, which makes it impossible to make a more fine-granular packaging (with per-plugin packages), a thing that's definitely wanted on OpenWRT.

Was/is there a reason for the current implementation?

nomis52 commented 9 years ago

ola used to use libftdl to dynamically load plugins. However it was a constant source of compile / link problems. Also the plugins depend on libolacommon and I seem to remember that on Windows it's not possible for a dlopen'ed library to depend on symbols in the program doing the dlopen'ing.

That said, I can see this is a problem for platforms like openwrt. I wouldn't be opposed to adding a configure time option to use dlopen rather than dynamic linking.

bk138 commented 9 years ago

Well for openwrt it's not a show stopper but it would be quite nice to have dlopen loading. Can you point me at the code wrt libftdl? I recognize there is a DynamicPluginLoader.cpp, but it's git history doesn't reveal anything wrt dlopen...

Am 18. Januar 2015 20:41:50 MEZ, schrieb Simon Newton notifications@github.com:

ola used to use libftdl to dynamically load plugins. However it was a constant source of compile / link problems. Also the plugins depend on libolacommon and I seem to remember that on Windows it's not possible for a dlopen'ed library to depend on symbols in the program doing the dlopen'ing.

That said, I can see this is a problem for platforms like openwrt. I wouldn't be opposed to adding a configure time option to use dlopen rather than dynamic linking.


Reply to this email directly or view it on GitHub: https://github.com/OpenLightingProject/ola/issues/603#issuecomment-70422266

Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

nomis52 commented 9 years ago

See 9b00984d06fdda711b87146b2993ad11e9b5871c 6b09ce8a95dc5a6d6e6783f2027e2e31fd7979b4 7d99a1d477e79f6bd2b99ee4ead23bfedc95b680

Each plugin library had a "create" & "destroy" symbol:

extern "C" ola::AbstractPlugin* create(const ola::PluginAdaptor *plugin_adaptor) { return new ola::plugin::usbpro::UsbProPlugin(plugin_adaptor); }

extern "C" void destroy(ola::AbstractPlugin* plugin) { delete plugin; }

Then in the DlOpenPluginLoader:

lt_dlinit(); lt_dlsetsearchpath(plugin_dir.c_str()); lt_dlhandle module = lt_dlopenext(plugin_path.c_str());

create_t _create = reinterpret_cast(lt_dlsym(module, "create")); AbstractPlugin *plugin = create(m_plugin_adaptor));

bk138 commented 9 years ago

Thanks, I'll have a look.