aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compiler/cpp_generator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/cpp_generator.cc')
-rw-r--r--src/compiler/cpp_generator.cc169
1 files changed, 93 insertions, 76 deletions
diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc
index f10824e6b0..891032343b 100644
--- a/src/compiler/cpp_generator.cc
+++ b/src/compiler/cpp_generator.cc
@@ -183,34 +183,40 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
printer->Print(*vars,
"::grpc::Status $Method$(::grpc::ClientContext* context, "
"const $Request$& request, $Response$* response);\n");
- printer->Print(*vars,
- "::grpc::ClientAsyncResponseReader< $Response$>* "
- "$Method$(::grpc::ClientContext* context, "
- "const $Request$& request, "
- "::grpc::CompletionQueue* cq, void* tag);\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientAsyncResponseReader< $Response$>> "
+ "$Method$(::grpc::ClientContext* context, "
+ "const $Request$& request, "
+ "::grpc::CompletionQueue* cq, void* tag);\n");
} else if (ClientOnlyStreaming(method)) {
- printer->Print(*vars,
- "::grpc::ClientWriter< $Request$>* $Method$("
- "::grpc::ClientContext* context, $Response$* response);\n");
- printer->Print(*vars,
- "::grpc::ClientAsyncWriter< $Request$>* $Method$("
- "::grpc::ClientContext* context, $Response$* response, "
- "::grpc::CompletionQueue* cq, void* tag);\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientWriter< $Request$>> $Method$("
+ "::grpc::ClientContext* context, $Response$* response);\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientAsyncWriter< $Request$>> $Method$("
+ "::grpc::ClientContext* context, $Response$* response, "
+ "::grpc::CompletionQueue* cq, void* tag);\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(
*vars,
- "::grpc::ClientReader< $Response$>* $Method$("
+ "std::unique_ptr< ::grpc::ClientReader< $Response$>> $Method$("
"::grpc::ClientContext* context, const $Request$& request);\n");
- printer->Print(*vars,
- "::grpc::ClientAsyncReader< $Response$>* $Method$("
- "::grpc::ClientContext* context, const $Request$& request, "
- "::grpc::CompletionQueue* cq, void* tag);\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientAsyncReader< $Response$>> $Method$("
+ "::grpc::ClientContext* context, const $Request$& request, "
+ "::grpc::CompletionQueue* cq, void* tag);\n");
} else if (BidiStreaming(method)) {
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientReaderWriter< $Request$, $Response$>> "
+ "$Method$(::grpc::ClientContext* context);\n");
printer->Print(*vars,
- "::grpc::ClientReaderWriter< $Request$, $Response$>* "
- "$Method$(::grpc::ClientContext* context);\n");
- printer->Print(*vars,
- "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>* "
+ "std::unique_ptr< ::grpc::ClientAsyncReaderWriter< "
+ "$Request$, $Response$>> "
"$Method$(::grpc::ClientContext* context, "
"::grpc::CompletionQueue* cq, void* tag);\n");
}
@@ -309,7 +315,8 @@ void PrintHeaderService(google::protobuf::io::Printer *printer,
printer->Outdent();
printer->Print("};\n");
printer->Print(
- "static Stub* NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& "
+ "static std::unique_ptr<Stub> NewStub(const std::shared_ptr< "
+ "::grpc::ChannelInterface>& "
"channel);\n");
printer->Print("\n");
@@ -380,91 +387,101 @@ void PrintSourceClientMethod(google::protobuf::io::Printer *printer,
"::grpc::RpcMethod($Service$_method_names[$Idx$]), "
"context, request, response);\n"
"}\n\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientAsyncResponseReader< $Response$>> "
+ "$Service$::Stub::$Method$(::grpc::ClientContext* context, "
+ "const $Request$& request, "
+ "::grpc::CompletionQueue* cq, void* tag) {\n");
printer->Print(*vars,
- "::grpc::ClientAsyncResponseReader< $Response$>* "
- "$Service$::Stub::$Method$(::grpc::ClientContext* context, "
- "const $Request$& request, "
- "::grpc::CompletionQueue* cq, void* tag) {\n");
- printer->Print(*vars,
- " return new ::grpc::ClientAsyncResponseReader< $Response$>("
+ " return std::unique_ptr< "
+ "::grpc::ClientAsyncResponseReader< $Response$>>(new "
+ "::grpc::ClientAsyncResponseReader< $Response$>("
"channel(), cq, "
"::grpc::RpcMethod($Service$_method_names[$Idx$]), "
- "context, request, tag);\n"
+ "context, request, tag));\n"
"}\n\n");
} else if (ClientOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "::grpc::ClientWriter< $Request$>* $Service$::Stub::$Method$("
- "::grpc::ClientContext* context, $Response$* response) {\n");
printer->Print(*vars,
- " return new ::grpc::ClientWriter< $Request$>("
+ "std::unique_ptr< ::grpc::ClientWriter< $Request$>> "
+ "$Service$::Stub::$Method$("
+ "::grpc::ClientContext* context, $Response$* response) {\n");
+ printer->Print(*vars,
+ " return std::unique_ptr< ::grpc::ClientWriter< "
+ "$Request$>>(new ::grpc::ClientWriter< $Request$>("
"channel(),"
"::grpc::RpcMethod($Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::CLIENT_STREAMING), "
- "context, response);\n"
+ "context, response));\n"
"}\n\n");
- printer->Print(
- *vars,
- "::grpc::ClientAsyncWriter< $Request$>* $Service$::Stub::$Method$("
- "::grpc::ClientContext* context, $Response$* response, "
- "::grpc::CompletionQueue* cq, void* tag) {\n");
printer->Print(*vars,
- " return new ::grpc::ClientAsyncWriter< $Request$>("
+ "std::unique_ptr< ::grpc::ClientAsyncWriter< $Request$>> "
+ "$Service$::Stub::$Method$("
+ "::grpc::ClientContext* context, $Response$* response, "
+ "::grpc::CompletionQueue* cq, void* tag) {\n");
+ printer->Print(*vars,
+ " return std::unique_ptr< ::grpc::ClientAsyncWriter< "
+ "$Request$>>(new ::grpc::ClientAsyncWriter< $Request$>("
"channel(), cq, "
"::grpc::RpcMethod($Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::CLIENT_STREAMING), "
- "context, response, tag);\n"
+ "context, response, tag));\n"
"}\n\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(
*vars,
- "::grpc::ClientReader< $Response$>* $Service$::Stub::$Method$("
+ "std::unique_ptr< ::grpc::ClientReader< $Response$>> "
+ "$Service$::Stub::$Method$("
"::grpc::ClientContext* context, const $Request$& request) {\n");
printer->Print(*vars,
- " return new ::grpc::ClientReader< $Response$>("
+ " return std::unique_ptr< ::grpc::ClientReader< "
+ "$Response$>>(new ::grpc::ClientReader< $Response$>("
"channel(),"
"::grpc::RpcMethod($Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::SERVER_STREAMING), "
- "context, request);\n"
+ "context, request));\n"
"}\n\n");
- printer->Print(
- *vars,
- "::grpc::ClientAsyncReader< $Response$>* $Service$::Stub::$Method$("
- "::grpc::ClientContext* context, const $Request$& request, "
- "::grpc::CompletionQueue* cq, void* tag) {\n");
printer->Print(*vars,
- " return new ::grpc::ClientAsyncReader< $Response$>("
+ "std::unique_ptr< ::grpc::ClientAsyncReader< $Response$>> "
+ "$Service$::Stub::$Method$("
+ "::grpc::ClientContext* context, const $Request$& request, "
+ "::grpc::CompletionQueue* cq, void* tag) {\n");
+ printer->Print(*vars,
+ " return std::unique_ptr< ::grpc::ClientAsyncReader< "
+ "$Response$>>(new ::grpc::ClientAsyncReader< $Response$>("
"channel(), cq, "
"::grpc::RpcMethod($Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::SERVER_STREAMING), "
- "context, request, tag);\n"
+ "context, request, tag));\n"
"}\n\n");
} else if (BidiStreaming(method)) {
printer->Print(
*vars,
- "::grpc::ClientReaderWriter< $Request$, $Response$>* "
+ "std::unique_ptr< ::grpc::ClientReaderWriter< $Request$, $Response$>> "
"$Service$::Stub::$Method$(::grpc::ClientContext* context) {\n");
- printer->Print(
- *vars,
- " return new ::grpc::ClientReaderWriter< $Request$, $Response$>("
- "channel(),"
- "::grpc::RpcMethod($Service$_method_names[$Idx$], "
- "::grpc::RpcMethod::RpcType::BIDI_STREAMING), "
- "context);\n"
- "}\n\n");
- printer->Print(
- *vars,
- "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>* "
- "$Service$::Stub::$Method$(::grpc::ClientContext* context, "
- "::grpc::CompletionQueue* cq, void* tag) {\n");
- printer->Print(
- *vars,
- " return new ::grpc::ClientAsyncReaderWriter< $Request$, $Response$>("
- "channel(), cq, "
- "::grpc::RpcMethod($Service$_method_names[$Idx$], "
- "::grpc::RpcMethod::RpcType::BIDI_STREAMING), "
- "context, tag);\n"
- "}\n\n");
+ printer->Print(*vars,
+ " return std::unique_ptr< ::grpc::ClientReaderWriter< "
+ "$Request$, $Response$>>(new ::grpc::ClientReaderWriter< "
+ "$Request$, $Response$>("
+ "channel(),"
+ "::grpc::RpcMethod($Service$_method_names[$Idx$], "
+ "::grpc::RpcMethod::RpcType::BIDI_STREAMING), "
+ "context));\n"
+ "}\n\n");
+ printer->Print(*vars,
+ "std::unique_ptr< ::grpc::ClientAsyncReaderWriter< "
+ "$Request$, $Response$>> "
+ "$Service$::Stub::$Method$(::grpc::ClientContext* context, "
+ "::grpc::CompletionQueue* cq, void* tag) {\n");
+ printer->Print(*vars,
+ " return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< "
+ "$Request$, $Response$>>(new "
+ "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>("
+ "channel(), cq, "
+ "::grpc::RpcMethod($Service$_method_names[$Idx$], "
+ "::grpc::RpcMethod::RpcType::BIDI_STREAMING), "
+ "context, tag));\n"
+ "}\n\n");
}
}
@@ -587,9 +604,9 @@ void PrintSourceService(google::protobuf::io::Printer *printer,
printer->Print(
*vars,
- "$Service$::Stub* $Service$::NewStub("
+ "std::unique_ptr< $Service$::Stub> $Service$::NewStub("
"const std::shared_ptr< ::grpc::ChannelInterface>& channel) {\n"
- " $Service$::Stub* stub = new $Service$::Stub();\n"
+ " std::unique_ptr< $Service$::Stub> stub(new $Service$::Stub());\n"
" stub->set_channel(channel);\n"
" return stub;\n"
"};\n\n");