mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-11 01:53:23 +01:00
Adds Sensors registry
This commit is contained in:
parent
406cebadb8
commit
fc1480314f
@ -1,4 +1,5 @@
|
|||||||
mod actuators;
|
mod actuators;
|
||||||
|
mod sensors;
|
||||||
|
|
||||||
pub use actuators::{Actuator, ActBox};
|
pub use actuators::{Actuator, ActBox};
|
||||||
|
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
|
use std::pin::Pin;
|
||||||
|
use futures::task::{Context, Poll};
|
||||||
use futures::{Future, Stream};
|
use futures::{Future, Stream};
|
||||||
|
use futures::future::BoxFuture;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use smol::lock::RwLock;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct Sensors {
|
pub struct Sensors {
|
||||||
|
inner: Arc<RwLock<Inner>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type SensBox<'a> = Box<dyn Sensor<'a>>;
|
||||||
|
type Inner = HashMap<String, SensBox<'static>>;
|
||||||
|
|
||||||
|
|
||||||
// Implementing Sensors.
|
// Implementing Sensors.
|
||||||
//
|
//
|
||||||
@ -11,6 +21,45 @@ pub struct Sensors {
|
|||||||
// machine update signal to actor doing thing being another, a Sensor implementation would send a
|
// 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.
|
// Stream of futures - each future being an atomic Machine update.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Sensor: Stream<Item = Box<dyn Future<Output = ()>>> {
|
/// BFFH Sensor
|
||||||
async fn setup() -> Self;
|
///
|
||||||
|
/// 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<Item = BoxFuture<'a, ()>> {
|
||||||
|
/// 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<Option<Self::Item>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user