grpcpp/generic/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 <functional>
23 
24 #include <grpcpp/client_context.h>
26 #include <grpcpp/impl/rpc_method.h>
31 #include <grpcpp/support/status.h>
32 
33 namespace grpc {
34 
36 
40 
44 template <class RequestType, class ResponseType>
45 class TemplatedGenericStub final {
46  public:
47  explicit TemplatedGenericStub(std::shared_ptr<grpc::ChannelInterface> channel)
48  : channel_(channel) {}
49 
54  std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
57  return CallInternal(channel_.get(), context, method, /*options=*/{}, cq,
58  false, nullptr);
59  }
60 
65  std::unique_ptr<ClientAsyncResponseReader<ResponseType>> PrepareUnaryCall(
68  return std::unique_ptr<ClientAsyncResponseReader<ResponseType>>(
69  internal::ClientAsyncResponseReaderHelper::Create<ResponseType>(
70  channel_.get(), cq,
72  /*suffix_for_stats=*/nullptr,
74  context, request));
75  }
76 
83  std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>> Call(
85  grpc::CompletionQueue* cq, void* tag) {
86  return CallInternal(channel_.get(), context, method, /*options=*/{}, cq,
87  true, tag);
88  }
89 
95  std::function<void(grpc::Status)> on_completion) {
97  std::move(on_completion));
98  }
99 
108  reactor);
109  }
110 
118  }
119 
120  private:
121  std::shared_ptr<grpc::ChannelInterface> channel_;
122 
126  std::function<void(grpc::Status)> on_completion) {
128  channel_.get(),
129  grpc::internal::RpcMethod(method.c_str(), options.suffix_for_stats(),
131  context, request, response, std::move(on_completion));
132  }
133 
136  const RequestType* request,
138  ClientUnaryReactor* reactor) {
139  internal::ClientCallbackUnaryFactory::Create<RequestType, ResponseType>(
140  channel_.get(),
141  grpc::internal::RpcMethod(method.c_str(), options.suffix_for_stats(),
143  context, request, response, reactor);
144  }
145 
150  Create(channel_.get(),
152  method.c_str(), options.suffix_for_stats(),
154  context, reactor);
155  }
156 
157  std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
160  grpc::CompletionQueue* cq, bool start, void* tag) {
161  return std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>(
165  method.c_str(), options.suffix_for_stats(),
167  context, start, tag));
168  }
169 };
170 
172 
173 } // namespace grpc
174 
175 #endif // GRPCPP_GENERIC_GENERIC_STUB_H
grpc::ClientUnaryReactor
Definition: impl/codegen/client_callback.h:441
grpc._simple_stubs.RequestType
RequestType
Definition: _simple_stubs.py:27
grpc._simple_stubs.ResponseType
ResponseType
Definition: _simple_stubs.py:28
grpc
Definition: grpcpp/alarm.h:33
grpc::ClientBidiReactor
ClientBidiReactor is the interface for a bidirectional streaming RPC.
Definition: impl/codegen/client_callback.h:151
options
double_dict options[]
Definition: capstone_test.c:55
benchmark.request
request
Definition: benchmark.py:77
grpc::internal::ClientCallbackReaderWriterFactory::Create
static void Create(grpc::ChannelInterface *channel, const grpc::internal::RpcMethod &method, grpc::ClientContext *context, ClientBidiReactor< Request, Response > *reactor)
Definition: impl/codegen/client_callback.h:710
grpc::GenericClientAsyncResponseReader
ClientAsyncResponseReader< ByteBuffer > GenericClientAsyncResponseReader
Definition: grpcpp/generic/generic_stub.h:39
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::internal::CallbackUnaryCall
void CallbackUnaryCall(grpc::ChannelInterface *channel, const grpc::internal::RpcMethod &method, grpc::ClientContext *context, const InputMessage *request, OutputMessage *result, std::function< void(grpc::Status)> on_completion)
Definition: impl/codegen/client_callback.h:51
grpc::TemplatedGenericStub::PrepareBidiStreamingCall
void PrepareBidiStreamingCall(ClientContext *context, const std::string &method, StubOptions options, ClientBidiReactor< RequestType, ResponseType > *reactor)
Definition: grpcpp/generic/generic_stub.h:114
rpc_method.h
grpc::TemplatedGenericStub::channel_
std::shared_ptr< grpc::ChannelInterface > channel_
Definition: grpcpp/generic/generic_stub.h:121
client_callback.h
grpc::TemplatedGenericStub::UnaryCall
void UnaryCall(ClientContext *context, const std::string &method, StubOptions options, const RequestType *request, ResponseType *response, std::function< void(grpc::Status)> on_completion)
Definition: grpcpp/generic/generic_stub.h:92
start
static uint64_t start
Definition: benchmark-pound.c:74
grpc::internal::RpcMethod::NORMAL_RPC
@ NORMAL_RPC
Definition: grpcpp/impl/codegen/rpc_method.h:34
grpc::ChannelInterface
Codegen interface for grpc::Channel.
Definition: grpcpp/impl/codegen/channel_interface.h:73
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc::internal::RpcMethod
Descriptor of an RPC method.
Definition: grpcpp/impl/codegen/rpc_method.h:31
tag
static void * tag(intptr_t t)
Definition: bad_client.cc:318
grpc::TemplatedGenericStub::CallInternal
std::unique_ptr< ClientAsyncReaderWriter< RequestType, ResponseType > > CallInternal(grpc::ChannelInterface *channel, ClientContext *context, const std::string &method, StubOptions options, grpc::CompletionQueue *cq, bool start, void *tag)
Definition: grpcpp/generic/generic_stub.h:158
grpc::TemplatedGenericStub::PrepareUnaryCall
void PrepareUnaryCall(ClientContext *context, const std::string &method, StubOptions options, const RequestType *request, ResponseType *response, ClientUnaryReactor *reactor)
Definition: grpcpp/generic/generic_stub.h:104
grpc::GenericClientAsyncReaderWriter
ClientAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericClientAsyncReaderWriter
Definition: grpcpp/generic/generic_stub.h:35
async_unary_call.h
grpc::TemplatedGenericStub::PrepareCall
std::unique_ptr< ClientAsyncReaderWriter< RequestType, ResponseType > > PrepareCall(ClientContext *context, const std::string &method, grpc::CompletionQueue *cq)
Definition: grpcpp/generic/generic_stub.h:55
grpc::TemplatedGenericStub::PrepareUnaryCallInternal
void PrepareUnaryCallInternal(ClientContext *context, const std::string &method, StubOptions options, const RequestType *request, ResponseType *response, ClientUnaryReactor *reactor)
Definition: grpcpp/generic/generic_stub.h:134
grpc::ClientContext
Definition: grpcpp/impl/codegen/client_context.h:195
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)
Definition: grpcpp/impl/codegen/async_stream.h:495
client_context.h
stub_options.h
grpc::TemplatedGenericStub::UnaryCallInternal
void UnaryCallInternal(ClientContext *context, const std::string &method, StubOptions options, const RequestType *request, ResponseType *response, std::function< void(grpc::Status)> on_completion)
Definition: grpcpp/generic/generic_stub.h:123
grpc::TemplatedGenericStub::PrepareUnaryCall
std::unique_ptr< ClientAsyncResponseReader< ResponseType > > PrepareUnaryCall(ClientContext *context, const std::string &method, const RequestType &request, grpc::CompletionQueue *cq)
Definition: grpcpp/generic/generic_stub.h:65
grpc::ClientAsyncReaderWriter
Definition: grpcpp/impl/codegen/async_stream.h:513
asyncio_get_stats.response
response
Definition: asyncio_get_stats.py:28
grpc::GenericStub
TemplatedGenericStub< grpc::ByteBuffer, grpc::ByteBuffer > GenericStub
Definition: grpcpp/generic/generic_stub.h:171
grpc::TemplatedGenericStub::TemplatedGenericStub
TemplatedGenericStub(std::shared_ptr< grpc::ChannelInterface > channel)
Definition: grpcpp/generic/generic_stub.h:47
grpc::ClientAsyncResponseReader
Definition: grpcpp/impl/codegen/async_unary_call.h:37
grpc::StubOptions
Useful interface for generated stubs.
Definition: grpcpp/impl/codegen/stub_options.h:27
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc::TemplatedGenericStub::Call
std::unique_ptr< ClientAsyncReaderWriter< RequestType, ResponseType > > Call(ClientContext *context, const std::string &method, grpc::CompletionQueue *cq, void *tag)
Definition: grpcpp/generic/generic_stub.h:83
grpc::TemplatedGenericStub
Definition: grpcpp/generic/generic_stub.h:45
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
grpc::CompletionQueue
Definition: include/grpcpp/impl/codegen/completion_queue.h:104
grpc::TemplatedGenericStub::PrepareBidiStreamingCallInternal
void PrepareBidiStreamingCallInternal(ClientContext *context, const std::string &method, StubOptions options, ClientBidiReactor< RequestType, ResponseType > *reactor)
Definition: grpcpp/generic/generic_stub.h:146
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
async_stream.h
grpc::internal::RpcMethod::BIDI_STREAMING
@ BIDI_STREAMING
Definition: grpcpp/impl/codegen/rpc_method.h:37
method
NSString * method
Definition: ProtoMethod.h:28
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37
status.h
byte_buffer.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:28