ModuleBase

Trait ModuleBase 

Source
pub trait ModuleBase {
Show 16 methods // Required methods fn describe(&self) -> Value; fn command(&mut self, cmd: &str, args: Value) -> Result<Value, Error>; fn read(&mut self, param: &str) -> Result<Value, Error>; fn change(&mut self, param: &str, value: Value) -> Result<Value, Error>; fn init_params(&mut self) -> Result<(), Error>; fn activate_updates(&mut self) -> Vec<Msg>; fn poll_normal(&mut self, n: usize); fn poll_busy(&mut self, n: usize); fn internals(&self) -> &ModInternals; fn internals_mut(&mut self) -> &mut ModInternals; // Provided methods fn name(&self) -> &str { ... } fn config(&self) -> &ModuleConfig { ... } fn init_parameter<T: Clone + PartialEq>( &mut self, param: &str, cached: impl Fn(&mut Self) -> &mut CachedParam<T>, partype: &impl TypeDesc<Repr = T>, update: impl Fn(&mut Self, T) -> Result<(), Error>, swonly: bool, readonly: bool, default: Option<impl Fn() -> T>, ) -> Result<(), Error> { ... } fn send_update(&self, param: &str, value: Value, tstamp: f64) { ... } fn update_pollinterval(&mut self, val: f64) -> Result<(), Error> { ... } fn run(self) where Self: Sized + Module { ... }
}
Expand description

Part of the Module trait that is implemented by the derive macro.

Required Methods§

Source

fn describe(&self) -> Value

Return the descriptive data for this module (a JSON object).

Source

fn command(&mut self, cmd: &str, args: Value) -> Result<Value, Error>

Execute a command.

Source

fn read(&mut self, param: &str) -> Result<Value, Error>

Read a parameter and possibly emit an update message.

Source

fn change(&mut self, param: &str, value: Value) -> Result<Value, Error>

Change a parameter and possibly emit an update message.

Source

fn init_params(&mut self) -> Result<(), Error>

Initialize cached values for all parameters.

Source

fn activate_updates(&mut self) -> Vec<Msg>

Get a list of updates for all parameters, which must be sent upon activation of the module.

Source

fn poll_normal(&mut self, n: usize)

Poll parameters. If device is busy, parameters that participate in busy-poll are not polled.

Source

fn poll_busy(&mut self, n: usize)

Poll parameters that participate in busy-poll if device status is busy.

Source

fn internals(&self) -> &ModInternals

Return a reference to the module internals. Even though we require the internals to be a member with a fixed name, the member is not known in the run method below.

Source

fn internals_mut(&mut self) -> &mut ModInternals

Provided Methods§

Source

fn name(&self) -> &str

Source

fn config(&self) -> &ModuleConfig

Source

fn init_parameter<T: Clone + PartialEq>( &mut self, param: &str, cached: impl Fn(&mut Self) -> &mut CachedParam<T>, partype: &impl TypeDesc<Repr = T>, update: impl Fn(&mut Self, T) -> Result<(), Error>, swonly: bool, readonly: bool, default: Option<impl Fn() -> T>, ) -> Result<(), Error>

Determine and set the initial value for a parameter.

This is quite complex since we have multiple sources (defaults from code, config file, hardware) and multiple ways of using them (depending on whether the parameter is writable at runtime).

Source

fn send_update(&self, param: &str, value: Value, tstamp: f64)

Send a general update message back to the dispatcher, which decides if and where to send it on.

Source

fn update_pollinterval(&mut self, val: f64) -> Result<(), Error>

Updates the regular poll interval to the given value in seconds, and the busy poll interval to 1/5 of it.

This is like an ordinary update_param method, but on the trait since it is always implemented the same.

Source

fn run(self)
where Self: Sized + Module,

Runs the main loop for the module, which does the following:

  • Initialize the module parameters
  • Handle incoming requests
  • Poll parameters periodically

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§