34 #ifndef GRPCXX_IMPL_CALL_H
35 #define GRPCXX_IMPL_CALL_H
37 #include <grpc/support/alloc.h>
59 std::multimap<grpc::string, grpc::string>* metadata);
61 const std::multimap<grpc::string, grpc::string>& metadata);
75 inline gpr_uint32
flags()
const {
83 SetBit(GRPC_WRITE_NO_COMPRESS);
91 ClearBit(GRPC_WRITE_NO_COMPRESS);
100 return GetBit(GRPC_WRITE_NO_COMPRESS);
108 SetBit(GRPC_WRITE_BUFFER_HINT);
117 ClearBit(GRPC_WRITE_BUFFER_HINT);
126 return GetBit(GRPC_WRITE_BUFFER_HINT);
135 void SetBit(
const gpr_int32 mask) {
139 void ClearBit(
const gpr_int32 mask) {
143 bool GetBit(
const gpr_int32 mask)
const {
144 return flags_ & mask;
155 void AddOp(grpc_op* ops,
size_t* nops) {}
156 void FinishOp(
bool* status,
int max_message_size) {}
164 const std::multimap<grpc::string, grpc::string>& metadata) {
171 void AddOp(grpc_op* ops,
size_t* nops) {
173 grpc_op* op = &ops[(*nops)++];
174 op->op = GRPC_OP_SEND_INITIAL_METADATA;
179 void FinishOp(
bool* status,
int max_message_size) {
204 void AddOp(grpc_op* ops,
size_t* nops) {
205 if (send_buf_ ==
nullptr)
return;
206 grpc_op* op = &ops[(*nops)++];
207 op->op = GRPC_OP_SEND_MESSAGE;
208 op->flags = write_options_.
flags();
209 op->data.send_message = send_buf_;
211 write_options_.
Clear();
213 void FinishOp(
bool* status,
int max_message_size) {
214 if (own_buf_) grpc_byte_buffer_destroy(send_buf_);
219 grpc_byte_buffer* send_buf_;
227 write_options_ = options;
246 void AddOp(grpc_op* ops,
size_t* nops) {
247 if (message_ ==
nullptr)
return;
248 grpc_op* op = &ops[(*nops)++];
249 op->op = GRPC_OP_RECV_MESSAGE;
251 op->data.recv_message = &recv_buf_;
254 void FinishOp(
bool* status,
int max_message_size) {
255 if (message_ ==
nullptr)
return;
264 grpc_byte_buffer_destroy(recv_buf_);
275 grpc_byte_buffer* recv_buf_;
278 namespace CallOpGenericRecvMessageHelper {
311 void AddOp(grpc_op* ops,
size_t* nops) {
312 if (!deserialize_)
return;
313 grpc_op* op = &ops[(*nops)++];
314 op->op = GRPC_OP_RECV_MESSAGE;
316 op->data.recv_message = &recv_buf_;
319 void FinishOp(
bool* status,
int max_message_size) {
320 if (!deserialize_)
return;
324 *status = deserialize_->Deserialize(recv_buf_, max_message_size).ok();
327 grpc_byte_buffer_destroy(recv_buf_);
333 deserialize_.reset();
337 std::unique_ptr<CallOpGenericRecvMessageHelper::DeserializeFunc> deserialize_;
338 grpc_byte_buffer* recv_buf_;
348 void AddOp(grpc_op* ops,
size_t* nops) {
350 grpc_op* op = &ops[(*nops)++];
351 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
354 void FinishOp(
bool* status,
int max_message_size) { send_ =
false; }
365 const std::multimap<grpc::string, grpc::string>& trailing_metadata,
367 trailing_metadata_count_ = trailing_metadata.size();
369 send_status_available_ =
true;
370 send_status_code_ =
static_cast<grpc_status_code
>(status.
error_code());
375 void AddOp(grpc_op* ops,
size_t* nops) {
376 if (!send_status_available_)
return;
377 grpc_op* op = &ops[(*nops)++];
378 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
379 op->data.send_status_from_server.trailing_metadata_count =
380 trailing_metadata_count_;
381 op->data.send_status_from_server.trailing_metadata = trailing_metadata_;
382 op->data.send_status_from_server.status = send_status_code_;
383 op->data.send_status_from_server.status_details =
384 send_status_details_.empty() ?
nullptr : send_status_details_.c_str();
388 void FinishOp(
bool* status,
int max_message_size) {
389 if (!send_status_available_)
return;
390 gpr_free(trailing_metadata_);
391 send_status_available_ =
false;
395 bool send_status_available_;
396 grpc_status_code send_status_code_;
398 size_t trailing_metadata_count_;
399 grpc_metadata* trailing_metadata_;
407 context->initial_metadata_received_ =
true;
408 recv_initial_metadata_ = &context->recv_initial_metadata_;
412 void AddOp(grpc_op* ops,
size_t* nops) {
413 if (!recv_initial_metadata_)
return;
414 memset(&recv_initial_metadata_arr_, 0,
sizeof(recv_initial_metadata_arr_));
415 grpc_op* op = &ops[(*nops)++];
416 op->op = GRPC_OP_RECV_INITIAL_METADATA;
417 op->data.recv_initial_metadata = &recv_initial_metadata_arr_;
420 void FinishOp(
bool* status,
int max_message_size) {
421 if (recv_initial_metadata_ ==
nullptr)
return;
423 recv_initial_metadata_ =
nullptr;
427 std::multimap<grpc::string, grpc::string>* recv_initial_metadata_;
428 grpc_metadata_array recv_initial_metadata_arr_;
436 recv_trailing_metadata_ = &context->trailing_metadata_;
437 recv_status_ = status;
441 void AddOp(grpc_op* ops,
size_t* nops) {
442 if (recv_status_ ==
nullptr)
return;
443 memset(&recv_trailing_metadata_arr_, 0,
444 sizeof(recv_trailing_metadata_arr_));
445 status_details_ =
nullptr;
446 status_details_capacity_ = 0;
447 grpc_op* op = &ops[(*nops)++];
448 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
449 op->data.recv_status_on_client.trailing_metadata =
450 &recv_trailing_metadata_arr_;
451 op->data.recv_status_on_client.status = &status_code_;
452 op->data.recv_status_on_client.status_details = &status_details_;
453 op->data.recv_status_on_client.status_details_capacity =
454 &status_details_capacity_;
458 void FinishOp(
bool* status,
int max_message_size) {
459 if (recv_status_ ==
nullptr)
return;
460 FillMetadataMap(&recv_trailing_metadata_arr_, recv_trailing_metadata_);
462 static_cast<StatusCode>(status_code_),
464 gpr_free(status_details_);
465 recv_status_ =
nullptr;
469 std::multimap<grpc::string, grpc::string>* recv_trailing_metadata_;
471 grpc_metadata_array recv_trailing_metadata_arr_;
472 grpc_status_code status_code_;
473 char* status_details_;
474 size_t status_details_capacity_;
487 virtual void FillOps(grpc_op* ops,
size_t* nops) = 0;
503 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
504 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
505 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
516 this->Op1::AddOp(ops, nops);
517 this->Op2::AddOp(ops, nops);
518 this->Op3::AddOp(ops, nops);
519 this->Op4::AddOp(ops, nops);
520 this->Op5::AddOp(ops, nops);
521 this->Op6::AddOp(ops, nops);
545 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
546 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
547 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
549 :
public CallOpSet<Op1, Op2, Op3, Op4, Op5, Op6> {
553 return Base::FinalizeResult(tag, status) &&
false;
574 grpc_call*
call() {
return call_; }
583 int max_message_size_;
588 #endif // GRPCXX_IMPL_CALL_H
void ServerSendStatus(const std::multimap< grpc::string, grpc::string > &trailing_metadata, const Status &status)
Definition: call.h:364
Call(grpc_call *call, CallHook *call_hook_, CompletionQueue *cq)
void RecvMessage(R *message)
Definition: call.h:303
Definition: completion_queue.h:75
WriteOptions & clear_buffer_hint()
Clears flag indicating that the write may be buffered and need not go out on the wire immediately...
Definition: call.h:116
Default argument for CallOpSet.
Definition: call.h:153
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:348
CallOpServerSendStatus()
Definition: call.h:362
void FillMetadataMap(grpc_metadata_array *arr, std::multimap< grpc::string, grpc::string > *metadata)
WriteOptions & set_buffer_hint()
Sets flag indicating that the write may be buffered and need not go out on the wire immediately...
Definition: call.h:107
grpc::string error_message() const
Definition: status.h:53
CallOpSendMessage()
Definition: call.h:192
std::string string
Definition: config.h:112
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:311
CompletionQueue * cq()
Definition: call.h:575
void FinishOp(bool *status, int max_message_size)
Definition: call.h:319
WriteOptions & clear_no_compression()
Clears flag for the disabling of compression for the next message write.
Definition: call.h:90
int max_message_size_
Definition: call.h:494
bool FinalizeResult(void **tag, bool *status) GRPC_OVERRIDE
Definition: call.h:551
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:482
void FinishOp(bool *status, int max_message_size)
Definition: call.h:354
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:246
bool FinalizeResult(void **tag, bool *status) GRPC_OVERRIDE
Definition: call.h:524
void Clear()
Clear all flags.
Definition: call.h:70
void FinishOp(bool *status, int max_message_size)
Definition: call.h:213
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:375
WriteOptions()
Definition: call.h:66
#define GRPC_FINAL
Definition: config.h:71
void FillOps(grpc_op *ops, size_t *nops) GRPC_OVERRIDE
Fills in grpc_op, starting from ops[*nops] and moving upwards.
Definition: call.h:515
grpc_metadata * FillMetadataArray(const std::multimap< grpc::string, grpc::string > &metadata)
grpc_call * call()
Definition: call.h:574
WriteOptions & set_no_compression()
Sets flag for the disabling of compression for the next message write.
Definition: call.h:82
Definition: client_context.h:74
WriteOptions & operator=(const WriteOptions &rhs)
Definition: call.h:129
gpr_uint32 flags() const
Returns raw flags bitset.
Definition: call.h:75
void FinishOp(bool *status, int max_message_size)
Definition: call.h:458
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:64
CallOpClientRecvStatus()
Definition: call.h:433
bool get_no_compression() const
Get value for the flag indicating whether compression for the next message write is forcefully disabl...
Definition: call.h:99
Status Deserialize(grpc_byte_buffer *buf, int max_message_size) GRPC_OVERRIDE
Definition: call.h:288
CallOpSet()
Definition: call.h:514
void FinishOp(bool *status, int max_message_size)
Definition: call.h:388
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:441
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:155
CallOpSetInterface()
Definition: call.h:484
WriteOptions(const WriteOptions &other)
Definition: call.h:67
Primary implementaiton of CallOpSetInterface.
Definition: call.h:506
void ClientSendClose()
Definition: call.h:345
int max_message_size()
Definition: call.h:577
Per-message write options.
Definition: call.h:64
CallOpClientSendClose()
Definition: call.h:343
bool get_buffer_hint() const
Get value for the flag indicating that the write may be buffered and need not go out on the wire imme...
Definition: call.h:125
CallOpRecvMessage()
Definition: call.h:239
StatusCode error_code() const
Definition: status.h:52
Definition: completion_queue.h:87
Status SendMessage(const M &message, const WriteOptions &options) GRPC_MUST_USE_RESULT
Send message using options for the write.
Definition: call.h:225
virtual void PerformOpsOnCall(CallOpSetInterface *ops, Call *call)=0
void FinishOp(bool *status, int max_message_size)
Definition: call.h:156
bool got_message
Definition: call.h:243
void ClientRecvStatus(ClientContext *context, Status *status)
Definition: call.h:435
void PerformOps(CallOpSetInterface *ops)
void FinishOp(bool *status, int max_message_size)
Definition: call.h:254
void set_max_message_size(int max_message_size)
Definition: call.h:489
DeserializeFuncType(R *message)
Definition: call.h:287
virtual Status Deserialize(grpc_byte_buffer *buf, int max_message_size)=0
void RecvMessage(R *message)
Definition: call.h:241
CallOpGenericRecvMessage()
Definition: call.h:300
bool got_message
Definition: call.h:308
A CallOpSet that does not post completions to the completion queue.
Definition: call.h:548
virtual void FillOps(grpc_op *ops, size_t *nops)=0
Fills in grpc_op, starting from ops[*nops] and moving upwards.
void set_output_tag(void *return_tag)
Definition: call.h:535
#define GRPC_OVERRIDE
Definition: config.h:77
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:204
virtual ~CallHook()
Definition: call.h:560