Struct GCPluginManager
pub struct GCPluginManager<T: GCPluginCallbackHandler> {
plugins: HashMap<String, GCPlugin<T>>,
plugins_path: PathBuf,
}Expand description
GCPluginManager is a system to manage plugins which is responsible for loading, unloading, starting, stopping and access running plugins. Different handlers of the same type can then be passed to the startup functions.
Fields§
§plugins: HashMap<String, GCPlugin<T>>§plugins_path: PathBufImplementations§
§impl<T: GCPluginCallbackHandler> GCPluginManager<T>
impl<T: GCPluginCallbackHandler> GCPluginManager<T>
pub fn new( plugins_path: impl Into<PathBuf>, ) -> Result<Self, GCPluginManagerError>
fn get_plugin_path_from_fs(
&self,
plugin_name: &str,
) -> Result<PathBuf, GCPluginManagerError>
fn get_plugin_path_from_fs( &self, plugin_name: &str, ) -> Result<PathBuf, GCPluginManagerError>
Given a plugin name, searches the filesystem for the correct plugin file and returns its path.
pub fn add_plugin_instance(
&mut self,
plugin_name: &str,
instance_name: &str,
callback_handler: Box<T>,
) -> Result<GCPluginInstance<T>, GCPluginManagerError>
pub fn add_plugin_instance( &mut self, plugin_name: &str, instance_name: &str, callback_handler: Box<T>, ) -> Result<GCPluginInstance<T>, GCPluginManagerError>
Add a plugin instance without starting it.
If the plugin does not exist yet, it will be loaded by the Operating System. If the plugin instance already exists, an error will be returned. The plugin instance has to be unique across all plugins.
pub fn start_plugin_instance(
&mut self,
config: GCPluginInstanceConfig<'_>,
instance: GCPluginInstance<T>,
) -> Result<(), GCPluginManagerError>
pub fn start_plugin_instance( &mut self, config: GCPluginInstanceConfig<'_>, instance: GCPluginInstance<T>, ) -> Result<(), GCPluginManagerError>
Start a plugin instance.
If the plugin or plugin instance does not exist yet, an error will be returned. If the instance is already running or cannot be found, an error will be returned.
pub fn add_start_plugin_instance(
&mut self,
plugin_name: &str,
instance_name: &str,
config: GCPluginInstanceConfig<'_>,
callback_handler: Box<T>,
) -> Result<GCPluginInstance<T>, GCPluginManagerError>
pub fn add_start_plugin_instance( &mut self, plugin_name: &str, instance_name: &str, config: GCPluginInstanceConfig<'_>, callback_handler: Box<T>, ) -> Result<GCPluginInstance<T>, GCPluginManagerError>
Add a plugin instance and starts it.
Calls add_plugin_instance and start_plugin_instance in sequence.
§Potential resource leak
If a new instance is added successfully but the startup fails, this function will return an error while the instance and plugin DLL will still exist and can only be removed by calling remove_plugin or when GCPluginManager is dropped.
pub fn get_plugin_info_by_name(
&self,
plugin_name: &str,
) -> Result<GCPluginInfo, GCPluginManagerError>
pub fn get_plugin_info_by_name( &self, plugin_name: &str, ) -> Result<GCPluginInfo, GCPluginManagerError>
Get information about a plugin by providing the path to it (the same value that used when initializing it).
pub fn get_plugin_info_by_instance(
&self,
instance: &GCPluginInstance<T>,
) -> Result<GCPluginInfo, GCPluginManagerError>
pub fn get_plugin_info_by_instance( &self, instance: &GCPluginInstance<T>, ) -> Result<GCPluginInfo, GCPluginManagerError>
Get information about a plugin by providing an instance of it.
pub fn get_instance_by_name(
&self,
instance_name: &str,
) -> Option<GCPluginInstance<T>>
pub fn get_instance_by_name( &self, instance_name: &str, ) -> Option<GCPluginInstance<T>>
Get a plugin instance by providing the instance name.
pub fn stop_plugin_instance(
&self,
instance: GCPluginInstance<T>,
) -> Result<(), GCPluginManagerError>
pub fn stop_plugin_instance( &self, instance: GCPluginInstance<T>, ) -> Result<(), GCPluginManagerError>
Restart plugin instance.
pub fn remove_plugin(
&mut self,
plugin_name: &str,
) -> Result<(), GCPluginManagerError>
pub fn remove_plugin( &mut self, plugin_name: &str, ) -> Result<(), GCPluginManagerError>
Remove a plugin from the system.
This will shutdown and invalidate all GCPluginInstances that are associated with the plugin, additionally the DLL will be unloaded from the current process.
pub fn remove_plugin_instance(
&mut self,
instance: &GCPluginInstance<T>,
) -> Result<(), GCPluginManagerError>
pub fn remove_plugin_instance( &mut self, instance: &GCPluginInstance<T>, ) -> Result<(), GCPluginManagerError>
Shutdowns and removes the plugin instance invalidating all GCPluginInstances that are associated with the current one.
If the plugin instance does not exist, an error will be returned. If the plugin instance is the last instance of the plugin, it will be removed.