HAL  v4.5.0-124-g47ab54673
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
hal::plugin_manager Namespace Reference

Classes

struct  PluginFeature
 

Functions

void add_existing_options_description (const ProgramOptions &existing_options)
 
std::set< std::string > get_plugin_names ()
 
std::filesystem::path get_plugin_path (std::string plugin_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=std::filesystem::path())
 
bool unload_all_plugins ()
 
bool unload (const std::string &plugin_name)
 
BasePluginInterfaceget_plugin_instance (const std::string &plugin_name, bool initialize=true, bool silent=false)
 
template<typename T >
T * get_plugin_instance (const std::string &plugin_name, bool initialize=true)
 
UIPluginInterfaceget_ui_plugin ()
 
template<typename T >
T * get_first_extension (const std::string &plugin_name, bool initialize=true)
 
u64 add_model_changed_callback (std::function< void(bool, std::string const &, std::string const &)> callback)
 
void remove_model_changed_callback (u64 id)
 
bool has_valid_file_extension (std::filesystem::path file_name)
 
std::vector< PluginFeatureget_plugin_features (std::string name)
 

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)

Register existing program options to avoid reuse by plugins.

Parameters
[in]existing_options- The program options.

Definition at line 501 of file plugin_manager.cpp.

Referenced by hal::plugin_manager_init().

◆ add_model_changed_callback()

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

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 486 of file plugin_manager.cpp.

References log_error.

Referenced by hal::plugin_manager_init(), and hal::PluginRelay::PluginRelay().

◆ get_cli_plugin_flags()

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

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

Returns
A map from flag to plugin name.

Definition at line 175 of file plugin_manager.cpp.

Referenced by hal::plugin_manager_init().

◆ get_cli_plugin_options()

ProgramOptions hal::plugin_manager::get_cli_plugin_options ( )

Get command line interface options for all plugins.

Returns
The program options.

Definition at line 185 of file plugin_manager.cpp.

Referenced by hal::plugin_manager_init().

◆ 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 169 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 168 of file plugin_manager.cpp.

References name.

Referenced by hal::plugin_manager_init(), and hal::GuiPluginEntry::updateFromLoaded().

◆ get_plugin_instance() [1/2]

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

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 146 of file plugin_manager.h.

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

◆ get_plugin_instance() [2/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 456 of file plugin_manager.cpp.

References hal::initialize(), instance, and log_error.

Referenced by get_first_extension(), get_plugin_instance(), hal::GuiPluginManager::getGuiExtensions(), hal::GuiPluginTable::load(), hal::dataflow::Result::open_dot_in_viewer(), hal::plugin_manager_init(), hal::SimulatorSerializer::restore(), and hal::WaveformViewer::restoreFromProject().

◆ 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 158 of file plugin_manager.cpp.

Referenced by hal::GuiPluginManager::getGuiExtensions(), hal::GexfWriter::GexfWriter(), 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 127 of file plugin_manager.cpp.

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

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

◆ get_ui_plugin()

UIPluginInterface * hal::plugin_manager::get_ui_plugin ( )

Gets the user interface plugin, i.e., the first loaded plugin implementing the UIPluginInterface.

Does not initialize the plugin and does not log an error if no such plugin is loaded, as running without a user interface is the normal case for scripts and for the command line.

Returns
The user interface plugin, or nullptr if none is loaded.

Definition at line 474 of file plugin_manager.cpp.

Referenced by hal::user_feedback::report_progress().

◆ get_ui_plugin_flags()

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

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

Returns
A map from flag to plugin name.

Definition at line 180 of file plugin_manager.cpp.

Referenced by hal::plugin_manager_init().

◆ 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 138 of file plugin_manager.cpp.

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

Referenced by load_all_plugins(), and hal::plugin_manager_init().

◆ 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 directories.
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 190 of file plugin_manager.cpp.

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

Referenced by hal::plugin_manager_init().

◆ remove_model_changed_callback()

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

Remove a registered callback.

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

Definition at line 496 of file plugin_manager.cpp.

Referenced by hal::plugin_manager_init(), and 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 362 of file plugin_manager.cpp.

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

Referenced by hal::plugin_manager_init().