pub trait PluginFactoryImpl: Send + Sync {
// Required methods
fn plugin_count(&self) -> u32;
fn plugin_descriptor(&self, index: u32) -> Option<&PluginDescriptor>;
fn create_plugin<'a>(
&'a self,
host_info: HostInfo<'a>,
plugin_id: &CStr,
) -> Option<PluginInstance<'a>>;
}Expand description
A Plugin Factory implementation.
See the module documentation to learn more about the role of a Plugin Factory.
§Example
The following example shows how to implement a basic, single-plugin factory.
use std::ffi::CStr;
use clack_plugin::entry::prelude::*;
use clack_plugin::prelude::*;
pub struct MyPlugin;
impl Plugin for MyPlugin {
type AudioProcessor<'a> = ();
type Shared<'a> = ();
type MainThread<'a> = ();
}
pub struct MyPluginFactory {
plugin_descriptor: PluginDescriptor
}
impl PluginFactoryImpl for MyPluginFactory {
fn plugin_count(&self) -> u32 {
1 // We only have a single plugin
}
fn plugin_descriptor(&self, index: u32) -> Option<&PluginDescriptor> {
match index {
0 => Some(&self.plugin_descriptor),
_ => None
}
}
fn create_plugin<'a>(&'a self, host_info: HostInfo<'a>, plugin_id: &CStr) -> Option<PluginInstance<'a>> {
if plugin_id == self.plugin_descriptor.id().unwrap_or_default() {
Some(PluginInstance::new::<MyPlugin>(
host_info,
&self.plugin_descriptor,
|_host| Ok(()) /* Create the shared struct */,
|_host, _shared| Ok(()) /* Create the main thread struct */,
))
} else {
None
}
}
}Required Methods§
Sourcefn plugin_count(&self) -> u32
fn plugin_count(&self) -> u32
Returns the number of plugins exposed by this factory.
Sourcefn plugin_descriptor(&self, index: u32) -> Option<&PluginDescriptor>
fn plugin_descriptor(&self, index: u32) -> Option<&PluginDescriptor>
Returns the PluginDescriptor of the plugin that is assigned the given index.
Hosts will usually call this method repeatedly with every index from 0 to the total returned
by plugin_count, in order to discover all the plugins
exposed by this factory.
If the given index is out of bounds, or in general does not match any given plugin, this
returns None.
Sourcefn create_plugin<'a>(
&'a self,
host_info: HostInfo<'a>,
plugin_id: &CStr,
) -> Option<PluginInstance<'a>>
fn create_plugin<'a>( &'a self, host_info: HostInfo<'a>, plugin_id: &CStr, ) -> Option<PluginInstance<'a>>
Creates a new plugin instance for the plugin type matching the given plugin_id.
If the given plugin_id matches against one of the plugin this factory manages,
implementors of this trait then use the PluginInstance::new method to instantiate the
corresponding plugin implementation.
If the given plugin_id does not match any known plugins to this factory, this method
returns None.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".