mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-10 17:43:23 +01:00
Updates to allow use()ing stuff
This commit is contained in:
parent
8f333b81ad
commit
55dcf6dd80
@ -1,5 +1,5 @@
|
|||||||
{ actor_connections = [] : List { _1 : Text, _2 : Text }
|
-- { actor_connections = [] : List { _1 : Text, _2 : Text }
|
||||||
-- { actor_connections = [{ _1 = "Testmachine", _2 = "Actor" }]
|
{ actor_connections = [{ _1 = "Testmachine", _2 = "Actor" }]
|
||||||
, actors =
|
, actors =
|
||||||
{ Actor = { module = "Shelly", params = {=} }
|
{ Actor = { module = "Shelly", params = {=} }
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use crate::schema::api_capnp::machine::*;
|
|||||||
use crate::connection::Session;
|
use crate::connection::Session;
|
||||||
use crate::db::Databases;
|
use crate::db::Databases;
|
||||||
use crate::db::machine::{Status, MachineState};
|
use crate::db::machine::{Status, MachineState};
|
||||||
use crate::machine::Machine as NwMachine;
|
use crate::machine::{Machine as NwMachine, ReturnToken};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Machine {
|
pub struct Machine {
|
||||||
@ -97,20 +97,29 @@ struct Write(Arc<Machine>);
|
|||||||
impl write::Server for Write {
|
impl write::Server for Write {
|
||||||
fn use_(&mut self,
|
fn use_(&mut self,
|
||||||
_params: write::UseParams,
|
_params: write::UseParams,
|
||||||
_results: write::UseResults)
|
mut results: write::UseResults)
|
||||||
-> Promise<(), Error>
|
-> Promise<(), Error>
|
||||||
{
|
{
|
||||||
let uid = self.0.session.user.try_lock().unwrap().as_ref().map(|u| u.id.clone());
|
let uid = self.0.session.user.try_lock().unwrap().as_ref().map(|u| u.id.clone());
|
||||||
let new_state = MachineState::used(uid.clone());
|
let new_state = MachineState::used(uid.clone());
|
||||||
let this = self.0.clone();
|
let this = self.0.clone();
|
||||||
let f = this.machine.request_state_change(this.session.user.try_lock().unwrap().as_ref(), new_state)
|
let f = async move {
|
||||||
.map(|res_token| match res_token {
|
let res_token = this.machine.request_state_change(
|
||||||
|
this.session.user.try_lock().unwrap().as_ref(),
|
||||||
|
new_state
|
||||||
|
).await;
|
||||||
|
|
||||||
|
match res_token {
|
||||||
// TODO: Do something with the token we get returned
|
// TODO: Do something with the token we get returned
|
||||||
Ok(_tok) => {
|
Ok(tok) => {
|
||||||
|
let gb = GiveBack(Some(tok));
|
||||||
|
results.get().set_ret(capnp_rpc::new_client(gb));
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
},
|
||||||
Err(e) => Err(capnp::Error::failed(format!("State change request returned {}", e))),
|
Err(e) => Err(capnp::Error::failed(format!("State change request returned {}", e))),
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Promise::from_future(f)
|
Promise::from_future(f)
|
||||||
}
|
}
|
||||||
@ -124,6 +133,23 @@ impl write::Server for Write {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct GiveBack(Option<ReturnToken>);
|
||||||
|
|
||||||
|
impl write::give_back::Server for GiveBack {
|
||||||
|
fn ret(&mut self,
|
||||||
|
_params: write::give_back::RetParams,
|
||||||
|
_results: write::give_back::RetResults)
|
||||||
|
-> Promise<(), Error>
|
||||||
|
{
|
||||||
|
if let Some(chan) = self.0.take() {
|
||||||
|
chan.send(())
|
||||||
|
.expect("Other end of GiveBack token was dropped?!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise::ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Manage(Arc<Machine>);
|
struct Manage(Arc<Machine>);
|
||||||
|
|
||||||
impl manage::Server for Manage {
|
impl manage::Server for Manage {
|
||||||
|
Loading…
Reference in New Issue
Block a user