Skip to main content

ad_core/plugin/
params.rs

1use asyn_rs::error::AsynResult;
2use asyn_rs::param::ParamType;
3use asyn_rs::port::PortDriverBase;
4
5/// Standard plugin base parameters registered on the PortDriverBase.
6#[derive(Clone, Copy)]
7pub struct PluginBaseParams {
8    pub enable_callbacks: usize,
9    pub blocking_callbacks: usize,
10    pub queue_size: usize,
11    pub dropped_arrays: usize,
12    pub queue_use: usize,
13    pub nd_array_port: usize,
14    pub nd_array_addr: usize,
15    pub plugin_type: usize,
16    pub execution_time: usize,
17}
18
19impl PluginBaseParams {
20    /// Register all base plugin params on the given port.
21    pub fn create(port_base: &mut PortDriverBase) -> AsynResult<Self> {
22        Ok(Self {
23            enable_callbacks: port_base.create_param("PLUGIN_ENABLE_CALLBACKS", ParamType::Int32)?,
24            blocking_callbacks: port_base
25                .create_param("PLUGIN_BLOCKING_CALLBACKS", ParamType::Int32)?,
26            queue_size: port_base.create_param("PLUGIN_QUEUE_SIZE", ParamType::Int32)?,
27            dropped_arrays: port_base.create_param("PLUGIN_DROPPED_ARRAYS", ParamType::Int32)?,
28            queue_use: port_base.create_param("PLUGIN_QUEUE_USE", ParamType::Int32)?,
29            nd_array_port: port_base.create_param("PLUGIN_NDARRAY_PORT", ParamType::Octet)?,
30            nd_array_addr: port_base.create_param("PLUGIN_NDARRAY_ADDR", ParamType::Int32)?,
31            plugin_type: port_base.create_param("PLUGIN_TYPE", ParamType::Octet)?,
32            execution_time: port_base.create_param("EXECUTION_TIME", ParamType::Float64)?,
33        })
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40    use asyn_rs::port::PortFlags;
41
42    #[test]
43    fn test_create_plugin_base_params() {
44        let mut base = PortDriverBase::new("test", 1, PortFlags::default());
45        let params = PluginBaseParams::create(&mut base).unwrap();
46        assert!(base.find_param("PLUGIN_ENABLE_CALLBACKS").is_some());
47        assert!(base.find_param("PLUGIN_QUEUE_SIZE").is_some());
48        assert!(base.find_param("PLUGIN_TYPE").is_some());
49        assert_eq!(
50            params.enable_callbacks,
51            base.find_param("PLUGIN_ENABLE_CALLBACKS").unwrap()
52        );
53    }
54}