GRPC C++  1.30.0
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 
27 
28 namespace grpc_impl {
29 
30 class ClientContext;
31 } // namespace grpc_impl
32 namespace grpc {
33 
34 namespace internal {
35 class RpcMethod;
37 template <class InputMessage, class OutputMessage>
39  grpc_impl::ClientContext* context,
40  const InputMessage& request, OutputMessage* result) {
42  channel, method, context, request, result)
43  .status();
44 }
45 
46 template <class InputMessage, class OutputMessage>
47 class BlockingUnaryCallImpl {
48  public:
50  grpc_impl::ClientContext* context,
51  const InputMessage& request, OutputMessage* result) {
54  nullptr}); // Pluckable completion queue
55  ::grpc::internal::Call call(channel->CreateCall(method, context, &cq));
59  ops;
60  status_ = ops.SendMessagePtr(&request);
61  if (!status_.ok()) {
62  return;
63  }
64  ops.SendInitialMetadata(&context->send_initial_metadata_,
65  context->initial_metadata_flags());
66  ops.RecvInitialMetadata(context);
67  ops.RecvMessage(result);
68  ops.AllowNoMessage();
69  ops.ClientSendClose();
70  ops.ClientRecvStatus(context, &status_);
71  call.PerformOps(&ops);
72  cq.Pluck(&ops);
73  // Some of the ops might fail. If the ops fail in the core layer, status
74  // would reflect the error. But, if the ops fail in the C++ layer, the
75  // status would still be the same as the one returned by gRPC Core. This can
76  // happen if deserialization of the message fails.
77  // TODO(yashykt): If deserialization fails, but the status received is OK,
78  // then it might be a good idea to change the status to something better
79  // than StatusCode::UNIMPLEMENTED to reflect this.
80  if (!ops.got_message && status_.ok()) {
82  "No message returned for unary request");
83  }
84  }
85  Status status() { return status_; }
86 
87  private:
88  Status status_;
89 };
90 
91 } // namespace internal
92 } // namespace grpc
93 
94 #endif // GRPCPP_IMPL_CODEGEN_CLIENT_UNARY_CALL_H
grpc::internal::CallOpRecvInitialMetadata
Definition: call_op_set.h:719
grpc::internal::CallOpClientSendClose
Definition: call_op_set.h:617
grpc
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
grpc::internal::CallOpSet
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:849
status.h
grpc::internal::CallOpSendMessage
Definition: call_op_set.h:286
grpc::internal::BlockingUnaryCall
Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, grpc_impl::ClientContext *context, const InputMessage &request, OutputMessage *result)
Wrapper that performs a blocking unary call.
Definition: client_unary_call.h:38
config.h
grpc::internal::BlockingUnaryCallImpl
Definition: channel_interface.h:70
grpc::internal::Call
Straightforward wrapping of the C call object.
Definition: call.h:38
core_codegen_interface.h
grpc::internal::CallOpSendInitialMetadata
Definition: call_op_set.h:216
grpc::Status::ok
bool ok() const
Is the status OK?
Definition: status.h:118
grpc::Status
Did it work? If it didn't, why?
Definition: status.h:31
GRPC_CQ_DEFAULT_POLLING
The completion queue will have an associated pollset and there is no restriction on the type of file ...
Definition: grpc_types.h:708
grpc::ChannelInterface
Codegen interface for grpc::Channel.
Definition: channel_interface.h:74
GRPC_CQ_PLUCK
Events are popped out by calling grpc_completion_queue_pluck() API ONLY.
Definition: grpc_types.h:728
grpc_completion_queue_attributes
Definition: grpc_types.h:759
grpc::protobuf::util::Status
::google::protobuf::util::Status Status
Definition: config_protobuf.h:90
grpc::UNIMPLEMENTED
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:115
grpc_impl::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue_impl.h:103
channel_interface.h
GRPC_CQ_CURRENT_VERSION
#define GRPC_CQ_CURRENT_VERSION
Definition: grpc_types.h:757
call.h
grpc::internal::CallOpClientRecvStatus
Definition: call_op_set.h:767
grpc_impl
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
grpc::internal::BlockingUnaryCallImpl::BlockingUnaryCallImpl
BlockingUnaryCallImpl(ChannelInterface *channel, const RpcMethod &method, grpc_impl::ClientContext *context, const InputMessage &request, OutputMessage *result)
Definition: client_unary_call.h:49
grpc_impl::ClientContext
A ClientContext allows the person implementing a service client to:
Definition: client_context_impl.h:184
grpc::internal::CallOpRecvMessage
Definition: byte_buffer.h:58
grpc::ClientContext
::grpc_impl::ClientContext ClientContext
Definition: client_context.h:26
grpc::internal::RpcMethod
Descriptor of an RPC method.
Definition: rpc_method.h:29
grpc::internal::BlockingUnaryCallImpl::status
Status status()
Definition: client_unary_call.h:85