mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-12-22 19:53:49 +01:00
Polling futures turns out to be a smart thing to do. Fixes #12
This commit is contained in:
parent
9c87c192fa
commit
14eb9b048a
@ -1,8 +1,10 @@
|
||||
{ actor_connections = [{ _1 = "Testmachine", _2 = "Actor" }]
|
||||
{ actor_connections = [] : List { _1 : Text, _2 : Text }
|
||||
-- { actor_connections = [{ _1 = "Testmachine", _2 = "Actor" }]
|
||||
, actors =
|
||||
{ Actor = { module = "Shelly", params = {=} }
|
||||
}
|
||||
, init_connections = [{ _1 = "Initiator", _2 = "Testmachine" }]
|
||||
, init_connections = [] : List { _1 : Text, _2 : Text }
|
||||
--, init_connections = [{ _1 = "Initiator", _2 = "Testmachine" }]
|
||||
, initiators =
|
||||
{ Initiator = { module = "Dummy", params = {=} }
|
||||
}
|
||||
@ -18,6 +20,23 @@
|
||||
, name = "Testmachine"
|
||||
, read = "lab.test.read"
|
||||
, write = "lab.test.write"
|
||||
} }
|
||||
},
|
||||
Another =
|
||||
{ description = Some "Another test machine"
|
||||
, disclose = "lab.test.read"
|
||||
, manage = "lab.test.admin"
|
||||
, name = "Another"
|
||||
, read = "lab.test.read"
|
||||
, write = "lab.test.write"
|
||||
},
|
||||
Yetmore =
|
||||
{ description = Some "Yet more test machines"
|
||||
, disclose = "lab.test.read"
|
||||
, manage = "lab.test.admin"
|
||||
, name = "Yetmore"
|
||||
, read = "lab.test.read"
|
||||
, write = "lab.test.write"
|
||||
}
|
||||
}
|
||||
, mqtt_url = "tcp://localhost:1883"
|
||||
}
|
||||
|
@ -26,9 +26,10 @@ impl Machine {
|
||||
}
|
||||
|
||||
pub fn fill(self: Arc<Self>, builder: &mut Builder) {
|
||||
// TODO check permissions
|
||||
builder.set_read(capnp_rpc::new_client(Read(self.clone())));
|
||||
// TODO set all the others
|
||||
builder.set_write(capnp_rpc::new_client(Write(self.clone())));
|
||||
builder.set_manage(capnp_rpc::new_client(Manage(self.clone())));
|
||||
builder.set_admin(capnp_rpc::new_client(Admin(self.clone())));
|
||||
}
|
||||
|
||||
pub async fn fill_info(&self, builder: &mut m_info::Builder<'_>) {
|
||||
@ -63,7 +64,14 @@ impl Machine {
|
||||
}
|
||||
}
|
||||
|
||||
struct Read(Arc<Machine>);
|
||||
#[derive(Clone)]
|
||||
pub struct Read(Arc<Machine>);
|
||||
|
||||
impl Read {
|
||||
pub fn new(inner: Arc<Machine>) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl read::Server for Read {
|
||||
fn info(&mut self,
|
||||
@ -71,9 +79,16 @@ impl read::Server for Read {
|
||||
mut results: read::InfoResults)
|
||||
-> Promise<(), Error>
|
||||
{
|
||||
let mut b = results.get().init_minfo();
|
||||
self.0.fill_info(&mut b);
|
||||
Promise::ok(())
|
||||
let this = self.clone();
|
||||
let f = async move {
|
||||
let mut b = results.get().init_minfo();
|
||||
|
||||
this.0.fill_info(&mut b).await;
|
||||
|
||||
Ok(())
|
||||
};
|
||||
|
||||
Promise::from_future(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use crate::db::Databases;
|
||||
|
||||
use crate::network::Network;
|
||||
|
||||
use super::machine::Machine;
|
||||
use super::machine::*;
|
||||
|
||||
/// An implementation of the `Machines` API
|
||||
pub struct Machines {
|
||||
@ -39,14 +39,13 @@ impl machines::Server for Machines {
|
||||
.map(|(n, m)| (n.clone(), m.clone()))
|
||||
.collect();
|
||||
|
||||
let res = results.get();
|
||||
let mut machines = res.init_machines(v.len() as u32);
|
||||
let mut machines = results.get().init_machines(v.len() as u32);
|
||||
|
||||
for (i, (name, machine)) in v.into_iter().enumerate() {
|
||||
debug!(self.session.log, "Adding machine {}: {:?}", name, machine);
|
||||
trace!(self.session.log, "Adding machine #{} {}: {:?}", i, name, machine);
|
||||
let machine = Arc::new(Machine::new(self.session.clone(), machine, self.db.clone()));
|
||||
let mut builder = machines.reborrow().get(i as u32);
|
||||
Machine::fill(machine, &mut builder);
|
||||
machine.fill(&mut builder);
|
||||
}
|
||||
|
||||
Promise::ok(())
|
||||
|
@ -1,3 +1,6 @@
|
||||
// FIXME: No.
|
||||
#[allow(dead_code)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate slog;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user