3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include <grpcpp/generic/generic_stub.h>
22 #include <grpcpp/impl/rpc_method.h>
23 #include <grpcpp/support/client_callback.h>
28 std::unique_ptr<grpc::GenericClientAsyncReaderWriter> CallInternal(
29 grpc::ChannelInterface* channel, grpc::ClientContext* context,
30 const grpc::string& method, grpc::CompletionQueue* cq, bool start,
32 return std::unique_ptr<grpc::GenericClientAsyncReaderWriter>(
33 grpc::internal::ClientAsyncReaderWriterFactory<grpc::ByteBuffer,
36 grpc::internal::RpcMethod(
37 method.c_str(), grpc::internal::RpcMethod::BIDI_STREAMING),
38 context, start, tag));
43 // begin a call to a named method
44 std::unique_ptr<grpc::GenericClientAsyncReaderWriter> GenericStub::Call(
45 grpc::ClientContext* context, const grpc::string& method,
46 grpc::CompletionQueue* cq, void* tag) {
47 return CallInternal(channel_.get(), context, method, cq, true, tag);
50 // setup a call to a named method
51 std::unique_ptr<grpc::GenericClientAsyncReaderWriter> GenericStub::PrepareCall(
52 grpc::ClientContext* context, const grpc::string& method,
53 grpc::CompletionQueue* cq) {
54 return CallInternal(channel_.get(), context, method, cq, false, nullptr);
57 // setup a unary call to a named method
58 std::unique_ptr<grpc::GenericClientAsyncResponseReader>
59 GenericStub::PrepareUnaryCall(grpc::ClientContext* context,
60 const grpc::string& method,
61 const grpc::ByteBuffer& request,
62 grpc::CompletionQueue* cq) {
63 return std::unique_ptr<grpc::GenericClientAsyncResponseReader>(
64 grpc::internal::ClientAsyncResponseReaderFactory<
65 grpc::ByteBuffer>::Create(channel_.get(), cq,
66 grpc::internal::RpcMethod(
68 grpc::internal::RpcMethod::NORMAL_RPC),
69 context, request, false));
72 void GenericStub::experimental_type::UnaryCall(
73 grpc::ClientContext* context, const grpc::string& method,
74 const grpc::ByteBuffer* request, grpc::ByteBuffer* response,
75 std::function<void(grpc::Status)> on_completion) {
76 grpc::internal::CallbackUnaryCall(
77 stub_->channel_.get(),
78 grpc::internal::RpcMethod(method.c_str(),
79 grpc::internal::RpcMethod::NORMAL_RPC),
80 context, request, response, std::move(on_completion));
83 void GenericStub::experimental_type::PrepareBidiStreamingCall(
84 grpc::ClientContext* context, const grpc::string& method,
85 grpc::experimental::ClientBidiReactor<grpc::ByteBuffer, grpc::ByteBuffer>*
87 grpc::internal::ClientCallbackReaderWriterFactory<
89 grpc::ByteBuffer>::Create(stub_->channel_.get(),
90 grpc::internal::RpcMethod(
92 grpc::internal::RpcMethod::BIDI_STREAMING),
96 } // namespace grpc_impl