2024-05-14 11:05:39 +02:00
|
|
|
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;
|
2024-05-24 12:48:58 +02:00
|
|
|
use api::claim_capnp::{claimable, claim};
|
|
|
|
use api::notify_capnp::notifiable;
|
|
|
|
use api::owned_capnp::owned;
|
|
|
|
use api::projects_capnp::project;
|
2024-05-14 11:05:39 +02:00
|
|
|
use capnp::capability::Promise;
|
2024-05-24 12:48:58 +02:00
|
|
|
use capnp::Error;
|
2024-05-14 11:05:39 +02:00
|
|
|
use capnp_rpc::pry;
|
2024-05-24 12:48:58 +02:00
|
|
|
use api::claim_capnp::claim::{DisownParams, DisownResults, TraitsParams, TraitsResults};
|
|
|
|
use api::claim_capnp::claimable::{ClaimParams, ClaimResults};
|
|
|
|
use api::owned_capnp::owned::{GetUserParams, GetUserResults};
|
2024-06-10 12:58:50 +02:00
|
|
|
use crate::capnp::traits::claimable::ClaimableServer;
|
2024-05-14 11:05:39 +02:00
|
|
|
|
|
|
|
#[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 {
|
2024-05-24 12:48:58 +02:00
|
|
|
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(())
|
|
|
|
}
|
|
|
|
}
|
2024-05-14 11:05:39 +02:00
|
|
|
|
2024-05-24 12:48:58 +02:00
|
|
|
pub struct Claim {
|
|
|
|
session: SessionHandle,
|
|
|
|
project: Option<project::Client>,
|
|
|
|
resource: Resource,
|
|
|
|
}
|
|
|
|
impl Claim {
|
|
|
|
fn new(session: SessionHandle, project: Option<project::Client>, 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 {
|
2024-06-10 12:58:50 +02:00
|
|
|
fn traits(&mut self, _: TraitsParams, mut results: TraitsResults) -> Promise<(), Error> {
|
|
|
|
let mut b = results.get().init_entries(1);
|
|
|
|
let mut builder = b.get(0);
|
|
|
|
let c = ClaimableServer {};
|
|
|
|
pry!(c.insert_into_map(builder));
|
|
|
|
Promise::ok(())
|
2024-05-24 12:48:58 +02:00
|
|
|
}
|
2024-05-14 11:05:39 +02:00
|
|
|
}
|