Skip to main content

sim_lib_plugin_core/
runtime.rs

1use sim_kernel::{Cx, Result, Symbol};
2use sim_lib_core::{SurfaceField, SurfacePackLib, SurfacePackSpec, SurfaceValueSpec, install_once};
3
4const PLUGIN_CORE_LIB_ID: &str = "plugin-core";
5
6/// Installs the plugin-core surface pack into the runtime context.
7///
8/// Registers one descriptor card per plugin-core export symbol; installing more
9/// than once is idempotent.
10///
11/// # Errors
12///
13/// Returns an error when the surface pack fails to install.
14pub fn install_plugin_core_lib(cx: &mut Cx) -> Result<()> {
15    install_once(cx, &plugin_core_pack())?;
16    Ok(())
17}
18
19/// Returns the qualified export symbols the plugin-core lib publishes.
20pub fn plugin_core_symbols() -> Vec<Symbol> {
21    [
22        "PluginDescriptor",
23        "ParameterDescriptor",
24        "PluginState",
25        "HostedPluginProcessor",
26        "ProcessorPlugin",
27    ]
28    .into_iter()
29    .map(|name| Symbol::qualified(PLUGIN_CORE_LIB_ID, name))
30    .collect()
31}
32
33/// The plugin-core surface pack: one uniform descriptor card per export symbol.
34fn plugin_core_pack() -> SurfacePackLib {
35    SurfacePackLib {
36        spec: SurfacePackSpec {
37            lib_id: Symbol::new(PLUGIN_CORE_LIB_ID),
38            values: plugin_core_symbols()
39                .into_iter()
40                .map(|symbol| SurfaceValueSpec {
41                    symbol: symbol.clone(),
42                    fields: vec![
43                        (Symbol::new("symbol"), SurfaceField::Symbol(symbol)),
44                        (
45                            Symbol::new("layer"),
46                            SurfaceField::Str(PLUGIN_CORE_LIB_ID.to_owned()),
47                        ),
48                        (
49                            Symbol::new("kind"),
50                            SurfaceField::Str("plugin-descriptor".to_owned()),
51                        ),
52                        (
53                            Symbol::new("role"),
54                            SurfaceField::Str(
55                                "common plugin descriptor and adapter surface".to_owned(),
56                            ),
57                        ),
58                    ],
59                })
60                .collect(),
61        },
62    }
63}