30 m_handle.reset(dlopen(sofile, RTLD_NOW));
32 std::cerr <<
"dlopen failed - shared library '"<< sofile <<
"' not loaded: " << dlerror() <<
"\n";
33 throw std::runtime_error(
"dlopen failed");
39 if (!create || !destroy) {
40 std::cerr <<
"Invalid plugin: " << sofile <<
"\n";
42 throw std::runtime_error(
"Invalid plugin - missing create_plugin or destroy_plugin");
46 m_plugin = std::unique_ptr<IPlugin, destroy_plugin_t>(create(), destroy);
48 throw std::runtime_error(
"null pointer");
52 std::cerr <<
"Error instantiating plugin: " << sofile <<
"\n";
54 throw std::runtime_error(
"Error instantiating plugin");
60 throw std::runtime_error(
"null pointer");
64 std::cerr<<
"Error retrieving parser" <<
"\n";
67 throw std::runtime_error(
"Error retrieving parser");
96 std::unique_ptr<IPlugin, destroy_plugin_t>
m_plugin;
Manages the lifecycle of a dynamically loaded plugin.
MaCh3ArgumentParser * get_parser() override
Get the argument parser for this plugin.
virtual ~DynamicPlugin()=default
Destructor closes the shared library handle.
DynamicPlugin(const char *sofile)
Constructor that loads a plugin from a shared library file.
std::unique_ptr< IPlugin, destroy_plugin_t > m_plugin
Smart pointer to plugin with custom deleter.
int Run() override
Run the plugin's main functionality.
static void dlcloser(void *h)
MaCh3ArgumentParser * m_parser
Pointer to the plugin's argument parser, owned by the shared library.
std::unique_ptr< void, decltype(&dlcloser)> m_handle
Handle to the loaded shared library.
DynamicPlugin(const std::string &sofile)
Constructor that loads a plugin from a shared library file.
Interface for MaCh3 plugins and modules.
Extended ArgumentParser with MaCh3-specific functionality.
Main namespace for MaCh3 software.
Plugin interface and registration macros for MaCh3.
M3::IPlugin *(* create_plugin_t)()
Function pointer type for plugin factory function.
void(* destroy_plugin_t)(M3::IPlugin *)
Function pointer type for plugin destructor function.