|
|
|
@ -34,9 +34,6 @@ |
|
|
|
|
#include <map> |
|
|
|
|
|
|
|
|
|
#include "src/compiler/cpp_generator.h" |
|
|
|
|
#include "src/compiler/cpp_generator_helpers.h" |
|
|
|
|
|
|
|
|
|
#include "src/compiler/config.h" |
|
|
|
|
|
|
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
|
@ -50,22 +47,6 @@ grpc::string as_string(T x) { |
|
|
|
|
return out.str(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool NoStreaming(const grpc::protobuf::MethodDescriptor *method) { |
|
|
|
|
return !method->client_streaming() && !method->server_streaming(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool ClientOnlyStreaming(const grpc::protobuf::MethodDescriptor *method) { |
|
|
|
|
return method->client_streaming() && !method->server_streaming(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool ServerOnlyStreaming(const grpc::protobuf::MethodDescriptor *method) { |
|
|
|
|
return !method->client_streaming() && method->server_streaming(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool BidiStreaming(const grpc::protobuf::MethodDescriptor *method) { |
|
|
|
|
return method->client_streaming() && method->server_streaming(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string FilenameIdentifier(const grpc::string &filename) { |
|
|
|
|
grpc::string result; |
|
|
|
|
for (unsigned i = 0; i < filename.size(); i++) { |
|
|
|
@ -86,7 +67,7 @@ grpc::string FilenameIdentifier(const grpc::string &filename) { |
|
|
|
|
template<class T, size_t N> |
|
|
|
|
T *array_end(T (&array)[N]) { return array + N; } |
|
|
|
|
|
|
|
|
|
void PrintIncludes(grpc::protobuf::io::Printer *printer, const std::vector<grpc::string>& headers, const Parameters ¶ms) { |
|
|
|
|
void PrintIncludes(Printer *printer, const std::vector<grpc::string>& headers, const Parameters ¶ms) { |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["l"] = params.use_system_headers ? '<' : '"'; |
|
|
|
@ -105,39 +86,36 @@ void PrintIncludes(grpc::protobuf::io::Printer *printer, const std::vector<grpc: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetHeaderPrologue(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string GetHeaderPrologue(File *file, const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
auto printer = file->CreatePrinter(&output); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_identifier"] = FilenameIdentifier(file->name()); |
|
|
|
|
vars["filename_base"] = grpc_generator::StripProto(file->name()); |
|
|
|
|
vars["filename"] = file->filename(); |
|
|
|
|
vars["filename_identifier"] = FilenameIdentifier(file->filename()); |
|
|
|
|
vars["filename_base"] = file->filename_without_ext(); |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "// Generated by the gRPC protobuf plugin.\n"); |
|
|
|
|
printer.Print(vars, |
|
|
|
|
printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n"); |
|
|
|
|
printer->Print(vars, |
|
|
|
|
"// If you make any local change, they will be lost.\n"); |
|
|
|
|
printer.Print(vars, "// source: $filename$\n"); |
|
|
|
|
printer.Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer.Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer->Print(vars, "// source: $filename$\n"); |
|
|
|
|
printer->Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer->Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer->Print(vars, "\n"); |
|
|
|
|
printer->Print(vars, "#include \"$filename_base$.pb.h\"\n"); |
|
|
|
|
printer->Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
grpc::string GetHeaderIncludes(File *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
auto printer = file->CreatePrinter(&output); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
static const char *headers_strs[] = { |
|
|
|
@ -151,42 +129,38 @@ grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
"grpc++/impl/codegen/sync_stream.h" |
|
|
|
|
}; |
|
|
|
|
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs)); |
|
|
|
|
PrintIncludes(&printer, headers, params); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer.Print(vars, "namespace grpc {\n"); |
|
|
|
|
printer.Print(vars, "class CompletionQueue;\n"); |
|
|
|
|
printer.Print(vars, "class Channel;\n"); |
|
|
|
|
printer.Print(vars, "class RpcService;\n"); |
|
|
|
|
printer.Print(vars, "class ServerCompletionQueue;\n"); |
|
|
|
|
printer.Print(vars, "class ServerContext;\n"); |
|
|
|
|
printer.Print(vars, "} // namespace grpc\n\n"); |
|
|
|
|
PrintIncludes(printer.get(), headers, params); |
|
|
|
|
printer->Print(vars, "\n"); |
|
|
|
|
printer->Print(vars, "namespace grpc {\n"); |
|
|
|
|
printer->Print(vars, "class CompletionQueue;\n"); |
|
|
|
|
printer->Print(vars, "class Channel;\n"); |
|
|
|
|
printer->Print(vars, "class RpcService;\n"); |
|
|
|
|
printer->Print(vars, "class ServerCompletionQueue;\n"); |
|
|
|
|
printer->Print(vars, "class ServerContext;\n"); |
|
|
|
|
printer->Print(vars, "} // namespace grpc\n\n"); |
|
|
|
|
|
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
std::vector<grpc::string> parts = |
|
|
|
|
grpc_generator::tokenize(file->package(), "."); |
|
|
|
|
std::vector<grpc::string> parts = file->package_parts(); |
|
|
|
|
|
|
|
|
|
for (auto part = parts.begin(); part != parts.end(); part++) { |
|
|
|
|
vars["part"] = *part; |
|
|
|
|
printer.Print(vars, "namespace $part$ {\n"); |
|
|
|
|
printer->Print(vars, "namespace $part$ {\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer->Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderClientMethodInterfaces( |
|
|
|
|
grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
Printer *printer, const Method *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars, bool is_public) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
|
(*vars)["Response"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->output_type(), true); |
|
|
|
|
(*vars)["Request"] = method->input_type_name(); |
|
|
|
|
(*vars)["Response"] = method->output_type_name(); |
|
|
|
|
|
|
|
|
|
if (is_public) { |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"virtual ::grpc::Status $Method$(::grpc::ClientContext* context, " |
|
|
|
@ -204,7 +178,7 @@ void PrintHeaderClientMethodInterfaces( |
|
|
|
|
"Async$Method$Raw(context, request, cq));\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientWriterInterface< $Request$>>" |
|
|
|
@ -230,7 +204,7 @@ void PrintHeaderClientMethodInterfaces( |
|
|
|
|
"Async$Method$Raw(context, response, cq, tag));\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientReaderInterface< $Response$>>" |
|
|
|
@ -256,7 +230,7 @@ void PrintHeaderClientMethodInterfaces( |
|
|
|
|
"Async$Method$Raw(context, request, cq, tag));\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientReaderWriterInterface< " |
|
|
|
|
"$Request$, $Response$>> " |
|
|
|
@ -285,14 +259,14 @@ void PrintHeaderClientMethodInterfaces( |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"virtual ::grpc::ClientAsyncResponseReaderInterface< $Response$>* " |
|
|
|
|
"Async$Method$Raw(::grpc::ClientContext* context, " |
|
|
|
|
"const $Request$& request, " |
|
|
|
|
"::grpc::CompletionQueue* cq) = 0;\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"virtual ::grpc::ClientWriterInterface< $Request$>*" |
|
|
|
@ -303,7 +277,7 @@ void PrintHeaderClientMethodInterfaces( |
|
|
|
|
" Async$Method$Raw(::grpc::ClientContext* context, " |
|
|
|
|
"$Response$* response, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) = 0;\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"virtual ::grpc::ClientReaderInterface< $Response$>* $Method$Raw(" |
|
|
|
@ -314,7 +288,7 @@ void PrintHeaderClientMethodInterfaces( |
|
|
|
|
"Async$Method$Raw(" |
|
|
|
|
"::grpc::ClientContext* context, const $Request$& request, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) = 0;\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"virtual ::grpc::ClientReaderWriterInterface< $Request$, " |
|
|
|
|
"$Response$>* " |
|
|
|
@ -328,17 +302,15 @@ void PrintHeaderClientMethodInterfaces( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
void PrintHeaderClientMethod(Printer *printer, |
|
|
|
|
const Method *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars, |
|
|
|
|
bool is_public) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
|
(*vars)["Response"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->output_type(), true); |
|
|
|
|
(*vars)["Request"] = method->input_type_name(); |
|
|
|
|
(*vars)["Response"] = method->output_type_name(); |
|
|
|
|
if (is_public) { |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"::grpc::Status $Method$(::grpc::ClientContext* context, " |
|
|
|
@ -356,7 +328,7 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"Async$Method$Raw(context, request, cq));\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientWriter< $Request$>>" |
|
|
|
@ -380,7 +352,7 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"Async$Method$Raw(context, response, cq, tag));\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientReader< $Response$>>" |
|
|
|
@ -406,7 +378,7 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"Async$Method$Raw(context, request, cq, tag));\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"std::unique_ptr< ::grpc::ClientReaderWriter< $Request$, $Response$>>" |
|
|
|
@ -432,13 +404,13 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::ClientAsyncResponseReader< $Response$>* " |
|
|
|
|
"Async$Method$Raw(::grpc::ClientContext* context, " |
|
|
|
|
"const $Request$& request, " |
|
|
|
|
"::grpc::CompletionQueue* cq) GRPC_OVERRIDE;\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::ClientWriter< $Request$>* $Method$Raw(" |
|
|
|
|
"::grpc::ClientContext* context, $Response$* response) " |
|
|
|
@ -448,7 +420,7 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"::grpc::ClientAsyncWriter< $Request$>* Async$Method$Raw(" |
|
|
|
|
"::grpc::ClientContext* context, $Response$* response, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE;\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::ClientReader< $Response$>* $Method$Raw(" |
|
|
|
|
"::grpc::ClientContext* context, const $Request$& request)" |
|
|
|
@ -458,7 +430,7 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"::grpc::ClientAsyncReader< $Response$>* Async$Method$Raw(" |
|
|
|
|
"::grpc::ClientContext* context, const $Request$& request, " |
|
|
|
|
"::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE;\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"::grpc::ClientReaderWriter< $Request$, $Response$>* " |
|
|
|
@ -472,38 +444,34 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderClientMethodData(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
void PrintHeaderClientMethodData(Printer *printer, const Method *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
printer->Print(*vars, "const ::grpc::RpcMethod rpcmethod_$Method$_;\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderServerMethodSync(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
void PrintHeaderServerMethodSync(Printer *printer, const Method *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
|
(*vars)["Response"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->output_type(), true); |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
(*vars)["Request"] = method->input_type_name(); |
|
|
|
|
(*vars)["Response"] = method->output_type_name(); |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"virtual ::grpc::Status $Method$(" |
|
|
|
|
"::grpc::ServerContext* context, const $Request$* request, " |
|
|
|
|
"$Response$* response);\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"virtual ::grpc::Status $Method$(" |
|
|
|
|
"::grpc::ServerContext* context, " |
|
|
|
|
"::grpc::ServerReader< $Request$>* reader, " |
|
|
|
|
"$Response$* response);\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"virtual ::grpc::Status $Method$(" |
|
|
|
|
"::grpc::ServerContext* context, const $Request$* request, " |
|
|
|
|
"::grpc::ServerWriter< $Response$>* writer);\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"virtual ::grpc::Status $Method$(" |
|
|
|
@ -514,20 +482,18 @@ void PrintHeaderServerMethodSync(grpc::protobuf::io::Printer *printer, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderServerMethodAsync( |
|
|
|
|
grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
Printer *printer, |
|
|
|
|
const Method *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
|
(*vars)["Response"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->output_type(), true); |
|
|
|
|
(*vars)["Request"] = method->input_type_name(); |
|
|
|
|
(*vars)["Response"] = method->output_type_name(); |
|
|
|
|
printer->Print(*vars, "template <class BaseClass>\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"class WithAsyncMethod_$Method$ : public BaseClass {\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
" private:\n" |
|
|
|
|
" void BaseClassMustBeDerivedFromService(Service *service) {}\n"); |
|
|
|
|
" void BaseClassMustBeDerivedFromService(const Service *service) {}\n"); |
|
|
|
|
printer->Print(" public:\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(*vars, |
|
|
|
@ -538,7 +504,7 @@ void PrintHeaderServerMethodAsync( |
|
|
|
|
"~WithAsyncMethod_$Method$() GRPC_OVERRIDE {\n" |
|
|
|
|
" BaseClassMustBeDerivedFromService(this);\n" |
|
|
|
|
"}\n"); |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"// disable synchronous version of this method\n" |
|
|
|
@ -559,7 +525,7 @@ void PrintHeaderServerMethodAsync( |
|
|
|
|
" ::grpc::Service::RequestAsyncUnary($Idx$, context, " |
|
|
|
|
"request, response, new_call_cq, notification_cq, tag);\n"); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"// disable synchronous version of this method\n" |
|
|
|
@ -581,7 +547,7 @@ void PrintHeaderServerMethodAsync( |
|
|
|
|
" ::grpc::Service::RequestAsyncClientStreaming($Idx$, " |
|
|
|
|
"context, reader, new_call_cq, notification_cq, tag);\n"); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"// disable synchronous version of this method\n" |
|
|
|
@ -604,7 +570,7 @@ void PrintHeaderServerMethodAsync( |
|
|
|
|
" ::grpc::Service::RequestAsyncServerStreaming($Idx$, " |
|
|
|
|
"context, request, writer, new_call_cq, notification_cq, tag);\n"); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"// disable synchronous version of this method\n" |
|
|
|
@ -632,20 +598,18 @@ void PrintHeaderServerMethodAsync( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderServerMethodGeneric( |
|
|
|
|
grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
Printer *printer, |
|
|
|
|
const Method *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
|
(*vars)["Response"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->output_type(), true); |
|
|
|
|
(*vars)["Request"] = method->input_type_name(); |
|
|
|
|
(*vars)["Response"] = method->output_type_name(); |
|
|
|
|
printer->Print(*vars, "template <class BaseClass>\n"); |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"class WithGenericMethod_$Method$ : public BaseClass {\n"); |
|
|
|
|
printer->Print( |
|
|
|
|
" private:\n" |
|
|
|
|
" void BaseClassMustBeDerivedFromService(Service *service) {}\n"); |
|
|
|
|
" void BaseClassMustBeDerivedFromService(const Service *service) {}\n"); |
|
|
|
|
printer->Print(" public:\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(*vars, |
|
|
|
@ -656,7 +620,7 @@ void PrintHeaderServerMethodGeneric( |
|
|
|
|
"~WithGenericMethod_$Method$() GRPC_OVERRIDE {\n" |
|
|
|
|
" BaseClassMustBeDerivedFromService(this);\n" |
|
|
|
|
"}\n"); |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"// disable synchronous version of this method\n" |
|
|
|
@ -666,7 +630,7 @@ void PrintHeaderServerMethodGeneric( |
|
|
|
|
" abort();\n" |
|
|
|
|
" return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" |
|
|
|
|
"}\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"// disable synchronous version of this method\n" |
|
|
|
@ -677,7 +641,7 @@ void PrintHeaderServerMethodGeneric( |
|
|
|
|
" abort();\n" |
|
|
|
|
" return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" |
|
|
|
|
"}\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"// disable synchronous version of this method\n" |
|
|
|
@ -688,7 +652,7 @@ void PrintHeaderServerMethodGeneric( |
|
|
|
|
" abort();\n" |
|
|
|
|
" return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" |
|
|
|
|
"}\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"// disable synchronous version of this method\n" |
|
|
|
@ -704,8 +668,8 @@ void PrintHeaderServerMethodGeneric( |
|
|
|
|
printer->Print(*vars, "};\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::ServiceDescriptor *service, |
|
|
|
|
void PrintHeaderService(Printer *printer, |
|
|
|
|
const Service *service, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Service"] = service->name(); |
|
|
|
|
|
|
|
|
@ -721,13 +685,13 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print("virtual ~StubInterface() {}\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
PrintHeaderClientMethodInterfaces(printer, service->method(i), vars, true); |
|
|
|
|
PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, true); |
|
|
|
|
} |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("private:\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
PrintHeaderClientMethodInterfaces(printer, service->method(i), vars, false); |
|
|
|
|
PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, false); |
|
|
|
|
} |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("};\n"); |
|
|
|
@ -737,17 +701,17 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
printer->Indent(); |
|
|
|
|
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, true); |
|
|
|
|
PrintHeaderClientMethod(printer, service->method(i).get(), vars, true); |
|
|
|
|
} |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("\n private:\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print("std::shared_ptr< ::grpc::ChannelInterface> channel_;\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
PrintHeaderClientMethod(printer, service->method(i), vars, false); |
|
|
|
|
PrintHeaderClientMethod(printer, service->method(i).get(), vars, false); |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
PrintHeaderClientMethodData(printer, service->method(i), vars); |
|
|
|
|
PrintHeaderClientMethodData(printer, service->method(i).get(), vars); |
|
|
|
|
} |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("};\n"); |
|
|
|
@ -766,7 +730,7 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
printer->Print("Service();\n"); |
|
|
|
|
printer->Print("virtual ~Service();\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
PrintHeaderServerMethodSync(printer, service->method(i), vars); |
|
|
|
|
PrintHeaderServerMethodSync(printer, service->method(i).get(), vars); |
|
|
|
|
} |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("};\n"); |
|
|
|
@ -774,13 +738,13 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
// Server side - Asynchronous
|
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
(*vars)["Idx"] = as_string(i); |
|
|
|
|
PrintHeaderServerMethodAsync(printer, service->method(i), vars); |
|
|
|
|
PrintHeaderServerMethodAsync(printer, service->method(i).get(), vars); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printer->Print("typedef "); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
(*vars)["method_name"] = service->method(i)->name(); |
|
|
|
|
(*vars)["method_name"] = service->method(i).get()->name(); |
|
|
|
|
printer->Print(*vars, "WithAsyncMethod_$method_name$<"); |
|
|
|
|
} |
|
|
|
|
printer->Print("Service"); |
|
|
|
@ -792,20 +756,19 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
// Server side - Generic
|
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
(*vars)["Idx"] = as_string(i); |
|
|
|
|
PrintHeaderServerMethodGeneric(printer, service->method(i), vars); |
|
|
|
|
PrintHeaderServerMethodGeneric(printer, service->method(i).get(), vars); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("};\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
grpc::string GetHeaderServices(File *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
auto printer = file->CreatePrinter(&output); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
// Package string is empty or ends with a dot. It is used to fully qualify
|
|
|
|
|
// method names.
|
|
|
|
@ -816,80 +779,76 @@ grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
|
|
|
|
|
if (!params.services_namespace.empty()) { |
|
|
|
|
vars["services_namespace"] = params.services_namespace; |
|
|
|
|
printer.Print(vars, "\nnamespace $services_namespace$ {\n\n"); |
|
|
|
|
printer->Print(vars, "\nnamespace $services_namespace$ {\n\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < file->service_count(); ++i) { |
|
|
|
|
PrintHeaderService(&printer, file->service(i), &vars); |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
PrintHeaderService(printer.get(), file->service(i).get(), &vars); |
|
|
|
|
printer->Print("\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!params.services_namespace.empty()) { |
|
|
|
|
printer.Print(vars, "} // namespace $services_namespace$\n\n"); |
|
|
|
|
printer->Print(vars, "} // namespace $services_namespace$\n\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetHeaderEpilogue(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
grpc::string GetHeaderEpilogue(File *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
auto printer = file->CreatePrinter(&output); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_identifier"] = FilenameIdentifier(file->name()); |
|
|
|
|
vars["filename"] = file->filename(); |
|
|
|
|
vars["filename_identifier"] = FilenameIdentifier(file->filename()); |
|
|
|
|
|
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
std::vector<grpc::string> parts = |
|
|
|
|
grpc_generator::tokenize(file->package(), "."); |
|
|
|
|
std::vector<grpc::string> parts = file->package_parts(); |
|
|
|
|
|
|
|
|
|
for (auto part = parts.rbegin(); part != parts.rend(); part++) { |
|
|
|
|
vars["part"] = *part; |
|
|
|
|
printer.Print(vars, "} // namespace $part$\n"); |
|
|
|
|
printer->Print(vars, "} // namespace $part$\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer->Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer.Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer->Print(vars, "\n"); |
|
|
|
|
printer->Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetSourcePrologue(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
grpc::string GetSourcePrologue(File *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
auto printer = file->CreatePrinter(&output); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_base"] = grpc_generator::StripProto(file->name()); |
|
|
|
|
vars["filename"] = file->filename(); |
|
|
|
|
vars["filename_base"] = file->filename_without_ext(); |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "// Generated by the gRPC protobuf plugin.\n"); |
|
|
|
|
printer.Print(vars, |
|
|
|
|
printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n"); |
|
|
|
|
printer->Print(vars, |
|
|
|
|
"// If you make any local change, they will be lost.\n"); |
|
|
|
|
printer.Print(vars, "// source: $filename$\n\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.grpc.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer->Print(vars, "// source: $filename$\n\n"); |
|
|
|
|
printer->Print(vars, "#include \"$filename_base$.pb.h\"\n"); |
|
|
|
|
printer->Print(vars, "#include \"$filename_base$.grpc.pb.h\"\n"); |
|
|
|
|
printer->Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetSourceIncludes(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
grpc::string GetSourceIncludes(File *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
auto printer = file->CreatePrinter(&output); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
static const char *headers_strs[] = { |
|
|
|
@ -903,32 +862,29 @@ grpc::string GetSourceIncludes(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
"grpc++/impl/codegen/sync_stream.h" |
|
|
|
|
}; |
|
|
|
|
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs)); |
|
|
|
|
PrintIncludes(&printer, headers, params); |
|
|
|
|
PrintIncludes(printer.get(), headers, params); |
|
|
|
|
|
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
std::vector<grpc::string> parts = |
|
|
|
|
grpc_generator::tokenize(file->package(), "."); |
|
|
|
|
std::vector<grpc::string> parts = file->package_parts(); |
|
|
|
|
|
|
|
|
|
for (auto part = parts.begin(); part != parts.end(); part++) { |
|
|
|
|
vars["part"] = *part; |
|
|
|
|
printer.Print(vars, "namespace $part$ {\n"); |
|
|
|
|
printer->Print(vars, "namespace $part$ {\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer->Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintSourceClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
void PrintSourceClientMethod(Printer *printer, |
|
|
|
|
const Method *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
|
(*vars)["Response"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->output_type(), true); |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
(*vars)["Request"] = method->input_type_name(); |
|
|
|
|
(*vars)["Response"] = method->output_type_name(); |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::Status $ns$$Service$::Stub::$Method$(" |
|
|
|
|
"::grpc::ClientContext* context, " |
|
|
|
@ -951,7 +907,7 @@ void PrintSourceClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"rpcmethod_$Method$_, " |
|
|
|
|
"context, request);\n" |
|
|
|
|
"}\n\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::ClientWriter< $Request$>* " |
|
|
|
|
"$ns$$Service$::Stub::$Method$Raw(" |
|
|
|
@ -973,7 +929,7 @@ void PrintSourceClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"rpcmethod_$Method$_, " |
|
|
|
|
"context, response, tag);\n" |
|
|
|
|
"}\n\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"::grpc::ClientReader< $Response$>* " |
|
|
|
@ -996,7 +952,7 @@ void PrintSourceClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"rpcmethod_$Method$_, " |
|
|
|
|
"context, request, tag);\n" |
|
|
|
|
"}\n\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"::grpc::ClientReaderWriter< $Request$, $Response$>* " |
|
|
|
@ -1023,15 +979,13 @@ void PrintSourceClientMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
void PrintSourceServerMethod(Printer *printer, |
|
|
|
|
const Method *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
|
(*vars)["Response"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->output_type(), true); |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
(*vars)["Request"] = method->input_type_name(); |
|
|
|
|
(*vars)["Response"] = method->output_type_name(); |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::Status $ns$$Service$::Service::$Method$(" |
|
|
|
|
"::grpc::ServerContext* context, " |
|
|
|
@ -1043,7 +997,7 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
" return ::grpc::Status(" |
|
|
|
|
"::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); |
|
|
|
|
printer->Print("}\n\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::Status $ns$$Service$::Service::$Method$(" |
|
|
|
|
"::grpc::ServerContext* context, " |
|
|
|
@ -1056,7 +1010,7 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
" return ::grpc::Status(" |
|
|
|
|
"::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); |
|
|
|
|
printer->Print("}\n\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::Status $ns$$Service$::Service::$Method$(" |
|
|
|
|
"::grpc::ServerContext* context, " |
|
|
|
@ -1069,7 +1023,7 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
" return ::grpc::Status(" |
|
|
|
|
"::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); |
|
|
|
|
printer->Print("}\n\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"::grpc::Status $ns$$Service$::Service::$Method$(" |
|
|
|
|
"::grpc::ServerContext* context, " |
|
|
|
@ -1084,15 +1038,15 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::ServiceDescriptor *service, |
|
|
|
|
void PrintSourceService(Printer *printer, |
|
|
|
|
const Service *service, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["Service"] = service->name(); |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
(*vars)["Method"] = service->method(i).get()->name(); |
|
|
|
|
printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n"); |
|
|
|
|
} |
|
|
|
|
printer->Print(*vars, "};\n\n"); |
|
|
|
@ -1111,14 +1065,14 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(": channel_(channel)"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method = service->method(i); |
|
|
|
|
auto method = service->method(i); |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Idx"] = as_string(i); |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
(*vars)["StreamingType"] = "NORMAL_RPC"; |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
(*vars)["StreamingType"] = "CLIENT_STREAMING"; |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
(*vars)["StreamingType"] = "SERVER_STREAMING"; |
|
|
|
|
} else { |
|
|
|
|
(*vars)["StreamingType"] = "BIDI_STREAMING"; |
|
|
|
@ -1135,21 +1089,19 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
(*vars)["Idx"] = as_string(i); |
|
|
|
|
PrintSourceClientMethod(printer, service->method(i), vars); |
|
|
|
|
PrintSourceClientMethod(printer, service->method(i).get(), vars); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printer->Print(*vars, "$ns$$Service$::Service::Service() {\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(*vars, "(void)$prefix$$Service$_method_names;\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method = service->method(i); |
|
|
|
|
auto method = service->method(i); |
|
|
|
|
(*vars)["Idx"] = as_string(i); |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
|
(*vars)["Response"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->output_type(), true); |
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
|
(*vars)["Request"] = method->input_type_name(); |
|
|
|
|
(*vars)["Response"] = method->output_type_name(); |
|
|
|
|
if (method->NoStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"AddMethod(new ::grpc::RpcServiceMethod(\n" |
|
|
|
@ -1159,7 +1111,7 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"$Request$, " |
|
|
|
|
"$Response$>(\n" |
|
|
|
|
" std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n"); |
|
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ClientOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"AddMethod(new ::grpc::RpcServiceMethod(\n" |
|
|
|
@ -1168,7 +1120,7 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
" new ::grpc::ClientStreamingHandler< " |
|
|
|
|
"$ns$$Service$::Service, $Request$, $Response$>(\n" |
|
|
|
|
" std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n"); |
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
|
} else if (method->ServerOnlyStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"AddMethod(new ::grpc::RpcServiceMethod(\n" |
|
|
|
@ -1177,7 +1129,7 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
" new ::grpc::ServerStreamingHandler< " |
|
|
|
|
"$ns$$Service$::Service, $Request$, $Response$>(\n" |
|
|
|
|
" std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n"); |
|
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
|
} else if (method->BidiStreaming()) { |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
|
"AddMethod(new ::grpc::RpcServiceMethod(\n" |
|
|
|
@ -1195,17 +1147,16 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
"}\n\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
(*vars)["Idx"] = as_string(i); |
|
|
|
|
PrintSourceServerMethod(printer, service->method(i), vars); |
|
|
|
|
PrintSourceServerMethod(printer, service->method(i).get(), vars); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
grpc::string GetSourceServices(File *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
auto printer = file->CreatePrinter(&output); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
// Package string is empty or ends with a dot. It is used to fully qualify
|
|
|
|
|
// method names.
|
|
|
|
@ -1222,20 +1173,19 @@ grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < file->service_count(); ++i) { |
|
|
|
|
PrintSourceService(&printer, file->service(i), &vars); |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
PrintSourceService(printer.get(), file->service(i).get(), &vars); |
|
|
|
|
printer->Print("\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetSourceEpilogue(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
grpc::string GetSourceEpilogue(File *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string temp; |
|
|
|
|
|
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
std::vector<grpc::string> parts = |
|
|
|
|
grpc_generator::tokenize(file->package(), "."); |
|
|
|
|
std::vector<grpc::string> parts = file->package_parts(); |
|
|
|
|
|
|
|
|
|
for (auto part = parts.begin(); part != parts.end(); part++) { |
|
|
|
|
temp.append("} // namespace "); |
|
|
|
|