Skip to main content

ad_core_rs/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///
7/// Param names match C ADCore NDPluginDriver.h string definitions.
8#[derive(Clone, Copy)]
9pub struct PluginBaseParams {
10    pub enable_callbacks: usize,
11    pub blocking_callbacks: usize,
12    pub queue_size: usize,
13    pub dropped_arrays: usize,
14    pub queue_use: usize,
15    pub nd_array_port: usize,
16    pub nd_array_addr: usize,
17    pub plugin_type: usize,
18    pub execution_time: usize,
19    pub max_threads: usize,
20    pub num_threads: usize,
21    pub sort_mode: usize,
22    pub sort_time: usize,
23    pub sort_size: usize,
24    pub sort_free: usize,
25    pub disordered_arrays: usize,
26    pub dropped_output_arrays: usize,
27    pub process_plugin: usize,
28    pub min_callback_time: usize,
29    pub max_byte_rate: usize,
30}
31
32impl PluginBaseParams {
33    /// Register all base plugin params on the given port.
34    pub fn create(port_base: &mut PortDriverBase) -> AsynResult<Self> {
35        Ok(Self {
36            enable_callbacks: port_base.create_param("ENABLE_CALLBACKS", ParamType::Int32)?,
37            blocking_callbacks: port_base.create_param("BLOCKING_CALLBACKS", ParamType::Int32)?,
38            queue_size: port_base.create_param("QUEUE_SIZE", ParamType::Int32)?,
39            dropped_arrays: port_base.create_param("DROPPED_ARRAYS", ParamType::Int32)?,
40            queue_use: port_base.create_param("QUEUE_FREE", ParamType::Int32)?,
41            nd_array_port: port_base.create_param("NDARRAY_PORT", ParamType::Octet)?,
42            nd_array_addr: port_base.create_param("NDARRAY_ADDR", ParamType::Int32)?,
43            plugin_type: port_base.create_param("PLUGIN_TYPE", ParamType::Octet)?,
44            execution_time: port_base.create_param("EXECUTION_TIME", ParamType::Float64)?,
45            max_threads: port_base.create_param("MAX_THREADS", ParamType::Int32)?,
46            num_threads: port_base.create_param("NUM_THREADS", ParamType::Int32)?,
47            sort_mode: port_base.create_param("SORT_MODE", ParamType::Int32)?,
48            sort_time: port_base.create_param("SORT_TIME", ParamType::Float64)?,
49            sort_size: port_base.create_param("SORT_SIZE", ParamType::Int32)?,
50            sort_free: port_base.create_param("SORT_FREE", ParamType::Int32)?,
51            disordered_arrays: port_base.create_param("DISORDERED_ARRAYS", ParamType::Int32)?,
52            dropped_output_arrays: port_base
53                .create_param("DROPPED_OUTPUT_ARRAYS", ParamType::Int32)?,
54            process_plugin: port_base.create_param("PROCESS_PLUGIN", ParamType::Int32)?,
55            min_callback_time: port_base.create_param("MIN_CALLBACK_TIME", ParamType::Float64)?,
56            max_byte_rate: port_base.create_param("MAX_BYTE_RATE", ParamType::Float64)?,
57        })
58    }
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64    use asyn_rs::port::PortFlags;
65
66    #[test]
67    fn test_create_plugin_base_params() {
68        let mut base = PortDriverBase::new("test", 1, PortFlags::default());
69        let params = PluginBaseParams::create(&mut base).unwrap();
70        assert!(base.find_param("ENABLE_CALLBACKS").is_some());
71        assert!(base.find_param("QUEUE_SIZE").is_some());
72        assert!(base.find_param("PLUGIN_TYPE").is_some());
73        assert!(base.find_param("SORT_MODE").is_some());
74        assert!(base.find_param("MAX_THREADS").is_some());
75        assert!(base.find_param("MIN_CALLBACK_TIME").is_some());
76        assert_eq!(
77            params.enable_callbacks,
78            base.find_param("ENABLE_CALLBACKS").unwrap()
79        );
80    }
81}