Trait API

Source
pub trait API: Send {
    type DeviceSet: Send + Sync;

    // Required methods
    fn register_devices(
        drc: RequestChan,
        cfg: &DriverConfig,
        max_history: Option<usize>,
    ) -> Pin<Box<dyn Future<Output = Result<Self::DeviceSet>> + Send>>;
    fn create_instance(
        cfg: &DriverConfig,
    ) -> Pin<Box<dyn Future<Output = Result<Box<Self>>> + Send>>
       where Self: Sized;
    fn run<'a>(
        &'a mut self,
        devices: Arc<Mutex<Self::DeviceSet>>,
    ) -> Pin<Box<dyn Future<Output = Infallible> + Send + 'a>>;
}
Expand description

All drivers implement the driver::API trait.

The API trait defines methods that are expected to be available from a driver instance. By supporting this API, the framework can create driver instances and monitor them as they run.

Required Associated Types§

Required Methods§

Source

fn register_devices( drc: RequestChan, cfg: &DriverConfig, max_history: Option<usize>, ) -> Pin<Box<dyn Future<Output = Result<Self::DeviceSet>> + Send>>

Source

fn create_instance( cfg: &DriverConfig, ) -> Pin<Box<dyn Future<Output = Result<Box<Self>>> + Send>>
where Self: Sized,

Creates an instance of the driver.

cfg contains the driver parameters, as specified in the drmem.toml configuration file. It is a toml::Table type so the keys for the parameter names are strings and the associated data are toml::Value types. This method should validate the parameters and convert them into forms useful to the driver. By convention, if any errors are found in the configuration, this method should return Error::BadConfig.

drc is a communication channel with which the driver makes requests to the core. Its typical use is to register devices with the framework, which is usually done in this method. As other request types are added, they can be used while the driver is running.

max_history is specified in the configuration file. It is a hint as to the maximum number of data point to save for each of the devices created by this driver. A backend can choose to interpret this in its own way. For instance, the simple backend can only ever save one data point. Redis will take this as a hint and will choose the most efficient way to prune the history. That means, if more than the limit is present, redis won’t prune the history to less than the limit. However there may be more than the limit – it just won’t grow without bound.

Source

fn run<'a>( &'a mut self, devices: Arc<Mutex<Self::DeviceSet>>, ) -> Pin<Box<dyn Future<Output = Infallible> + Send + 'a>>

Runs the instance of the driver.

Since drivers provide access to hardware, this method should never return unless something severe occurs and, in that case, it should use panic!(). All drivers are monitored by a task and if a driver panics or returns an error from this method, it gets reported in the log and then, after a short delay, the driver is restarted.

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§