Merge pull request #28 from yang-g/codegen

Make cpp codegen consistent with protoc in template format.
pull/30/head^2
Tim Emiola 10 years ago
commit f1f7213a9d
  1. 83
      src/compiler/cpp_generator.cc
  2. 1
      src/core/support/log_posix.c
  3. 8
      test/core/util/test_config.c

@ -143,16 +143,16 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer* printer,
} else if (ClientOnlyStreaming(method)) { } else if (ClientOnlyStreaming(method)) {
printer->Print( printer->Print(
*vars, *vars,
"::grpc::ClientWriter<$Request$>* $Method$(" "::grpc::ClientWriter< $Request$>* $Method$("
"::grpc::ClientContext* context, $Response$* response);\n\n"); "::grpc::ClientContext* context, $Response$* response);\n\n");
} else if (ServerOnlyStreaming(method)) { } else if (ServerOnlyStreaming(method)) {
printer->Print( printer->Print(
*vars, *vars,
"::grpc::ClientReader<$Response$>* $Method$(" "::grpc::ClientReader< $Response$>* $Method$("
"::grpc::ClientContext* context, const $Request$* request);\n\n"); "::grpc::ClientContext* context, const $Request$* request);\n\n");
} else if (BidiStreaming(method)) { } else if (BidiStreaming(method)) {
printer->Print(*vars, printer->Print(*vars,
"::grpc::ClientReaderWriter<$Request$, $Response$>* " "::grpc::ClientReaderWriter< $Request$, $Response$>* "
"$Method$(::grpc::ClientContext* context);\n\n"); "$Method$(::grpc::ClientContext* context);\n\n");
} }
} }
@ -174,19 +174,20 @@ void PrintHeaderServerMethod(google::protobuf::io::Printer* printer,
printer->Print(*vars, printer->Print(*vars,
"virtual ::grpc::Status $Method$(" "virtual ::grpc::Status $Method$("
"::grpc::ServerContext* context, " "::grpc::ServerContext* context, "
"::grpc::ServerReader<$Request$>* reader, " "::grpc::ServerReader< $Request$>* reader, "
"$Response$* response);\n"); "$Response$* response);\n");
} else if (ServerOnlyStreaming(method)) { } else if (ServerOnlyStreaming(method)) {
printer->Print(*vars, printer->Print(*vars,
"virtual ::grpc::Status $Method$(" "virtual ::grpc::Status $Method$("
"::grpc::ServerContext* context, const $Request$* request, " "::grpc::ServerContext* context, const $Request$* request, "
"::grpc::ServerWriter<$Response$>* writer);\n"); "::grpc::ServerWriter< $Response$>* writer);\n");
} else if (BidiStreaming(method)) { } else if (BidiStreaming(method)) {
printer->Print(*vars, printer->Print(
"virtual ::grpc::Status $Method$(" *vars,
"::grpc::ServerContext* context, " "virtual ::grpc::Status $Method$("
"::grpc::ServerReaderWriter<$Response$, $Request$>* stream);" "::grpc::ServerContext* context, "
"\n"); "::grpc::ServerReaderWriter< $Response$, $Request$>* stream);"
"\n");
} }
} }
@ -211,7 +212,7 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
printer->Outdent(); printer->Outdent();
printer->Print("};\n"); printer->Print("};\n");
printer->Print( printer->Print(
"static Stub* NewStub(const std::shared_ptr<::grpc::ChannelInterface>& " "static Stub* NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& "
"channel);\n"); "channel);\n");
printer->Print("\n"); printer->Print("\n");
@ -269,11 +270,12 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
"context, request, response);\n" "context, request, response);\n"
"}\n\n"); "}\n\n");
} else if (ClientOnlyStreaming(method)) { } else if (ClientOnlyStreaming(method)) {
printer->Print(
*vars,
"::grpc::ClientWriter< $Request$>* $Service$::Stub::$Method$("
"::grpc::ClientContext* context, $Response$* response) {\n");
printer->Print(*vars, printer->Print(*vars,
"::grpc::ClientWriter<$Request$>* $Service$::Stub::$Method$(" " return new ::grpc::ClientWriter< $Request$>("
"::grpc::ClientContext* context, $Response$* response) {\n");
printer->Print(*vars,
" return new ::grpc::ClientWriter<$Request$>("
"channel()->CreateStream(" "channel()->CreateStream("
"::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", " "::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", "
"::grpc::RpcMethod::RpcType::CLIENT_STREAMING), " "::grpc::RpcMethod::RpcType::CLIENT_STREAMING), "
@ -282,10 +284,10 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
} else if (ServerOnlyStreaming(method)) { } else if (ServerOnlyStreaming(method)) {
printer->Print( printer->Print(
*vars, *vars,
"::grpc::ClientReader<$Response$>* $Service$::Stub::$Method$(" "::grpc::ClientReader< $Response$>* $Service$::Stub::$Method$("
"::grpc::ClientContext* context, const $Request$* request) {\n"); "::grpc::ClientContext* context, const $Request$* request) {\n");
printer->Print(*vars, printer->Print(*vars,
" return new ::grpc::ClientReader<$Response$>(" " return new ::grpc::ClientReader< $Response$>("
"channel()->CreateStream(" "channel()->CreateStream("
"::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", " "::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", "
"::grpc::RpcMethod::RpcType::SERVER_STREAMING), " "::grpc::RpcMethod::RpcType::SERVER_STREAMING), "
@ -294,11 +296,11 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
} else if (BidiStreaming(method)) { } else if (BidiStreaming(method)) {
printer->Print( printer->Print(
*vars, *vars,
"::grpc::ClientReaderWriter<$Request$, $Response$>* " "::grpc::ClientReaderWriter< $Request$, $Response$>* "
"$Service$::Stub::$Method$(::grpc::ClientContext* context) {\n"); "$Service$::Stub::$Method$(::grpc::ClientContext* context) {\n");
printer->Print( printer->Print(
*vars, *vars,
" return new ::grpc::ClientReaderWriter<$Request$, $Response$>(" " return new ::grpc::ClientReaderWriter< $Request$, $Response$>("
"channel()->CreateStream(" "channel()->CreateStream("
"::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", " "::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", "
"::grpc::RpcMethod::RpcType::BIDI_STREAMING), " "::grpc::RpcMethod::RpcType::BIDI_STREAMING), "
@ -328,7 +330,7 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
printer->Print(*vars, printer->Print(*vars,
"::grpc::Status $Service$::Service::$Method$(" "::grpc::Status $Service$::Service::$Method$("
"::grpc::ServerContext* context, " "::grpc::ServerContext* context, "
"::grpc::ServerReader<$Request$>* reader, " "::grpc::ServerReader< $Request$>* reader, "
"$Response$* response) {\n"); "$Response$* response) {\n");
printer->Print( printer->Print(
" return ::grpc::Status(" " return ::grpc::Status("
@ -339,7 +341,7 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
"::grpc::Status $Service$::Service::$Method$(" "::grpc::Status $Service$::Service::$Method$("
"::grpc::ServerContext* context, " "::grpc::ServerContext* context, "
"const $Request$* request, " "const $Request$* request, "
"::grpc::ServerWriter<$Response$>* writer) {\n"); "::grpc::ServerWriter< $Response$>* writer) {\n");
printer->Print( printer->Print(
" return ::grpc::Status(" " return ::grpc::Status("
"::grpc::StatusCode::UNIMPLEMENTED);\n"); "::grpc::StatusCode::UNIMPLEMENTED);\n");
@ -348,7 +350,7 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
printer->Print(*vars, printer->Print(*vars,
"::grpc::Status $Service$::Service::$Method$(" "::grpc::Status $Service$::Service::$Method$("
"::grpc::ServerContext* context, " "::grpc::ServerContext* context, "
"::grpc::ServerReaderWriter<$Response$, $Request$>* " "::grpc::ServerReaderWriter< $Response$, $Request$>* "
"stream) {\n"); "stream) {\n");
printer->Print( printer->Print(
" return ::grpc::Status(" " return ::grpc::Status("
@ -361,13 +363,14 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
const google::protobuf::ServiceDescriptor* service, const google::protobuf::ServiceDescriptor* service,
map<string, string>* vars) { map<string, string>* vars) {
(*vars)["Service"] = service->name(); (*vars)["Service"] = service->name();
printer->Print(*vars, printer->Print(
"$Service$::Stub* $Service$::NewStub(" *vars,
"const std::shared_ptr<::grpc::ChannelInterface>& channel) {\n" "$Service$::Stub* $Service$::NewStub("
" $Service$::Stub* stub = new $Service$::Stub();\n" "const std::shared_ptr< ::grpc::ChannelInterface>& channel) {\n"
" stub->set_channel(channel);\n" " $Service$::Stub* stub = new $Service$::Stub();\n"
" return stub;\n" " stub->set_channel(channel);\n"
"};\n\n"); " return stub;\n"
"};\n\n");
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
PrintSourceClientMethod(printer, service->method(i), vars); PrintSourceClientMethod(printer, service->method(i), vars);
} }
@ -400,9 +403,9 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n" "service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
" \"/$Package$$Service$/$Method$\",\n" " \"/$Package$$Service$/$Method$\",\n"
" ::grpc::RpcMethod::NORMAL_RPC,\n" " ::grpc::RpcMethod::NORMAL_RPC,\n"
" new ::grpc::RpcMethodHandler<$Service$::Service, $Request$, " " new ::grpc::RpcMethodHandler< $Service$::Service, $Request$, "
"$Response$>(\n" "$Response$>(\n"
" std::function<::grpc::Status($Service$::Service*, " " std::function< ::grpc::Status($Service$::Service*, "
"::grpc::ServerContext*, const $Request$*, $Response$*)>(" "::grpc::ServerContext*, const $Request$*, $Response$*)>("
"&$Service$::Service::$Method$), this),\n" "&$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n"); " new $Request$, new $Response$));\n");
@ -412,11 +415,11 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n" "service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
" \"/$Package$$Service$/$Method$\",\n" " \"/$Package$$Service$/$Method$\",\n"
" ::grpc::RpcMethod::CLIENT_STREAMING,\n" " ::grpc::RpcMethod::CLIENT_STREAMING,\n"
" new ::grpc::ClientStreamingHandler<" " new ::grpc::ClientStreamingHandler< "
"$Service$::Service, $Request$, $Response$>(\n" "$Service$::Service, $Request$, $Response$>(\n"
" std::function<::grpc::Status($Service$::Service*, " " std::function< ::grpc::Status($Service$::Service*, "
"::grpc::ServerContext*, " "::grpc::ServerContext*, "
"::grpc::ServerReader<$Request$>*, $Response$*)>(" "::grpc::ServerReader< $Request$>*, $Response$*)>("
"&$Service$::Service::$Method$), this),\n" "&$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n"); " new $Request$, new $Response$));\n");
} else if (ServerOnlyStreaming(method)) { } else if (ServerOnlyStreaming(method)) {
@ -425,11 +428,11 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n" "service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
" \"/$Package$$Service$/$Method$\",\n" " \"/$Package$$Service$/$Method$\",\n"
" ::grpc::RpcMethod::SERVER_STREAMING,\n" " ::grpc::RpcMethod::SERVER_STREAMING,\n"
" new ::grpc::ServerStreamingHandler<" " new ::grpc::ServerStreamingHandler< "
"$Service$::Service, $Request$, $Response$>(\n" "$Service$::Service, $Request$, $Response$>(\n"
" std::function<::grpc::Status($Service$::Service*, " " std::function< ::grpc::Status($Service$::Service*, "
"::grpc::ServerContext*, " "::grpc::ServerContext*, "
"const $Request$*, ::grpc::ServerWriter<$Response$>*)>(" "const $Request$*, ::grpc::ServerWriter< $Response$>*)>("
"&$Service$::Service::$Method$), this),\n" "&$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n"); " new $Request$, new $Response$));\n");
} else if (BidiStreaming(method)) { } else if (BidiStreaming(method)) {
@ -438,11 +441,11 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n" "service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
" \"/$Package$$Service$/$Method$\",\n" " \"/$Package$$Service$/$Method$\",\n"
" ::grpc::RpcMethod::BIDI_STREAMING,\n" " ::grpc::RpcMethod::BIDI_STREAMING,\n"
" new ::grpc::BidiStreamingHandler<" " new ::grpc::BidiStreamingHandler< "
"$Service$::Service, $Request$, $Response$>(\n" "$Service$::Service, $Request$, $Response$>(\n"
" std::function<::grpc::Status($Service$::Service*, " " std::function< ::grpc::Status($Service$::Service*, "
"::grpc::ServerContext*, " "::grpc::ServerContext*, "
"::grpc::ServerReaderWriter<$Response$, $Request$>*)>(" "::grpc::ServerReaderWriter< $Response$, $Request$>*)>("
"&$Service$::Service::$Method$), this),\n" "&$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n"); " new $Request$, new $Response$));\n");
} }

@ -31,7 +31,6 @@
* *
*/ */
#ifndef _POSIX_C_SOURCE #ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#endif #endif

@ -39,16 +39,12 @@
#if GPR_GETPID_IN_UNISTD_H #if GPR_GETPID_IN_UNISTD_H
#include <unistd.h> #include <unistd.h>
static int seed() { static int seed() { return getpid(); }
return getpid();
}
#endif #endif
#if GPR_GETPID_IN_PROCESS_H #if GPR_GETPID_IN_PROCESS_H
#include <process.h> #include <process.h>
static int seed(void) { static int seed(void) { return _getpid(); }
return _getpid();
}
#endif #endif
void grpc_test_init(int argc, char **argv) { void grpc_test_init(int argc, char **argv) {

Loading…
Cancel
Save