From a279a2ed48034d3e75ed7a354353d6585f2c6c06 Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Wed, 16 Dec 2020 12:49:56 +0100 Subject: [PATCH] Actually implement fill_info in a way that compiles. ^^' --- src/api/machine.rs | 18 +++++++++++------- src/machine.rs | 6 +++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/api/machine.rs b/src/api/machine.rs index 060da01..90b2ed5 100644 --- a/src/api/machine.rs +++ b/src/api/machine.rs @@ -1,4 +1,5 @@ use std::sync::Arc; +use std::ops::Deref; use capnp::capability::Promise; use capnp::Error; @@ -28,29 +29,32 @@ impl Machine { // TODO set all the others } - pub async fn fill_info(&self, builder: &mut m_info::Builder) { + pub async fn fill_info(&self, builder: &mut m_info::Builder<'_>) { let guard = self.machine.lock().await; builder.set_name(guard.desc.name.as_ref()); - builder.set_description(guard.desc.description.as_ref()); - match guard.state.read_only().lock_ref().status { + if let Some(desc) = guard.desc.description.as_ref() { + builder.set_description(desc); + } + + match guard.read_state().lock_ref().deref().state { Status::Free => { builder.set_state(State::Free); } Status::Disabled => { builder.set_state(State::Disabled); } - Status::Blocked(who, prio) => { + Status::Blocked(_,_) => { builder.set_state(State::Blocked); } - Status::InUse(who, prio) => { + Status::InUse(_,_) => { builder.set_state(State::InUse); } - Status::ToCheck(who, prio) => { + Status::ToCheck(_,_) => { builder.set_state(State::ToCheck); } - Status::Reserved(who, prio) => { + Status::Reserved(_,_) => { builder.set_state(State::Reserved); } } diff --git a/src/machine.rs b/src/machine.rs index 711c1d6..f96943e 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -14,7 +14,7 @@ use serde::{Serialize, Deserialize}; use futures_signals::signal::Signal; use futures_signals::signal::SignalExt; -use futures_signals::signal::Mutable; +use futures_signals::signal::{Mutable, ReadOnlyMutable}; use uuid::Uuid; @@ -172,6 +172,10 @@ impl Inner { return Ok(tx); } + pub fn read_state(&self) -> ReadOnlyMutable { + self.state.read_only() + } + pub fn get_signal(&self) -> impl Signal { self.state.signal_cloned() }