1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use capnp::{any_pointer};
use capnp::Error;
use capnp::private::capability::{ClientHook, ParamsHook, PipelineHook, PipelineOp,
RequestHook, ResultsHook};
use capnp::capability::{Promise, RemotePromise};
use std::rc::{Rc};
pub struct Pipeline {
error: Error,
}
impl Pipeline {
pub fn new(error: Error) -> Pipeline {
Pipeline {
error: error
}
}
}
impl PipelineHook for Pipeline {
fn add_ref(&self) -> Box<dyn PipelineHook> {
Box::new(Pipeline::new(self.error.clone()))
}
fn get_pipelined_cap(&self, _ops: &[PipelineOp]) -> Box<dyn ClientHook> {
new_cap(self.error.clone())
}
}
pub struct Request {
error: Error,
message: ::capnp::message::Builder<::capnp::message::HeapAllocator>,
}
impl Request {
pub fn new(error: Error, _size_hint: Option<::capnp::MessageSize>) -> Request {
Request {
error: error,
message: ::capnp::message::Builder::new_default(),
}
}
}
impl RequestHook for Request {
fn get<'a>(&'a mut self) -> any_pointer::Builder<'a> {
self.message.get_root().unwrap()
}
fn get_brand(&self) -> usize {
0
}
fn send<'a>(self: Box<Self>) -> RemotePromise<any_pointer::Owned> {
let pipeline = Pipeline::new(self.error.clone());
RemotePromise {
promise: Promise::err(self.error),
pipeline: any_pointer::Pipeline::new(Box::new(pipeline)),
}
}
fn tail_send(self: Box<Self>)
-> Option<(u32, Promise<(), Error>, Box<dyn PipelineHook>)>
{
None
}
}
struct ClientInner {
error: Error,
_resolved: bool,
brand: usize,
}
pub struct Client {
inner: Rc<ClientInner>,
}
impl Client {
pub fn new(error: Error, resolved: bool, brand: usize) -> Client {
Client {
inner: Rc::new(ClientInner {
error: error,
_resolved: resolved,
brand: brand,
}),
}
}
}
impl ClientHook for Client {
fn add_ref(&self) -> Box<dyn ClientHook> {
Box::new(Client { inner: self.inner.clone() } )
}
fn new_call(&self, _interface_id: u64, _method_id: u16,
size_hint: Option<::capnp::MessageSize>)
-> ::capnp::capability::Request<any_pointer::Owned, any_pointer::Owned>
{
::capnp::capability::Request::new(
Box::new(Request::new(self.inner.error.clone(), size_hint)))
}
fn call(&self, _interface_id: u64, _method_id: u16, _params: Box<dyn ParamsHook>, _results: Box<dyn ResultsHook>)
-> Promise<(), Error>
{
Promise::err(self.inner.error.clone())
}
fn get_ptr(&self) -> usize {
(self.inner.as_ref()) as * const _ as usize
}
fn get_brand(&self) -> usize {
self.inner.brand
}
fn get_resolved(&self) -> Option<Box<dyn ClientHook>> {
None
}
fn when_more_resolved(&self) -> Option<Promise<Box<dyn ClientHook>, Error>> {
None
}
fn when_resolved(&self) -> Promise<(), Error> {
crate::rpc::default_when_resolved_impl(self)
}
}
pub fn new_cap(exception: Error) -> Box<dyn ClientHook> {
Box::new(Client::new(exception, false, 0))
}