Skip to main content

GCPluginManager

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: PathBuf

Implementations§

§

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>

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>

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>

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>

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>

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>

Get information about a plugin by providing an instance of it.

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>

Restart plugin instance.

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>

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.

pub fn iter(&self) -> impl Iterator<Item = &GCPlugin<T>>

Returns an iterator over all the plugins that are currently loaded.

Trait Implementations§

§

impl<T: GCPluginCallbackHandler> Drop for GCPluginManager<T>

§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for GCPluginManager<T>

§

impl<T> RefUnwindSafe for GCPluginManager<T>
where T: RefUnwindSafe,

§

impl<T> Send for GCPluginManager<T>

§

impl<T> Sync for GCPluginManager<T>

§

impl<T> Unpin for GCPluginManager<T>

§

impl<T> UnsafeUnpin for GCPluginManager<T>

§

impl<T> UnwindSafe for GCPluginManager<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.