|
|
@ -176,9 +176,8 @@ std::string GetServiceClassName(const ServiceDescriptor* service) { |
|
|
|
return service->name(); |
|
|
|
return service->name(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string GetClientClassName(const ServiceDescriptor* service, |
|
|
|
std::string GetClientClassName(const ServiceDescriptor* service) { |
|
|
|
bool lite_client) { |
|
|
|
return service->name() + "Client"; |
|
|
|
return service->name() + (lite_client ? "LiteClient" : "Client"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string GetServerClassName(const ServiceDescriptor* service) { |
|
|
|
std::string GetServerClassName(const ServiceDescriptor* service) { |
|
|
@ -415,19 +414,11 @@ void GenerateServerClass(Printer* out, const ServiceDescriptor* service) { |
|
|
|
out->Print("\n"); |
|
|
|
out->Print("\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GenerateClientStub(Printer* out, const ServiceDescriptor* service, |
|
|
|
void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { |
|
|
|
bool lite_client) { |
|
|
|
out->Print("/// <summary>Client for $servicename$</summary>\n", "servicename", |
|
|
|
if (!lite_client) { |
|
|
|
GetServiceClassName(service)); |
|
|
|
out->Print("/// <summary>Client for $servicename$</summary>\n", |
|
|
|
out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n", "name", |
|
|
|
"servicename", GetServiceClassName(service)); |
|
|
|
GetClientClassName(service)); |
|
|
|
out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n", |
|
|
|
|
|
|
|
"name", GetClientClassName(service, lite_client)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
out->Print("/// <summary>Lite client for $servicename$</summary>\n", |
|
|
|
|
|
|
|
"servicename", GetServiceClassName(service)); |
|
|
|
|
|
|
|
out->Print("public partial class $name$ : grpc::LiteClientBase\n", "name", |
|
|
|
|
|
|
|
GetClientClassName(service, lite_client)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Indent(); |
|
|
|
out->Indent(); |
|
|
|
|
|
|
|
|
|
|
@ -449,30 +440,26 @@ 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, lite_client)); |
|
|
|
"name", GetClientClassName(service)); |
|
|
|
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, lite_client)); |
|
|
|
GetClientClassName(service)); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("}\n"); |
|
|
|
if (!lite_client) { |
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"/// <summary>Protected constructor to allow creation of configured " |
|
|
|
"/// <summary>Protected constructor to allow creation of configured " |
|
|
|
"clients.</summary>\n" |
|
|
|
"clients.</summary>\n" |
|
|
|
"/// <param name=\"configuration\">The client configuration.</param>\n"); |
|
|
|
"/// <param name=\"configuration\">The client " |
|
|
|
out->Print( |
|
|
|
"configuration.</param>\n"); |
|
|
|
"protected $name$(ClientBaseConfiguration configuration)" |
|
|
|
out->Print( |
|
|
|
" : base(configuration)\n", |
|
|
|
"protected $name$(ClientBaseConfiguration configuration)" |
|
|
|
"name", GetClientClassName(service)); |
|
|
|
" : base(configuration)\n", |
|
|
|
out->Print("{\n"); |
|
|
|
"name", GetClientClassName(service, lite_client)); |
|
|
|
out->Print("}\n\n"); |
|
|
|
out->Print("{\n"); |
|
|
|
|
|
|
|
out->Print("}\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
out->Print("\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
const MethodDescriptor* method = service->method(i); |
|
|
|
const MethodDescriptor* method = service->method(i); |
|
|
@ -590,21 +577,19 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// override NewInstance method
|
|
|
|
// override NewInstance method
|
|
|
|
if (!lite_client) { |
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"/// <summary>Creates a new instance of client from given " |
|
|
|
"/// <summary>Creates a new instance of client from given " |
|
|
|
"<c>ClientBaseConfiguration</c>.</summary>\n"); |
|
|
|
"<c>ClientBaseConfiguration</c>.</summary>\n"); |
|
|
|
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"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out->Outdent(); |
|
|
|
out->Outdent(); |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("}\n"); |
|
|
@ -685,8 +670,8 @@ void GenerateBindServiceWithBinderMethod(Printer* out, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GenerateService(Printer* out, const ServiceDescriptor* service, |
|
|
|
void GenerateService(Printer* out, const ServiceDescriptor* service, |
|
|
|
bool generate_client, bool generate_lite_client, |
|
|
|
bool generate_client, bool generate_server, |
|
|
|
bool generate_server, bool internal_access) { |
|
|
|
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", |
|
|
@ -708,12 +693,8 @@ void GenerateService(Printer* out, const ServiceDescriptor* service, |
|
|
|
GenerateServerClass(out, service); |
|
|
|
GenerateServerClass(out, service); |
|
|
|
} |
|
|
|
} |
|
|
|
if (generate_client) { |
|
|
|
if (generate_client) { |
|
|
|
GenerateClientStub(out, service, false); |
|
|
|
GenerateClientStub(out, service); |
|
|
|
} |
|
|
|
|
|
|
|
if (generate_lite_client) { |
|
|
|
|
|
|
|
GenerateClientStub(out, service, true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (generate_server) { |
|
|
|
if (generate_server) { |
|
|
|
GenerateBindServiceMethod(out, service); |
|
|
|
GenerateBindServiceMethod(out, service); |
|
|
|
GenerateBindServiceWithBinderMethod(out, service); |
|
|
|
GenerateBindServiceWithBinderMethod(out, service); |
|
|
@ -726,8 +707,7 @@ 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_lite_client, bool generate_server, |
|
|
|
bool generate_server, bool internal_access) { |
|
|
|
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.
|
|
|
@ -768,8 +748,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, |
|
|
|
GenerateService(&out, file->service(i), generate_client, generate_server, |
|
|
|
generate_lite_client, generate_server, internal_access); |
|
|
|
internal_access); |
|
|
|
} |
|
|
|
} |
|
|
|
if (file_namespace != "") { |
|
|
|
if (file_namespace != "") { |
|
|
|
out.Outdent(); |
|
|
|
out.Outdent(); |
|
|
|