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
use any_pointer;
use private::capability::{CallContextHook, ClientHook, RequestHook, ResponseHook};
pub struct ResultFuture<Results> where Results: for<'a> ::traits::Owned<'a> {
pub answer_port : ::std::sync::mpsc::Receiver<Box<ResponseHook+Send>>,
pub answer_result : Result<Box<ResponseHook+Send>, ()>,
pub pipeline : <Results as ::traits::Owned<'static>>::Pipeline,
}
pub struct Request<Params, Results> {
pub marker : ::std::marker::PhantomData<(Params, Results)>,
pub hook : Box<RequestHook+Send>
}
impl <Params, Results> Request <Params, Results> {
pub fn new(hook : Box<RequestHook+Send>) -> Request <Params, Results> {
Request { hook : hook, marker: ::std::marker::PhantomData }
}
}
impl <Params, Results> Request <Params, Results>
where Results : for<'a> ::traits::Owned<'a>,
<Results as ::traits::Owned<'static>>::Pipeline : FromTypelessPipeline
{
pub fn send(self) -> ResultFuture<Results> {
let ResultFuture {answer_port, answer_result, pipeline, ..} = self.hook.send();
ResultFuture { answer_port : answer_port, answer_result : answer_result,
pipeline : FromTypelessPipeline::new(pipeline)
}
}
}
pub struct CallContext<Params, Results> {
pub marker: ::std::marker::PhantomData<(Params, Results)>,
pub hook: Box<CallContextHook+Send>,
}
impl <Params, Results> CallContext<Params, Results> {
pub fn fail(self, message: String) {self.hook.fail(message);}
pub fn done(self) {self.hook.done();}
}
impl <Params, Results> CallContext<Params, Results> {
pub fn get<'a>(&'a mut self) -> (<Params as ::traits::Owned<'a>>::Reader,
<Results as ::traits::Owned<'a>>::Builder)
where Params: ::traits::Owned<'a>, Results: ::traits::Owned<'a>
{
let (any_params, any_results) = self.hook.get();
(any_params.get_as().unwrap(), any_results.get_as().unwrap())
}
}
pub trait FromTypelessPipeline {
fn new (typeless : any_pointer::Pipeline) -> Self;
}
pub trait FromClientHook {
fn new(Box<ClientHook+Send>) -> Self;
}
pub trait Server {
fn dispatch_call(&mut self, interface_id : u64, method_id : u16,
context : CallContext<any_pointer::Reader, any_pointer::Builder>);
}