|
|
@ -257,7 +257,7 @@ void GenerateStaticMethodField(Printer* out, const MethodDescriptor *method) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GenerateClientInterface(Printer* out, const ServiceDescriptor *service) { |
|
|
|
void GenerateClientInterface(Printer* out, const ServiceDescriptor *service) { |
|
|
|
out->Print("// client-side stub interface\n"); |
|
|
|
out->Print("// client interface\n"); |
|
|
|
out->Print("public interface $name$\n", "name", |
|
|
|
out->Print("public interface $name$\n", "name", |
|
|
|
GetClientInterfaceName(service)); |
|
|
|
GetClientInterfaceName(service)); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("{\n"); |
|
|
@ -269,7 +269,7 @@ void GenerateClientInterface(Printer* out, const ServiceDescriptor *service) { |
|
|
|
if (method_type == METHODTYPE_NO_STREAMING) { |
|
|
|
if (method_type == METHODTYPE_NO_STREAMING) { |
|
|
|
// unary calls have an extra synchronous stub method
|
|
|
|
// unary calls have an extra synchronous stub method
|
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"$response$ $methodname$($request$ request, CancellationToken token = default(CancellationToken));\n", |
|
|
|
"$response$ $methodname$($request$ request, Metadata headers = null, CancellationToken cancellationToken = default(CancellationToken));\n", |
|
|
|
"methodname", method->name(), "request", |
|
|
|
"methodname", method->name(), "request", |
|
|
|
GetClassName(method->input_type()), "response", |
|
|
|
GetClassName(method->input_type()), "response", |
|
|
|
GetClassName(method->output_type())); |
|
|
|
GetClassName(method->output_type())); |
|
|
@ -280,7 +280,7 @@ void GenerateClientInterface(Printer* out, const ServiceDescriptor *service) { |
|
|
|
method_name += "Async"; // prevent name clash with synchronous method.
|
|
|
|
method_name += "Async"; // prevent name clash with synchronous method.
|
|
|
|
} |
|
|
|
} |
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"$returntype$ $methodname$($request_maybe$CancellationToken token = default(CancellationToken));\n", |
|
|
|
"$returntype$ $methodname$($request_maybe$Metadata headers = null, CancellationToken cancellationToken = default(CancellationToken));\n", |
|
|
|
"methodname", method_name, "request_maybe", |
|
|
|
"methodname", method_name, "request_maybe", |
|
|
|
GetMethodRequestParamMaybe(method), "returntype", |
|
|
|
GetMethodRequestParamMaybe(method), "returntype", |
|
|
|
GetMethodReturnTypeClient(method)); |
|
|
|
GetMethodReturnTypeClient(method)); |
|
|
@ -312,7 +312,7 @@ void GenerateServerInterface(Printer* out, const ServiceDescriptor *service) { |
|
|
|
void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { |
|
|
|
void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { |
|
|
|
out->Print("// client stub\n"); |
|
|
|
out->Print("// client stub\n"); |
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"public class $name$ : AbstractStub<$name$, StubConfiguration>, $interface$\n", |
|
|
|
"public class $name$ : ClientBase, $interface$\n", |
|
|
|
"name", GetClientClassName(service), "interface", |
|
|
|
"name", GetClientClassName(service), "interface", |
|
|
|
GetClientInterfaceName(service)); |
|
|
|
GetClientInterfaceName(service)); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("{\n"); |
|
|
@ -320,12 +320,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { |
|
|
|
|
|
|
|
|
|
|
|
// constructors
|
|
|
|
// constructors
|
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"public $name$(Channel channel) : this(channel, StubConfiguration.Default)\n", |
|
|
|
"public $name$(Channel channel) : base(channel)\n", |
|
|
|
"name", GetClientClassName(service)); |
|
|
|
|
|
|
|
out->Print("{\n"); |
|
|
|
|
|
|
|
out->Print("}\n"); |
|
|
|
|
|
|
|
out->Print( |
|
|
|
|
|
|
|
"public $name$(Channel channel, StubConfiguration config) : base(channel, config)\n", |
|
|
|
|
|
|
|
"name", GetClientClassName(service)); |
|
|
|
"name", GetClientClassName(service)); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("}\n"); |
|
|
@ -337,16 +332,16 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { |
|
|
|
if (method_type == METHODTYPE_NO_STREAMING) { |
|
|
|
if (method_type == METHODTYPE_NO_STREAMING) { |
|
|
|
// unary calls have an extra synchronous stub method
|
|
|
|
// unary calls have an extra synchronous stub method
|
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"public $response$ $methodname$($request$ request, CancellationToken token = default(CancellationToken))\n", |
|
|
|
"public $response$ $methodname$($request$ request, Metadata headers = null, CancellationToken cancellationToken = default(CancellationToken))\n", |
|
|
|
"methodname", method->name(), "request", |
|
|
|
"methodname", method->name(), "request", |
|
|
|
GetClassName(method->input_type()), "response", |
|
|
|
GetClassName(method->input_type()), "response", |
|
|
|
GetClassName(method->output_type())); |
|
|
|
GetClassName(method->output_type())); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Indent(); |
|
|
|
out->Indent(); |
|
|
|
out->Print("var call = CreateCall($servicenamefield$, $methodfield$);\n", |
|
|
|
out->Print("var call = CreateCall($servicenamefield$, $methodfield$, headers);\n", |
|
|
|
"servicenamefield", GetServiceNameFieldName(), "methodfield", |
|
|
|
"servicenamefield", GetServiceNameFieldName(), "methodfield", |
|
|
|
GetMethodFieldName(method)); |
|
|
|
GetMethodFieldName(method)); |
|
|
|
out->Print("return Calls.BlockingUnaryCall(call, request, token);\n"); |
|
|
|
out->Print("return Calls.BlockingUnaryCall(call, request, cancellationToken);\n"); |
|
|
|
out->Outdent(); |
|
|
|
out->Outdent(); |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("}\n"); |
|
|
|
} |
|
|
|
} |
|
|
@ -356,28 +351,28 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { |
|
|
|
method_name += "Async"; // prevent name clash with synchronous method.
|
|
|
|
method_name += "Async"; // prevent name clash with synchronous method.
|
|
|
|
} |
|
|
|
} |
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"public $returntype$ $methodname$($request_maybe$CancellationToken token = default(CancellationToken))\n", |
|
|
|
"public $returntype$ $methodname$($request_maybe$Metadata headers = null, CancellationToken cancellationToken = default(CancellationToken))\n", |
|
|
|
"methodname", method_name, "request_maybe", |
|
|
|
"methodname", method_name, "request_maybe", |
|
|
|
GetMethodRequestParamMaybe(method), "returntype", |
|
|
|
GetMethodRequestParamMaybe(method), "returntype", |
|
|
|
GetMethodReturnTypeClient(method)); |
|
|
|
GetMethodReturnTypeClient(method)); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Indent(); |
|
|
|
out->Indent(); |
|
|
|
out->Print("var call = CreateCall($servicenamefield$, $methodfield$);\n", |
|
|
|
out->Print("var call = CreateCall($servicenamefield$, $methodfield$, headers);\n", |
|
|
|
"servicenamefield", GetServiceNameFieldName(), "methodfield", |
|
|
|
"servicenamefield", GetServiceNameFieldName(), "methodfield", |
|
|
|
GetMethodFieldName(method)); |
|
|
|
GetMethodFieldName(method)); |
|
|
|
switch (GetMethodType(method)) { |
|
|
|
switch (GetMethodType(method)) { |
|
|
|
case METHODTYPE_NO_STREAMING: |
|
|
|
case METHODTYPE_NO_STREAMING: |
|
|
|
out->Print("return Calls.AsyncUnaryCall(call, request, token);\n"); |
|
|
|
out->Print("return Calls.AsyncUnaryCall(call, request, cancellationToken);\n"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case METHODTYPE_CLIENT_STREAMING: |
|
|
|
case METHODTYPE_CLIENT_STREAMING: |
|
|
|
out->Print("return Calls.AsyncClientStreamingCall(call, token);\n"); |
|
|
|
out->Print("return Calls.AsyncClientStreamingCall(call, cancellationToken);\n"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case METHODTYPE_SERVER_STREAMING: |
|
|
|
case METHODTYPE_SERVER_STREAMING: |
|
|
|
out->Print( |
|
|
|
out->Print( |
|
|
|
"return Calls.AsyncServerStreamingCall(call, request, token);\n"); |
|
|
|
"return Calls.AsyncServerStreamingCall(call, request, cancellationToken);\n"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case METHODTYPE_BIDI_STREAMING: |
|
|
|
case METHODTYPE_BIDI_STREAMING: |
|
|
|
out->Print("return Calls.AsyncDuplexStreamingCall(call, token);\n"); |
|
|
|
out->Print("return Calls.AsyncDuplexStreamingCall(call, cancellationToken);\n"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
GOOGLE_LOG(FATAL)<< "Can't get here."; |
|
|
|
GOOGLE_LOG(FATAL)<< "Can't get here."; |
|
|
@ -423,9 +418,9 @@ void GenerateBindServiceMethod(Printer* out, const ServiceDescriptor *service) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GenerateNewStubMethods(Printer* out, const ServiceDescriptor *service) { |
|
|
|
void GenerateNewStubMethods(Printer* out, const ServiceDescriptor *service) { |
|
|
|
out->Print("// creates a new client stub\n"); |
|
|
|
out->Print("// creates a new client\n"); |
|
|
|
out->Print("public static $interface$ NewStub(Channel channel)\n", |
|
|
|
out->Print("public static $classname$ NewClient(Channel channel)\n", |
|
|
|
"interface", GetClientInterfaceName(service)); |
|
|
|
"classname", GetClientClassName(service)); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Print("{\n"); |
|
|
|
out->Indent(); |
|
|
|
out->Indent(); |
|
|
|
out->Print("return new $classname$(channel);\n", "classname", |
|
|
|
out->Print("return new $classname$(channel);\n", "classname", |
|
|
@ -433,17 +428,6 @@ void GenerateNewStubMethods(Printer* out, const ServiceDescriptor *service) { |
|
|
|
out->Outdent(); |
|
|
|
out->Outdent(); |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("\n"); |
|
|
|
out->Print("\n"); |
|
|
|
|
|
|
|
|
|
|
|
out->Print("// creates a new client stub\n"); |
|
|
|
|
|
|
|
out->Print( |
|
|
|
|
|
|
|
"public static $interface$ NewStub(Channel channel, StubConfiguration config)\n", |
|
|
|
|
|
|
|
"interface", GetClientInterfaceName(service)); |
|
|
|
|
|
|
|
out->Print("{\n"); |
|
|
|
|
|
|
|
out->Indent(); |
|
|
|
|
|
|
|
out->Print("return new $classname$(channel, config);\n", "classname", |
|
|
|
|
|
|
|
GetClientClassName(service)); |
|
|
|
|
|
|
|
out->Outdent(); |
|
|
|
|
|
|
|
out->Print("}\n"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GenerateService(Printer* out, const ServiceDescriptor *service) { |
|
|
|
void GenerateService(Printer* out, const ServiceDescriptor *service) { |
|
|
|