Implement claimable

This commit is contained in:
Nadja von Reitzenstein Čerpnjak 2024-06-10 12:58:50 +02:00
parent 2acf35d54d
commit bba0d3e7c8
3 changed files with 42 additions and 4 deletions

View File

@ -13,6 +13,7 @@ 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};
use crate::capnp::traits::claimable::ClaimableServer;
#[derive(Clone)]
pub struct Machine {
@ -64,7 +65,11 @@ impl owned::Server for Claim {
}
impl claim::Server for Claim {
fn traits(&mut self, _: TraitsParams, _: TraitsResults) -> Promise<(), Error> {
todo!()
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(())
}
}

View File

@ -1,7 +1,40 @@
use capnp::capability::Promise;
use capnp::Error;
use capnp_rpc::pry;
use crate::oid;
use crate::utils::oid::ObjectIdentifier;
use api::traits::claimable_capnp::trait_claimable;
use api::traits::claimable_capnp::trait_claimable::{GetStateParams, GetStateResults};
use api::traits_capnp::trait_super::{GetNameParams, GetNameResults, Server};
use api::schema::utils_capnp::map::entry as api_map;
pub const CLAIMABLE_TRAIT_ID: ObjectIdentifier = oid!(1.3.6.1.4.1.61783.612.1.0);
pub struct ClaimableServer {
}
impl ClaimableServer {
pub fn insert_into_map(self, mut builder: api_map::Builder<capnp::data::Owned, capnp::any_pointer::Owned>) -> Result<(), capnp::Error> {
builder.set_key(CLAIMABLE_TRAIT_ID.as_bytes())?;
let client: trait_claimable::Client = capnp_rpc::new_client(self);
let mut cap_builder = builder.init_value();
cap_builder.set_as_capability(client.client.hook);
Ok(())
}
}
impl Server for ClaimableServer {
fn get_name(&mut self, _: GetNameParams, mut result: GetNameResults) -> Promise<(), Error> {
result.get().set_name("Claimable");
Promise::ok(())
}
}
impl trait_claimable::Server for ClaimableServer {
fn get_state(&mut self, _: GetStateParams, mut results: GetStateResults) -> Promise<(), Error> {
let mut builder = pry!(results.get().get_claims());
Promise::ok(())
}
}

View File

@ -1,2 +1,2 @@
mod claimable;
mod powerable;
pub mod claimable;
pub mod powerable;