Restructure code to handle cases exposed by the callback api

pull/17806/head
Yash Tibrewal 6 years ago
parent 4dcb14ec9e
commit 9dd8a13439
  1. 13
      include/grpcpp/impl/codegen/call_op_set.h
  2. 26
      include/grpcpp/impl/codegen/interceptor_common.h

@ -871,9 +871,6 @@ class CallOpSet : public CallOpSetInterface,
if (RunInterceptors()) {
ContinueFillOpsAfterInterception();
} else {
// This call is going to go through interceptors and would need to
// schedule new batches, so delay completion queue shutdown
call_.cq()->RegisterAvalanching();
// After the interceptors are run, ContinueFillOpsAfterInterception will
// be run
}
@ -881,6 +878,8 @@ class CallOpSet : public CallOpSetInterface,
bool FinalizeResult(void** tag, bool* status) override {
if (done_intercepting_) {
// Complete the avalanching since we are done with this batch of ops
call_.cq()->CompleteAvalanching();
// We have already finished intercepting and filling in the results. This
// round trip from the core needed to be made because interceptors were
// run
@ -951,8 +950,6 @@ class CallOpSet : public CallOpSetInterface,
GPR_CODEGEN_ASSERT(GRPC_CALL_OK ==
g_core_codegen_interface->grpc_call_start_batch(
call_.call(), nullptr, 0, core_cq_tag(), nullptr));
// Complete the avalanching since we are done with this batch of ops
call_.cq()->CompleteAvalanching();
}
private:
@ -967,6 +964,12 @@ class CallOpSet : public CallOpSetInterface,
this->Op4::SetInterceptionHookPoint(&interceptor_methods_);
this->Op5::SetInterceptionHookPoint(&interceptor_methods_);
this->Op6::SetInterceptionHookPoint(&interceptor_methods_);
if (interceptor_methods_.InterceptorsListEmpty()) {
return true;
}
// This call will go through interceptors and would need to
// schedule new batches, so delay completion queue shutdown
call_.cq()->RegisterAvalanching();
return interceptor_methods_.RunInterceptors();
}
// Returns true if no interceptors need to be run

@ -219,10 +219,28 @@ class InterceptorBatchMethodsImpl
// Alternatively, RunInterceptors(std::function<void(void)> f) can be used.
void SetCallOpSetInterface(CallOpSetInterface* ops) { ops_ = ops; }
// Returns true if no interceptors are run. This should be used only by
// subclasses of CallOpSetInterface. SetCall and SetCallOpSetInterface should
// have been called before this. After all the interceptors are done running,
// either ContinueFillOpsAfterInterception or
// Returns true if the interceptors list is empty
bool InterceptorsListEmpty() {
auto* client_rpc_info = call_->client_rpc_info();
if (client_rpc_info != nullptr) {
if (client_rpc_info->interceptors_.size() == 0) {
return true;
} else {
return false;
}
}
auto* server_rpc_info = call_->server_rpc_info();
if (server_rpc_info == nullptr ||
server_rpc_info->interceptors_.size() == 0) {
return true;
}
return false;
}
// This should be used only by subclasses of CallOpSetInterface. SetCall and
// SetCallOpSetInterface should have been called before this. After all the
// interceptors are done running, either ContinueFillOpsAfterInterception or
// ContinueFinalizeOpsAfterInterception will be called. Note that neither of
// them is invoked if there were no interceptors registered.
bool RunInterceptors() {

Loading…
Cancel
Save