Skip to content

Commit

Permalink
Rename GrpcXxx to grpc::Xxx
Browse files Browse the repository at this point in the history
  • Loading branch information
stepancheg committed May 15, 2017
1 parent 70b7e4d commit 4a963a6
Show file tree
Hide file tree
Showing 29 changed files with 589 additions and 595 deletions.
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl CounterServiceImpl {
}

impl CounterService for CounterServiceImpl {
fn Count(&self, req: Request) -> GrpcResult<Reply> {
fn Count(&self, req: Request) -> grpc::Result<Reply> {
println!("Request url: {}", req.get_url());
*self.requests.lock().unwrap() += 1;
Ok(Reply::new())
Expand Down
32 changes: 16 additions & 16 deletions grpc-compiler/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ impl<'a> MethodGen<'a> {
fn input(&self) -> String {
match self.proto.get_client_streaming() {
false => self.input_message(),
true => format!("::grpc::GrpcStreamingRequest<{}>", self.input_message()),
true => format!("::grpc::StreamingRequest<{}>", self.input_message()),
}
}

fn output(&self) -> String {
match self.proto.get_server_streaming() {
false => format!("::grpc::GrpcSingleResponse<{}>", self.output_message()),
true => format!("::grpc::GrpcStreamingResponse<{}>", self.output_message()),
false => format!("::grpc::SingleResponse<{}>", self.output_message()),
true => format!("::grpc::StreamingResponse<{}>", self.output_message()),
}
}

fn sig(&self) -> String {
format!("{}(&self, o: ::grpc::GrpcRequestOptions, p: {}) -> {}",
format!("{}(&self, o: ::grpc::RequestOptions, p: {}) -> {}",
self.snake_name(), self.input(), self.output())
}

Expand Down Expand Up @@ -136,8 +136,8 @@ impl<'a> MethodGen<'a> {
w.block(&format!("{}{}", before, "::grpc::method::MethodDescriptor {"), &format!("{}{}", "}", after), |w| {
w.field_entry("name", &format!("\"{}/{}\".to_string()", self.service_path, self.proto.get_name()));
w.field_entry("streaming", &format!("::grpc::method::GrpcStreaming::{}", self.streaming_upper()));
w.field_entry("req_marshaller", "Box::new(::grpc::grpc_protobuf::MarshallerProtobuf)");
w.field_entry("resp_marshaller", "Box::new(::grpc::grpc_protobuf::MarshallerProtobuf)");
w.field_entry("req_marshaller", "Box::new(::grpc::protobuf::MarshallerProtobuf)");
w.field_entry("resp_marshaller", "Box::new(::grpc::protobuf::MarshallerProtobuf)");
});
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ impl<'a> ServiceGen<'a> {

fn write_client(&self, w: &mut CodeWriter) {
w.pub_struct(&self.client_name(), |w| {
w.field_decl("grpc_client", "::grpc::client::GrpcClient");
w.field_decl("grpc_client", "::grpc::Client");
for method in &self.methods {
w.field_decl(
&method.descriptor_field_name(),
Expand All @@ -224,16 +224,16 @@ impl<'a> ServiceGen<'a> {

w.impl_self_block(&self.client_name(), |w| {

let sig = "with_client(grpc_client: ::grpc::client::GrpcClient) -> Self";
let sig = "with_client(grpc_client: ::grpc::Client) -> Self";
w.pub_fn(sig, |w| {
self.write_client_object("grpc_client", w);
});

w.write_line("");

let sig = "new(host: &str, port: u16, tls: bool, conf: ::grpc::client::GrpcClientConf) -> ::grpc::result::GrpcResult<Self>";
let sig = "new(host: &str, port: u16, tls: bool, conf: ::grpc::ClientConf) -> ::grpc::Result<Self>";
w.pub_fn(sig, |w| {
w.write_line("::grpc::client::GrpcClient::new(host, port, tls, conf).map(|c| {");
w.write_line("::grpc::Client::new(host, port, tls, conf).map(|c| {");
w.indented(|w| {
w.write_line(&format!("{}::with_client(c)", self.client_name()));
});
Expand Down Expand Up @@ -278,13 +278,13 @@ impl<'a> ServiceGen<'a> {

fn write_server(&self, w: &mut CodeWriter) {
w.pub_struct(&self.server_name(), |w| {
w.pub_field_decl("grpc_server", "::grpc::server::GrpcServer");
w.pub_field_decl("grpc_server", "::grpc::Server");
});

w.write_line("");

w.impl_for_block("::std::ops::Deref", &self.server_name(), |w| {
w.write_line("type Target = ::grpc::server::GrpcServer;");
w.write_line("type Target = ::grpc::Server;");
w.write_line("");
w.def_fn("deref(&self) -> &Self::Target", |w| {
w.write_line("&self.grpc_server");
Expand All @@ -295,26 +295,26 @@ impl<'a> ServiceGen<'a> {

w.impl_self_block(&self.server_name(), |w| {
let sig = format!(
"new<A : ::std::net::ToSocketAddrs, H : {} + 'static + Sync + Send + 'static>(addr: A, conf: ::grpc::server::GrpcServerConf, h: H) -> Self",
"new<A : ::std::net::ToSocketAddrs, H : {} + 'static + Sync + Send + 'static>(addr: A, conf: ::grpc::ServerConf, h: H) -> Self",
self.intf_name());
w.pub_fn(&sig, |w| {
w.write_line(format!("let service_definition = {}::new_service_def(h);", self.server_name()));

w.expr_block(&self.server_name(), |w| {
w.field_entry("grpc_server", "::grpc::server::GrpcServer::new_plain(addr, conf, service_definition)");
w.field_entry("grpc_server", "::grpc::Server::new_plain(addr, conf, service_definition)");
});
});

w.write_line("");

let sig = format!(
"new_pool<A : ::std::net::ToSocketAddrs, H : {} + 'static + Sync + Send + 'static>(addr: A, conf: ::grpc::server::GrpcServerConf, h: H, cpu_pool: ::futures_cpupool::CpuPool) -> Self",
"new_pool<A : ::std::net::ToSocketAddrs, H : {} + 'static + Sync + Send + 'static>(addr: A, conf: ::grpc::ServerConf, h: H, cpu_pool: ::futures_cpupool::CpuPool) -> Self",
self.intf_name());
w.pub_fn(&sig, |w| {
w.write_line(format!("let service_definition = {}::new_service_def(h);", self.server_name()));

w.expr_block(&self.server_name(), |w| {
w.field_entry("grpc_server", "::grpc::server::GrpcServer::new_plain_pool(addr, conf, service_definition, cpu_pool)");
w.field_entry("grpc_server", "::grpc::Server::new_plain_pool(addr, conf, service_definition, cpu_pool)");
});
});

Expand Down
4 changes: 1 addition & 3 deletions grpc-examples/src/bin/greeter_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ extern crate grpc_examples;
extern crate grpc;
extern crate futures;

use grpc::*;

use grpc_examples::helloworld_grpc::*;
use grpc_examples::helloworld::*;

Expand All @@ -18,7 +16,7 @@ fn main() {
let mut req = HelloRequest::new();
req.set_name(name);

let resp = client.say_hello(GrpcRequestOptions::new(), req);
let resp = client.say_hello(grpc::RequestOptions::new(), req);

println!("{:?}", resp.wait());
}
6 changes: 2 additions & 4 deletions grpc-examples/src/bin/greeter_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ use std::thread;

use futures_cpupool::CpuPool;

use grpc::*;

use grpc_examples::helloworld_grpc::*;
use grpc_examples::helloworld::*;

struct GreeterImpl;

impl Greeter for GreeterImpl {
fn say_hello(&self, _m: GrpcRequestOptions, req: HelloRequest) -> GrpcSingleResponse<HelloReply> {
fn say_hello(&self, _m: grpc::RequestOptions, req: HelloRequest) -> grpc::SingleResponse<HelloReply> {
let mut r = HelloReply::new();
let name = if req.get_name().is_empty() { "world" } else { req.get_name() };
println!("greeting request from {}", name);
r.set_message(format!("Hello {}", name));
GrpcSingleResponse::completed(r)
grpc::SingleResponse::completed(r)
}
}

Expand Down
9 changes: 3 additions & 6 deletions grpc-examples/src/bin/greeter_server_multi_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,23 @@ extern crate grpc;

use std::thread;

use grpc::*;
use grpc::server::GrpcServerConf;

use grpc_examples::helloworld_grpc::*;
use grpc_examples::helloworld::*;

struct GreeterImpl;

impl Greeter for GreeterImpl {
fn say_hello(&self, _m: GrpcRequestOptions, req: HelloRequest) -> GrpcSingleResponse<HelloReply> {
fn say_hello(&self, _m: grpc::RequestOptions, req: HelloRequest) -> grpc::SingleResponse<HelloReply> {
let mut r = HelloReply::new();
let name = if req.get_name().is_empty() { "world" } else { req.get_name() };
println!("greeting request from {}", name);
r.set_message(format!("Hello {}", name));
GrpcSingleResponse::completed(r)
grpc::SingleResponse::completed(r)
}
}

fn main() {
let mut conf = GrpcServerConf::default();
let mut conf = grpc::ServerConf::default();
conf.http.reuse_port = Some(true);

let _server1 = GreeterServer::new("[::]:50051", conf.clone(), GreeterImpl);
Expand Down
32 changes: 16 additions & 16 deletions grpc-examples/src/helloworld_grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,68 +22,68 @@
// interface

pub trait Greeter {
fn say_hello(&self, o: ::grpc::GrpcRequestOptions, p: super::helloworld::HelloRequest) -> ::grpc::GrpcSingleResponse<super::helloworld::HelloReply>;
fn say_hello(&self, o: ::grpc::RequestOptions, p: super::helloworld::HelloRequest) -> ::grpc::SingleResponse<super::helloworld::HelloReply>;
}

// client

pub struct GreeterClient {
grpc_client: ::grpc::client::GrpcClient,
grpc_client: ::grpc::Client,
method_SayHello: ::std::sync::Arc<::grpc::method::MethodDescriptor<super::helloworld::HelloRequest, super::helloworld::HelloReply>>,
}

impl GreeterClient {
pub fn with_client(grpc_client: ::grpc::client::GrpcClient) -> Self {
pub fn with_client(grpc_client: ::grpc::Client) -> Self {
GreeterClient {
grpc_client: grpc_client,
method_SayHello: ::std::sync::Arc::new(::grpc::method::MethodDescriptor {
name: "/helloworld.Greeter/SayHello".to_string(),
streaming: ::grpc::method::GrpcStreaming::Unary,
req_marshaller: Box::new(::grpc::grpc_protobuf::MarshallerProtobuf),
resp_marshaller: Box::new(::grpc::grpc_protobuf::MarshallerProtobuf),
req_marshaller: Box::new(::grpc::protobuf::MarshallerProtobuf),
resp_marshaller: Box::new(::grpc::protobuf::MarshallerProtobuf),
}),
}
}

pub fn new(host: &str, port: u16, tls: bool, conf: ::grpc::client::GrpcClientConf) -> ::grpc::result::GrpcResult<Self> {
::grpc::client::GrpcClient::new(host, port, tls, conf).map(|c| {
pub fn new(host: &str, port: u16, tls: bool, conf: ::grpc::ClientConf) -> ::grpc::Result<Self> {
::grpc::Client::new(host, port, tls, conf).map(|c| {
GreeterClient::with_client(c)
})
}
}

impl Greeter for GreeterClient {
fn say_hello(&self, o: ::grpc::GrpcRequestOptions, p: super::helloworld::HelloRequest) -> ::grpc::GrpcSingleResponse<super::helloworld::HelloReply> {
fn say_hello(&self, o: ::grpc::RequestOptions, p: super::helloworld::HelloRequest) -> ::grpc::SingleResponse<super::helloworld::HelloReply> {
self.grpc_client.call_unary(o, p, self.method_SayHello.clone())
}
}

// server

pub struct GreeterServer {
pub grpc_server: ::grpc::server::GrpcServer,
pub grpc_server: ::grpc::Server,
}

impl ::std::ops::Deref for GreeterServer {
type Target = ::grpc::server::GrpcServer;
type Target = ::grpc::Server;

fn deref(&self) -> &Self::Target {
&self.grpc_server
}
}

impl GreeterServer {
pub fn new<A : ::std::net::ToSocketAddrs, H : Greeter + 'static + Sync + Send + 'static>(addr: A, conf: ::grpc::server::GrpcServerConf, h: H) -> Self {
pub fn new<A : ::std::net::ToSocketAddrs, H : Greeter + 'static + Sync + Send + 'static>(addr: A, conf: ::grpc::ServerConf, h: H) -> Self {
let service_definition = GreeterServer::new_service_def(h);
GreeterServer {
grpc_server: ::grpc::server::GrpcServer::new_plain(addr, conf, service_definition),
grpc_server: ::grpc::Server::new_plain(addr, conf, service_definition),
}
}

pub fn new_pool<A : ::std::net::ToSocketAddrs, H : Greeter + 'static + Sync + Send + 'static>(addr: A, conf: ::grpc::server::GrpcServerConf, h: H, cpu_pool: ::futures_cpupool::CpuPool) -> Self {
pub fn new_pool<A : ::std::net::ToSocketAddrs, H : Greeter + 'static + Sync + Send + 'static>(addr: A, conf: ::grpc::ServerConf, h: H, cpu_pool: ::futures_cpupool::CpuPool) -> Self {
let service_definition = GreeterServer::new_service_def(h);
GreeterServer {
grpc_server: ::grpc::server::GrpcServer::new_plain_pool(addr, conf, service_definition, cpu_pool),
grpc_server: ::grpc::Server::new_plain_pool(addr, conf, service_definition, cpu_pool),
}
}

Expand All @@ -95,8 +95,8 @@ impl GreeterServer {
::std::sync::Arc::new(::grpc::method::MethodDescriptor {
name: "/helloworld.Greeter/SayHello".to_string(),
streaming: ::grpc::method::GrpcStreaming::Unary,
req_marshaller: Box::new(::grpc::grpc_protobuf::MarshallerProtobuf),
resp_marshaller: Box::new(::grpc::grpc_protobuf::MarshallerProtobuf),
req_marshaller: Box::new(::grpc::protobuf::MarshallerProtobuf),
resp_marshaller: Box::new(::grpc::protobuf::MarshallerProtobuf),
}),
{
let handler_copy = handler_arc.clone();
Expand Down
Loading

0 comments on commit 4a963a6

Please sign in to comment.