ipcconfig trait

This commit is contained in:
NikVolf 2016-04-07 23:18:48 +03:00
parent 46a25b31ab
commit 72acd67644
8 changed files with 35 additions and 2 deletions

View File

@ -36,6 +36,8 @@ use syntax::ptr::P;
pub struct Error;
const RESERVED_MESSAGE_IDS: u16 = 16;
pub fn expand_ipc_implementation(
cx: &mut ExtCtxt,
span: Span,

View File

@ -8,3 +8,4 @@ license = "GPL-3.0"
[dependencies]
ethcore-devtools = { path = "../../devtools" }
semver = "0.2.0"

View File

@ -19,8 +19,24 @@
use std::io::{Read, Write};
use std::marker::Sync;
use std::sync::atomic::*;
use semver::Version;
pub trait IpcInterface<T> {
pub struct Handshake {
protocol_version: Version,
api_version: Version,
reserved: [u8; 64],
}
pub trait IpcConfig {
fn api_version() -> Version {
Version::parse("1.0.0").unwrap()
}
fn protocol_version() -> Version {
Version::parse("1.0.0").unwrap()
}
}
pub trait IpcInterface<T> where T: IpcConfig {
/// reads the message from io, dispatches the call and returns serialized result
fn dispatch<R>(&self, r: &mut R) -> Vec<u8> where R: Read;

View File

@ -17,6 +17,7 @@
//! IPC RPC interface
extern crate ethcore_devtools as devtools;
extern crate semver;
pub mod interface;
pub use interface::{IpcInterface, IpcSocket, invoke};
pub use interface::{IpcInterface, IpcSocket, invoke, IpcConfig};

View File

@ -12,6 +12,7 @@ path = "run.rs"
bincode = "*"
serde = "0.7.0"
ethcore-devtools = { path = "../../devtools" }
semver = "0.2.0"
[build-dependencies]
syntex = "0.30.0"

View File

@ -20,6 +20,7 @@ mod tests {
use super::super::service::*;
use ipc::*;
use devtools::*;
use semver::Version;
#[test]
fn call_service() {
@ -57,4 +58,12 @@ mod tests {
assert_eq!(vec![0, 1, 1, 0, 0, 0, 5, 0, 0, 0, 10], service_client.socket().borrow().write_buffer.clone());
assert_eq!(10, result);
}
#[test]
fn query_default_version() {
let ver = Service::protocol_version();
assert_eq!(ver, Version::parse("1.0.0").unwrap());
let ver = Service::api_version();
assert_eq!(ver, Version::parse("1.0.0").unwrap());
}
}

View File

@ -18,6 +18,7 @@ extern crate bincode;
extern crate ethcore_ipc as ipc;
extern crate serde;
extern crate ethcore_devtools as devtools;
extern crate semver;
pub mod service;
mod examples;

View File

@ -45,3 +45,5 @@ impl Service {
}
}
}
impl ::ipc::IpcConfig for Service {}