Don't expose internal functions.. Add a layer of indirection namely InternalInterceptorBatchMethods

pull/16842/head
Yash Tibrewal 6 years ago
parent 456231b26d
commit 52765e9cb1
  1. 193
      include/grpcpp/impl/codegen/call.h
  2. 10
      include/grpcpp/impl/codegen/client_interceptor.h
  3. 33
      include/grpcpp/impl/codegen/interceptor.h
  4. 10
      include/grpcpp/impl/codegen/server_interceptor.h

@ -204,6 +204,36 @@ class WriteOptions {
}; };
namespace internal { namespace internal {
class InternalInterceptorBatchMethods
: public experimental::InterceptorBatchMethods {
public:
virtual ~InternalInterceptorBatchMethods() {}
virtual void AddInterceptionHookPoint(
experimental::InterceptionHookPoints type) = 0;
virtual void SetSendMessage(ByteBuffer* buf) = 0;
virtual void SetSendInitialMetadata(
std::multimap<grpc::string, grpc::string>* metadata) = 0;
virtual void SetSendStatus(grpc_status_code* code,
grpc::string* error_details,
grpc::string* error_message) = 0;
virtual void SetSendTrailingMetadata(
std::multimap<grpc::string, grpc::string>* metadata) = 0;
virtual void SetRecvMessage(void* message) = 0;
virtual void SetRecvInitialMetadata(internal::MetadataMap* map) = 0;
virtual void SetRecvStatus(Status* status) = 0;
virtual void SetRecvTrailingMetadata(internal::MetadataMap* map) = 0;
};
/// Default argument for CallOpSet. I is unused by the class, but can be /// Default argument for CallOpSet. I is unused by the class, but can be
/// used for generating multiple names for the same thing. /// used for generating multiple names for the same thing.
template <int I> template <int I>
@ -212,12 +242,12 @@ class CallNoOp {
void AddOp(grpc_op* ops, size_t* nops) {} void AddOp(grpc_op* ops, size_t* nops) {}
void FinishOp(bool* status) {} void FinishOp(bool* status) {}
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) {} InternalInterceptorBatchMethods* interceptor_methods) {}
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) {} InternalInterceptorBatchMethods* interceptor_methods) {}
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {} }
}; };
class CallOpSendInitialMetadata { class CallOpSendInitialMetadata {
@ -264,7 +294,7 @@ class CallOpSendInitialMetadata {
} }
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
if (!send_) return; if (!send_) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA); experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA);
@ -272,10 +302,9 @@ class CallOpSendInitialMetadata {
} }
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) {} InternalInterceptorBatchMethods* interceptor_methods) {}
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {
hijacked_ = true; hijacked_ = true;
} }
@ -318,7 +347,7 @@ class CallOpSendMessage {
void FinishOp(bool* status) { send_buf_.Clear(); } void FinishOp(bool* status) { send_buf_.Clear(); }
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
if (!send_buf_.Valid()) return; if (!send_buf_.Valid()) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_MESSAGE); experimental::InterceptionHookPoints::PRE_SEND_MESSAGE);
@ -326,10 +355,9 @@ class CallOpSendMessage {
} }
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) {} InternalInterceptorBatchMethods* interceptor_methods) {}
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {
hijacked_ = true; hijacked_ = true;
} }
@ -407,18 +435,17 @@ class CallOpRecvMessage {
} }
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
interceptor_methods->SetRecvMessage(message_); interceptor_methods->SetRecvMessage(message_);
} }
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
if (!got_message) return; if (!got_message) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
experimental::InterceptionHookPoints::POST_RECV_MESSAGE); experimental::InterceptionHookPoints::POST_RECV_MESSAGE);
} }
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {
hijacked_ = true; hijacked_ = true;
if (message_ == nullptr) return; if (message_ == nullptr) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
@ -503,18 +530,17 @@ class CallOpGenericRecvMessage {
} }
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
interceptor_methods->SetRecvMessage(message_); interceptor_methods->SetRecvMessage(message_);
} }
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
if (!got_message) return; if (!got_message) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
experimental::InterceptionHookPoints::POST_RECV_MESSAGE); experimental::InterceptionHookPoints::POST_RECV_MESSAGE);
} }
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {
hijacked_ = true; hijacked_ = true;
if (!deserialize_) return; if (!deserialize_) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
@ -546,17 +572,16 @@ class CallOpClientSendClose {
void FinishOp(bool* status) { send_ = false; } void FinishOp(bool* status) { send_ = false; }
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
if (!send_) return; if (!send_) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_CLOSE); experimental::InterceptionHookPoints::PRE_SEND_CLOSE);
} }
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) {} InternalInterceptorBatchMethods* interceptor_methods) {}
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {
hijacked_ = true; hijacked_ = true;
} }
@ -604,7 +629,7 @@ class CallOpServerSendStatus {
} }
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
if (!send_status_available_) return; if (!send_status_available_) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_STATUS); experimental::InterceptionHookPoints::PRE_SEND_STATUS);
@ -614,10 +639,9 @@ class CallOpServerSendStatus {
} }
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) {} InternalInterceptorBatchMethods* interceptor_methods) {}
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {
hijacked_ = true; hijacked_ = true;
} }
@ -657,20 +681,19 @@ class CallOpRecvInitialMetadata {
} }
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
interceptor_methods->SetRecvInitialMetadata(metadata_map_); interceptor_methods->SetRecvInitialMetadata(metadata_map_);
} }
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
if (metadata_map_ == nullptr) return; if (metadata_map_ == nullptr) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA); experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA);
metadata_map_ = nullptr; metadata_map_ = nullptr;
} }
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {
hijacked_ = true; hijacked_ = true;
if (metadata_map_ == nullptr) return; if (metadata_map_ == nullptr) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
@ -726,21 +749,20 @@ class CallOpClientRecvStatus {
} }
void SetInterceptionHookPoint( void SetInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
interceptor_methods->SetRecvStatus(recv_status_); interceptor_methods->SetRecvStatus(recv_status_);
interceptor_methods->SetRecvTrailingMetadata(metadata_map_); interceptor_methods->SetRecvTrailingMetadata(metadata_map_);
} }
void SetFinishInterceptionHookPoint( void SetFinishInterceptionHookPoint(
experimental::InterceptorBatchMethods* interceptor_methods) { InternalInterceptorBatchMethods* interceptor_methods) {
if (recv_status_ == nullptr) return; if (recv_status_ == nullptr) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
experimental::InterceptionHookPoints::POST_RECV_STATUS); experimental::InterceptionHookPoints::POST_RECV_STATUS);
recv_status_ = nullptr; recv_status_ = nullptr;
} }
void SetHijackingState( void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) {
experimental::InterceptorBatchMethods* interceptor_methods) {
hijacked_ = true; hijacked_ = true;
if (recv_status_ == nullptr) return; if (recv_status_ == nullptr) return;
interceptor_methods->AddInterceptionHookPoint( interceptor_methods->AddInterceptionHookPoint(
@ -834,11 +856,11 @@ class CallOpSetInterface : public CompletionQueueTag {
// RPC. This should set hijacking state for each of the ops. // RPC. This should set hijacking state for each of the ops.
virtual void SetHijackingState() = 0; virtual void SetHijackingState() = 0;
/* Should be called after interceptors are done running */ // Should be called after interceptors are done running
virtual void ContinueFillOpsAfterInterception() = 0; virtual void ContinueFillOpsAfterInterception() = 0;
/* Should be called after interceptors are done running on the finalize result // Should be called after interceptors are done running on the finalize result
* path */ // path
virtual void ContinueFinalizeResultAfterInterception() = 0; virtual void ContinueFinalizeResultAfterInterception() = 0;
}; };
@ -847,8 +869,7 @@ template <class Op1 = CallNoOp<1>, class Op2 = CallNoOp<2>,
class Op5 = CallNoOp<5>, class Op6 = CallNoOp<6>> class Op5 = CallNoOp<5>, class Op6 = CallNoOp<6>>
class CallOpSet; class CallOpSet;
class InterceptorBatchMethodsImpl class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods {
: public experimental::InterceptorBatchMethods {
public: public:
InterceptorBatchMethodsImpl() { InterceptorBatchMethodsImpl() {
for (auto i = 0; for (auto i = 0;
@ -874,8 +895,8 @@ class InterceptorBatchMethodsImpl
ProceedServer(); ProceedServer();
} }
virtual void Hijack() override { /* fill this */ virtual void Hijack() override {
/* Only the client can hijack when sending down initial metadata */ // Only the client can hijack when sending down initial metadata
GPR_CODEGEN_ASSERT(!reverse_ && ops_ != nullptr && GPR_CODEGEN_ASSERT(!reverse_ && ops_ != nullptr &&
call_->client_rpc_info() != nullptr); call_->client_rpc_info() != nullptr);
auto* rpc_info = call_->client_rpc_info(); auto* rpc_info = call_->client_rpc_info();
@ -930,58 +951,55 @@ class InterceptorBatchMethodsImpl
return recv_trailing_metadata_->map(); return recv_trailing_metadata_->map();
} }
virtual void SetSendMessage(ByteBuffer* buf) override { send_message_ = buf; } virtual void SetSendMessage(ByteBuffer* buf) { send_message_ = buf; }
virtual void SetSendInitialMetadata( virtual void SetSendInitialMetadata(
std::multimap<grpc::string, grpc::string>* metadata) override { std::multimap<grpc::string, grpc::string>* metadata) {
send_initial_metadata_ = metadata; send_initial_metadata_ = metadata;
} }
virtual void SetSendStatus(grpc_status_code* code, virtual void SetSendStatus(grpc_status_code* code,
grpc::string* error_details, grpc::string* error_details,
grpc::string* error_message) override { grpc::string* error_message) {
code_ = code; code_ = code;
error_details_ = error_details; error_details_ = error_details;
error_message_ = error_message; error_message_ = error_message;
} }
virtual void SetSendTrailingMetadata( virtual void SetSendTrailingMetadata(
std::multimap<grpc::string, grpc::string>* metadata) override { std::multimap<grpc::string, grpc::string>* metadata) {
send_trailing_metadata_ = metadata; send_trailing_metadata_ = metadata;
} }
virtual void SetRecvMessage(void* message) override { virtual void SetRecvMessage(void* message) { recv_message_ = message; }
recv_message_ = message;
}
virtual void SetRecvInitialMetadata(internal::MetadataMap* map) override { virtual void SetRecvInitialMetadata(internal::MetadataMap* map) {
recv_initial_metadata_ = map; recv_initial_metadata_ = map;
} }
virtual void SetRecvStatus(Status* status) override { recv_status_ = status; } virtual void SetRecvStatus(Status* status) { recv_status_ = status; }
virtual void SetRecvTrailingMetadata(internal::MetadataMap* map) override { virtual void SetRecvTrailingMetadata(internal::MetadataMap* map) {
recv_trailing_metadata_ = map; recv_trailing_metadata_ = map;
} }
/* Prepares for Post_recv operations */ // Prepares for Post_recv operations
void SetReverse() { void SetReverse() {
reverse_ = true; reverse_ = true;
ClearHookPoints(); ClearHookPoints();
} }
/* This needs to be set before interceptors are run */ // This needs to be set before interceptors are run
void SetCall(Call* call) { call_ = call; } void SetCall(Call* call) { call_ = call; }
void SetCallOpSetInterface(CallOpSetInterface* ops) { ops_ = ops; } void SetCallOpSetInterface(CallOpSetInterface* ops) { ops_ = ops; }
/* Returns true if no interceptors are run. This should be used only by // Returns true if no interceptors are run. This should be used only by
subclasses of CallOpSetInterface. SetCall and SetCallOpSetInterface should // subclasses of CallOpSetInterface. SetCall and SetCallOpSetInterface should
have been called before this. After all the interceptors are done running, // have been called before this. After all the interceptors are done running,
either ContinueFillOpsAfterInterception or // either ContinueFillOpsAfterInterception or
ContinueFinalizeOpsAfterInterception will be called. Note that neither of them // ContinueFinalizeOpsAfterInterception will be called. Note that neither of
is invoked if there were no interceptors registered. // them is invoked if there were no interceptors registered.
*/
bool RunInterceptors() { bool RunInterceptors() {
auto* client_rpc_info = call_->client_rpc_info(); auto* client_rpc_info = call_->client_rpc_info();
if (client_rpc_info == nullptr || if (client_rpc_info == nullptr ||
@ -1001,9 +1019,10 @@ class InterceptorBatchMethodsImpl
return false; return false;
} }
/* Returns true if no interceptors are run. Returns false otherwise if there // Returns true if no interceptors are run. Returns false otherwise if there
are interceptors registered. After the interceptors are done running \a f will // are interceptors registered. After the interceptors are done running \a f
be invoked. This is to be used only by BaseAsyncRequest and SyncRequest. */ // will
// be invoked. This is to be used only by BaseAsyncRequest and SyncRequest.
bool RunInterceptors(std::function<void(void)> f) { bool RunInterceptors(std::function<void(void)> f) {
GPR_CODEGEN_ASSERT(reverse_ == true); GPR_CODEGEN_ASSERT(reverse_ == true);
GPR_CODEGEN_ASSERT(call_->client_rpc_info() == nullptr); GPR_CODEGEN_ASSERT(call_->client_rpc_info() == nullptr);
@ -1049,33 +1068,33 @@ class InterceptorBatchMethodsImpl
auto* rpc_info = call_->client_rpc_info(); auto* rpc_info = call_->client_rpc_info();
if (rpc_info->hijacked_ && if (rpc_info->hijacked_ &&
(!reverse_ && curr_iteration_ == rpc_info->hijacked_interceptor_ + 1)) { (!reverse_ && curr_iteration_ == rpc_info->hijacked_interceptor_ + 1)) {
/* We now need to provide hijacked recv ops to this interceptor */ // We now need to provide hijacked recv ops to this interceptor
ClearHookPoints(); ClearHookPoints();
ops_->SetHijackingState(); ops_->SetHijackingState();
rpc_info->RunInterceptor(this, curr_iteration_ - 1); rpc_info->RunInterceptor(this, curr_iteration_ - 1);
return; return;
} }
if (!reverse_) { if (!reverse_) {
/* We are going down the stack of interceptors */ // We are going down the stack of interceptors
if (curr_iteration_ < static_cast<long>(rpc_info->interceptors_.size())) { if (curr_iteration_ < static_cast<long>(rpc_info->interceptors_.size())) {
if (rpc_info->hijacked_ && if (rpc_info->hijacked_ &&
curr_iteration_ > rpc_info->hijacked_interceptor_) { curr_iteration_ > rpc_info->hijacked_interceptor_) {
/* This is a hijacked RPC and we are done with hijacking */ // This is a hijacked RPC and we are done with hijacking
ops_->ContinueFillOpsAfterInterception(); ops_->ContinueFillOpsAfterInterception();
} else { } else {
rpc_info->RunInterceptor(this, curr_iteration_); rpc_info->RunInterceptor(this, curr_iteration_);
} }
} else { } else {
/* we are done running all the interceptors without any hijacking */ // we are done running all the interceptors without any hijacking
ops_->ContinueFillOpsAfterInterception(); ops_->ContinueFillOpsAfterInterception();
} }
} else { } else {
/* We are going up the stack of interceptors */ // We are going up the stack of interceptors
if (curr_iteration_ >= 0) { if (curr_iteration_ >= 0) {
/* Continue running interceptors */ // Continue running interceptors
rpc_info->RunInterceptor(this, curr_iteration_); rpc_info->RunInterceptor(this, curr_iteration_);
} else { } else {
/* we are done running all the interceptors without any hijacking */ // we are done running all the interceptors without any hijacking
ops_->ContinueFinalizeResultAfterInterception(); ops_->ContinueFinalizeResultAfterInterception();
} }
} }
@ -1090,13 +1109,13 @@ class InterceptorBatchMethodsImpl
} }
} else { } else {
curr_iteration_--; curr_iteration_--;
/* We are going up the stack of interceptors */ // We are going up the stack of interceptors
if (curr_iteration_ >= 0) { if (curr_iteration_ >= 0) {
/* Continue running interceptors */ // Continue running interceptors
return rpc_info->RunInterceptor(this, curr_iteration_); return rpc_info->RunInterceptor(this, curr_iteration_);
} }
} }
/* we are done running all the interceptors */ // we are done running all the interceptors
if (ops_) { if (ops_) {
ops_->ContinueFinalizeResultAfterInterception(); ops_->ContinueFinalizeResultAfterInterception();
} }
@ -1170,16 +1189,16 @@ class CallOpSet : public CallOpSetInterface,
if (RunInterceptors()) { if (RunInterceptors()) {
ContinueFillOpsAfterInterception(); ContinueFillOpsAfterInterception();
} else { } else {
/* After the interceptors are run, ContinueFillOpsAfterInterception will // After the interceptors are run, ContinueFillOpsAfterInterception will
* be run */ // be run
} }
} }
bool FinalizeResult(void** tag, bool* status) override { bool FinalizeResult(void** tag, bool* status) override {
if (done_intercepting_) { if (done_intercepting_) {
/* We have already finished intercepting and filling in the results. This // We have already finished intercepting and filling in the results. This
* round trip from the core needed to be made because interceptors were // round trip from the core needed to be made because interceptors were
* run */ // run
*tag = return_tag_; *tag = return_tag_;
g_core_codegen_interface->grpc_call_unref(call_.call()); g_core_codegen_interface->grpc_call_unref(call_.call());
return true; return true;
@ -1198,8 +1217,8 @@ class CallOpSet : public CallOpSetInterface,
return true; return true;
} }
/* Interceptors are going to be run, so we can't return the tag just yet. // Interceptors are going to be run, so we can't return the tag just yet.
After the interceptors are run, ContinueFinalizeResultAfterInterception */ // After the interceptors are run, ContinueFinalizeResultAfterInterception
return false; return false;
} }
@ -1224,7 +1243,7 @@ class CallOpSet : public CallOpSetInterface,
this->Op6::SetHijackingState(&interceptor_methods_); this->Op6::SetHijackingState(&interceptor_methods_);
} }
/* Should be called after interceptors are done running */ // Should be called after interceptors are done running
void ContinueFillOpsAfterInterception() override { void ContinueFillOpsAfterInterception() override {
static const size_t MAX_OPS = 6; static const size_t MAX_OPS = 6;
grpc_op ops[MAX_OPS]; grpc_op ops[MAX_OPS];
@ -1240,8 +1259,8 @@ class CallOpSet : public CallOpSetInterface,
call_.call(), ops, nops, cq_tag(), nullptr)); call_.call(), ops, nops, cq_tag(), nullptr));
} }
/* Should be called after interceptors are done running on the finalize result // Should be called after interceptors are done running on the finalize result
* path */ // path
void ContinueFinalizeResultAfterInterception() override { void ContinueFinalizeResultAfterInterception() override {
done_intercepting_ = true; done_intercepting_ = true;
GPR_CODEGEN_ASSERT(GRPC_CALL_OK == GPR_CODEGEN_ASSERT(GRPC_CALL_OK ==
@ -1250,7 +1269,7 @@ class CallOpSet : public CallOpSetInterface,
} }
private: private:
/* Returns true if no interceptors need to be run */ // Returns true if no interceptors need to be run
bool RunInterceptors() { bool RunInterceptors() {
this->Op1::SetInterceptionHookPoint(&interceptor_methods_); this->Op1::SetInterceptionHookPoint(&interceptor_methods_);
this->Op2::SetInterceptionHookPoint(&interceptor_methods_); this->Op2::SetInterceptionHookPoint(&interceptor_methods_);
@ -1264,7 +1283,7 @@ class CallOpSet : public CallOpSetInterface,
// SetHijackingState, ContinueFinalizeResultAfterInterception); // SetHijackingState, ContinueFinalizeResultAfterInterception);
return interceptor_methods_.RunInterceptors(); return interceptor_methods_.RunInterceptors();
} }
/* Returns true if no interceptors need to be run */ // Returns true if no interceptors need to be run
bool RunInterceptorsPostRecv() { bool RunInterceptorsPostRecv() {
interceptor_methods_.SetReverse(); interceptor_methods_.SetReverse();
this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_); this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_);

@ -31,8 +31,7 @@ class ClientContext;
class Channel; class Channel;
namespace internal { namespace internal {
template <int I> class InterceptorBatchMethodsImpl;
class CallNoOp;
} }
namespace experimental { namespace experimental {
@ -69,8 +68,7 @@ class ClientRpcInfo {
grpc::ClientContext* client_context() { return ctx_; } grpc::ClientContext* client_context() { return ctx_; }
public: public:
/* Runs interceptor at pos \a pos. If \a reverse is set, the interceptor order // Runs interceptor at pos \a pos.
* is the reverse */
void RunInterceptor( void RunInterceptor(
experimental::InterceptorBatchMethods* interceptor_methods, experimental::InterceptorBatchMethods* interceptor_methods,
unsigned int pos) { unsigned int pos) {
@ -82,11 +80,11 @@ class ClientRpcInfo {
grpc::ClientContext* ctx_ = nullptr; grpc::ClientContext* ctx_ = nullptr;
const char* method_ = nullptr; const char* method_ = nullptr;
const grpc::Channel* channel_ = nullptr; const grpc::Channel* channel_ = nullptr;
public:
std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_;
bool hijacked_ = false; bool hijacked_ = false;
int hijacked_interceptor_ = false; int hijacked_interceptor_ = false;
friend class internal::InterceptorBatchMethodsImpl;
}; };
} // namespace experimental } // namespace experimental

@ -75,49 +75,38 @@ class InterceptorBatchMethods {
// valid if the batch contains send_initial_metadata on the client side) // valid if the batch contains send_initial_metadata on the client side)
virtual void Hijack() = 0; virtual void Hijack() = 0;
virtual void AddInterceptionHookPoint(InterceptionHookPoints type) = 0; // Returns a modifable ByteBuffer holding serialized form of the message to be
// sent
virtual ByteBuffer* GetSendMessage() = 0; virtual ByteBuffer* GetSendMessage() = 0;
// Returns a modifiable multimap of the initial metadata to be sent
virtual std::multimap<grpc::string, grpc::string>* virtual std::multimap<grpc::string, grpc::string>*
GetSendInitialMetadata() = 0; GetSendInitialMetadata() = 0;
// Returns the status to be sent
virtual Status GetSendStatus() = 0; virtual Status GetSendStatus() = 0;
// Modifies the status with \a status
virtual void ModifySendStatus(const Status& status) = 0; virtual void ModifySendStatus(const Status& status) = 0;
// Returns a modifiable multimap of the trailing metadata to be sent
virtual std::multimap<grpc::string, grpc::string>* virtual std::multimap<grpc::string, grpc::string>*
GetSendTrailingMetadata() = 0; GetSendTrailingMetadata() = 0;
// Returns a pointer to the modifiable received message. Note that the message
// is already deserialized
virtual void* GetRecvMessage() = 0; virtual void* GetRecvMessage() = 0;
// Returns a modifiable multimap of the received initial metadata
virtual std::multimap<grpc::string_ref, grpc::string_ref>* virtual std::multimap<grpc::string_ref, grpc::string_ref>*
GetRecvInitialMetadata() = 0; GetRecvInitialMetadata() = 0;
// Returns a modifiable view of the received status
virtual Status* GetRecvStatus() = 0; virtual Status* GetRecvStatus() = 0;
// Returns a modifiable multimap of the received trailing metadata
virtual std::multimap<grpc::string_ref, grpc::string_ref>* virtual std::multimap<grpc::string_ref, grpc::string_ref>*
GetRecvTrailingMetadata() = 0; GetRecvTrailingMetadata() = 0;
virtual void SetSendMessage(ByteBuffer* buf) = 0;
virtual void SetSendInitialMetadata(
std::multimap<grpc::string, grpc::string>* metadata) = 0;
virtual void SetSendStatus(grpc_status_code* code,
grpc::string* error_details,
grpc::string* error_message) = 0;
virtual void SetSendTrailingMetadata(
std::multimap<grpc::string, grpc::string>* metadata) = 0;
virtual void SetRecvMessage(void* message) = 0;
virtual void SetRecvInitialMetadata(internal::MetadataMap* map) = 0;
virtual void SetRecvStatus(Status* status) = 0;
virtual void SetRecvTrailingMetadata(internal::MetadataMap* map) = 0;
}; };
class Interceptor { class Interceptor {

@ -30,8 +30,7 @@ namespace grpc {
class ServerContext; class ServerContext;
namespace internal { namespace internal {
template <int I> class InterceptorBatchMethodsImpl;
class CallNoOp;
} }
namespace experimental { namespace experimental {
@ -66,8 +65,7 @@ class ServerRpcInfo {
grpc::ServerContext* server_context() { return ctx_; } grpc::ServerContext* server_context() { return ctx_; }
public: public:
/* Runs interceptor at pos \a pos. If \a reverse is set, the interceptor order // Runs interceptor at pos \a pos.
* is the reverse */
void RunInterceptor( void RunInterceptor(
experimental::InterceptorBatchMethods* interceptor_methods, experimental::InterceptorBatchMethods* interceptor_methods,
unsigned int pos) { unsigned int pos) {
@ -78,9 +76,9 @@ class ServerRpcInfo {
private: private:
grpc::ServerContext* ctx_ = nullptr; grpc::ServerContext* ctx_ = nullptr;
const char* method_ = nullptr; const char* method_ = nullptr;
public:
std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_;
friend class internal::InterceptorBatchMethodsImpl;
}; };
} // namespace experimental } // namespace experimental

Loading…
Cancel
Save