use crate::capnp::user::User; use crate::resources::modules::fabaccess::{ArchivedStatus, Status}; use crate::resources::Resource; use crate::session::SessionHandle; use api::resource_capnp::resource; use api::claim_capnp::{claimable, claim}; use api::notify_capnp::notifiable; use api::owned_capnp::owned; use api::projects_capnp::project; use capnp::capability::Promise; use capnp::Error; use capnp_rpc::pry; use api::claim_capnp::claim::{DisownParams, DisownResults, TraitsParams, TraitsResults}; use api::claim_capnp::claimable::{ClaimParams, ClaimResults}; use api::owned_capnp::owned::{GetUserParams, GetUserResults}; #[derive(Clone)] pub struct Machine { session: SessionHandle, resource: Resource, } impl Machine { pub fn new(session: SessionHandle, resource: Resource) -> Self { Self { session, resource } } pub fn fill_resource(self, builder: &mut resource::Builder) { builder.set_identifier(self.resource.get_id()); builder.set_claim(capnp_rpc::new_client(self.clone())); } } impl claimable::Server for Machine { fn claim(&mut self, params: ClaimParams, mut results: ClaimResults) -> Promise<(), Error> { let project = params.get().and_then(|r| r.get_project()).ok(); //self.resource.try_claim(); let claim = Claim::new(self.session.clone(), project, self.resource.clone()); pry!(results.get().set_ok(capnp_rpc::new_client(claim))); Promise::ok(()) } } pub struct Claim { session: SessionHandle, project: Option, resource: Resource, } impl Claim { fn new(session: SessionHandle, project: Option, resource: Resource) -> Self { Self { session, project, resource } } } impl notifiable::Server for Claim {} impl owned::Server for Claim { fn get_user(&mut self, _: GetUserParams, mut results: GetUserResults) -> Promise<(), Error> { let owner = User::new_self(self.session.clone()); results.get().set_owner(capnp_rpc::new_client(owner)); Promise::ok(()) } } impl claim::Server for Claim { fn traits(&mut self, _: TraitsParams, _: TraitsResults) -> Promise<(), Error> { todo!() } }