GRPC C++  1.66.0
generic_stub.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 //
18 
19 #ifndef GRPCPP_GENERIC_GENERIC_STUB_H
20 #define GRPCPP_GENERIC_GENERIC_STUB_H
21 
22 #include <grpcpp/client_context.h>
24 #include <grpcpp/impl/rpc_method.h>
29 
30 namespace grpc {
31 
33 
37 
41 template <class RequestType, class ResponseType>
44  ResponseType> {
45  public:
47  RequestType, ResponseType>::TemplatedGenericStubCallbackInternal;
48 
53  std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
54  PrepareCall(ClientContext* context, const std::string& method,
56  return CallInternal(channel_.get(), context, method, /*options=*/{}, cq,
57  false, nullptr);
58  }
59 
64  std::unique_ptr<ClientAsyncResponseReader<ResponseType>> PrepareUnaryCall(
65  ClientContext* context, const std::string& method,
66  const RequestType& request, grpc::CompletionQueue* cq) {
67  return std::unique_ptr<ClientAsyncResponseReader<ResponseType>>(
68  internal::ClientAsyncResponseReaderHelper::Create<ResponseType>(
69  channel_.get(), cq,
70  grpc::internal::RpcMethod(method.c_str(),
71  /*suffix_for_stats=*/nullptr,
73  context, request));
74  }
75 
77  RequestType, ResponseType>::PrepareUnaryCall;
78 
85  std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>> Call(
86  ClientContext* context, const std::string& method,
87  grpc::CompletionQueue* cq, void* tag) {
88  return CallInternal(channel_.get(), context, method, /*options=*/{}, cq,
89  true, tag);
90  }
91 
92  private:
94  ResponseType>::channel_;
95 
96  std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
97  CallInternal(grpc::ChannelInterface* channel, ClientContext* context,
98  const std::string& method, StubOptions options,
99  grpc::CompletionQueue* cq, bool start, void* tag) {
100  return std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>(
102  Create(channel, cq,
104  method.c_str(), options.suffix_for_stats(),
106  context, start, tag));
107  }
108 };
109 
111 
112 } // namespace grpc
113 
114 #endif // GRPCPP_GENERIC_GENERIC_STUB_H
grpc::internal::TemplatedGenericStubCallbackInternal::TemplatedGenericStubCallbackInternal
TemplatedGenericStubCallbackInternal(std::shared_ptr< grpc::ChannelInterface > channel)
Definition: generic_stub_internal.h:46
grpc::internal::TemplatedGenericStubCallbackInternal
Generic stubs provide a type-unaware interface to call gRPC methods by name.
Definition: generic_stub_internal.h:44
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
stub_options.h
grpc::StubOptions::suffix_for_stats
const char * suffix_for_stats() const
Definition: stub_options.h:34
grpc::GenericClientAsyncResponseReader
ClientAsyncResponseReader< ByteBuffer > GenericClientAsyncResponseReader
Definition: generic_stub.h:36
rpc_method.h
grpc::internal::ClientAsyncReaderWriterFactory::Create
static ClientAsyncReaderWriter< W, R > * Create(grpc::ChannelInterface *channel, grpc::CompletionQueue *cq, const grpc::internal::RpcMethod &method, grpc::ClientContext *context, bool start, void *tag)
Create a stream object.
Definition: async_stream.h:497
grpc::StubOptions
Useful interface for generated stubs.
Definition: stub_options.h:25
grpc::internal::RpcMethod::BIDI_STREAMING
@ BIDI_STREAMING
Definition: rpc_method.h:35
grpc::ClientContext
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:195
grpc::ClientAsyncResponseReader
Async API for client-side unary RPCs, where the message response received from the server is of type ...
Definition: client_context.h:93
grpc::GenericClientAsyncReaderWriter
ClientAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericClientAsyncReaderWriter
Definition: generic_stub.h:32
grpc::ChannelInterface
Codegen interface for grpc::Channel.
Definition: channel_interface.h:71
async_unary_call.h
grpc::TemplatedGenericStub::PrepareCall
std::unique_ptr< ClientAsyncReaderWriter< RequestType, ResponseType > > PrepareCall(ClientContext *context, const std::string &method, grpc::CompletionQueue *cq)
Setup a call to a named method method using context, but don't start it.
Definition: generic_stub.h:54
generic_stub_internal.h
grpc::internal::RpcMethod::NORMAL_RPC
@ NORMAL_RPC
Definition: rpc_method.h:32
client_context.h
grpc::TemplatedGenericStub
Generic stubs provide a type-unaware interface to call gRPC methods by name.
Definition: generic_stub.h:42
grpc::ClientAsyncReaderWriter
Async client-side interface for bi-directional streaming, where the outgoing message stream going to ...
Definition: client_context.h:91
byte_buffer.h
grpc::GenericStub
TemplatedGenericStub< grpc::ByteBuffer, grpc::ByteBuffer > GenericStub
Definition: generic_stub.h:110
grpc::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:105
grpc::internal::RpcMethod
Descriptor of an RPC method.
Definition: rpc_method.h:29
grpc::TemplatedGenericStub::Call
std::unique_ptr< ClientAsyncReaderWriter< RequestType, ResponseType > > Call(ClientContext *context, const std::string &method, grpc::CompletionQueue *cq, void *tag)
DEPRECATED for multi-threaded use Begin a call to a named method method using context.
Definition: generic_stub.h:85
async_stream.h
grpc::TemplatedGenericStub::PrepareUnaryCall
std::unique_ptr< ClientAsyncResponseReader< ResponseType > > PrepareUnaryCall(ClientContext *context, const std::string &method, const RequestType &request, grpc::CompletionQueue *cq)
Setup a unary call to a named method method using context, and don't start it.
Definition: generic_stub.h:64