GRPC C++  1.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 GRPCXX_IMPL_CODEGEN_CLIENT_UNARY_CALL_H
20 #define GRPCXX_IMPL_CODEGEN_CLIENT_UNARY_CALL_H
21 
27 
28 namespace grpc {
29 
30 class Channel;
31 class ClientContext;
32 class CompletionQueue;
33 class RpcMethod;
34 
36 template <class InputMessage, class OutputMessage>
38  ClientContext* context, const InputMessage& request,
39  OutputMessage* result) {
42  GRPC_CQ_DEFAULT_POLLING}); // Pluckable completion queue
43  Call call(channel->CreateCall(method, context, &cq));
47  ops;
48  Status status = ops.SendMessage(request);
49  if (!status.ok()) {
50  return status;
51  }
52  ops.SendInitialMetadata(context->send_initial_metadata_,
53  context->initial_metadata_flags());
54  ops.RecvInitialMetadata(context);
55  ops.RecvMessage(result);
56  ops.ClientSendClose();
57  ops.ClientRecvStatus(context, &status);
58  call.PerformOps(&ops);
59  if (cq.Pluck(&ops)) {
60  if (!ops.got_message && status.ok()) {
62  "No message returned for unary request");
63  }
64  } else {
65  GPR_CODEGEN_ASSERT(!status.ok());
66  }
67  return status;
68 }
69 
70 } // namespace grpc
71 
72 #endif // GRPCXX_IMPL_CODEGEN_CLIENT_UNARY_CALL_H
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:126
Definition: call.h:524
#define GRPC_CQ_CURRENT_VERSION
Definition: grpc_types.h:600
Definition: grpc_types.h:601
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:153
Definition: call.h:256
Events are popped out by calling grpc_completion_queue_pluck() API ONLY.
Definition: grpc_types.h:597
Definition: call.h:428
Straightforward wrapping of the C call object.
Definition: call.h:647
Codegen interface for grpc::Channel.
Definition: channel_interface.h:49
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:37
The completion queue will have an associated pollset and there is no restriction on the type of file ...
Definition: grpc_types.h:577
Primary implementaiton of CallOpSetInterface.
Definition: call.h:591
Definition: call.h:303
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:86
Descriptor of an RPC method.
Definition: rpc_method.h:29
bool ok() const
Is the status OK?
Definition: status.h:64
Did it work? If it didn't, why?
Definition: status.h:30
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:115
Definition: call.h:203
Definition: call.h:495