Async 1.8.0
Async::Plugin Class Reference

A base class for making a class into a dynamic loadable plugin. More...

#include <AsyncPlugin.h>

Public Member Functions

 Plugin (void)
 Default constructor.
 
 Plugin (const Plugin &)=delete
 Disallow copy construction.
 
Pluginoperator= (const Plugin &)=delete
 Disallow copy assignment.
 
void * pluginHandle (void) const
 Retrieve the handle returned from the dlopen function.
 
const std::string & pluginPath (void) const
 Retrieve the path used to find the plugin.
 

Static Public Member Functions

static Pluginload (const std::string &path)
 Load the plugin from the specified path.
 
template<class T >
static T * load (const std::string &path)
 Load the plugin from the specified path returning correct type.
 
static void unload (Plugin *p)
 

Protected Member Functions

virtual ~Plugin (void)
 Destructor.
 

Detailed Description

A base class for making a class into a dynamic loadable plugin.

Author
Tobias Blomberg / SM0SVX
Date
2022-08-23
#include <iostream>
#include "DemoPluginBase.h"
int main(void)
{
auto p = Async::Plugin::load<DemoPluginBase>("DemoPlugin.so");
if (p == nullptr)
{
exit(1);
}
std::cout << "Found plugin " << p->pluginPath() << std::endl;
p->initialize("hello");
p = nullptr;
return 0;
}
static void unload(Plugin *p)
static Plugin * load(const std::string &path)
Load the plugin from the specified path.

Definition at line 115 of file AsyncPlugin.h.

Constructor & Destructor Documentation

◆ Plugin() [1/2]

Async::Plugin::Plugin ( void )

Default constructor.

◆ Plugin() [2/2]

Async::Plugin::Plugin ( const Plugin & )
delete

Disallow copy construction.

◆ ~Plugin()

virtual Async::Plugin::~Plugin ( void )
protectedvirtual

Destructor.

Member Function Documentation

◆ load() [1/2]

static Plugin * Async::Plugin::load ( const std::string & path)
static

Load the plugin from the specified path.

Parameters
pathThe file path
Examples
AsyncPlugin_demo.cpp.

Referenced by load().

◆ load() [2/2]

template<class T >
static T * Async::Plugin::load ( const std::string & path)
inlinestatic

Load the plugin from the specified path returning correct type.

Parameters
pathThe file path

The application may use this function to load the plugin, check that it is of the correct type and then return a pointer to that type.

Definition at line 132 of file AsyncPlugin.h.

References load().

◆ operator=()

Plugin & Async::Plugin::operator= ( const Plugin & )
delete

Disallow copy assignment.

◆ pluginHandle()

void * Async::Plugin::pluginHandle ( void ) const
inline

Retrieve the handle returned from the dlopen function.

Returns
Returns a handle from dlopen (
See also
man 3 dlopen)

Definition at line 171 of file AsyncPlugin.h.

◆ pluginPath()

const std::string & Async::Plugin::pluginPath ( void ) const
inline

Retrieve the path used to find the plugin.

Returns
Returns the path to the plugin

This function can be called to find out which path was used to load the plugin.

Definition at line 180 of file AsyncPlugin.h.

◆ unload()

static void Async::Plugin::unload ( Plugin * p)
static

The documentation for this class was generated from the following file: