diff --git a/src/registries.rs b/src/registries.rs index e5d218c..bf7d371 100644 --- a/src/registries.rs +++ b/src/registries.rs @@ -1,4 +1,5 @@ mod actuators; +mod sensors; pub use actuators::{Actuator, ActBox}; diff --git a/src/registries/sensors.rs b/src/registries/sensors.rs index 3508b2e..25c41ee 100644 --- a/src/registries/sensors.rs +++ b/src/registries/sensors.rs @@ -1,9 +1,19 @@ +use std::pin::Pin; +use futures::task::{Context, Poll}; use futures::{Future, Stream}; +use futures::future::BoxFuture; + +use std::sync::Arc; +use smol::lock::RwLock; +use std::collections::HashMap; pub struct Sensors { - + inner: Arc>, } +pub type SensBox<'a> = Box>; +type Inner = HashMap>; + // Implementing Sensors. // @@ -11,6 +21,45 @@ pub struct Sensors { // machine update signal to actor doing thing being another, a Sensor implementation would send a // Stream of futures - each future being an atomic Machine update. #[async_trait] -pub trait Sensor: Stream>> { - async fn setup() -> Self; +/// BFFH Sensor +/// +/// A sensor is anything that can forward an intent of an user to do something to bffh. +/// This may be a card reader connected to a machine, a website allowing users to select a machine +/// they want to use or something like QRHello +pub trait Sensor<'a>: Stream> { + /// Setup the Sensor. + /// + /// After this async function completes the Stream implementation should be able to generate + /// futures when polled. + /// Implementations can rely on this function being polled to completeion before the stream + /// is polled. + async fn setup(&mut self); + + /// Shutdown the sensor gracefully + /// + /// Implementations can rely on that the stream will not be polled after this function has been + /// called. + async fn shutdown(&mut self); +} + +struct Dummy<'a> { + phantom: &'a std::marker::PhantomData<()>, +} +#[async_trait] +impl<'a> Sensor<'a> for Dummy<'a> { + async fn setup(&mut self) { + return; + } + + async fn shutdown(&mut self) { + return; + } +} + +impl<'a> Stream for Dummy<'a> { + type Item = BoxFuture<'a, ()>; + + fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + todo!() + } }