mirror of
https://gitlab.com/fabinfra/fabaccess/sute.git
synced 2025-03-12 14:41:52 +01:00
Print stuff
This commit is contained in:
parent
ec719ba890
commit
f561cc7df1
14
src/app.rs
14
src/app.rs
@ -101,14 +101,14 @@ impl<'a, S: Unpin> Sute<'a, S> {
|
|||||||
if let Some(mut api) = self.session.as_ref().map(|s| s.bootstrap.clone()) {
|
if let Some(mut api) = self.session.as_ref().map(|s| s.bootstrap.clone()) {
|
||||||
let log = self.log.clone();
|
let log = self.log.clone();
|
||||||
|
|
||||||
let f = api.machines().map(|mut machines| {
|
let machines = api.machines();
|
||||||
machines.get_machine(uuid).map(move |res| {
|
let machine = machines.then(|mut machines| {
|
||||||
res.map(|m| {
|
machines.get_machine(uuid)
|
||||||
m.get_info().map(move |info| {
|
});
|
||||||
info!(log, "Yay, stuff! {:?}", info);
|
let f = machine.then(move |res| {
|
||||||
})
|
res.as_ref().unwrap().get_info().map(move |info| {
|
||||||
|
info!(log, "Yay, stuff! {:?}", info);
|
||||||
})
|
})
|
||||||
})
|
|
||||||
});
|
});
|
||||||
let old_f = self.future.replace(Box::pin(f.map(|_| ())));
|
let old_f = self.future.replace(Box::pin(f.map(|_| ())));
|
||||||
if !old_f.is_none() {
|
if !old_f.is_none() {
|
||||||
|
@ -1,30 +1,36 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
use futures::FutureExt;
|
||||||
|
|
||||||
use super::api_capnp::machine::read::Client;
|
use super::api_capnp::machine::read::Client;
|
||||||
|
|
||||||
pub struct Machine {
|
pub struct Machine {
|
||||||
read: Option<Client>,
|
read: Client,
|
||||||
}
|
}
|
||||||
impl fmt::Debug for Machine {
|
impl fmt::Debug for Machine {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut b = f.debug_struct("Machine");
|
let mut b = f.debug_struct("Machine");
|
||||||
if let Some(r) = self.read.as_ref() {
|
b.field("read", &self.read.type_id());
|
||||||
b.field("read", &r.type_id());
|
|
||||||
}
|
|
||||||
b.finish()
|
b.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Machine {
|
impl Machine {
|
||||||
pub fn new(read: Option<Client>) -> Self {
|
pub fn new(read: Client) -> Self {
|
||||||
Machine {
|
Machine {
|
||||||
read,
|
read,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_info(&self) -> impl Future<Output=Option<String>> {
|
pub fn get_info(&self) -> impl Future<Output=Option<String>> {
|
||||||
futures::future::ready(None)
|
let req = self.read.info_request().send().promise;
|
||||||
|
req.map(|res| {
|
||||||
|
res.unwrap().get().unwrap().get_minfo().ok().map(|minfo| {
|
||||||
|
// TODO state
|
||||||
|
format!("Name: {:?}\n Description: {:?}\nState: ",
|
||||||
|
minfo.get_name(), minfo.get_description())
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
use futures::FutureExt;
|
||||||
|
|
||||||
use super::api_capnp::machines::Client;
|
use super::api_capnp::machines::Client;
|
||||||
|
|
||||||
use super::machine::Machine;
|
use super::machine::Machine;
|
||||||
|
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct Machines {
|
pub struct Machines {
|
||||||
inner: Client,
|
inner: Client,
|
||||||
}
|
}
|
||||||
@ -23,6 +27,39 @@ impl Machines {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_machine(&mut self, uuid: String) -> impl Future<Output=Option<Machine>> {
|
pub fn get_machine(&mut self, uuid: String) -> impl Future<Output=Option<Machine>> {
|
||||||
futures::future::ready(None)
|
let mut req = self.inner.get_machine_request();
|
||||||
|
let param_builder = req.get();
|
||||||
|
let uuid_builder = param_builder.init_uuid();
|
||||||
|
api_from_uuid(Uuid::from_str(&uuid).unwrap(), uuid_builder);
|
||||||
|
|
||||||
|
let prom = req.send().promise;
|
||||||
|
|
||||||
|
// TODO: When's that an Err?
|
||||||
|
prom.map(|res| {
|
||||||
|
// TODO: When's that an Err?
|
||||||
|
let tmp = res.unwrap();
|
||||||
|
let moretmp = tmp.get().unwrap();
|
||||||
|
if let Ok(m) = moretmp.get_machine() {
|
||||||
|
match m.get_read() {
|
||||||
|
Ok(m) => return Some(Machine::new(m)),
|
||||||
|
Err(e) => println!("{}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn uuid_from_api(uuid: crate::schema::api_capnp::u_u_i_d::Reader) -> Uuid {
|
||||||
|
let uuid0 = uuid.get_uuid0() as u128;
|
||||||
|
let uuid1 = uuid.get_uuid1() as u128;
|
||||||
|
let num: u128 = (uuid0 << 64) + uuid1;
|
||||||
|
Uuid::from_u128(num)
|
||||||
|
}
|
||||||
|
pub fn api_from_uuid(uuid: Uuid, mut wr: crate::schema::api_capnp::u_u_i_d::Builder) {
|
||||||
|
let num = uuid.as_u128();
|
||||||
|
let uuid0 = num as u64;
|
||||||
|
let uuid1 = (num >> 64) as u64;
|
||||||
|
wr.set_uuid0(uuid0);
|
||||||
|
wr.set_uuid1(uuid1);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user