GRPC C++  1.22.0-dev
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 {
29 
30 class ClientContext;
31 
32 namespace internal {
33 class RpcMethod;
35 template <class InputMessage, class OutputMessage>
37  ClientContext* context, const InputMessage& request,
38  OutputMessage* result) {
40  channel, method, context, request, result)
41  .status();
42 }
43 
44 template <class InputMessage, class OutputMessage>
46  public:
48  ClientContext* context, const InputMessage& request,
49  OutputMessage* result) {
52  nullptr}); // Pluckable completion queue
53  Call call(channel->CreateCall(method, context, &cq));
57  ops;
58  status_ = ops.SendMessagePtr(&request);
59  if (!status_.ok()) {
60  return;
61  }
62  ops.SendInitialMetadata(&context->send_initial_metadata_,
63  context->initial_metadata_flags());
64  ops.RecvInitialMetadata(context);
65  ops.RecvMessage(result);
66  ops.AllowNoMessage();
67  ops.ClientSendClose();
68  ops.ClientRecvStatus(context, &status_);
69  call.PerformOps(&ops);
70  cq.Pluck(&ops);
71  // Some of the ops might fail. If the ops fail in the core layer, status
72  // would reflect the error. But, if the ops fail in the C++ layer, the
73  // status would still be the same as the one returned by gRPC Core. This can
74  // happen if deserialization of the message fails.
75  // TODO(yashykt): If deserialization fails, but the status received is OK,
76  // then it might be a good idea to change the status to something better
77  // than StatusCode::UNIMPLEMENTED to reflect this.
78  if (!ops.got_message && status_.ok()) {
80  "No message returned for unary request");
81  }
82  }
83  Status status() { return status_; }
84 
85  private:
86  Status status_;
87 };
88 
89 } // namespace internal
90 } // namespace grpc
91 
92 #endif // GRPCPP_IMPL_CODEGEN_CLIENT_UNARY_CALL_H
Status status()
Definition: client_unary_call.h:83
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:826
#define GRPC_CQ_CURRENT_VERSION
Definition: grpc_types.h:711
Definition: grpc_types.h:713
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:179
::google::protobuf::util::Status Status
Definition: config_protobuf.h:96
Descriptor of an RPC method.
Definition: rpc_method.h:29
Definition: call_op_set.h:223
Events are popped out by calling grpc_completion_queue_pluck() API ONLY.
Definition: grpc_types.h:686
Definition: call_op_set.h:701
Definition: call_op_set.h:293
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
Codegen interface for grpc::Channel.
Definition: channel_interface.h:69
The completion queue will have an associated pollset and there is no restriction on the type of file ...
Definition: grpc_types.h:666
Definition: byte_buffer.h:41
Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, const InputMessage &request, OutputMessage *result)
Wrapper that performs a blocking unary call.
Definition: client_unary_call.h:36
Definition: call_op_set.h:599
BlockingUnaryCallImpl(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, const InputMessage &request, OutputMessage *result)
Definition: client_unary_call.h:47
bool ok() const
Is the status OK?
Definition: status.h:118
Definition: channel_interface.h:47
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue_impl.h:103
Did it work? If it didn&#39;t, why?
Definition: status.h:31
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:115
Definition: call_op_set.h:749
Straightforward wrapping of the C call object.
Definition: call.h:38