blob: 4b4b8dd427b0edf0f520639743189228367f9f04 [file] [log] [blame]
Yang Gao75e2f6d2015-03-19 07:04:38 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Yang Gao75e2f6d2015-03-19 07:04:38 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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
Yang Gao75e2f6d2015-03-19 07:04:38 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Yang Gao75e2f6d2015-03-19 07:04:38 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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.
Yang Gao75e2f6d2015-03-19 07:04:38 -070016 *
17 */
18
yang-g9e2f90c2015-08-21 15:35:03 -070019#include <grpc++/generic/generic_stub.h>
Yang Gao75e2f6d2015-03-19 07:04:38 -070020
21#include <grpc++/impl/rpc_method.h>
22
23namespace grpc {
24
Vijay Pai4b047a32017-08-21 22:34:37 -070025namespace {
26std::unique_ptr<GenericClientAsyncReaderWriter> CallInternal(
27 ChannelInterface* channel, ClientContext* context,
28 const grpc::string& method, CompletionQueue* cq, bool start, void* tag) {
29 return std::unique_ptr<GenericClientAsyncReaderWriter>(
Vijay Pai7a648852017-10-27 10:22:51 -070030 internal::ClientAsyncReaderWriterFactory<ByteBuffer, ByteBuffer>::Create(
Craig Tillerbaa14a92017-11-03 09:09:36 -070031 channel, cq,
32 internal::RpcMethod(method.c_str(),
33 internal::RpcMethod::BIDI_STREAMING),
Vijay Pai4b047a32017-08-21 22:34:37 -070034 context, start, tag));
35}
36
37} // namespace
38
Yang Gao75e2f6d2015-03-19 07:04:38 -070039// begin a call to a named method
40std::unique_ptr<GenericClientAsyncReaderWriter> GenericStub::Call(
Craig Tiller277d3cf2015-04-14 14:04:51 -070041 ClientContext* context, const grpc::string& method, CompletionQueue* cq,
42 void* tag) {
Vijay Pai4b047a32017-08-21 22:34:37 -070043 return CallInternal(channel_.get(), context, method, cq, true, tag);
44}
45
46// setup a call to a named method
47std::unique_ptr<GenericClientAsyncReaderWriter> GenericStub::PrepareCall(
48 ClientContext* context, const grpc::string& method, CompletionQueue* cq) {
49 return CallInternal(channel_.get(), context, method, cq, false, nullptr);
Yang Gao75e2f6d2015-03-19 07:04:38 -070050}
51
Vijay Pai2046d0b2017-09-19 15:30:11 -070052// setup a unary call to a named method
53std::unique_ptr<GenericClientAsyncResponseReader> GenericStub::PrepareUnaryCall(
54 ClientContext* context, const grpc::string& method,
55 const ByteBuffer& request, CompletionQueue* cq) {
56 return std::unique_ptr<GenericClientAsyncResponseReader>(
Vijay Pai7a648852017-10-27 10:22:51 -070057 internal::ClientAsyncResponseReaderFactory<ByteBuffer>::Create(
Vijay Pai06e174a2017-10-20 05:51:12 -070058 channel_.get(), cq,
59 internal::RpcMethod(method.c_str(), internal::RpcMethod::NORMAL_RPC),
Vijay Pai2046d0b2017-09-19 15:30:11 -070060 context, request, false));
61}
62
Craig Tiller277d3cf2015-04-14 14:04:51 -070063} // namespace grpc