Add new overload to BindService that doesn't require an implementation

pull/17837/head
John Luo 6 years ago committed by =
parent 2cb652c687
commit d98de1facf
  1. 31
      src/compiler/csharp_generator.cc
  2. 14
      src/csharp/Grpc.Core/ServiceBinderBase.cs
  3. 17
      src/csharp/Grpc.Examples/MathGrpc.cs
  4. 15
      src/csharp/Grpc.HealthCheck/HealthGrpc.cs
  5. 18
      src/csharp/Grpc.IntegrationTesting/BenchmarkServiceGrpc.cs
  6. 10
      src/csharp/Grpc.IntegrationTesting/Control.cs
  7. 1
      src/csharp/Grpc.IntegrationTesting/Empty.cs
  8. 13
      src/csharp/Grpc.IntegrationTesting/EmptyServiceGrpc.cs
  9. 17
      src/csharp/Grpc.IntegrationTesting/MetricsGrpc.cs
  10. 14
      src/csharp/Grpc.IntegrationTesting/ReportQpsScenarioServiceGrpc.cs
  11. 38
      src/csharp/Grpc.IntegrationTesting/TestGrpc.cs
  12. 17
      src/csharp/Grpc.IntegrationTesting/WorkerServiceGrpc.cs
  13. 14
      src/csharp/Grpc.Reflection/ReflectionGrpc.cs

@ -645,6 +645,36 @@ void GenerateBindServiceWithBinderMethod(Printer* out,
out->Print("\n");
}
void GenerateBindServiceWithBinderMethodWithoutImplementation(
Printer* out, const ServiceDescriptor* service) {
out->Print(
"/// <summary>Register service method with a service "
"binder without implementation. Useful when customizing the service "
"binding logic.\n"
"/// Note: this method is part of an experimental API that can change or "
"be "
"removed without any prior notice.</summary>\n");
out->Print(
"/// <param name=\"serviceBinder\">Service methods will be bound by "
"calling <c>AddMethod</c> on this object."
"</param>\n");
out->Print(
"public static void BindService(grpc::ServiceBinderBase "
"serviceBinder)\n");
out->Print("{\n");
out->Indent();
for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor* method = service->method(i);
out->Print("serviceBinder.AddMethod($methodfield$);\n", "methodfield",
GetMethodFieldName(method));
}
out->Outdent();
out->Print("}\n");
out->Print("\n");
}
void GenerateService(Printer* out, const ServiceDescriptor* service,
bool generate_client, bool generate_server,
bool internal_access) {
@ -674,6 +704,7 @@ void GenerateService(Printer* out, const ServiceDescriptor* service,
if (generate_server) {
GenerateBindServiceMethod(out, service);
GenerateBindServiceWithBinderMethod(out, service);
GenerateBindServiceWithBinderMethodWithoutImplementation(out, service);
}
out->Outdent();

@ -97,5 +97,19 @@ namespace Grpc.Core
{
throw new NotImplementedException();
}
/// <summary>
/// Adds a method without a handler.
/// </summary>
/// <typeparam name="TRequest">The request message class.</typeparam>
/// <typeparam name="TResponse">The response message class.</typeparam>
/// <param name="method">The method.</param>
public virtual void AddMethod<TRequest, TResponse>(
Method<TRequest, TResponse> method)
where TRequest : class
where TResponse : class
{
throw new NotImplementedException();
}
}
}

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2015 gRPC authors.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -299,6 +299,17 @@ namespace Math {
serviceBinder.AddMethod(__Method_Sum, serviceImpl.Sum);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_Div);
serviceBinder.AddMethod(__Method_DivMany);
serviceBinder.AddMethod(__Method_Fib);
serviceBinder.AddMethod(__Method_Sum);
}
}
}
#endregion

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2015 The gRPC Authors
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -243,6 +243,15 @@ namespace Grpc.Health.V1 {
serviceBinder.AddMethod(__Method_Watch, serviceImpl.Watch);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_Check);
serviceBinder.AddMethod(__Method_Watch);
}
}
}
#endregion

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2015 gRPC authors.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -337,6 +337,18 @@ namespace Grpc.Testing {
serviceBinder.AddMethod(__Method_StreamingBothWays, serviceImpl.StreamingBothWays);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_UnaryCall);
serviceBinder.AddMethod(__Method_StreamingCall);
serviceBinder.AddMethod(__Method_StreamingFromClient);
serviceBinder.AddMethod(__Method_StreamingFromServer);
serviceBinder.AddMethod(__Method_StreamingBothWays);
}
}
}
#endregion

@ -96,12 +96,13 @@ namespace Grpc.Testing {
"GAcgAygIEhYKDnNlcnZlcl9zdWNjZXNzGAggAygIEjkKD3JlcXVlc3RfcmVz",
"dWx0cxgJIAMoCzIgLmdycGMudGVzdGluZy5SZXF1ZXN0UmVzdWx0Q291bnQq",
"VgoKQ2xpZW50VHlwZRIPCgtTWU5DX0NMSUVOVBAAEhAKDEFTWU5DX0NMSUVO",
"VBABEhAKDE9USEVSX0NMSUVOVBACEhMKD0NBTExCQUNLX0NMSUVOVBADKlsK",
"VBABEhAKDE9USEVSX0NMSUVOVBACEhMKD0NBTExCQUNLX0NMSUVOVBADKnAK",
"ClNlcnZlclR5cGUSDwoLU1lOQ19TRVJWRVIQABIQCgxBU1lOQ19TRVJWRVIQ",
"ARIYChRBU1lOQ19HRU5FUklDX1NFUlZFUhACEhAKDE9USEVSX1NFUlZFUhAD",
"KnIKB1JwY1R5cGUSCQoFVU5BUlkQABINCglTVFJFQU1JTkcQARIZChVTVFJF",
"QU1JTkdfRlJPTV9DTElFTlQQAhIZChVTVFJFQU1JTkdfRlJPTV9TRVJWRVIQ",
"AxIXChNTVFJFQU1JTkdfQk9USF9XQVlTEARiBnByb3RvMw=="));
"EhMKD0NBTExCQUNLX1NFUlZFUhAEKnIKB1JwY1R5cGUSCQoFVU5BUlkQABIN",
"CglTVFJFQU1JTkcQARIZChVTVFJFQU1JTkdfRlJPTV9DTElFTlQQAhIZChVT",
"VFJFQU1JTkdfRlJPTV9TRVJWRVIQAxIXChNTVFJFQU1JTkdfQk9USF9XQVlT",
"EARiBnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Grpc.Testing.PayloadsReflection.Descriptor, global::Grpc.Testing.StatsReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Grpc.Testing.ClientType), typeof(global::Grpc.Testing.ServerType), typeof(global::Grpc.Testing.RpcType), }, new pbr::GeneratedClrTypeInfo[] {
@ -152,6 +153,7 @@ namespace Grpc.Testing {
/// used for some language-specific variants
/// </summary>
[pbr::OriginalName("OTHER_SERVER")] OtherServer = 3,
[pbr::OriginalName("CALLBACK_SERVER")] CallbackServer = 4,
}
public enum RpcType {

@ -44,6 +44,7 @@ namespace Grpc.Testing {
/// service Foo {
/// rpc Bar (grpc.testing.Empty) returns (grpc.testing.Empty) { };
/// };
///
/// </summary>
public sealed partial class Empty : pb::IMessage<Empty> {
private static readonly pb::MessageParser<Empty> _parser = new pb::MessageParser<Empty>(() => new Empty());

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2018 gRPC authors.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -88,6 +88,13 @@ namespace Grpc.Testing {
{
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
}
}
}
#endregion

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2015-2016 gRPC authors.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -19,7 +19,7 @@
//
// Contains the definitions for a metrics service and the type of metrics
// exposed by the service.
//
//
// Currently, 'Gauge' (i.e a metric that represents the measured value of
// something at an instant of time) is the only metric type supported by the
// service.
@ -203,6 +203,15 @@ namespace Grpc.Testing {
serviceBinder.AddMethod(__Method_GetGauge, serviceImpl.GetGauge);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_GetAllGauges);
serviceBinder.AddMethod(__Method_GetGauge);
}
}
}
#endregion

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2015 gRPC authors.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -152,6 +152,14 @@ namespace Grpc.Testing {
serviceBinder.AddMethod(__Method_ReportScenario, serviceImpl.ReportScenario);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_ReportScenario);
}
}
}
#endregion

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2015-2016 gRPC authors.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -555,6 +555,21 @@ namespace Grpc.Testing {
serviceBinder.AddMethod(__Method_UnimplementedCall, serviceImpl.UnimplementedCall);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_EmptyCall);
serviceBinder.AddMethod(__Method_UnaryCall);
serviceBinder.AddMethod(__Method_CacheableUnaryCall);
serviceBinder.AddMethod(__Method_StreamingOutputCall);
serviceBinder.AddMethod(__Method_StreamingInputCall);
serviceBinder.AddMethod(__Method_FullDuplexCall);
serviceBinder.AddMethod(__Method_HalfDuplexCall);
serviceBinder.AddMethod(__Method_UnimplementedCall);
}
}
/// <summary>
/// A simple service NOT implemented at servers so clients can test for
@ -686,6 +701,14 @@ namespace Grpc.Testing {
serviceBinder.AddMethod(__Method_UnimplementedCall, serviceImpl.UnimplementedCall);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_UnimplementedCall);
}
}
/// <summary>
/// A service used to control reconnect server.
@ -814,6 +837,15 @@ namespace Grpc.Testing {
serviceBinder.AddMethod(__Method_Stop, serviceImpl.Stop);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_Start);
serviceBinder.AddMethod(__Method_Stop);
}
}
}
#endregion

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2015 gRPC authors.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -333,6 +333,17 @@ namespace Grpc.Testing {
serviceBinder.AddMethod(__Method_QuitWorker, serviceImpl.QuitWorker);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_RunServer);
serviceBinder.AddMethod(__Method_RunClient);
serviceBinder.AddMethod(__Method_CoreCount);
serviceBinder.AddMethod(__Method_QuitWorker);
}
}
}
#endregion

@ -4,13 +4,13 @@
// </auto-generated>
// Original file comments:
// Copyright 2016 gRPC authors.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -132,6 +132,14 @@ namespace Grpc.Reflection.V1Alpha {
serviceBinder.AddMethod(__Method_ServerReflectionInfo, serviceImpl.ServerReflectionInfo);
}
/// <summary>Register service method with a service binder without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
public static void BindService(grpc::ServiceBinderBase serviceBinder)
{
serviceBinder.AddMethod(__Method_ServerReflectionInfo);
}
}
}
#endregion

Loading…
Cancel
Save