fabaccess-bffh/bffhd/capnp/machine.rs

283 lines
8.4 KiB
Rust
Raw Normal View History

2022-03-13 20:11:37 +01:00
use crate::resources::modules::fabaccess::{MachineState, Status};
2022-03-13 17:29:21 +01:00
use crate::resources::Resource;
use crate::session::SessionHandle;
use api::machine_capnp::machine::{
2022-03-13 17:29:21 +01:00
admin, admin::Server as AdminServer, check, check::Server as CheckServer, in_use as inuse,
in_use::Server as InUseServer, info, info::Server as InfoServer, manage,
manage::Server as ManageServer, use_, use_::Server as UseServer, Builder,
};
2022-03-13 17:29:21 +01:00
use capnp::capability::Promise;
use capnp_rpc::pry;
2022-03-13 17:29:21 +01:00
#[derive(Clone)]
2022-03-12 17:31:53 +01:00
pub struct Machine {
session: SessionHandle,
2022-03-13 17:29:21 +01:00
resource: Resource,
}
impl Machine {
/// Builds a machine into the given builder. Re
pub fn build(session: SessionHandle, resource: Resource, builder: Builder) {
if resource.visible(&session) {}
}
2022-03-12 17:31:53 +01:00
}
impl InfoServer for Machine {
fn get_property_list(
&mut self,
_: info::GetPropertyListParams,
_: info::GetPropertyListResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
fn get_reservation_list(
&mut self,
_: info::GetReservationListParams,
_: info::GetReservationListResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
}
impl UseServer for Machine {
2022-03-13 17:29:21 +01:00
fn use_(&mut self, _: use_::UseParams, _: use_::UseResults) -> Promise<(), ::capnp::Error> {
let resource = self.resource.clone();
let session = self.session.clone();
Promise::from_future(async move {
let user = session.get_user();
2022-03-13 20:11:37 +01:00
resource.try_update(session, Status::InUse(user)).await;
2022-03-13 17:29:21 +01:00
Ok(())
})
}
2022-03-13 17:29:21 +01:00
fn reserve(
&mut self,
_: use_::ReserveParams,
_: use_::ReserveResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
let resource = self.resource.clone();
let session = self.session.clone();
Promise::from_future(async move {
let user = session.get_user();
resource
2022-03-13 20:11:37 +01:00
.try_update(session, Status::Reserved(user))
2022-03-13 17:29:21 +01:00
.await;
Ok(())
})
}
2022-03-13 17:29:21 +01:00
fn reserveto(
&mut self,
_: use_::ReservetoParams,
_: use_::ReservetoResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
}
impl InUseServer for Machine {
fn give_back(
&mut self,
_: inuse::GiveBackParams,
_: inuse::GiveBackResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
let resource = self.resource.clone();
let session = self.session.clone();
Promise::from_future(async move {
resource.give_back(session.clone()).await;
Ok(())
})
}
2022-03-13 17:29:21 +01:00
fn send_raw_data(
&mut self,
_: inuse::SendRawDataParams,
_: inuse::SendRawDataResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
}
impl CheckServer for Machine {
fn check(
&mut self,
_: check::CheckParams,
_: check::CheckResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
2022-03-13 17:29:21 +01:00
fn reject(
&mut self,
_: check::RejectParams,
_: check::RejectResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
}
impl ManageServer for Machine {
2022-03-12 02:00:55 +01:00
fn get_machine_info_extended(
&mut self,
_: manage::GetMachineInfoExtendedParams,
_: manage::GetMachineInfoExtendedResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
2022-03-12 02:00:55 +01:00
"method not implemented".to_string(),
))
}
fn set_property(
&mut self,
_: manage::SetPropertyParams,
_: manage::SetPropertyResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
fn remove_property(
&mut self,
_: manage::RemovePropertyParams,
_: manage::RemovePropertyResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
2022-03-13 17:29:21 +01:00
fn force_use(
&mut self,
_: manage::ForceUseParams,
_: manage::ForceUseResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
let resource = self.resource.clone();
let session = self.session.clone();
Promise::from_future(async move {
resource
2022-03-13 20:11:37 +01:00
.force_set(Status::InUse(session.get_user()))
2022-03-13 17:29:21 +01:00
.await;
Ok(())
})
}
2022-03-13 17:29:21 +01:00
fn force_free(
&mut self,
_: manage::ForceFreeParams,
_: manage::ForceFreeResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
let resource = self.resource.clone();
let session = self.session.clone();
Promise::from_future(async move {
2022-03-13 20:11:37 +01:00
resource.force_set(Status::Free).await;
2022-03-13 17:29:21 +01:00
Ok(())
})
}
fn force_transfer(
&mut self,
_: manage::ForceTransferParams,
_: manage::ForceTransferResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
2022-03-13 17:29:21 +01:00
fn block(
&mut self,
_: manage::BlockParams,
_: manage::BlockResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
let resource = self.resource.clone();
let session = self.session.clone();
Promise::from_future(async move {
resource
2022-03-13 20:11:37 +01:00
.force_set(Status::Blocked(session.get_user()))
2022-03-13 17:29:21 +01:00
.await;
Ok(())
})
}
fn disabled(
&mut self,
_: manage::DisabledParams,
_: manage::DisabledResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
let mut resource = self.resource.clone();
Promise::from_future(async move {
2022-03-13 20:11:37 +01:00
resource.force_set(Status::Disabled).await;
2022-03-13 17:29:21 +01:00
Ok(())
})
}
}
impl AdminServer for Machine {
fn force_set_state(
&mut self,
2022-03-13 17:29:21 +01:00
params: admin::ForceSetStateParams,
_: admin::ForceSetStateResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
use api::schema::machine_capnp::machine::MachineState as APIMState;
let user = self.session.get_user();
let state = match pry!(pry!(params.get()).get_state()) {
2022-03-13 20:11:37 +01:00
APIMState::Free => Status::Free,
APIMState::Blocked => Status::Blocked(user),
APIMState::Disabled => Status::Disabled,
APIMState::InUse => Status::InUse(user),
APIMState::Reserved => Status::Reserved(user),
APIMState::ToCheck => Status::ToCheck(user),
2022-03-13 17:29:21 +01:00
APIMState::Totakeover => return Promise::err(::capnp::Error::unimplemented(
"totakeover not implemented".to_string(),
)),
};
self.resource.force_set(state);
Promise::ok(())
}
fn force_set_user(
&mut self,
_: admin::ForceSetUserParams,
_: admin::ForceSetUserResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
fn get_admin_property_list(
&mut self,
_: admin::GetAdminPropertyListParams,
_: admin::GetAdminPropertyListResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
fn set_admin_property(
&mut self,
_: admin::SetAdminPropertyParams,
_: admin::SetAdminPropertyResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
fn remove_admin_property(
&mut self,
_: admin::RemoveAdminPropertyParams,
_: admin::RemoveAdminPropertyResults,
2022-03-13 17:29:21 +01:00
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
}