From bba0d3e7c8fa8b125cf5c7e4e1e361a44398672c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nadja=20von=20Reitzenstein=20=C4=8Cerpnjak?= Date: Mon, 10 Jun 2024 12:58:50 +0200 Subject: [PATCH] Implement claimable --- bffhd/capnp/resource.rs | 9 +++++++-- bffhd/capnp/traits/claimable.rs | 33 +++++++++++++++++++++++++++++++++ bffhd/capnp/traits/mod.rs | 4 ++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/bffhd/capnp/resource.rs b/bffhd/capnp/resource.rs index ae50c7b..6865e0b 100644 --- a/bffhd/capnp/resource.rs +++ b/bffhd/capnp/resource.rs @@ -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(()) } } \ No newline at end of file diff --git a/bffhd/capnp/traits/claimable.rs b/bffhd/capnp/traits/claimable.rs index 3712bcf..3cdbaf2 100644 --- a/bffhd/capnp/traits/claimable.rs +++ b/bffhd/capnp/traits/claimable.rs @@ -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) -> 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(()) + } +} \ No newline at end of file diff --git a/bffhd/capnp/traits/mod.rs b/bffhd/capnp/traits/mod.rs index 329f76e..ed02bc9 100644 --- a/bffhd/capnp/traits/mod.rs +++ b/bffhd/capnp/traits/mod.rs @@ -1,2 +1,2 @@ -mod claimable; -mod powerable; \ No newline at end of file +pub mod claimable; +pub mod powerable; \ No newline at end of file