diff --git a/examples/bffh.dhall b/examples/bffh.dhall index 4ff8bb3..76bc1b7 100644 --- a/examples/bffh.dhall +++ b/examples/bffh.dhall @@ -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" } diff --git a/src/api/machine.rs b/src/api/machine.rs index e9946bb..64bbf4f 100644 --- a/src/api/machine.rs +++ b/src/api/machine.rs @@ -26,9 +26,10 @@ impl Machine { } pub fn fill(self: Arc, 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); +#[derive(Clone)] +pub struct Read(Arc); + +impl Read { + pub fn new(inner: Arc) -> 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) } } diff --git a/src/api/machines.rs b/src/api/machines.rs index 602e194..2feaed9 100644 --- a/src/api/machines.rs +++ b/src/api/machines.rs @@ -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(()) diff --git a/src/main.rs b/src/main.rs index 40faf95..fb6057a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +// FIXME: No. +#[allow(dead_code)] + #[macro_use] extern crate slog;