mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-14 03:07:57 +01:00
Move Actuator into actor.rs
This commit is contained in:
parent
a8af3b287e
commit
fc477d2d56
16
src/actor.rs
16
src/actor.rs
@ -11,12 +11,15 @@ use futures::channel::mpsc;
|
|||||||
use futures_signals::signal::{Signal, MutableSignalCloned, MutableSignal, Mutable};
|
use futures_signals::signal::{Signal, MutableSignalCloned, MutableSignal, Mutable};
|
||||||
|
|
||||||
use crate::db::machine::MachineState;
|
use crate::db::machine::MachineState;
|
||||||
use crate::registries::actuators::Actuator;
|
|
||||||
use crate::config::Settings;
|
use crate::config::Settings;
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
|
|
||||||
use crate::network::ActorMap;
|
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 type ActorSignal = Box<dyn Signal<Item=MachineState> + Unpin + Send>;
|
||||||
|
|
||||||
pub struct Actor {
|
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>)> {
|
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 (tx, a) = Actor::wrap(d);
|
||||||
|
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
|
@ -1,2 +1 @@
|
|||||||
pub mod actuators;
|
|
||||||
pub mod sensors;
|
pub mod sensors;
|
||||||
|
@ -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(()))
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user