use alloc::boxed::Box;
use alloc::vec::Vec;
use crate::any_pointer;
use crate::capability::{Params, Promise, RemotePromise, Request, Results};
use crate::MessageSize;
pub trait ResponseHook {
fn get(&self) -> crate::Result<any_pointer::Reader<'_>>;
}
pub trait RequestHook {
fn get(&mut self) -> any_pointer::Builder<'_>;
fn get_brand(&self) -> usize;
fn send(self: Box<Self>) -> RemotePromise<any_pointer::Owned>;
fn tail_send(
self: Box<Self>,
) -> Option<(
u32,
crate::capability::Promise<(), crate::Error>,
Box<dyn PipelineHook>,
)>;
}
pub trait ClientHook {
fn add_ref(&self) -> Box<dyn ClientHook>;
fn new_call(
&self,
interface_id: u64,
method_id: u16,
size_hint: Option<MessageSize>,
) -> Request<any_pointer::Owned, any_pointer::Owned>;
fn call(
&self,
interface_id: u64,
method_id: u16,
params: Box<dyn ParamsHook>,
results: Box<dyn ResultsHook>,
) -> crate::capability::Promise<(), crate::Error>;
fn get_brand(&self) -> usize;
fn get_ptr(&self) -> usize;
fn get_resolved(&self) -> Option<Box<dyn ClientHook>>;
fn when_more_resolved(
&self,
) -> Option<crate::capability::Promise<Box<dyn ClientHook>, crate::Error>>;
fn when_resolved(&self) -> Promise<(), crate::Error>;
}
impl Clone for Box<dyn ClientHook> {
fn clone(&self) -> Self {
self.add_ref()
}
}
pub trait ResultsHook {
fn get(&mut self) -> crate::Result<any_pointer::Builder<'_>>;
fn allow_cancellation(&self);
fn tail_call(self: Box<Self>, request: Box<dyn RequestHook>) -> Promise<(), crate::Error>;
fn direct_tail_call(
self: Box<Self>,
request: Box<dyn RequestHook>,
) -> (
crate::capability::Promise<(), crate::Error>,
Box<dyn PipelineHook>,
);
}
pub trait ParamsHook {
fn get(&self) -> crate::Result<crate::any_pointer::Reader<'_>>;
}
pub fn internal_get_typed_params<T>(typeless: Params<any_pointer::Owned>) -> Params<T> {
Params {
hook: typeless.hook,
marker: ::core::marker::PhantomData,
}
}
pub fn internal_get_typed_results<T>(typeless: Results<any_pointer::Owned>) -> Results<T> {
Results {
hook: typeless.hook,
marker: ::core::marker::PhantomData,
}
}
pub fn internal_get_untyped_results<T>(typeful: Results<T>) -> Results<any_pointer::Owned> {
Results {
hook: typeful.hook,
marker: ::core::marker::PhantomData,
}
}
pub trait PipelineHook {
fn add_ref(&self) -> Box<dyn PipelineHook>;
fn get_pipelined_cap(&self, ops: &[PipelineOp]) -> Box<dyn ClientHook>;
fn get_pipelined_cap_move(&self, ops: Vec<PipelineOp>) -> Box<dyn ClientHook> {
self.get_pipelined_cap(&ops)
}
}
impl Clone for Box<dyn PipelineHook> {
fn clone(&self) -> Self {
self.add_ref()
}
}
#[derive(Clone, Copy)]
pub enum PipelineOp {
Noop,
GetPointerField(u16),
}