pub struct PluginRegistry<R: Reactor> { /* private fields */ }Expand description
Manages loaded plugins and their actor type factories.
PluginRegistry is the single source of truth for which plugins are
loaded and which actor types they export. It does not interact with
the engine directly — callers are responsible for stopping any running
actors before calling unload.
Implementations§
Source§impl<R: Reactor> PluginRegistry<R>
impl<R: Reactor> PluginRegistry<R>
Sourcepub fn load_native(&mut self, path: &Path) -> Result<PluginInfo, PluginError>
pub fn load_native(&mut self, path: &Path) -> Result<PluginInfo, PluginError>
Load a native shared library plugin from path.
Steps:
- Open the library with
libloading. - Resolve all required C symbols; fail fast on missing exports.
- Call
pd_plugin_initand verify the returned ABI version. - For each declared actor type, register a factory that constructs an
[
FfiActor] wrapping the plugin’s lifecycle functions. - Record the loaded library in the registry so it stays mapped in memory for the lifetime of the actors it created.
Returns PluginInfo describing the newly loaded plugin.
§Errors
PluginError::LoadFailed— library not found, symbol missing, or UTF-8 decoding of plugin name/type names failed.PluginError::InitFailed—pd_plugin_initreturned null.PluginError::AbiMismatch—abi_versionin the returned struct does not equalPD_ABI_VERSION.
Source§impl<R: Reactor> PluginRegistry<R>
impl<R: Reactor> PluginRegistry<R>
Sourcepub fn list(&self) -> Vec<PluginInfo>
pub fn list(&self) -> Vec<PluginInfo>
List metadata for all currently loaded plugins, sorted by name.
Sourcepub fn create_actor(
&self,
type_name: &str,
config: &[u8],
) -> Result<Box<dyn Actor<R>>, PluginError>
pub fn create_actor( &self, type_name: &str, config: &[u8], ) -> Result<Box<dyn Actor<R>>, PluginError>
Create an actor instance from a registered type.
config is an opaque byte slice forwarded to the factory; pass &[]
for types that require no configuration.
Returns Err(PluginError::UnknownType(...)) if no factory is registered
for type_name.
Sourcepub fn actor_types_for_plugin(&self, plugin_name: &str) -> Vec<String>
pub fn actor_types_for_plugin(&self, plugin_name: &str) -> Vec<String>
Return actor type names registered by a specific plugin, sorted.
Sourcepub fn unload(&mut self, name: &str) -> Result<(), PluginError>
pub fn unload(&mut self, name: &str) -> Result<(), PluginError>
Unload a plugin by name.
Removes all actor type factories that belong to name from the
registry, then drops the plugin’s library handle (for native plugins,
this calls dlclose).
Caller’s responsibility: stop all running actors created by this
plugin before calling unload. Dropping the native library while
actors are still executing code from it is undefined behaviour.
Returns Err(PluginError::UnknownType(...)) if no plugin named name
is loaded.
Sourcepub fn register_type(
&mut self,
plugin_name: impl Into<String>,
type_name: impl Into<String>,
factory: impl Fn(&[u8]) -> Result<Box<dyn Actor<R>>, PluginError> + Send + Sync + 'static,
)
pub fn register_type( &mut self, plugin_name: impl Into<String>, type_name: impl Into<String>, factory: impl Fn(&[u8]) -> Result<Box<dyn Actor<R>>, PluginError> + Send + Sync + 'static, )
Register an actor type factory.
Called internally by load_native and
load_wasm after reading plugin metadata.
Can also be used for programmatic (in-process) plugin registration
— for example, registering test actors without loading a shared library.
Note that register_type alone does not add an entry to list;
the plugin must also be recorded via insert_loaded to appear there.
Sourcepub fn load_wasm(
&mut self,
path: &Path,
host: Arc<dyn WasmHost>,
) -> Result<PluginInfo, PluginError>
pub fn load_wasm( &mut self, path: &Path, host: Arc<dyn WasmHost>, ) -> Result<PluginInfo, PluginError>
Load a WASM plugin from path, using host to compile and inspect it.
Protocol:
- Read
.wasmbytes frompath. - Compile via
host.compile. - Instantiate with no-op imports (metadata pass).
- Call the module’s
pd_plugin_init() -> i32export, which returns a pointer into WASM linear memory where a WASM-layoutPdPluginInfostruct is stored (32-bit pointer fields). - Parse the struct to extract name, version, ABI version, and actor type names. Reject mismatched ABI.
- Register a
WasmActorfactory for each declared actor type.