mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-11 01:53:23 +01:00
Minimal draft implementation of getGiveBack
It's untested but it should(TM) work.
This commit is contained in:
parent
dcdbc42274
commit
8ce5c2f6ff
@ -131,6 +131,37 @@ impl write::Server for Write {
|
|||||||
{
|
{
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_give_back(&mut self,
|
||||||
|
_params: write::GetGiveBackParams,
|
||||||
|
mut results: write::GetGiveBackResults)
|
||||||
|
-> Promise<(), Error>
|
||||||
|
{
|
||||||
|
let this = self.0.clone();
|
||||||
|
|
||||||
|
let f = async move {
|
||||||
|
let status = this.machine.get_status().await;
|
||||||
|
let sess = this.session.clone();
|
||||||
|
|
||||||
|
match status {
|
||||||
|
Status::InUse(Some(uid)) => {
|
||||||
|
let user = sess.user.lock().await;
|
||||||
|
if let Some(u) = user.as_ref() {
|
||||||
|
if u.id == uid {
|
||||||
|
let token = this.machine.create_token();
|
||||||
|
let gb = GiveBack(Some(token));
|
||||||
|
results.get().set_ret(capnp_rpc::new_client(gb));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Machine not in use
|
||||||
|
_ => {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Promise::from_future(f.map(|_| Ok(())))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GiveBack(Option<ReturnToken>);
|
struct GiveBack(Option<ReturnToken>);
|
||||||
|
@ -23,7 +23,7 @@ use futures_signals::signal::{Mutable, ReadOnlyMutable};
|
|||||||
use crate::error::{Result, Error};
|
use crate::error::{Result, Error};
|
||||||
|
|
||||||
use crate::db::access;
|
use crate::db::access;
|
||||||
use crate::db::machine::{MachineIdentifier, MachineState};
|
use crate::db::machine::{MachineIdentifier, MachineState, Status};
|
||||||
use crate::db::user::{User, UserData};
|
use crate::db::user::{User, UserData};
|
||||||
|
|
||||||
use crate::network::MachineMap;
|
use crate::network::MachineMap;
|
||||||
@ -113,6 +113,15 @@ impl Machine {
|
|||||||
Box::pin(f)
|
Box::pin(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_token(&self) -> ReturnToken {
|
||||||
|
ReturnToken::new(self.inner.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_status(&self) -> Status {
|
||||||
|
let guard = self.inner.lock().await;
|
||||||
|
guard.state.get_cloned().state
|
||||||
|
}
|
||||||
|
|
||||||
pub fn signal(&self) -> impl Signal<Item=MachineState> {
|
pub fn signal(&self) -> impl Signal<Item=MachineState> {
|
||||||
let guard = self.inner.try_lock().unwrap();
|
let guard = self.inner.try_lock().unwrap();
|
||||||
guard.signal()
|
guard.signal()
|
||||||
|
Loading…
Reference in New Issue
Block a user