Move Actuator into actor.rs

This commit is contained in:
Gregor Reitzenstein 2020-12-09 10:49:34 +01:00
parent a8af3b287e
commit fc477d2d56
3 changed files with 14 additions and 32 deletions

View File

@ -11,12 +11,15 @@ use futures::channel::mpsc;
use futures_signals::signal::{Signal, MutableSignalCloned, MutableSignal, Mutable};
use crate::db::machine::MachineState;
use crate::registries::actuators::Actuator;
use crate::config::Settings;
use crate::error::Result;
use crate::network::ActorMap;
pub trait Actuator {
fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()>;
}
pub type ActorSignal = Box<dyn Signal<Item=MachineState> + Unpin + Send>;
pub struct Actor {
@ -92,8 +95,17 @@ impl Future for Actor {
}
}
pub struct Dummy;
impl Actuator for Dummy {
fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()> {
println!("New state for dummy actuator: {:?}", state);
Box::pin(smol::future::ready(()))
}
}
pub fn load() -> Result<(ActorMap, Vec<Actor>)> {
let d = Box::new(crate::registries::actuators::Dummy);
let d = Box::new(Dummy);
let (tx, a) = Actor::wrap(d);
let mut map = HashMap::new();

View File

@ -1,2 +1 @@
pub mod actuators;
pub mod sensors;

View File

@ -1,29 +0,0 @@
use slog::Logger;
use std::sync::Arc;
use smol::lock::RwLock;
use std::pin::Pin;
use futures::ready;
use futures::prelude::*;
use futures::future::BoxFuture;
use futures::channel::mpsc;
use futures::task::{Context, Poll, Spawn};
use futures_signals::signal::Signal;
use crate::db::machine::MachineState;
use std::collections::HashMap;
pub trait Actuator {
fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()>;
}
pub struct Dummy;
impl Actuator for Dummy {
fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()> {
println!("New state for dummy actuator: {:?}", state);
Box::pin(smol::future::ready(()))
}
}