capnp/private/
capability.rs1#![cfg(feature = "alloc")]
23
24use crate::any_pointer;
25use crate::capability::{Params, Promise, RemotePromise, Request, Results};
26use crate::MessageSize;
27
28pub trait ResponseHook {
29 fn get(&self) -> crate::Result<any_pointer::Reader<'_>>;
30}
31
32pub trait RequestHook {
33 fn get(&mut self) -> any_pointer::Builder<'_>;
34 fn get_brand(&self) -> usize;
35 fn send(self: alloc::boxed::Box<Self>) -> RemotePromise<any_pointer::Owned>;
36 fn send_streaming(self: alloc::boxed::Box<Self>) -> Promise<(), crate::Error>;
37 fn tail_send(
38 self: alloc::boxed::Box<Self>,
39 ) -> Option<(
40 u32,
41 crate::capability::Promise<(), crate::Error>,
42 alloc::boxed::Box<dyn PipelineHook>,
43 )>;
44}
45
46pub trait ClientHook {
47 fn add_ref(&self) -> alloc::boxed::Box<dyn ClientHook>;
48 fn new_call(
49 &self,
50 interface_id: u64,
51 method_id: u16,
52 size_hint: Option<MessageSize>,
53 ) -> Request<any_pointer::Owned, any_pointer::Owned>;
54
55 fn call(
56 &self,
57 interface_id: u64,
58 method_id: u16,
59 params: alloc::boxed::Box<dyn ParamsHook>,
60 results: alloc::boxed::Box<dyn ResultsHook>,
61 ) -> crate::capability::Promise<(), crate::Error>;
62
63 fn get_brand(&self) -> usize;
66
67 fn get_ptr(&self) -> usize;
69
70 fn get_resolved(&self) -> Option<alloc::boxed::Box<dyn ClientHook>>;
75
76 fn when_more_resolved(
81 &self,
82 ) -> Option<crate::capability::Promise<alloc::boxed::Box<dyn ClientHook>, crate::Error>>;
83
84 fn when_resolved(&self) -> Promise<(), crate::Error>;
86}
87
88impl Clone for alloc::boxed::Box<dyn ClientHook> {
89 fn clone(&self) -> Self {
90 self.add_ref()
91 }
92}
93
94pub trait ResultsHook {
95 fn get(&mut self) -> crate::Result<any_pointer::Builder<'_>>;
96
97 fn set_pipeline(&mut self) -> crate::Result<()>;
98
99 fn allow_cancellation(&self);
100 fn tail_call(
101 self: alloc::boxed::Box<Self>,
102 request: alloc::boxed::Box<dyn RequestHook>,
103 ) -> Promise<(), crate::Error>;
104 fn direct_tail_call(
105 self: alloc::boxed::Box<Self>,
106 request: alloc::boxed::Box<dyn RequestHook>,
107 ) -> (
108 crate::capability::Promise<(), crate::Error>,
109 alloc::boxed::Box<dyn PipelineHook>,
110 );
111}
112
113pub trait ParamsHook {
114 fn get(&self) -> crate::Result<crate::any_pointer::Reader<'_>>;
115}
116
117pub fn internal_get_typed_params<T>(typeless: Params<any_pointer::Owned>) -> Params<T> {
119 Params {
120 hook: typeless.hook,
121 marker: ::core::marker::PhantomData,
122 }
123}
124
125pub fn internal_get_typed_results<T>(typeless: Results<any_pointer::Owned>) -> Results<T> {
126 Results {
127 hook: typeless.hook,
128 marker: ::core::marker::PhantomData,
129 }
130}
131
132pub fn internal_get_untyped_results<T>(typeful: Results<T>) -> Results<any_pointer::Owned> {
133 Results {
134 hook: typeful.hook,
135 marker: ::core::marker::PhantomData,
136 }
137}
138
139pub trait PipelineHook {
140 fn add_ref(&self) -> alloc::boxed::Box<dyn PipelineHook>;
141 fn get_pipelined_cap(&self, ops: &[PipelineOp]) -> alloc::boxed::Box<dyn ClientHook>;
142
143 fn get_pipelined_cap_move(
146 &self,
147 ops: alloc::vec::Vec<PipelineOp>,
148 ) -> alloc::boxed::Box<dyn ClientHook> {
149 self.get_pipelined_cap(&ops)
150 }
151}
152
153impl Clone for alloc::boxed::Box<dyn PipelineHook> {
154 fn clone(&self) -> Self {
155 self.add_ref()
156 }
157}
158
159#[derive(Clone, Copy)]
160pub enum PipelineOp {
161 Noop,
162 GetPointerField(u16),
163}