GRPC C++  1.66.0
generic_stub_internal.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2024 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_IMPL_GENERIC_STUB_INTERNAL_H
20 #define GRPCPP_IMPL_GENERIC_STUB_INTERNAL_H
21 
22 #include <functional>
23 
24 #include <grpcpp/client_context.h>
25 #include <grpcpp/impl/rpc_method.h>
28 #include <grpcpp/support/status.h>
30 
31 namespace grpc {
32 
33 template <class RequestType, class ResponseType>
34 class TemplatedGenericStub;
35 template <class RequestType, class ResponseType>
36 class TemplatedGenericStubCallback;
37 
38 namespace internal {
39 
43 template <class RequestType, class ResponseType>
45  public:
47  std::shared_ptr<grpc::ChannelInterface> channel)
48  : channel_(channel) {}
49 
52  void UnaryCall(ClientContext* context, const std::string& method,
53  StubOptions options, const RequestType* request,
54  ResponseType* response,
55  std::function<void(grpc::Status)> on_completion) {
56  UnaryCallInternal(context, method, options, request, response,
57  std::move(on_completion));
58  }
59 
64  void PrepareUnaryCall(ClientContext* context, const std::string& method,
65  StubOptions options, const RequestType* request,
66  ResponseType* response, ClientUnaryReactor* reactor) {
67  PrepareUnaryCallInternal(context, method, options, request, response,
68  reactor);
69  }
70 
75  ClientContext* context, const std::string& method, StubOptions options,
77  PrepareBidiStreamingCallInternal(context, method, options, reactor);
78  }
79 
80  private:
81  template <class Req, class Resp>
83  template <class Req, class Resp>
85  std::shared_ptr<grpc::ChannelInterface> channel_;
86 
87  void UnaryCallInternal(ClientContext* context, const std::string& method,
88  StubOptions options, const RequestType* request,
89  ResponseType* response,
90  std::function<void(grpc::Status)> on_completion) {
92  channel_.get(),
93  grpc::internal::RpcMethod(method.c_str(), options.suffix_for_stats(),
95  context, request, response, std::move(on_completion));
96  }
97 
98  void PrepareUnaryCallInternal(ClientContext* context,
99  const std::string& method, StubOptions options,
100  const RequestType* request,
101  ResponseType* response,
102  ClientUnaryReactor* reactor) {
103  internal::ClientCallbackUnaryFactory::Create<RequestType, ResponseType>(
104  channel_.get(),
105  grpc::internal::RpcMethod(method.c_str(), options.suffix_for_stats(),
107  context, request, response, reactor);
108  }
109 
110  void PrepareBidiStreamingCallInternal(
111  ClientContext* context, const std::string& method, StubOptions options,
114  Create(channel_.get(),
116  method.c_str(), options.suffix_for_stats(),
118  context, reactor);
119  }
120 };
121 
122 } // namespace internal
123 } // namespace grpc
124 
125 #endif // GRPCPP_IMPL_GENERIC_STUB_INTERNAL_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::ClientUnaryReactor
ClientUnaryReactor is a reactor-style interface for a unary RPC.
Definition: client_callback.h:433
grpc::internal::ClientCallbackReaderWriterFactory::Create
static void Create(grpc::ChannelInterface *channel, const grpc::internal::RpcMethod &method, grpc::ClientContext *context, ClientBidiReactor< Request, Response > *reactor)
Definition: client_callback.h:704
grpc::StubOptions::suffix_for_stats
const char * suffix_for_stats() const
Definition: stub_options.h:34
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)
Perform a callback-based unary call.
Definition: client_callback.h:53
grpc::internal::TemplatedGenericStubCallbackInternal::PrepareBidiStreamingCall
void PrepareBidiStreamingCall(ClientContext *context, const std::string &method, StubOptions options, ClientBidiReactor< RequestType, ResponseType > *reactor)
Setup a call to a named method method using context and tied to reactor .
Definition: generic_stub_internal.h:74
status.h
rpc_method.h
grpc::StubOptions
Useful interface for generated stubs.
Definition: stub_options.h:25
client_callback.h
grpc::Status
Did it work? If it didn't, why?
Definition: status.h:34
grpc::internal::TemplatedGenericStubCallbackInternal::UnaryCall
void UnaryCall(ClientContext *context, const std::string &method, StubOptions options, const RequestType *request, ResponseType *response, std::function< void(grpc::Status)> on_completion)
Setup and start a unary call to a named method method using context and specifying the request and re...
Definition: generic_stub_internal.h:52
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::internal::TemplatedGenericStubCallbackInternal::PrepareUnaryCall
void PrepareUnaryCall(ClientContext *context, const std::string &method, StubOptions options, const RequestType *request, ResponseType *response, ClientUnaryReactor *reactor)
Setup a unary call to a named method method using context and specifying the request and response buf...
Definition: generic_stub_internal.h:64
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
byte_buffer.h
grpc::ClientBidiReactor
ClientBidiReactor is the interface for a bidirectional streaming RPC.
Definition: client_callback.h:143
grpc::internal::RpcMethod
Descriptor of an RPC method.
Definition: rpc_method.h:29
grpc::TemplatedGenericStubCallback
Generic stubs provide a type-unaware interface to call gRPC methods by name.
Definition: generic_stub_callback.h:31