irccd  3.0.3
Public Types | Public Member Functions | List of all members
irccd::daemon::plugin_service Class Reference

Manage plugins. More...

#include <plugin_service.hpp>

Public Types

using plugins = std::vector< std::shared_ptr< plugin > >
 Map of plugins. More...
 
using plugin_loaders = std::vector< std::unique_ptr< plugin_loader > >
 List of loaders. More...
 

Public Member Functions

 plugin_service (bot &bot) noexcept
 
virtual ~plugin_service ()
 
auto list () const noexcept -> plugins
 
auto has (std::string_view id) const noexcept -> bool
 
auto get (std::string_view id) const noexcept -> std::shared_ptr< plugin >
 
auto require (std::string_view id) const -> std::shared_ptr< plugin >
 
void add (std::shared_ptr< plugin > plg)
 
void add_loader (std::unique_ptr< plugin_loader > loader)
 
auto get_options (std::string_view id) -> plugin::map
 
auto get_templates (std::string_view id) -> plugin::map
 
auto get_paths (std::string_view id) -> plugin::map
 
auto open (std::string_view id, std::string_view path) -> std::shared_ptr< plugin >
 
auto find (std::string_view id) -> std::shared_ptr< plugin >
 
void load (std::string_view id, std::string_view path="")
 
void unload (std::string_view id)
 
void reload (std::string_view id)
 
template<typename Func , typename... Args>
void exec (std::shared_ptr< plugin > plugin, Func &&fn, Args &&... args)
 
template<typename Func , typename... Args>
void exec (std::string_view name, Func &&fn, Args &&... args)
 
void clear () noexcept
 
void load (const config &cfg) noexcept
 

Detailed Description

Manage plugins.

Member Typedef Documentation

◆ plugin_loaders

using irccd::daemon::plugin_service::plugin_loaders = std::vector<std::unique_ptr<plugin_loader> >

List of loaders.

◆ plugins

using irccd::daemon::plugin_service::plugins = std::vector<std::shared_ptr<plugin> >

Map of plugins.

Constructor & Destructor Documentation

◆ plugin_service()

irccd::daemon::plugin_service::plugin_service ( bot bot)
noexcept

Create the plugin service.

Parameters
botthe irccd instance

◆ ~plugin_service()

virtual irccd::daemon::plugin_service::~plugin_service ( )
virtual

Destroy plugins.

Member Function Documentation

◆ add()

void irccd::daemon::plugin_service::add ( std::shared_ptr< plugin plg)

Add the specified plugin to the registry.

Precondition
plg != nullptr
Parameters
plgthe plugin
Note
the plugin is only added to the list, no action is performed on it

◆ add_loader()

void irccd::daemon::plugin_service::add_loader ( std::unique_ptr< plugin_loader loader)

Add a loader.

Precondition
loader != nullptr
Parameters
loaderthe loader

◆ clear()

void irccd::daemon::plugin_service::clear ( )
noexcept

Remove all plugins.

◆ exec() [1/2]

template<typename Func , typename... Args>
void irccd::daemon::plugin_service::exec ( std::shared_ptr< plugin plugin,
Func &&  fn,
Args &&...  args 
)
inline

Call a plugin function and throw an exception with the following errors:

Precondition
plugin != nullptr
Parameters
pluginthe plugin
fnthe plugin member function (pointer to member)
argsthe arguments to pass

◆ exec() [2/2]

template<typename Func , typename... Args>
void irccd::daemon::plugin_service::exec ( std::string_view  name,
Func &&  fn,
Args &&...  args 
)
inline

Overloaded function.

Parameters
namethe plugin name
fnthe plugin member function (pointer to member)
argsthe arguments to pass

◆ find()

auto irccd::daemon::plugin_service::find ( std::string_view  id) -> std::shared_ptr< plugin >

Generic function for finding a plugin.

Parameters
idthe plugin id
Returns
the plugin or nullptr on failures

◆ get()

auto irccd::daemon::plugin_service::get ( std::string_view  id) const -> std::shared_ptr< plugin >
noexcept

Get a loaded plugin or null if not found.

Parameters
idthe plugin id
Returns
the plugin or empty one if not found

◆ get_options()

auto irccd::daemon::plugin_service::get_options ( std::string_view  id) -> plugin::map

Get the configuration for the specified plugin.

Parameters
idthe plugin id
Returns
the configuration

◆ get_paths()

auto irccd::daemon::plugin_service::get_paths ( std::string_view  id) -> plugin::map

Get the paths for the specified plugin.

If none is defined, return the default ones.

Parameters
idthe plugin id
Returns
the paths

◆ get_templates()

auto irccd::daemon::plugin_service::get_templates ( std::string_view  id) -> plugin::map

Get the templates for the specified plugin.

Parameters
idthe plugin id
Returns
the formats

◆ has()

auto irccd::daemon::plugin_service::has ( std::string_view  id) const -> bool
noexcept

Check if a plugin is loaded.

Parameters
idthe plugin id
Returns
true if has plugin

◆ list()

auto irccd::daemon::plugin_service::list ( ) const -> plugins
noexcept

Get the list of plugins.

Returns
the list of plugins

◆ load() [1/2]

void irccd::daemon::plugin_service::load ( const config cfg)
noexcept

Load all plugins.

Parameters
cfgthe config

◆ load() [2/2]

void irccd::daemon::plugin_service::load ( std::string_view  id,
std::string_view  path = "" 
)

Convenient wrapper that loads a plugin, call handle_load and add it to the registry.

Any errors are printed using logger.

Parameters
idthe plugin id
paththe optional path (searched if empty)

◆ open()

auto irccd::daemon::plugin_service::open ( std::string_view  id,
std::string_view  path 
) -> std::shared_ptr< plugin >

Generic function for opening the plugin at the given path.

This function will search for every plugin_loader and call open() on it the first one that success will be returned.

Parameters
idthe plugin id
paththe path to the file
Returns
the plugin or nullptr on failures

◆ reload()

void irccd::daemon::plugin_service::reload ( std::string_view  id)

Reload a plugin by calling onReload.

Parameters
idthe plugin id
Exceptions
std::exceptionon failures

◆ require()

auto irccd::daemon::plugin_service::require ( std::string_view  id) const -> std::shared_ptr< plugin >

Find a loaded plugin.

Parameters
idthe plugin id
Returns
the plugin
Exceptions
plugin_erroron errors

◆ unload()

void irccd::daemon::plugin_service::unload ( std::string_view  id)

Unload a plugin and remove it.

Parameters
idthe plugin id

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