34 #ifndef GRPCXX_IMPL_CODEGEN_CALL_H
35 #define GRPCXX_IMPL_CODEGEN_CALL_H
42 #include <grpc/impl/codegen/alloc.h>
43 #include <grpc/impl/codegen/grpc_types.h>
51 struct grpc_byte_buffer;
58 class CompletionQueue;
61 grpc_metadata_array* arr,
62 std::multimap<grpc::string_ref, grpc::string_ref>* metadata);
64 const std::multimap<grpc::string, grpc::string>& metadata);
73 inline void Clear() { flags_ = 0; }
76 inline uint32_t
flags()
const {
return flags_; }
82 SetBit(GRPC_WRITE_NO_COMPRESS);
90 ClearBit(GRPC_WRITE_NO_COMPRESS);
99 return GetBit(GRPC_WRITE_NO_COMPRESS);
107 SetBit(GRPC_WRITE_BUFFER_HINT);
116 ClearBit(GRPC_WRITE_BUFFER_HINT);
132 void SetBit(
const uint32_t mask) { flags_ |= mask; }
134 void ClearBit(
const uint32_t mask) { flags_ &= ~mask; }
136 bool GetBit(
const uint32_t mask)
const {
return (flags_ & mask) != 0; }
146 void AddOp(grpc_op* ops,
size_t* nops) {}
147 void FinishOp(
bool* status,
int max_message_size) {}
155 const std::multimap<grpc::string, grpc::string>& metadata) {
162 void AddOp(grpc_op* ops,
size_t* nops) {
164 grpc_op* op = &ops[(*nops)++];
165 op->op = GRPC_OP_SEND_INITIAL_METADATA;
171 void FinishOp(
bool* status,
int max_message_size) {
196 void AddOp(grpc_op* ops,
size_t* nops) {
197 if (send_buf_ ==
nullptr)
return;
198 grpc_op* op = &ops[(*nops)++];
199 op->op = GRPC_OP_SEND_MESSAGE;
200 op->flags = write_options_.
flags();
202 op->data.send_message = send_buf_;
204 write_options_.
Clear();
206 void FinishOp(
bool* status,
int max_message_size) {
207 if (own_buf_) grpc_byte_buffer_destroy(send_buf_);
212 grpc_byte_buffer* send_buf_;
220 write_options_ = options;
239 void AddOp(grpc_op* ops,
size_t* nops) {
240 if (message_ ==
nullptr)
return;
241 grpc_op* op = &ops[(*nops)++];
242 op->op = GRPC_OP_RECV_MESSAGE;
245 op->data.recv_message = &recv_buf_;
248 void FinishOp(
bool* status,
int max_message_size) {
249 if (message_ ==
nullptr)
return;
254 max_message_size).ok();
257 grpc_byte_buffer_destroy(recv_buf_);
268 grpc_byte_buffer* recv_buf_;
271 namespace CallOpGenericRecvMessageHelper {
307 void AddOp(grpc_op* ops,
size_t* nops) {
308 if (!deserialize_)
return;
309 grpc_op* op = &ops[(*nops)++];
310 op->op = GRPC_OP_RECV_MESSAGE;
313 op->data.recv_message = &recv_buf_;
316 void FinishOp(
bool* status,
int max_message_size) {
317 if (!deserialize_)
return;
321 *status = deserialize_->Deserialize(recv_buf_, max_message_size).ok();
324 grpc_byte_buffer_destroy(recv_buf_);
330 deserialize_.reset();
334 std::unique_ptr<CallOpGenericRecvMessageHelper::DeserializeFunc> deserialize_;
335 grpc_byte_buffer* recv_buf_;
345 void AddOp(grpc_op* ops,
size_t* nops) {
347 grpc_op* op = &ops[(*nops)++];
348 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
352 void FinishOp(
bool* status,
int max_message_size) { send_ =
false; }
363 const std::multimap<grpc::string, grpc::string>& trailing_metadata,
365 trailing_metadata_count_ = trailing_metadata.size();
367 send_status_available_ =
true;
368 send_status_code_ =
static_cast<grpc_status_code
>(status.
error_code());
373 void AddOp(grpc_op* ops,
size_t* nops) {
374 if (!send_status_available_)
return;
375 grpc_op* op = &ops[(*nops)++];
376 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
377 op->data.send_status_from_server.trailing_metadata_count =
378 trailing_metadata_count_;
379 op->data.send_status_from_server.trailing_metadata = trailing_metadata_;
380 op->data.send_status_from_server.status = send_status_code_;
381 op->data.send_status_from_server.status_details =
382 send_status_details_.empty() ?
nullptr : send_status_details_.c_str();
387 void FinishOp(
bool* status,
int max_message_size) {
388 if (!send_status_available_)
return;
389 gpr_free(trailing_metadata_);
390 send_status_available_ =
false;
394 bool send_status_available_;
395 grpc_status_code send_status_code_;
397 size_t trailing_metadata_count_;
398 grpc_metadata* trailing_metadata_;
406 context->initial_metadata_received_ =
true;
407 recv_initial_metadata_ = &context->recv_initial_metadata_;
411 void AddOp(grpc_op* ops,
size_t* nops) {
412 if (!recv_initial_metadata_)
return;
413 memset(&recv_initial_metadata_arr_, 0,
sizeof(recv_initial_metadata_arr_));
414 grpc_op* op = &ops[(*nops)++];
415 op->op = GRPC_OP_RECV_INITIAL_METADATA;
416 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_ref, grpc::string_ref>* 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_;
459 void FinishOp(
bool* status,
int max_message_size) {
460 if (recv_status_ ==
nullptr)
return;
461 FillMetadataMap(&recv_trailing_metadata_arr_, recv_trailing_metadata_);
463 static_cast<StatusCode>(status_code_),
465 gpr_free(status_details_);
466 recv_status_ =
nullptr;
470 std::multimap<grpc::string_ref, grpc::string_ref>* recv_trailing_metadata_;
472 grpc_metadata_array recv_trailing_metadata_arr_;
473 grpc_status_code status_code_;
474 char* status_details_;
475 size_t status_details_capacity_;
487 :
public std::enable_shared_from_this<CallOpSetCollectionInterface> {};
499 virtual void FillOps(grpc_op* ops,
size_t* nops) = 0;
506 void SetCollection(std::shared_ptr<CallOpSetCollectionInterface> collection) {
521 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
522 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
523 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
534 this->Op1::AddOp(ops, nops);
535 this->Op2::AddOp(ops, nops);
536 this->Op3::AddOp(ops, nops);
537 this->Op4::AddOp(ops, nops);
538 this->Op5::AddOp(ops, nops);
539 this->Op6::AddOp(ops, nops);
564 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
565 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
566 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
571 return Base::FinalizeResult(tag, status) &&
false;
585 grpc_call*
call() {
return call_; }
594 int max_message_size_;
599 #endif // GRPCXX_IMPL_CODEGEN_CALL_H
void ServerSendStatus(const std::multimap< grpc::string, grpc::string > &trailing_metadata, const Status &status)
Definition: call.h:362
Call(grpc_call *call, CallHook *call_hook_, CompletionQueue *cq)
void RecvMessage(R *message)
Definition: call.h:299
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:40
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:115
Default argument for CallOpSet.
Definition: call.h:144
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:345
CallOpServerSendStatus()
Definition: call.h:360
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:106
grpc::string error_message() const
Return the instance's error message.
Definition: status.h:64
CallOpSendMessage()
Definition: call.h:184
std::string string
Definition: config.h:112
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:307
CompletionQueue * cq()
Definition: call.h:586
void SetCollection(std::shared_ptr< CallOpSetCollectionInterface > collection)
Mark this as belonging to a collection if needed.
Definition: call.h:506
void FinishOp(bool *status, int max_message_size)
Definition: call.h:316
WriteOptions & clear_no_compression()
Clears flag for the disabling of compression for the next message write.
Definition: call.h:89
int max_message_size_
Definition: call.h:511
bool FinalizeResult(void **tag, bool *status) GRPC_OVERRIDE
Definition: call.h:569
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:494
void FinishOp(bool *status, int max_message_size)
Definition: call.h:352
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:239
bool FinalizeResult(void **tag, bool *status) GRPC_OVERRIDE
Definition: call.h:542
void Clear()
Clear all flags.
Definition: call.h:73
void FinishOp(bool *status, int max_message_size)
Definition: call.h:206
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:373
An abstract collection of CallOpSet's, to be used whenever CallOpSet objects must be thought of as a ...
Definition: call.h:486
WriteOptions()
Definition: call.h:69
void FillOps(grpc_op *ops, size_t *nops) GRPC_OVERRIDE
Fills in grpc_op, starting from ops[*nops] and moving upwards.
Definition: call.h:533
uint32_t flags() const
Returns raw flags bitset.
Definition: call.h:76
grpc_metadata * FillMetadataArray(const std::multimap< grpc::string, grpc::string > &metadata)
grpc_call * call()
Definition: call.h:585
WriteOptions & set_no_compression()
Sets flag for the disabling of compression for the next message write.
Definition: call.h:81
Definition: client_context.h:152
WriteOptions & operator=(const WriteOptions &rhs)
Definition: call.h:126
void FinishOp(bool *status, int max_message_size)
Definition: call.h:459
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:98
Status Deserialize(grpc_byte_buffer *buf, int max_message_size) GRPC_OVERRIDE
Definition: call.h:282
CallOpSet()
Definition: call.h:532
void FinishOp(bool *status, int max_message_size)
Definition: call.h:387
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:441
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:146
CallOpSetInterface()
Definition: call.h:496
WriteOptions(const WriteOptions &other)
Definition: call.h:70
Primary implementaiton of CallOpSetInterface.
Definition: call.h:524
void ClientSendClose()
Definition: call.h:342
int max_message_size()
Definition: call.h:588
Per-message write options.
Definition: call.h:67
CallOpClientSendClose()
Definition: call.h:340
std::shared_ptr< CallOpSetCollectionInterface > collection_
Definition: call.h:512
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:124
CallOpRecvMessage()
Definition: call.h:232
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:218
#define GRPC_FINAL
Definition: config.h:71
~DeserializeFuncType() override
Definition: call.h:287
void FinishOp(bool *status, int max_message_size)
Definition: call.h:147
bool got_message
Definition: call.h:236
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:248
void set_max_message_size(int max_message_size)
Definition: call.h:501
DeserializeFuncType(R *message)
Definition: call.h:281
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:234
CallOpGenericRecvMessage()
Definition: call.h:296
bool got_message
Definition: call.h:304
A CallOpSet that does not post completions to the completion queue.
Definition: call.h:567
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:554
Channel and Server implement this to allow them to hook performing ops.
Definition: call_hook.h:43
#define GRPC_OVERRIDE
Definition: config.h:77
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:196
virtual ~DeserializeFunc()
Definition: call.h:275