diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-02-18 14:50:14 -0800 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-02-18 14:50:14 -0800 |
commit | 8a287d1a1bfbc2250abe43aa433397f68d07a632 (patch) | |
tree | 6b32636acbee57c60a7a098248774289576cadfe /src | |
parent | 1ff680a545c0212008bb568f198c91b48a27df89 (diff) | |
parent | 68bc778b63c1e82ec8c68cf9e2b9be23c0b9104d (diff) |
Merge pull request #588 from yang-g/c++api
Async client api change. Add a ClientAsyncResponseReader.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/cpp_generator.cc | 22 | ||||
-rw-r--r-- | src/cpp/client/client_unary_call.cc | 26 |
2 files changed, 13 insertions, 35 deletions
diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index aa764cbb33..b73b000a1c 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -127,6 +127,8 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) { "class ServerContext;\n"; if (HasUnaryCalls(file)) { temp.append( + "template <class OutMessage> class ClientAsyncResponseReader;\n"); + temp.append( "template <class OutMessage> class ServerAsyncResponseWriter;\n"); } if (HasClientOnlyStreaming(file)) { @@ -160,7 +162,8 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) { } std::string GetSourceIncludes() { - return "#include <grpc++/channel_interface.h>\n" + return "#include <grpc++/async_unary_call.h>\n" + "#include <grpc++/channel_interface.h>\n" "#include <grpc++/impl/client_unary_call.h>\n" "#include <grpc++/impl/rpc_method.h>\n" "#include <grpc++/impl/rpc_service_method.h>\n" @@ -181,9 +184,9 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer, "::grpc::Status $Method$(::grpc::ClientContext* context, " "const $Request$& request, $Response$* response);\n"); printer->Print(*vars, - "void $Method$(::grpc::ClientContext* context, " - "const $Request$& request, $Response$* response, " - "::grpc::Status* status, " + "::grpc::ClientAsyncResponseReader< $Response$>* " + "$Method$(::grpc::ClientContext* context, " + "const $Request$& request, " "::grpc::CompletionQueue* cq, void* tag);\n"); } else if (ClientOnlyStreaming(method)) { printer->Print(*vars, @@ -378,14 +381,15 @@ void PrintSourceClientMethod(google::protobuf::io::Printer *printer, "context, request, response);\n" "}\n\n"); printer->Print(*vars, - "void $Service$::Stub::$Method$(" - "::grpc::ClientContext* context, " - "const $Request$& request, $Response$* response, ::grpc::Status* status, " + "::grpc::ClientAsyncResponseReader< $Response$>* " + "$Service$::Stub::$Method$(::grpc::ClientContext* context, " + "const $Request$& request, " "::grpc::CompletionQueue* cq, void* tag) {\n"); printer->Print(*vars, - " ::grpc::AsyncUnaryCall(channel()," + " return new ClientAsyncResponseReader< $Response$>(" + "channel(), cq, " "::grpc::RpcMethod($Service$_method_names[$Idx$]), " - "context, request, response, status, cq, tag);\n" + "context, request, tag);\n" "}\n\n"); } else if (ClientOnlyStreaming(method)) { printer->Print( diff --git a/src/cpp/client/client_unary_call.cc b/src/cpp/client/client_unary_call.cc index 8fdd483474..08491f40f7 100644 --- a/src/cpp/client/client_unary_call.cc +++ b/src/cpp/client/client_unary_call.cc @@ -60,30 +60,4 @@ Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, GPR_ASSERT((cq.Pluck(&buf) && buf.got_message) || !status.IsOk()); return status; } - -class ClientAsyncRequest final : public CallOpBuffer { - public: - void FinalizeResult(void **tag, bool *status) override { - CallOpBuffer::FinalizeResult(tag, status); - delete this; - } -}; - -void AsyncUnaryCall(ChannelInterface *channel, const RpcMethod &method, - ClientContext *context, - const google::protobuf::Message &request, - google::protobuf::Message *result, Status *status, - CompletionQueue *cq, void *tag) { - ClientAsyncRequest *buf = new ClientAsyncRequest; - buf->Reset(tag); - Call call(channel->CreateCall(method, context, cq)); - buf->AddSendInitialMetadata(context); - buf->AddSendMessage(request); - buf->AddRecvInitialMetadata(context); - buf->AddRecvMessage(result); - buf->AddClientSendClose(); - buf->AddClientRecvStatus(context, status); - call.PerformOps(buf); -} - } // namespace grpc |