grpcpp/impl/codegen/client_unary_call.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_IMPL_CODEGEN_CLIENT_UNARY_CALL_H
20 #define GRPCPP_IMPL_CODEGEN_CLIENT_UNARY_CALL_H
21 
22 // IWYU pragma: private, include <grpcpp/impl/client_unary_call.h>
23 
30 
31 namespace grpc {
32 
33 class ClientContext;
34 namespace internal {
35 class RpcMethod;
36 
42 template <class InputMessage, class OutputMessage,
43  class BaseInputMessage = InputMessage,
44  class BaseOutputMessage = OutputMessage>
47  const InputMessage& request, OutputMessage* result) {
49  "Invalid input message specification");
51  "Invalid output message specification");
54  .status();
55 }
56 
57 template <class InputMessage, class OutputMessage>
58 class BlockingUnaryCallImpl {
59  public:
62  const InputMessage& request, OutputMessage* result) {
65  nullptr}); // Pluckable completion queue
70  ops;
71  status_ = ops.SendMessagePtr(&request);
72  if (!status_.ok()) {
73  return;
74  }
75  ops.SendInitialMetadata(&context->send_initial_metadata_,
77  ops.RecvInitialMetadata(context);
78  ops.RecvMessage(result);
79  ops.AllowNoMessage();
80  ops.ClientSendClose();
81  ops.ClientRecvStatus(context, &status_);
82  call.PerformOps(&ops);
83  cq.Pluck(&ops);
84  // Some of the ops might fail. If the ops fail in the core layer, status
85  // would reflect the error. But, if the ops fail in the C++ layer, the
86  // status would still be the same as the one returned by gRPC Core. This can
87  // happen if deserialization of the message fails.
88  // TODO(yashykt): If deserialization fails, but the status received is OK,
89  // then it might be a good idea to change the status to something better
90  // than StatusCode::UNIMPLEMENTED to reflect this.
91  if (!ops.got_message && status_.ok()) {
93  "No message returned for unary request");
94  }
95  }
96  Status status() { return status_; }
97 
98  private:
100 };
101 
102 } // namespace internal
103 } // namespace grpc
104 
105 #endif // GRPCPP_IMPL_CODEGEN_CLIENT_UNARY_CALL_H
grpc::ClientContext::send_initial_metadata_
std::multimap< std::string, std::string > send_initial_metadata_
Definition: grpcpp/impl/codegen/client_context.h:502
grpc::internal::CallOpSendMessage
Definition: call_op_set.h:289
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
grpc::internal::BlockingUnaryCallImpl::status
Status status()
Definition: grpcpp/impl/codegen/client_unary_call.h:96
grpc
Definition: grpcpp/alarm.h:33
grpc::Status::ok
bool ok() const
Is the status OK?
Definition: include/grpcpp/impl/codegen/status.h:126
grpc::internal::BlockingUnaryCallImpl
Definition: grpcpp/impl/codegen/channel_interface.h:69
benchmark.request
request
Definition: benchmark.py:77
core_codegen_interface.h
config.h
call
FilterStackCall * call
Definition: call.cc:750
grpc::internal::CallOpClientRecvStatus
Definition: call_op_set.h:776
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
GRPC_CQ_DEFAULT_POLLING
@ GRPC_CQ_DEFAULT_POLLING
Definition: grpc_types.h:743
grpc::internal::RpcMethod
Descriptor of an RPC method.
Definition: grpcpp/impl/codegen/rpc_method.h:31
grpc::internal::CallOpRecvMessage
Definition: include/grpcpp/impl/codegen/byte_buffer.h:52
GRPC_CQ_PLUCK
@ GRPC_CQ_PLUCK
Definition: grpc_types.h:763
grpc::internal::Call
Straightforward wrapping of the C call object.
Definition: include/grpcpp/impl/codegen/call.h:37
grpc_completion_queue_attributes
Definition: grpc_types.h:791
grpc::internal::CallOpSet
Definition: call_op_set.h:859
grpc.StatusCode.UNIMPLEMENTED
tuple UNIMPLEMENTED
Definition: src/python/grpcio/grpc/__init__.py:276
grpc::internal::CallOpRecvInitialMetadata
Definition: call_op_set.h:728
grpc::ClientContext::initial_metadata_flags
uint32_t initial_metadata_flags() const
Definition: grpcpp/impl/codegen/client_context.h:474
grpc::ClientContext
Definition: grpcpp/impl/codegen/client_context.h:195
value
const char * value
Definition: hpack_parser_table.cc:165
status.h
grpc::internal::CallOpSendInitialMetadata
Definition: call_op_set.h:219
channel_interface.h
GRPC_CQ_CURRENT_VERSION
#define GRPC_CQ_CURRENT_VERSION
Definition: grpc_types.h:789
call_op_set.h
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc::internal::CallOpClientSendClose
Definition: call_op_set.h:626
grpc::internal::BlockingUnaryCallImpl::status_
Status status_
Definition: grpcpp/impl/codegen/client_unary_call.h:99
grpc::internal::BlockingUnaryCallImpl::BlockingUnaryCallImpl
BlockingUnaryCallImpl(ChannelInterface *channel, const RpcMethod &method, grpc::ClientContext *context, const InputMessage &request, OutputMessage *result)
Definition: grpcpp/impl/codegen/client_unary_call.h:60
internal
Definition: benchmark/test/output_test_helper.cc:20
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
grpc::CompletionQueue
Definition: include/grpcpp/impl/codegen/completion_queue.h:104
method
NSString * method
Definition: ProtoMethod.h:28
grpc::internal::BlockingUnaryCall
Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, grpc::ClientContext *context, const InputMessage &request, OutputMessage *result)
Definition: grpcpp/impl/codegen/client_unary_call.h:45
ops
static grpc_op ops[6]
Definition: test/core/fling/client.cc:39
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37
call.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:55