34 #ifndef GRPCXX_IMPL_CALL_H
35 #define GRPCXX_IMPL_CALL_H
42 #include <grpc/support/alloc.h>
58 grpc_metadata_array* arr,
59 std::multimap<grpc::string_ref, grpc::string_ref>* metadata);
61 const std::multimap<grpc::string, grpc::string>& metadata);
70 inline void Clear() { flags_ = 0; }
73 inline gpr_uint32
flags()
const {
return flags_; }
79 SetBit(GRPC_WRITE_NO_COMPRESS);
87 ClearBit(GRPC_WRITE_NO_COMPRESS);
96 return GetBit(GRPC_WRITE_NO_COMPRESS);
104 SetBit(GRPC_WRITE_BUFFER_HINT);
113 ClearBit(GRPC_WRITE_BUFFER_HINT);
129 void SetBit(
const gpr_int32 mask) { flags_ |= mask; }
131 void ClearBit(
const gpr_int32 mask) { flags_ &= ~mask; }
133 bool GetBit(
const gpr_int32 mask)
const {
return flags_ & mask; }
143 void AddOp(grpc_op* ops,
size_t* nops) {}
144 void FinishOp(
bool* status,
int max_message_size) {}
152 const std::multimap<grpc::string, grpc::string>& metadata) {
159 void AddOp(grpc_op* ops,
size_t* nops) {
161 grpc_op* op = &ops[(*nops)++];
162 op->op = GRPC_OP_SEND_INITIAL_METADATA;
168 void FinishOp(
bool* status,
int max_message_size) {
193 void AddOp(grpc_op* ops,
size_t* nops) {
194 if (send_buf_ ==
nullptr)
return;
195 grpc_op* op = &ops[(*nops)++];
196 op->op = GRPC_OP_SEND_MESSAGE;
197 op->flags = write_options_.
flags();
199 op->data.send_message = send_buf_;
201 write_options_.
Clear();
203 void FinishOp(
bool* status,
int max_message_size) {
204 if (own_buf_) grpc_byte_buffer_destroy(send_buf_);
209 grpc_byte_buffer* send_buf_;
217 write_options_ = options;
236 void AddOp(grpc_op* ops,
size_t* nops) {
237 if (message_ ==
nullptr)
return;
238 grpc_op* op = &ops[(*nops)++];
239 op->op = GRPC_OP_RECV_MESSAGE;
242 op->data.recv_message = &recv_buf_;
245 void FinishOp(
bool* status,
int max_message_size) {
246 if (message_ ==
nullptr)
return;
255 grpc_byte_buffer_destroy(recv_buf_);
266 grpc_byte_buffer* recv_buf_;
269 namespace CallOpGenericRecvMessageHelper {
302 void AddOp(grpc_op* ops,
size_t* nops) {
303 if (!deserialize_)
return;
304 grpc_op* op = &ops[(*nops)++];
305 op->op = GRPC_OP_RECV_MESSAGE;
308 op->data.recv_message = &recv_buf_;
311 void FinishOp(
bool* status,
int max_message_size) {
312 if (!deserialize_)
return;
316 *status = deserialize_->Deserialize(recv_buf_, max_message_size).ok();
319 grpc_byte_buffer_destroy(recv_buf_);
325 deserialize_.reset();
329 std::unique_ptr<CallOpGenericRecvMessageHelper::DeserializeFunc> deserialize_;
330 grpc_byte_buffer* recv_buf_;
340 void AddOp(grpc_op* ops,
size_t* nops) {
342 grpc_op* op = &ops[(*nops)++];
343 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
347 void FinishOp(
bool* status,
int max_message_size) { send_ =
false; }
358 const std::multimap<grpc::string, grpc::string>& trailing_metadata,
360 trailing_metadata_count_ = trailing_metadata.size();
362 send_status_available_ =
true;
363 send_status_code_ =
static_cast<grpc_status_code
>(status.
error_code());
368 void AddOp(grpc_op* ops,
size_t* nops) {
369 if (!send_status_available_)
return;
370 grpc_op* op = &ops[(*nops)++];
371 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
372 op->data.send_status_from_server.trailing_metadata_count =
373 trailing_metadata_count_;
374 op->data.send_status_from_server.trailing_metadata = trailing_metadata_;
375 op->data.send_status_from_server.status = send_status_code_;
376 op->data.send_status_from_server.status_details =
377 send_status_details_.empty() ?
nullptr : send_status_details_.c_str();
382 void FinishOp(
bool* status,
int max_message_size) {
383 if (!send_status_available_)
return;
384 gpr_free(trailing_metadata_);
385 send_status_available_ =
false;
389 bool send_status_available_;
390 grpc_status_code send_status_code_;
392 size_t trailing_metadata_count_;
393 grpc_metadata* trailing_metadata_;
401 context->initial_metadata_received_ =
true;
402 recv_initial_metadata_ = &context->recv_initial_metadata_;
406 void AddOp(grpc_op* ops,
size_t* nops) {
407 if (!recv_initial_metadata_)
return;
408 memset(&recv_initial_metadata_arr_, 0,
sizeof(recv_initial_metadata_arr_));
409 grpc_op* op = &ops[(*nops)++];
410 op->op = GRPC_OP_RECV_INITIAL_METADATA;
411 op->data.recv_initial_metadata = &recv_initial_metadata_arr_;
415 void FinishOp(
bool* status,
int max_message_size) {
416 if (recv_initial_metadata_ ==
nullptr)
return;
418 recv_initial_metadata_ =
nullptr;
422 std::multimap<grpc::string_ref, grpc::string_ref>* recv_initial_metadata_;
423 grpc_metadata_array recv_initial_metadata_arr_;
431 recv_trailing_metadata_ = &context->trailing_metadata_;
432 recv_status_ = status;
436 void AddOp(grpc_op* ops,
size_t* nops) {
437 if (recv_status_ ==
nullptr)
return;
438 memset(&recv_trailing_metadata_arr_, 0,
439 sizeof(recv_trailing_metadata_arr_));
440 status_details_ =
nullptr;
441 status_details_capacity_ = 0;
442 grpc_op* op = &ops[(*nops)++];
443 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
444 op->data.recv_status_on_client.trailing_metadata =
445 &recv_trailing_metadata_arr_;
446 op->data.recv_status_on_client.status = &status_code_;
447 op->data.recv_status_on_client.status_details = &status_details_;
448 op->data.recv_status_on_client.status_details_capacity =
449 &status_details_capacity_;
454 void FinishOp(
bool* status,
int max_message_size) {
455 if (recv_status_ ==
nullptr)
return;
456 FillMetadataMap(&recv_trailing_metadata_arr_, recv_trailing_metadata_);
458 static_cast<StatusCode>(status_code_),
460 gpr_free(status_details_);
461 recv_status_ =
nullptr;
465 std::multimap<grpc::string_ref, grpc::string_ref>* recv_trailing_metadata_;
467 grpc_metadata_array recv_trailing_metadata_arr_;
468 grpc_status_code status_code_;
469 char* status_details_;
470 size_t status_details_capacity_;
483 virtual void FillOps(grpc_op* ops,
size_t* nops) = 0;
499 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
500 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
501 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
512 this->Op1::AddOp(ops, nops);
513 this->Op2::AddOp(ops, nops);
514 this->Op3::AddOp(ops, nops);
515 this->Op4::AddOp(ops, nops);
516 this->Op5::AddOp(ops, nops);
517 this->Op6::AddOp(ops, nops);
541 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
542 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
543 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
548 return Base::FinalizeResult(tag, status) &&
false;
569 grpc_call*
call() {
return call_; }
578 int max_message_size_;
583 #endif // GRPCXX_IMPL_CALL_H
void ServerSendStatus(const std::multimap< grpc::string, grpc::string > &trailing_metadata, const Status &status)
Definition: call.h:357
Call(grpc_call *call, CallHook *call_hook_, CompletionQueue *cq)
void RecvMessage(R *message)
Definition: call.h:294
An interface allowing implementors to process and filter event tags.
Definition: completion_queue.h:192
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:112
Default argument for CallOpSet.
Definition: call.h:141
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:340
CallOpServerSendStatus()
Definition: call.h:355
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:103
grpc::string error_message() const
Return the instance's error message.
Definition: status.h:64
CallOpSendMessage()
Definition: call.h:181
std::string string
Definition: config.h:112
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:302
CompletionQueue * cq()
Definition: call.h:570
void FinishOp(bool *status, int max_message_size)
Definition: call.h:311
WriteOptions & clear_no_compression()
Clears flag for the disabling of compression for the next message write.
Definition: call.h:86
int max_message_size_
Definition: call.h:490
bool FinalizeResult(void **tag, bool *status) GRPC_OVERRIDE
Definition: call.h:546
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:478
void FinishOp(bool *status, int max_message_size)
Definition: call.h:347
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:236
bool FinalizeResult(void **tag, bool *status) GRPC_OVERRIDE
Definition: call.h:520
void Clear()
Clear all flags.
Definition: call.h:70
void FinishOp(bool *status, int max_message_size)
Definition: call.h:203
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:368
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:511
grpc_metadata * FillMetadataArray(const std::multimap< grpc::string, grpc::string > &metadata)
grpc_call * call()
Definition: call.h:569
WriteOptions & set_no_compression()
Sets flag for the disabling of compression for the next message write.
Definition: call.h:78
Definition: client_context.h:149
WriteOptions & operator=(const WriteOptions &rhs)
Definition: call.h:123
gpr_uint32 flags() const
Returns raw flags bitset.
Definition: call.h:73
void FinishOp(bool *status, int max_message_size)
Definition: call.h:454
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:64
CallOpClientRecvStatus()
Definition: call.h:428
bool get_no_compression() const
Get value for the flag indicating whether compression for the next message write is forcefully disabl...
Definition: call.h:95
Status Deserialize(grpc_byte_buffer *buf, int max_message_size) GRPC_OVERRIDE
Definition: call.h:279
CallOpSet()
Definition: call.h:510
void FinishOp(bool *status, int max_message_size)
Definition: call.h:382
void FillMetadataMap(grpc_metadata_array *arr, std::multimap< grpc::string_ref, grpc::string_ref > *metadata)
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:436
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:143
CallOpSetInterface()
Definition: call.h:480
WriteOptions(const WriteOptions &other)
Definition: call.h:67
Primary implementaiton of CallOpSetInterface.
Definition: call.h:502
void ClientSendClose()
Definition: call.h:337
int max_message_size()
Definition: call.h:572
Per-message write options.
Definition: call.h:64
CallOpClientSendClose()
Definition: call.h:335
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:121
CallOpRecvMessage()
Definition: call.h:229
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:62
A thin wrapper around grpc_completion_queue (see / src/core/surface/completion_queue.h).
Definition: completion_queue.h:81
Status SendMessage(const M &message, const WriteOptions &options) GRPC_MUST_USE_RESULT
Send message using options for the write.
Definition: call.h:215
virtual void PerformOpsOnCall(CallOpSetInterface *ops, Call *call)=0
void FinishOp(bool *status, int max_message_size)
Definition: call.h:144
bool got_message
Definition: call.h:233
void ClientRecvStatus(ClientContext *context, Status *status)
Definition: call.h:430
void PerformOps(CallOpSetInterface *ops)
void FinishOp(bool *status, int max_message_size)
Definition: call.h:245
void set_max_message_size(int max_message_size)
Definition: call.h:485
DeserializeFuncType(R *message)
Definition: call.h:278
Did it work? If it didn't, why?
Definition: status.h:45
virtual Status Deserialize(grpc_byte_buffer *buf, int max_message_size)=0
void RecvMessage(R *message)
Definition: call.h:231
CallOpGenericRecvMessage()
Definition: call.h:291
bool got_message
Definition: call.h:299
A CallOpSet that does not post completions to the completion queue.
Definition: call.h:544
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:531
#define GRPC_OVERRIDE
Definition: config.h:77
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:193
virtual ~CallHook()
Definition: call.h:555