Revert "only generate full or lite client, never both"

This reverts commit 1b8418b546.
pull/20149/head
Jan Tattermusch 5 years ago
parent f78966eb52
commit 7b2c253530
  1. 56
      src/compiler/csharp_generator.cc
  2. 4
      src/compiler/csharp_generator.h
  3. 12
      src/compiler/csharp_plugin.cc

@ -176,8 +176,9 @@ std::string GetServiceClassName(const ServiceDescriptor* service) {
return service->name(); return service->name();
} }
std::string GetClientClassName(const ServiceDescriptor* service) { std::string GetClientClassName(const ServiceDescriptor* service,
return service->name() + "Client"; bool lite_client) {
return service->name() + (lite_client ? "LiteClient" : "Client");
} }
std::string GetServerClassName(const ServiceDescriptor* service) { std::string GetServerClassName(const ServiceDescriptor* service) {
@ -420,28 +421,26 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
out->Print("/// <summary>Client for $servicename$</summary>\n", out->Print("/// <summary>Client for $servicename$</summary>\n",
"servicename", GetServiceClassName(service)); "servicename", GetServiceClassName(service));
out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n", out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n",
"name", GetClientClassName(service)); "name", GetClientClassName(service, lite_client));
} else { } else {
out->Print("/// <summary>Lite client for $servicename$</summary>\n", out->Print("/// <summary>Lite client for $servicename$</summary>\n",
"servicename", GetServiceClassName(service)); "servicename", GetServiceClassName(service));
out->Print("public partial class $name$ : grpc::LiteClientBase\n", "name", out->Print("public partial class $name$ : grpc::LiteClientBase\n", "name",
GetClientClassName(service)); GetClientClassName(service, lite_client));
} }
out->Print("{\n"); out->Print("{\n");
out->Indent(); out->Indent();
// constructors // constructors
if (!lite_client) { out->Print(
out->Print( "/// <summary>Creates a new client for $servicename$</summary>\n"
"/// <summary>Creates a new client for $servicename$</summary>\n" "/// <param name=\"channel\">The channel to use to make remote "
"/// <param name=\"channel\">The channel to use to make remote " "calls.</param>\n",
"calls.</param>\n", "servicename", GetServiceClassName(service));
"servicename", GetServiceClassName(service)); out->Print("public $name$(grpc::ChannelBase channel) : base(channel)\n",
out->Print("public $name$(grpc::ChannelBase channel) : base(channel)\n", "name", GetClientClassName(service));
"name", GetClientClassName(service)); out->Print("{\n");
out->Print("{\n"); out->Print("}\n");
out->Print("}\n");
}
out->Print( out->Print(
"/// <summary>Creates a new client for $servicename$ that uses a custom " "/// <summary>Creates a new client for $servicename$ that uses a custom "
"<c>CallInvoker</c>.</summary>\n" "<c>CallInvoker</c>.</summary>\n"
@ -450,14 +449,14 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
"servicename", GetServiceClassName(service)); "servicename", GetServiceClassName(service));
out->Print( out->Print(
"public $name$(grpc::CallInvoker callInvoker) : base(callInvoker)\n", "public $name$(grpc::CallInvoker callInvoker) : base(callInvoker)\n",
"name", GetClientClassName(service)); "name", GetClientClassName(service, lite_client));
out->Print("{\n"); out->Print("{\n");
out->Print("}\n"); out->Print("}\n");
out->Print( out->Print(
"/// <summary>Protected parameterless constructor to allow creation" "/// <summary>Protected parameterless constructor to allow creation"
" of test doubles.</summary>\n"); " of test doubles.</summary>\n");
out->Print("protected $name$() : base()\n", "name", out->Print("protected $name$() : base()\n", "name",
GetClientClassName(service)); GetClientClassName(service, lite_client));
out->Print("{\n"); out->Print("{\n");
out->Print("}\n"); out->Print("}\n");
if (!lite_client) { if (!lite_client) {
@ -469,7 +468,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
out->Print( out->Print(
"protected $name$(ClientBaseConfiguration configuration)" "protected $name$(ClientBaseConfiguration configuration)"
" : base(configuration)\n", " : base(configuration)\n",
"name", GetClientClassName(service)); "name", GetClientClassName(service, lite_client));
out->Print("{\n"); out->Print("{\n");
out->Print("}\n"); out->Print("}\n");
} }
@ -598,11 +597,11 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
out->Print( out->Print(
"protected override $name$ NewInstance(ClientBaseConfiguration " "protected override $name$ NewInstance(ClientBaseConfiguration "
"configuration)\n", "configuration)\n",
"name", GetClientClassName(service)); "name", GetClientClassName(service, lite_client));
out->Print("{\n"); out->Print("{\n");
out->Indent(); out->Indent();
out->Print("return new $name$(configuration);\n", "name", out->Print("return new $name$(configuration);\n", "name",
GetClientClassName(service)); GetClientClassName(service, lite_client));
out->Outdent(); out->Outdent();
out->Print("}\n"); out->Print("}\n");
} }
@ -686,8 +685,8 @@ void GenerateBindServiceWithBinderMethod(Printer* out,
} }
void GenerateService(Printer* out, const ServiceDescriptor* service, void GenerateService(Printer* out, const ServiceDescriptor* service,
bool generate_client, bool generate_server, bool generate_client, bool generate_lite_client,
bool internal_access, bool lite_client) { bool generate_server, bool internal_access) {
GenerateDocCommentBody(out, service); GenerateDocCommentBody(out, service);
out->Print("$access_level$ static partial class $classname$\n", out->Print("$access_level$ static partial class $classname$\n",
"access_level", GetAccessLevel(internal_access), "classname", "access_level", GetAccessLevel(internal_access), "classname",
@ -709,7 +708,10 @@ void GenerateService(Printer* out, const ServiceDescriptor* service,
GenerateServerClass(out, service); GenerateServerClass(out, service);
} }
if (generate_client) { if (generate_client) {
GenerateClientStub(out, service, lite_client); GenerateClientStub(out, service, false);
}
if (generate_lite_client) {
GenerateClientStub(out, service, true);
} }
if (generate_server) { if (generate_server) {
@ -724,8 +726,8 @@ void GenerateService(Printer* out, const ServiceDescriptor* service,
} // anonymous namespace } // anonymous namespace
grpc::string GetServices(const FileDescriptor* file, bool generate_client, grpc::string GetServices(const FileDescriptor* file, bool generate_client,
bool generate_server, bool internal_access, bool generate_lite_client, bool generate_server,
bool lite_client) { bool internal_access) {
grpc::string output; grpc::string output;
{ {
// Scope the output stream so it closes and finalizes output to the string. // Scope the output stream so it closes and finalizes output to the string.
@ -766,8 +768,8 @@ grpc::string GetServices(const FileDescriptor* file, bool generate_client,
out.Indent(); out.Indent();
} }
for (int i = 0; i < file->service_count(); i++) { for (int i = 0; i < file->service_count(); i++) {
GenerateService(&out, file->service(i), generate_client, generate_server, GenerateService(&out, file->service(i), generate_client,
internal_access, lite_client); generate_lite_client, generate_server, internal_access);
} }
if (file_namespace != "") { if (file_namespace != "") {
out.Outdent(); out.Outdent();

@ -26,8 +26,8 @@
namespace grpc_csharp_generator { namespace grpc_csharp_generator {
grpc::string GetServices(const grpc::protobuf::FileDescriptor* file, grpc::string GetServices(const grpc::protobuf::FileDescriptor* file,
bool generate_client, bool generate_server, bool generate_client, bool generate_lite_client,
bool internal_access, bool lite_client); bool generate_server, bool internal_access);
} // namespace grpc_csharp_generator } // namespace grpc_csharp_generator

@ -38,19 +38,18 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
bool generate_client = true; bool generate_client = true;
bool generate_server = true; bool generate_server = true;
bool generate_lite_client = true;
bool internal_access = false; bool internal_access = false;
bool lite_client = false;
for (size_t i = 0; i < options.size(); i++) { for (size_t i = 0; i < options.size(); i++) {
if (options[i].first == "no_client") { if (options[i].first == "no_client") {
generate_client = false; generate_client = false;
} else if (options[i].first == "no_lite_client") {
// TODO: better option
generate_lite_client = false;
} else if (options[i].first == "no_server") { } else if (options[i].first == "no_server") {
generate_server = false; generate_server = false;
} else if (options[i].first == "internal_access") { } else if (options[i].first == "internal_access") {
internal_access = true; internal_access = true;
} else if (options[i].first == "lite_client") {
// will only be used if generate_client is true.
// NOTE: experimental option, can be removed in future release
lite_client = true;
} else { } else {
*error = "Unknown generator option: " + options[i].first; *error = "Unknown generator option: " + options[i].first;
return false; return false;
@ -58,7 +57,8 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
} }
grpc::string code = grpc_csharp_generator::GetServices( grpc::string code = grpc_csharp_generator::GetServices(
file, generate_client, generate_server, internal_access, lite_client); file, generate_client, generate_lite_client, generate_server,
internal_access);
if (code.size() == 0) { if (code.size() == 0) {
return true; // don't generate a file if there are no services return true; // don't generate a file if there are no services
} }

Loading…
Cancel
Save