Module dygpi::plugin[][src]

Expand description

The components required to define a plugin API.

The types defined in this module are required in defining the plugin API, the

Example - Define Plugin

use dygpi::plugin::Plugin;

#[derive(Debug)]
struct SoundEffectPlugin {
    id: String,
    engine: SoundEngine,
    media: MediaStream,
};

impl Plugin for SoundEffectPlugin {
    fn plugin_id(&self) -> &String {
        &self.id
    }

    fn on_load(&self) -> dygpi::error::Result<()> {
        // connect to sound engine
        // load media stream
        Ok(())
    }

    fn on_unload(&self) -> dygpi::error::Result<()> {
        // unload media stream
        // disconnect from sound engine
        Ok(())
    }
}

impl SoundEffectPlugin {
    pub fn new(id: &str) -> Self { unimplemented!() }
    pub fn play(&self) {}
}

Example - Register Plugin

use dygpi::plugin::PluginRegistrar;

const PLUGIN_ID: &str = concat!(env!("CARGO_PKG_NAME"), "::", module_path!(), "::DelayEffect");

#[no_mangle]
pub extern "C" fn register_plugins<MyPlugin>(
    registrar: &mut PluginRegistrar<SoundEffectPlugin>
) {
    registrar.register(SoundEffectPlugin::new(PLUGIN_ID));
}

Structs

A registrar is created by a plugin manager and provided to the library’s registration function to register any plugins it has.

Constants

The required name of the registration function (see the PluginRegistrationFn type).

Traits

This trait must be implemented by any plugin type, it not only provides a plugin id, but also provides lifecycle methods which implementors can use to manage resources owned by the plugin.

Functions

This function is exposed so that the version linked into a plugin provider may be compared to the one linked into the plugin host.

Type Definitions

The type for the registration function that a plugin provider MUST include in their library. This function constructs plugin instances and uses the registrar as a callback into the plugin manager.