Load Machines

This commit is contained in:
Gregor Reitzenstein 2020-12-07 12:27:53 +01:00
parent 6fbf63a7b9
commit a16712c66f
2 changed files with 16 additions and 4 deletions

View File

@ -76,6 +76,11 @@ impl Machine {
let mut guard = self.inner.try_lock().unwrap();
guard.request_state_change(who, new_state)
}
pub fn signal(&self) -> impl Signal<Item=MachineState> {
let mut guard = self.inner.try_lock().unwrap();
guard.signal()
}
}
impl Deref for Machine {
@ -227,7 +232,14 @@ impl MachineDescription {
}
pub fn load(config: &crate::config::Settings) -> Result<Vec<Machine>> {
unimplemented!()
let mut map = MachineDescription::load_file(&config.machines)?;
Ok(map.drain()
.map(|(k,v)| {
// TODO: Read state from the state db
Machine::construct(k, v, MachineState::new())
})
.collect())
}
#[cfg(test_DISABLED)]

View File

@ -133,10 +133,9 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
error!(log, "Loading is currently not implemented");
Ok(())
} else {
//let machines = machine::load(&config)?;
let ex = Executor::new();
let machines = machine::load(&config)?;
let m = futures_signals::signal::Mutable::new(crate::db::machine::MachineState::new());
let (mut tx, actor) = actor::load()?;
@ -145,7 +144,8 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
// TODO HERE: restore connections between initiators, machines, actors
// Like so
tx.try_send(Some(m.signal_cloned())).unwrap();
let m = machines[0].signal();
tx.try_send(Some(m)).unwrap();
// TODO HERE: Spawn all actors & inits