HAL
hal::plugin_manager Namespace Reference

Classes

struct  PluginFeature
 

Functions

std::filesystem::path get_plugin_path (std::string plugin_name)
 
bool has_valid_file_extension (std::filesystem::path file_name)
 
std::set< std::string > get_plugin_names ()
 
std::vector< PluginFeatureget_plugin_features (std::string name)
 
std::unordered_map< std::string, std::string > get_cli_plugin_flags ()
 
std::unordered_map< std::string, std::string > get_ui_plugin_flags ()
 
ProgramOptions get_cli_plugin_options ()
 
bool load_all_plugins (const std::vector< std::filesystem::path > &directory_names)
 
bool load (const std::string &plugin_name, const std::filesystem::path &file_path_or_empty)
 
bool unload_all_plugins ()
 
bool unload (const std::string &plugin_name)
 
BasePluginInterfaceget_plugin_instance (const std::string &plugin_name, bool initialize, bool silent)
 
u64 add_model_changed_callback (std::function< void(bool, std::string const &, std::string const &)> callback)
 
void remove_model_changed_callback (u64 id)
 
void add_existing_options_description (const ProgramOptions &existing_options)
 
template<typename T >
T * get_plugin_instance (const std::string &plugin_name, bool initialize=true)
 
template<typename T >
T * get_first_extension (const std::string &plugin_name, bool initialize=true)
 

Detailed Description

The plugin manager takes care of loading and unloading plugins at runtime.

Function Documentation

◆ add_existing_options_description()

void hal::plugin_manager::add_existing_options_description ( const ProgramOptions existing_options)

TODO Python binding.

Register existing program options to avoid reuse by plugins.

Parameters
[in]existing_options- The program options.

Definition at line 454 of file plugin_manager.cpp.

◆ add_model_changed_callback()

u64 hal::plugin_manager::add_model_changed_callback ( std::function< void(bool, std::string const &, std::string const &)>  callback)

TODO Python binding.

Add a callback to notify the GUI about loaded or unloaded plugins.

Parameters
[in]callback- The callback function. Parameters are:
  • bool - True = load, false = unload.
  • std::string - The plugin name.
  • std::string - The plugin path.
Returns
The id of the registered callback.

Definition at line 439 of file plugin_manager.cpp.

References log_error.

Referenced by hal::PluginRelay::PluginRelay().

◆ get_cli_plugin_flags()

std::unordered_map< std::string, std::string > hal::plugin_manager::get_cli_plugin_flags ( )

TODO Python binding.

Get a mapping of flags pointing to their corresponding CLI plugin.

Returns
A map from flag to plugin name.

Definition at line 140 of file plugin_manager.cpp.

◆ get_cli_plugin_options()

ProgramOptions hal::plugin_manager::get_cli_plugin_options ( )

TODO Python binding.

Get command line interface options for all plugins.

Returns
The program options.

Definition at line 150 of file plugin_manager.cpp.

◆ get_first_extension()

template<typename T >
T* hal::plugin_manager::get_first_extension ( const std::string &  plugin_name,
bool  initialize = true 
)

Get first plugin extension of given type T.

Parameters
[in]plugin_name- The name of the plugin.
[in]initialize- If false, the plugin's initialize function is not called.
Returns
pointer to first extension of type T or nullptr if no such extension exists.

Definition at line 167 of file plugin_manager.h.

References hal::BasePluginInterface::get_first_extension(), get_plugin_instance(), hal::initialize(), and hal::T.

◆ get_plugin_features()

std::vector< PluginFeature > hal::plugin_manager::get_plugin_features ( std::string  name)

Returns list of features for plugin identified by file name stem

Parameters
namefile name stem
Returns
list of features like parser or writer

Definition at line 133 of file plugin_manager.cpp.

References name.

Referenced by hal::GuiPluginEntry::updateFromLoaded().

◆ get_plugin_instance() [1/2]

BasePluginInterface * hal::plugin_manager::get_plugin_instance ( const std::string &  plugin_name,
bool  initialize = true,
bool  silent = false 
)

Gets the basic interface for a plugin specified by name. By default calls the initialize() function of the plugin.

Parameters
[in]plugin_name- The name of the plugin.
[in]initialize- If false, the plugin's initialize function is not called.
[in]silent- If true error message gets omitted if plugin not found
Returns
The basic plugin interface.

Definition at line 421 of file plugin_manager.cpp.

References hal::initialize(), and log_error.

Referenced by get_first_extension(), get_plugin_instance(), hal::GuiPluginManager::getGuiExtensions(), and hal::GuiPluginTable::load().

◆ get_plugin_instance() [2/2]

template<typename T >
T* hal::plugin_manager::get_plugin_instance ( const std::string &  plugin_name,
bool  initialize = true 
)

TODO Python bindings for different types and extend by initialize flag.

Gets a specific interface for a plugin specified by name. By default calls the initialize() function of the plugin.

Parameters
[in]plugin_name- The name of the plugin.
[in]initialize- If false, the plugin's initialize function is not called.
Returns
The specific plugin interface.

Definition at line 154 of file plugin_manager.h.

References get_plugin_instance(), hal::initialize(), and hal::T.

◆ get_plugin_names()

std::set< std::string > hal::plugin_manager::get_plugin_names ( )

Get the names of all loaded plugins.

Returns
The set of plugin names.

Definition at line 123 of file plugin_manager.cpp.

References names.

Referenced by hal::GuiPluginManager::getGuiExtensions(), hal::plugin_manager_init(), and unload_all_plugins().

◆ get_plugin_path()

std::filesystem::path hal::plugin_manager::get_plugin_path ( std::string  plugin_name)

Get the full path for plugin. Will probe several possible extension on MAC

Returns
The full path to plugin in HAL build directory.

Definition at line 92 of file plugin_manager.cpp.

References ALTERNATE_LIBRARY_FILE_EXTENSION, hal::utils::get_file(), and LIBRARY_FILE_EXTENSION.

Referenced by hal::GuiPluginEntry::GuiPluginEntry(), and load().

◆ get_ui_plugin_flags()

std::unordered_map< std::string, std::string > hal::plugin_manager::get_ui_plugin_flags ( )

TODO Python binding.

Get a mapping of flags pointing to their corresponding UI plugin.

Returns
A map from flag to plugin name.

Definition at line 145 of file plugin_manager.cpp.

◆ has_valid_file_extension()

bool hal::plugin_manager::has_valid_file_extension ( std::filesystem::path  file_name)

Returns whether file has an extension which is legal for plugins in OS

Parameters
file_name
Returns
False if extension indicated that this file cannot be a plugin, true otherwise

Definition at line 103 of file plugin_manager.cpp.

References ALTERNATE_LIBRARY_FILE_EXTENSION, hal::utils::ends_with(), and LIBRARY_FILE_EXTENSION.

Referenced by load_all_plugins().

◆ load()

◆ load_all_plugins()

bool hal::plugin_manager::load_all_plugins ( const std::vector< std::filesystem::path > &  directory_names = {})

Load all plugins in the specified diretories.
If directory_names is empty, the default directories will be searched.

Parameters
[in]directory_names- A vector of directory paths.
Returns
True on success, false otherwise.

Definition at line 155 of file plugin_manager.cpp.

References file, has_valid_file_extension(), load(), and log_debug.

Referenced by hal::plugin_manager_init(), and hal::VerilogWriterTest::SetUp().

◆ remove_model_changed_callback()

void hal::plugin_manager::remove_model_changed_callback ( u64  id)

TODO Python binding.

Remove a registered callback.

Parameters
[in]id- The id of the registered callback.

Definition at line 449 of file plugin_manager.cpp.

Referenced by hal::PluginRelay::~PluginRelay().

◆ unload()

◆ unload_all_plugins()

bool hal::plugin_manager::unload_all_plugins ( )

Releases all plugins and their associated resources.

Returns
True on success, false otherwise.

Definition at line 327 of file plugin_manager.cpp.

References get_plugin_names(), log_debug, log_error, log_info, name, and unload().

Referenced by hal::plugin_manager_init(), and hal::VerilogWriterTest::TearDown().