ipc-nested-interfaces

This commit is contained in:
NikVolf 2016-04-15 17:50:10 +03:00
parent 099e57c4e3
commit 29b0bb1184
3 changed files with 64 additions and 32 deletions

View File

@ -466,7 +466,6 @@ fn implement_client_method(
{ {
let _sp = ext_cx.call_site(); let _sp = ext_cx.call_site();
let mut tt = ::std::vec::Vec::new(); let mut tt = ::std::vec::Vec::new();
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::Ident(ext_cx.ident_of("pub"), ::syntax::parse::token::Plain)));
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::Ident(ext_cx.ident_of("fn"), ::syntax::parse::token::Plain))); tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::Ident(ext_cx.ident_of("fn"), ::syntax::parse::token::Plain)));
tt.extend(::quasi::ToTokens::to_tokens(&method_name, ext_cx).into_iter()); tt.extend(::quasi::ToTokens::to_tokens(&method_name, ext_cx).into_iter());
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::OpenDelim(::syntax::parse::token::Paren))); tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::OpenDelim(::syntax::parse::token::Paren)));
@ -595,41 +594,74 @@ fn push_client_implementation(
let client_ident = client_qualified_ident(builder, interface_map); let client_ident = client_qualified_ident(builder, interface_map);
let where_clause = &generics.where_clause; let where_clause = &generics.where_clause;
let implement = quote_item!(cx, let handshake_item = quote_impl_item!(cx,
impl $generics $client_ident $where_clause { pub fn handshake(&self) -> Result<(), ::ipc::Error> {
pub fn handshake(&self) -> Result<(), ::ipc::Error> { let payload = BinHandshake {
let payload = BinHandshake { protocol_version: $item_ident::protocol_version().to_string(),
protocol_version: $item_ident::protocol_version().to_string(), api_version: $item_ident::api_version().to_string(),
api_version: $item_ident::api_version().to_string(), _reserved: vec![0u8; 64],
_reserved: vec![0u8; 64], };
};
let mut socket_ref = self.socket.borrow_mut(); let mut socket_ref = self.socket.borrow_mut();
let mut socket = socket_ref.deref_mut(); let mut socket = socket_ref.deref_mut();
::ipc::invoke( ::ipc::invoke(
0, 0,
&Some(::bincode::serde::serialize(&payload, ::bincode::SizeLimit::Infinite).unwrap()), &Some(::bincode::serde::serialize(&payload, ::bincode::SizeLimit::Infinite).unwrap()),
&mut socket); &mut socket);
let mut result = vec![0u8; 1]; let mut result = vec![0u8; 1];
if try!(socket.read(&mut result).map_err(|_| ::ipc::Error::HandshakeFailed)) == 1 { if try!(socket.read(&mut result).map_err(|_| ::ipc::Error::HandshakeFailed)) == 1 {
match result[0] { match result[0] {
1 => Ok(()), 1 => Ok(()),
_ => Err(::ipc::Error::RemoteServiceUnsupported), _ => Err(::ipc::Error::RemoteServiceUnsupported),
}
} }
else { Err(::ipc::Error::HandshakeFailed) }
} }
else { Err(::ipc::Error::HandshakeFailed) }
#[cfg(test)]
pub fn socket(&self) -> &::std::cell::RefCell<S> {
&self.socket
}
$items
}).unwrap(); }).unwrap();
push(Annotatable::Item(implement)); let socket_item = quote_impl_item!(cx,
#[cfg(test)]
pub fn socket(&self) -> &::std::cell::RefCell<S> {
&self.socket
}).unwrap();
let generic_items = vec![P(handshake_item), P(socket_item)];
if interface_map.impl_trait.is_some() {
let trait_ty = builder.id(
::syntax::print::pprust::path_to_string(
&interface_map.impl_trait.as_ref().unwrap().path));
let implement_trait =
quote_item!(cx,
impl $generics $trait_ty for $client_ident $where_clause {
$items
}
).unwrap();
push(Annotatable::Item(implement_trait));
let implement =
quote_item!(cx,
impl $generics $client_ident $where_clause {
$generic_items
}
).unwrap();
push(Annotatable::Item(implement));
}
else {
let pub_items = items.iter().map(|item| {
let pub_item = item.clone();
pub_item.map(|mut val| { val.vis = ast::Visibility::Public; val })
}).collect::<Vec<P<ast::ImplItem>>>();
let implement = quote_item!(cx,
impl $generics $client_ident $where_clause {
$pub_items
$generic_items
}).unwrap();
push(Annotatable::Item(implement));
}
} }
/// implements dispatching of system handshake invocation (method_num 0) /// implements dispatching of system handshake invocation (method_num 0)

View File

@ -18,7 +18,7 @@
mod tests { mod tests {
use super::super::service::*; use super::super::service::*;
use super::super::nested::DBClient; use super::super::nested::{DBClient,DBWriter};
use ipc::*; use ipc::*;
use devtools::*; use devtools::*;
use semver::Version; use semver::Version;

View File

@ -24,7 +24,7 @@ pub struct DB<L: Sized> {
pub holdings: L, pub holdings: L,
} }
trait DBWriter { pub trait DBWriter {
fn write(&self, data: Vec<u8>) -> Result<(), DBError>; fn write(&self, data: Vec<u8>) -> Result<(), DBError>;
} }