Skip to content

implement this_cap() as a method of Params #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}

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()
}
}

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())
}
}

/// 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