Skip to content

Commit

Permalink
get rid of deprecated server and client interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jtattermusch committed Jun 6, 2016
1 parent 562cd05 commit fcc8d97
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 720 deletions.
112 changes: 6 additions & 106 deletions src/compiler/csharp_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,10 @@ std::string GetServiceClassName(const ServiceDescriptor* service) {
return service->name();
}

std::string GetClientInterfaceName(const ServiceDescriptor* service) {
return "I" + service->name() + "Client";
}

std::string GetClientClassName(const ServiceDescriptor* service) {
return service->name() + "Client";
}

std::string GetServerInterfaceName(const ServiceDescriptor* service) {
return "I" + service->name();
}

std::string GetServerClassName(const ServiceDescriptor* service) {
return service->name() + "Base";
}
Expand Down Expand Up @@ -302,86 +294,6 @@ void GenerateServiceDescriptorProperty(Printer* out, const ServiceDescriptor *se
out->Print("\n");
}

void GenerateClientInterface(Printer* out, const ServiceDescriptor *service) {
out->Print("/// <summary>Client for $servicename$</summary>\n",
"servicename", GetServiceClassName(service));
out->Print("[System.Obsolete(\"Client side interfaced will be removed "
"in the next release. Use client class directly.\")]\n");
out->Print("public interface $name$\n", "name",
GetClientInterfaceName(service));
out->Print("{\n");
out->Indent();
for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor *method = service->method(i);
MethodType method_type = GetMethodType(method);

if (method_type == METHODTYPE_NO_STREAMING) {
// unary calls have an extra synchronous stub method
GenerateDocCommentBody(out, method);
out->Print(
"$response$ $methodname$($request$ request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));\n",
"methodname", method->name(), "request",
GetClassName(method->input_type()), "response",
GetClassName(method->output_type()));

// overload taking CallOptions as a param
GenerateDocCommentBody(out, method);
out->Print(
"$response$ $methodname$($request$ request, CallOptions options);\n",
"methodname", method->name(), "request",
GetClassName(method->input_type()), "response",
GetClassName(method->output_type()));
}

std::string method_name = method->name();
if (method_type == METHODTYPE_NO_STREAMING) {
method_name += "Async"; // prevent name clash with synchronous method.
}
GenerateDocCommentBody(out, method);
out->Print(
"$returntype$ $methodname$($request_maybe$Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));\n",
"methodname", method_name, "request_maybe",
GetMethodRequestParamMaybe(method), "returntype",
GetMethodReturnTypeClient(method));

// overload taking CallOptions as a param
GenerateDocCommentBody(out, method);
out->Print(
"$returntype$ $methodname$($request_maybe$CallOptions options);\n",
"methodname", method_name, "request_maybe",
GetMethodRequestParamMaybe(method), "returntype",
GetMethodReturnTypeClient(method));
}
out->Outdent();
out->Print("}\n");
out->Print("\n");
}

void GenerateServerInterface(Printer* out, const ServiceDescriptor *service) {
out->Print("/// <summary>Interface of server-side implementations of $servicename$</summary>\n",
"servicename", GetServiceClassName(service));
out->Print("[System.Obsolete(\"Service implementations should inherit"
" from the generated abstract base class instead.\")]\n");
out->Print("public interface $name$\n", "name",
GetServerInterfaceName(service));
out->Print("{\n");
out->Indent();
for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor *method = service->method(i);
GenerateDocCommentBody(out, method);
out->Print(
"$returntype$ $methodname$($request$$response_stream_maybe$, "
"ServerCallContext context);\n",
"methodname", method->name(), "returntype",
GetMethodReturnTypeServer(method), "request",
GetMethodRequestParamServer(method), "response_stream_maybe",
GetMethodResponseStreamMaybe(method));
}
out->Outdent();
out->Print("}\n");
out->Print("\n");
}

void GenerateServerClass(Printer* out, const ServiceDescriptor *service) {
out->Print("/// <summary>Base class for server-side implementations of $servicename$</summary>\n",
"servicename", GetServiceClassName(service));
Expand Down Expand Up @@ -414,12 +326,9 @@ void GenerateServerClass(Printer* out, const ServiceDescriptor *service) {
void GenerateClientStub(Printer* out, const ServiceDescriptor *service) {
out->Print("/// <summary>Client for $servicename$</summary>\n",
"servicename", GetServiceClassName(service));
out->Print("#pragma warning disable 0618\n");
out->Print(
"public class $name$ : ClientBase<$name$>, $interface$\n",
"name", GetClientClassName(service),
"interface", GetClientInterfaceName(service));
out->Print("#pragma warning restore 0618\n");
"public class $name$ : ClientBase<$name$>\n",
"name", GetClientClassName(service));
out->Print("{\n");
out->Indent();

Expand Down Expand Up @@ -546,16 +455,12 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) {
out->Print("\n");
}

void GenerateBindServiceMethod(Printer* out, const ServiceDescriptor *service,
bool use_server_class) {
void GenerateBindServiceMethod(Printer* out, const ServiceDescriptor *service) {
out->Print(
"/// <summary>Creates service definition that can be registered with a server</summary>\n");
out->Print("#pragma warning disable 0618\n");
out->Print(
"public static ServerServiceDefinition BindService($interface$ serviceImpl)\n",
"interface", use_server_class ? GetServerClassName(service) :
GetServerInterfaceName(service));
out->Print("#pragma warning restore 0618\n");
"public static ServerServiceDefinition BindService($implclass$ serviceImpl)\n",
"implclass", GetServerClassName(service));
out->Print("{\n");
out->Indent();

Expand Down Expand Up @@ -614,20 +519,15 @@ void GenerateService(Printer* out, const ServiceDescriptor *service,
}
GenerateServiceDescriptorProperty(out, service);

if (generate_client) {
GenerateClientInterface(out, service);
}
if (generate_server) {
GenerateServerInterface(out, service);
GenerateServerClass(out, service);
}
if (generate_client) {
GenerateClientStub(out, service);
GenerateNewStubMethods(out, service);
}
if (generate_server) {
GenerateBindServiceMethod(out, service, false);
GenerateBindServiceMethod(out, service, true);
GenerateBindServiceMethod(out, service);
}

out->Outdent();
Expand Down
109 changes: 1 addition & 108 deletions src/csharp/Grpc.Examples/MathGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,97 +81,6 @@ public static class Math
get { return global::Math.MathReflection.Descriptor.Services[0]; }
}

/// <summary>Client for Math</summary>
[System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface IMathClient
{
/// <summary>
/// Div divides args.dividend by args.divisor and returns the quotient and
/// remainder.
/// </summary>
global::Math.DivReply Div(global::Math.DivArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Div divides args.dividend by args.divisor and returns the quotient and
/// remainder.
/// </summary>
global::Math.DivReply Div(global::Math.DivArgs request, CallOptions options);
/// <summary>
/// Div divides args.dividend by args.divisor and returns the quotient and
/// remainder.
/// </summary>
AsyncUnaryCall<global::Math.DivReply> DivAsync(global::Math.DivArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Div divides args.dividend by args.divisor and returns the quotient and
/// remainder.
/// </summary>
AsyncUnaryCall<global::Math.DivReply> DivAsync(global::Math.DivArgs request, CallOptions options);
/// <summary>
/// DivMany accepts an arbitrary number of division args from the client stream
/// and sends back the results in the reply stream. The stream continues until
/// the client closes its end; the server does the same after sending all the
/// replies. The stream ends immediately if either end aborts.
/// </summary>
AsyncDuplexStreamingCall<global::Math.DivArgs, global::Math.DivReply> DivMany(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// DivMany accepts an arbitrary number of division args from the client stream
/// and sends back the results in the reply stream. The stream continues until
/// the client closes its end; the server does the same after sending all the
/// replies. The stream ends immediately if either end aborts.
/// </summary>
AsyncDuplexStreamingCall<global::Math.DivArgs, global::Math.DivReply> DivMany(CallOptions options);
/// <summary>
/// Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib
/// generates up to limit numbers; otherwise it continues until the call is
/// canceled. Unlike Fib above, Fib has no final FibReply.
/// </summary>
AsyncServerStreamingCall<global::Math.Num> Fib(global::Math.FibArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib
/// generates up to limit numbers; otherwise it continues until the call is
/// canceled. Unlike Fib above, Fib has no final FibReply.
/// </summary>
AsyncServerStreamingCall<global::Math.Num> Fib(global::Math.FibArgs request, CallOptions options);
/// <summary>
/// Sum sums a stream of numbers, returning the final result once the stream
/// is closed.
/// </summary>
AsyncClientStreamingCall<global::Math.Num, global::Math.Num> Sum(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Sum sums a stream of numbers, returning the final result once the stream
/// is closed.
/// </summary>
AsyncClientStreamingCall<global::Math.Num, global::Math.Num> Sum(CallOptions options);
}

/// <summary>Interface of server-side implementations of Math</summary>
[System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface IMath
{
/// <summary>
/// Div divides args.dividend by args.divisor and returns the quotient and
/// remainder.
/// </summary>
global::System.Threading.Tasks.Task<global::Math.DivReply> Div(global::Math.DivArgs request, ServerCallContext context);
/// <summary>
/// DivMany accepts an arbitrary number of division args from the client stream
/// and sends back the results in the reply stream. The stream continues until
/// the client closes its end; the server does the same after sending all the
/// replies. The stream ends immediately if either end aborts.
/// </summary>
global::System.Threading.Tasks.Task DivMany(IAsyncStreamReader<global::Math.DivArgs> requestStream, IServerStreamWriter<global::Math.DivReply> responseStream, ServerCallContext context);
/// <summary>
/// Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib
/// generates up to limit numbers; otherwise it continues until the call is
/// canceled. Unlike Fib above, Fib has no final FibReply.
/// </summary>
global::System.Threading.Tasks.Task Fib(global::Math.FibArgs request, IServerStreamWriter<global::Math.Num> responseStream, ServerCallContext context);
/// <summary>
/// Sum sums a stream of numbers, returning the final result once the stream
/// is closed.
/// </summary>
global::System.Threading.Tasks.Task<global::Math.Num> Sum(IAsyncStreamReader<global::Math.Num> requestStream, ServerCallContext context);
}

/// <summary>Base class for server-side implementations of Math</summary>
public abstract class MathBase
{
Expand Down Expand Up @@ -217,9 +126,7 @@ public abstract class MathBase
}

/// <summary>Client for Math</summary>
#pragma warning disable 0618
public class MathClient : ClientBase<MathClient>, IMathClient
#pragma warning restore 0618
public class MathClient : ClientBase<MathClient>
{
public MathClient(Channel channel) : base(channel)
{
Expand Down Expand Up @@ -335,21 +242,7 @@ public static MathClient NewClient(Channel channel)
}

/// <summary>Creates service definition that can be registered with a server</summary>
#pragma warning disable 0618
public static ServerServiceDefinition BindService(IMath serviceImpl)
#pragma warning restore 0618
{
return ServerServiceDefinition.CreateBuilder()
.AddMethod(__Method_Div, serviceImpl.Div)
.AddMethod(__Method_DivMany, serviceImpl.DivMany)
.AddMethod(__Method_Fib, serviceImpl.Fib)
.AddMethod(__Method_Sum, serviceImpl.Sum).Build();
}

/// <summary>Creates service definition that can be registered with a server</summary>
#pragma warning disable 0618
public static ServerServiceDefinition BindService(MathBase serviceImpl)
#pragma warning restore 0618
{
return ServerServiceDefinition.CreateBuilder()
.AddMethod(__Method_Div, serviceImpl.Div)
Expand Down
32 changes: 1 addition & 31 deletions src/csharp/Grpc.HealthCheck/HealthGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,6 @@ public static class Health
get { return global::Grpc.Health.V1.HealthReflection.Descriptor.Services[0]; }
}

/// <summary>Client for Health</summary>
[System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface IHealthClient
{
global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options);
AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options);
}

/// <summary>Interface of server-side implementations of Health</summary>
[System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface IHealth
{
global::System.Threading.Tasks.Task<global::Grpc.Health.V1.HealthCheckResponse> Check(global::Grpc.Health.V1.HealthCheckRequest request, ServerCallContext context);
}

/// <summary>Base class for server-side implementations of Health</summary>
public abstract class HealthBase
{
Expand All @@ -86,9 +69,7 @@ public abstract class HealthBase
}

/// <summary>Client for Health</summary>
#pragma warning disable 0618
public class HealthClient : ClientBase<HealthClient>, IHealthClient
#pragma warning restore 0618
public class HealthClient : ClientBase<HealthClient>
{
public HealthClient(Channel channel) : base(channel)
{
Expand Down Expand Up @@ -134,18 +115,7 @@ public static HealthClient NewClient(Channel channel)
}

/// <summary>Creates service definition that can be registered with a server</summary>
#pragma warning disable 0618
public static ServerServiceDefinition BindService(IHealth serviceImpl)
#pragma warning restore 0618
{
return ServerServiceDefinition.CreateBuilder()
.AddMethod(__Method_Check, serviceImpl.Check).Build();
}

/// <summary>Creates service definition that can be registered with a server</summary>
#pragma warning disable 0618
public static ServerServiceDefinition BindService(HealthBase serviceImpl)
#pragma warning restore 0618
{
return ServerServiceDefinition.CreateBuilder()
.AddMethod(__Method_Check, serviceImpl.Check).Build();
Expand Down
Loading

0 comments on commit fcc8d97

Please sign in to comment.