Skip to content

Commit

Permalink
implement this_cap() as a method of Params
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Jan 12, 2024
1 parent d4d96aa commit 3f18f6c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
14 changes: 12 additions & 2 deletions capnp-rpc/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ impl ResponseHook for Response {
struct Params {
request: message::Builder<message::HeapAllocator>,
cap_table: Vec<Option<Box<dyn ClientHook>>>,
this_cap: Box<dyn ClientHook>,
}

impl Params {
fn new(
request: message::Builder<message::HeapAllocator>,
cap_table: Vec<Option<Box<dyn ClientHook>>>,
this_cap: Box<dyn ClientHook>,
) -> Self {
Self { request, cap_table }
Self {
request,
cap_table,
this_cap,
}
}
}

Expand All @@ -79,6 +85,10 @@ impl ParamsHook for Params {
result.imbue(&self.cap_table);
Ok(result)
}

fn this_cap(&self) -> Box<dyn ClientHook> {
self.this_cap.add_ref()
}

Check warning on line 91 in capnp-rpc/src/local.rs

View check run for this annotation

Codecov / codecov/patch

capnp-rpc/src/local.rs#L89-L91

Added lines #L89 - L91 were not covered by tests
}

struct Results {
Expand Down Expand Up @@ -218,7 +228,7 @@ impl RequestHook for Request {
method_id,
client,
} = tmp;
let params = Params::new(message, cap_table);
let params = Params::new(message, cap_table, client.add_ref());

let (results_done_fulfiller, results_done_promise) =
oneshot::channel::<Box<dyn ResultsDoneHook>>();
Expand Down
14 changes: 12 additions & 2 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ impl<VatId> ConnectionState<VatId> {
)));
}

let params = Params::new(message, cap_table_array);
let params = Params::new(message, cap_table_array, capability.add_ref());

let answer = Answer::new();

Expand Down Expand Up @@ -2135,14 +2135,20 @@ impl<VatId> PipelineHook for Pipeline<VatId> {
pub struct Params {
request: Box<dyn crate::IncomingMessage>,
cap_table: Vec<Option<Box<dyn ClientHook>>>,
this_cap: Box<dyn ClientHook>,
}

impl Params {
fn new(
request: Box<dyn crate::IncomingMessage>,
cap_table: Vec<Option<Box<dyn ClientHook>>>,
this_cap: Box<dyn ClientHook>,
) -> Self {
Self { request, cap_table }
Self {
request,
cap_table,
this_cap,
}
}
}

Expand All @@ -2161,6 +2167,10 @@ impl ParamsHook for Params {
}
}
}

fn this_cap(&self) -> Box<dyn ClientHook> {
self.this_cap.add_ref()
}

Check warning on line 2173 in capnp-rpc/src/rpc.rs

View check run for this annotation

Codecov / codecov/patch

capnp-rpc/src/rpc.rs#L2171-L2173

Added lines #L2171 - L2173 were not covered by tests
}

enum ResultsVariant {
Expand Down
3 changes: 3 additions & 0 deletions capnp/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ impl<T> Params<T> {
{
self.hook.get()?.get_as()
}
pub fn this_cap<C: FromClientHook>(&self) -> C {
FromClientHook::new(self.hook.this_cap())
}

Check warning on line 242 in capnp/src/capability.rs

View check run for this annotation

Codecov / codecov/patch

capnp/src/capability.rs#L240-L242

Added lines #L240 - L242 were not covered by tests
}

/// The return values of a method, written in-place by the method body.
Expand Down
1 change: 1 addition & 0 deletions capnp/src/private/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub trait ResultsHook {

pub trait ParamsHook {
fn get(&self) -> crate::Result<crate::any_pointer::Reader<'_>>;
fn this_cap(&self) -> Box<dyn ClientHook>;
}

// Where should this live?
Expand Down

0 comments on commit 3f18f6c

Please sign in to comment.