|
|
|
@ -110,7 +110,7 @@ bool HasBidiStreaming(const grpc::protobuf::FileDescriptor *file) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string FilenameIdentifier(const grpc::string& filename) { |
|
|
|
|
grpc::string FilenameIdentifier(const grpc::string &filename) { |
|
|
|
|
grpc::string result; |
|
|
|
|
for (unsigned i = 0; i < filename.size(); i++) { |
|
|
|
|
char c = filename[i]; |
|
|
|
@ -173,7 +173,9 @@ grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
temp.append("template <class OutMessage> class ClientWriter;\n"); |
|
|
|
|
temp.append("template <class InMessage> class ServerReader;\n"); |
|
|
|
|
temp.append("template <class OutMessage> class ClientAsyncWriter;\n"); |
|
|
|
|
temp.append("template <class OutMessage, class InMessage> class ServerAsyncReader;\n"); |
|
|
|
|
temp.append( |
|
|
|
|
"template <class OutMessage, class InMessage> class " |
|
|
|
|
"ServerAsyncReader;\n"); |
|
|
|
|
} |
|
|
|
|
if (HasServerOnlyStreaming(file)) { |
|
|
|
|
temp.append("template <class InMessage> class ClientReader;\n"); |
|
|
|
@ -247,11 +249,11 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientReader< $Response$>> $Method$(" |
|
|
|
|
"::grpc::ClientContext* context, const $Request$& request);\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientAsyncReader< $Response$>> Async$Method$(" |
|
|
|
|
"::grpc::ClientContext* context, const $Request$& request, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag);\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientAsyncReader< $Response$>> " |
|
|
|
|
"Async$Method$(" |
|
|
|
|
"::grpc::ClientContext* context, const $Request$& request, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag);\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
@ -272,10 +274,9 @@ void PrintHeaderClientMethodData(grpc::protobuf::io::Printer *printer, |
|
|
|
|
printer->Print(*vars, "const ::grpc::RpcMethod rpcmethod_$Method$_;\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderServerMethodSync( |
|
|
|
|
grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
void PrintHeaderServerMethodSync(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
@ -359,7 +360,8 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"class Stub GRPC_FINAL : public ::grpc::InternalStub {\n" |
|
|
|
|
" public:\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print("Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
"Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
PrintHeaderClientMethod(printer, service->method(i), vars); |
|
|
|
|
} |
|
|
|
@ -607,11 +609,12 @@ void PrintSourceClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"rpcmethod_$Method$_, " |
|
|
|
|
"context));\n" |
|
|
|
|
"}\n\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientAsyncReaderWriter< " |
|
|
|
|
"$Request$, $Response$>> " |
|
|
|
|
"$ns$$Service$::Stub::Async$Method$(::grpc::ClientContext* context, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) {\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientAsyncReaderWriter< " |
|
|
|
|
"$Request$, $Response$>> " |
|
|
|
|
"$ns$$Service$::Stub::Async$Method$(::grpc::ClientContext* context, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) {\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
" return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< " |
|
|
|
|
"$Request$, $Response$>>(new " |
|
|
|
@ -689,9 +692,9 @@ void PrintSourceServerAsyncMethod( |
|
|
|
|
"$Request$* request, " |
|
|
|
|
"::grpc::ServerAsyncResponseWriter< $Response$>* response, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) {\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
" AsynchronousService::RequestAsyncUnary($Idx$, context, request, response, cq, tag);\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
" AsynchronousService::RequestAsyncUnary($Idx$, context, " |
|
|
|
|
"request, response, cq, tag);\n"); |
|
|
|
|
printer->Print("}\n\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
@ -699,9 +702,9 @@ void PrintSourceServerAsyncMethod( |
|
|
|
|
"::grpc::ServerContext* context, " |
|
|
|
|
"::grpc::ServerAsyncReader< $Response$, $Request$>* reader, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) {\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
" AsynchronousService::RequestClientStreaming($Idx$, context, reader, cq, tag);\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
" AsynchronousService::RequestClientStreaming($Idx$, " |
|
|
|
|
"context, reader, cq, tag);\n"); |
|
|
|
|
printer->Print("}\n\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
@ -710,9 +713,9 @@ void PrintSourceServerAsyncMethod( |
|
|
|
|
"$Request$* request, " |
|
|
|
|
"::grpc::ServerAsyncWriter< $Response$>* writer, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) {\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
" AsynchronousService::RequestServerStreaming($Idx$, context, request, writer, cq, tag);\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
" AsynchronousService::RequestServerStreaming($Idx$, " |
|
|
|
|
"context, request, writer, cq, tag);\n"); |
|
|
|
|
printer->Print("}\n\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
printer->Print( |
|
|
|
@ -721,9 +724,9 @@ void PrintSourceServerAsyncMethod( |
|
|
|
|
"::grpc::ServerContext* context, " |
|
|
|
|
"::grpc::ServerAsyncReaderWriter< $Response$, $Request$>* stream, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void *tag) {\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
" AsynchronousService::RequestBidiStreaming($Idx$, context, stream, cq, tag);\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
" AsynchronousService::RequestBidiStreaming($Idx$, " |
|
|
|
|
"context, stream, cq, tag);\n"); |
|
|
|
|
printer->Print("}\n\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -733,7 +736,8 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Service"] = service->name(); |
|
|
|
|
|
|
|
|
|
printer->Print(*vars, "static const char* $prefix$$Service$_method_names[] = {\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"static const char* $prefix$$Service$_method_names[] = {\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
(*vars)["Method"] = service->method(i)->name(); |
|
|
|
|
printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n"); |
|
|
|
@ -744,10 +748,13 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub(" |
|
|
|
|
"const std::shared_ptr< ::grpc::ChannelInterface>& channel) {\n" |
|
|
|
|
" std::unique_ptr< $ns$$Service$::Stub> stub(new $ns$$Service$::Stub(channel));\n" |
|
|
|
|
" std::unique_ptr< $ns$$Service$::Stub> stub(new " |
|
|
|
|
"$ns$$Service$::Stub(channel));\n" |
|
|
|
|
" return stub;\n" |
|
|
|
|
"}\n\n"); |
|
|
|
|
printer->Print(*vars, "$ns$$Service$::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel)\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"$ns$$Service$::Stub::Stub(const std::shared_ptr< " |
|
|
|
|
"::grpc::ChannelInterface>& channel)\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(": ::grpc::InternalStub(channel)"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
@ -763,11 +770,13 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
} else { |
|
|
|
|
(*vars)["StreamingType"] = "BIDI_STREAMING"; |
|
|
|
|
} |
|
|
|
|
printer->Print(*vars, ", rpcmethod_$Method$_(" |
|
|
|
|
"$prefix$$Service$_method_names[$Idx$], " |
|
|
|
|
"::grpc::RpcMethod::$StreamingType$, " |
|
|
|
|
"channel->RegisterMethod($prefix$$Service$_method_names[$Idx$])" |
|
|
|
|
")\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
", rpcmethod_$Method$_(" |
|
|
|
|
"$prefix$$Service$_method_names[$Idx$], " |
|
|
|
|
"::grpc::RpcMethod::$StreamingType$, " |
|
|
|
|
"channel->RegisterMethod($prefix$$Service$_method_names[$Idx$])" |
|
|
|
|
")\n"); |
|
|
|
|
} |
|
|
|
|
printer->Print("{}\n\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
@ -778,11 +787,12 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
(*vars)["MethodCount"] = as_string(service->method_count()); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"$ns$$Service$::AsyncService::AsyncService(::grpc::CompletionQueue* cq) : " |
|
|
|
|
"::grpc::AsynchronousService(cq, $prefix$$Service$_method_names, $MethodCount$) " |
|
|
|
|
"{}\n\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"$ns$$Service$::AsyncService::AsyncService(::grpc::" |
|
|
|
|
"CompletionQueue* cq) : " |
|
|
|
|
"::grpc::AsynchronousService(cq, " |
|
|
|
|
"$prefix$$Service$_method_names, $MethodCount$) " |
|
|
|
|
"{}\n\n"); |
|
|
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"$ns$$Service$::Service::~Service() {\n" |
|
|
|
@ -815,7 +825,8 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n" |
|
|
|
|
" $prefix$$Service$_method_names[$Idx$],\n" |
|
|
|
|
" ::grpc::RpcMethod::NORMAL_RPC,\n" |
|
|
|
|
" new ::grpc::RpcMethodHandler< $ns$$Service$::Service, $Request$, " |
|
|
|
|
" new ::grpc::RpcMethodHandler< $ns$$Service$::Service, " |
|
|
|
|
"$Request$, " |
|
|
|
|
"$Response$>(\n" |
|
|
|
|
" std::function< ::grpc::Status($ns$$Service$::Service*, " |
|
|
|
|
"::grpc::ServerContext*, const $Request$*, $Response$*)>(" |
|
|
|
|