diff options
author | 2018-10-19 17:07:05 -0700 | |
---|---|---|
committer | 2018-10-19 17:07:05 -0700 | |
commit | 52765e9cb1e18780fcd4701e91e019bf78c9b957 (patch) | |
tree | d047c5147004a941c38faa3285f07a6bc6e390ba /include | |
parent | 456231b26d56e13b9a56b93baabede4dd8fc2519 (diff) |
Don't expose internal functions.. Add a layer of indirection namely InternalInterceptorBatchMethods
Diffstat (limited to 'include')
-rw-r--r-- | include/grpcpp/impl/codegen/call.h | 193 | ||||
-rw-r--r-- | include/grpcpp/impl/codegen/client_interceptor.h | 10 | ||||
-rw-r--r-- | include/grpcpp/impl/codegen/interceptor.h | 33 | ||||
-rw-r--r-- | include/grpcpp/impl/codegen/server_interceptor.h | 10 |
4 files changed, 125 insertions, 121 deletions
diff --git a/include/grpcpp/impl/codegen/call.h b/include/grpcpp/impl/codegen/call.h index 167db8d4dd..5033890912 100644 --- a/include/grpcpp/impl/codegen/call.h +++ b/include/grpcpp/impl/codegen/call.h @@ -204,6 +204,36 @@ class WriteOptions { }; 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 /// used for generating multiple names for the same thing. template <int I> @@ -212,12 +242,12 @@ class CallNoOp { void AddOp(grpc_op* ops, size_t* nops) {} void FinishOp(bool* status) {} void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) {} + InternalInterceptorBatchMethods* interceptor_methods) {} void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) {} - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) {} + InternalInterceptorBatchMethods* interceptor_methods) {} + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { + } }; class CallOpSendInitialMetadata { @@ -264,7 +294,7 @@ class CallOpSendInitialMetadata { } void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { if (!send_) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA); @@ -272,10 +302,9 @@ class CallOpSendInitialMetadata { } void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) {} + InternalInterceptorBatchMethods* interceptor_methods) {} - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) { + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { hijacked_ = true; } @@ -318,7 +347,7 @@ class CallOpSendMessage { void FinishOp(bool* status) { send_buf_.Clear(); } void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { if (!send_buf_.Valid()) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::PRE_SEND_MESSAGE); @@ -326,10 +355,9 @@ class CallOpSendMessage { } void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) {} + InternalInterceptorBatchMethods* interceptor_methods) {} - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) { + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { hijacked_ = true; } @@ -407,18 +435,17 @@ class CallOpRecvMessage { } void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { interceptor_methods->SetRecvMessage(message_); } void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { if (!got_message) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::POST_RECV_MESSAGE); } - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) { + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { hijacked_ = true; if (message_ == nullptr) return; interceptor_methods->AddInterceptionHookPoint( @@ -503,18 +530,17 @@ class CallOpGenericRecvMessage { } void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { interceptor_methods->SetRecvMessage(message_); } void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { if (!got_message) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::POST_RECV_MESSAGE); } - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) { + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { hijacked_ = true; if (!deserialize_) return; interceptor_methods->AddInterceptionHookPoint( @@ -546,17 +572,16 @@ class CallOpClientSendClose { void FinishOp(bool* status) { send_ = false; } void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { if (!send_) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::PRE_SEND_CLOSE); } void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) {} + InternalInterceptorBatchMethods* interceptor_methods) {} - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) { + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { hijacked_ = true; } @@ -604,7 +629,7 @@ class CallOpServerSendStatus { } void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { if (!send_status_available_) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::PRE_SEND_STATUS); @@ -614,10 +639,9 @@ class CallOpServerSendStatus { } void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) {} + InternalInterceptorBatchMethods* interceptor_methods) {} - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) { + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { hijacked_ = true; } @@ -657,20 +681,19 @@ class CallOpRecvInitialMetadata { } void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { interceptor_methods->SetRecvInitialMetadata(metadata_map_); } void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { if (metadata_map_ == nullptr) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA); metadata_map_ = nullptr; } - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) { + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { hijacked_ = true; if (metadata_map_ == nullptr) return; interceptor_methods->AddInterceptionHookPoint( @@ -726,21 +749,20 @@ class CallOpClientRecvStatus { } void SetInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { interceptor_methods->SetRecvStatus(recv_status_); interceptor_methods->SetRecvTrailingMetadata(metadata_map_); } void SetFinishInterceptionHookPoint( - experimental::InterceptorBatchMethods* interceptor_methods) { + InternalInterceptorBatchMethods* interceptor_methods) { if (recv_status_ == nullptr) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::POST_RECV_STATUS); recv_status_ = nullptr; } - void SetHijackingState( - experimental::InterceptorBatchMethods* interceptor_methods) { + void SetHijackingState(InternalInterceptorBatchMethods* interceptor_methods) { hijacked_ = true; if (recv_status_ == nullptr) return; interceptor_methods->AddInterceptionHookPoint( @@ -834,11 +856,11 @@ class CallOpSetInterface : public CompletionQueueTag { // RPC. This should set hijacking state for each of the ops. virtual void SetHijackingState() = 0; - /* Should be called after interceptors are done running */ + // Should be called after interceptors are done running virtual void ContinueFillOpsAfterInterception() = 0; - /* Should be called after interceptors are done running on the finalize result - * path */ + // Should be called after interceptors are done running on the finalize result + // path 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 CallOpSet; -class InterceptorBatchMethodsImpl - : public experimental::InterceptorBatchMethods { +class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods { public: InterceptorBatchMethodsImpl() { for (auto i = 0; @@ -874,8 +895,8 @@ class InterceptorBatchMethodsImpl ProceedServer(); } - virtual void Hijack() override { /* fill this */ - /* Only the client can hijack when sending down initial metadata */ + virtual void Hijack() override { + // Only the client can hijack when sending down initial metadata GPR_CODEGEN_ASSERT(!reverse_ && ops_ != nullptr && call_->client_rpc_info() != nullptr); auto* rpc_info = call_->client_rpc_info(); @@ -930,58 +951,55 @@ class InterceptorBatchMethodsImpl 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( - std::multimap<grpc::string, grpc::string>* metadata) override { + std::multimap<grpc::string, grpc::string>* metadata) { send_initial_metadata_ = metadata; } virtual void SetSendStatus(grpc_status_code* code, grpc::string* error_details, - grpc::string* error_message) override { + grpc::string* error_message) { code_ = code; error_details_ = error_details; error_message_ = error_message; } virtual void SetSendTrailingMetadata( - std::multimap<grpc::string, grpc::string>* metadata) override { + std::multimap<grpc::string, grpc::string>* metadata) { send_trailing_metadata_ = metadata; } - virtual void SetRecvMessage(void* message) override { - recv_message_ = message; - } + virtual void SetRecvMessage(void* message) { recv_message_ = message; } - virtual void SetRecvInitialMetadata(internal::MetadataMap* map) override { + virtual void SetRecvInitialMetadata(internal::MetadataMap* 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; } - /* Prepares for Post_recv operations */ + // Prepares for Post_recv operations void SetReverse() { reverse_ = true; 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 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 - ContinueFinalizeOpsAfterInterception will be called. Note that neither of them - is invoked if there were no interceptors registered. - */ + // 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 + // ContinueFinalizeOpsAfterInterception will be called. Note that neither of + // them is invoked if there were no interceptors registered. bool RunInterceptors() { auto* client_rpc_info = call_->client_rpc_info(); if (client_rpc_info == nullptr || @@ -1001,9 +1019,10 @@ class InterceptorBatchMethodsImpl return false; } - /* Returns true if no interceptors are run. Returns false otherwise if there - are interceptors registered. After the interceptors are done running \a f will - be invoked. This is to be used only by BaseAsyncRequest and SyncRequest. */ + // Returns true if no interceptors are run. Returns false otherwise if there + // are interceptors registered. After the interceptors are done running \a f + // will + // be invoked. This is to be used only by BaseAsyncRequest and SyncRequest. bool RunInterceptors(std::function<void(void)> f) { GPR_CODEGEN_ASSERT(reverse_ == true); GPR_CODEGEN_ASSERT(call_->client_rpc_info() == nullptr); @@ -1049,33 +1068,33 @@ class InterceptorBatchMethodsImpl auto* rpc_info = call_->client_rpc_info(); if (rpc_info->hijacked_ && (!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(); ops_->SetHijackingState(); rpc_info->RunInterceptor(this, curr_iteration_ - 1); return; } 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 (rpc_info->hijacked_ && 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(); } else { rpc_info->RunInterceptor(this, curr_iteration_); } } else { - /* we are done running all the interceptors without any hijacking */ + // we are done running all the interceptors without any hijacking ops_->ContinueFillOpsAfterInterception(); } } else { - /* We are going up the stack of interceptors */ + // We are going up the stack of interceptors if (curr_iteration_ >= 0) { - /* Continue running interceptors */ + // Continue running interceptors rpc_info->RunInterceptor(this, curr_iteration_); } else { - /* we are done running all the interceptors without any hijacking */ + // we are done running all the interceptors without any hijacking ops_->ContinueFinalizeResultAfterInterception(); } } @@ -1090,13 +1109,13 @@ class InterceptorBatchMethodsImpl } } else { curr_iteration_--; - /* We are going up the stack of interceptors */ + // We are going up the stack of interceptors if (curr_iteration_ >= 0) { - /* Continue running interceptors */ + // Continue running interceptors return rpc_info->RunInterceptor(this, curr_iteration_); } } - /* we are done running all the interceptors */ + // we are done running all the interceptors if (ops_) { ops_->ContinueFinalizeResultAfterInterception(); } @@ -1170,16 +1189,16 @@ class CallOpSet : public CallOpSetInterface, if (RunInterceptors()) { ContinueFillOpsAfterInterception(); } else { - /* After the interceptors are run, ContinueFillOpsAfterInterception will - * be run */ + // After the interceptors are run, ContinueFillOpsAfterInterception will + // be run } } bool FinalizeResult(void** tag, bool* status) override { if (done_intercepting_) { - /* We have already finished intercepting and filling in the results. This - * round trip from the core needed to be made because interceptors were - * run */ + // We have already finished intercepting and filling in the results. This + // round trip from the core needed to be made because interceptors were + // run *tag = return_tag_; g_core_codegen_interface->grpc_call_unref(call_.call()); return true; @@ -1198,8 +1217,8 @@ class CallOpSet : public CallOpSetInterface, return true; } - /* Interceptors are going to be run, so we can't return the tag just yet. - After the interceptors are run, ContinueFinalizeResultAfterInterception */ + // Interceptors are going to be run, so we can't return the tag just yet. + // After the interceptors are run, ContinueFinalizeResultAfterInterception return false; } @@ -1224,7 +1243,7 @@ class CallOpSet : public CallOpSetInterface, this->Op6::SetHijackingState(&interceptor_methods_); } - /* Should be called after interceptors are done running */ + // Should be called after interceptors are done running void ContinueFillOpsAfterInterception() override { static const size_t MAX_OPS = 6; grpc_op ops[MAX_OPS]; @@ -1240,8 +1259,8 @@ class CallOpSet : public CallOpSetInterface, call_.call(), ops, nops, cq_tag(), nullptr)); } - /* Should be called after interceptors are done running on the finalize result - * path */ + // Should be called after interceptors are done running on the finalize result + // path void ContinueFinalizeResultAfterInterception() override { done_intercepting_ = true; GPR_CODEGEN_ASSERT(GRPC_CALL_OK == @@ -1250,7 +1269,7 @@ class CallOpSet : public CallOpSetInterface, } private: - /* Returns true if no interceptors need to be run */ + // Returns true if no interceptors need to be run bool RunInterceptors() { this->Op1::SetInterceptionHookPoint(&interceptor_methods_); this->Op2::SetInterceptionHookPoint(&interceptor_methods_); @@ -1264,7 +1283,7 @@ class CallOpSet : public CallOpSetInterface, // SetHijackingState, ContinueFinalizeResultAfterInterception); return interceptor_methods_.RunInterceptors(); } - /* Returns true if no interceptors need to be run */ + // Returns true if no interceptors need to be run bool RunInterceptorsPostRecv() { interceptor_methods_.SetReverse(); this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_); diff --git a/include/grpcpp/impl/codegen/client_interceptor.h b/include/grpcpp/impl/codegen/client_interceptor.h index 0a3a2ab07f..6feec224ce 100644 --- a/include/grpcpp/impl/codegen/client_interceptor.h +++ b/include/grpcpp/impl/codegen/client_interceptor.h @@ -31,8 +31,7 @@ class ClientContext; class Channel; namespace internal { -template <int I> -class CallNoOp; +class InterceptorBatchMethodsImpl; } namespace experimental { @@ -69,8 +68,7 @@ class ClientRpcInfo { grpc::ClientContext* client_context() { return ctx_; } public: - /* Runs interceptor at pos \a pos. If \a reverse is set, the interceptor order - * is the reverse */ + // Runs interceptor at pos \a pos. void RunInterceptor( experimental::InterceptorBatchMethods* interceptor_methods, unsigned int pos) { @@ -82,11 +80,11 @@ class ClientRpcInfo { grpc::ClientContext* ctx_ = nullptr; const char* method_ = nullptr; const grpc::Channel* channel_ = nullptr; - - public: std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; bool hijacked_ = false; int hijacked_interceptor_ = false; + + friend class internal::InterceptorBatchMethodsImpl; }; } // namespace experimental diff --git a/include/grpcpp/impl/codegen/interceptor.h b/include/grpcpp/impl/codegen/interceptor.h index 3e16b99326..e66f684c29 100644 --- a/include/grpcpp/impl/codegen/interceptor.h +++ b/include/grpcpp/impl/codegen/interceptor.h @@ -75,49 +75,38 @@ class InterceptorBatchMethods { // valid if the batch contains send_initial_metadata on the client side) 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; + // Returns a modifiable multimap of the initial metadata to be sent virtual std::multimap<grpc::string, grpc::string>* GetSendInitialMetadata() = 0; + // Returns the status to be sent virtual Status GetSendStatus() = 0; + // Modifies the status with \a status 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>* GetSendTrailingMetadata() = 0; + // Returns a pointer to the modifiable received message. Note that the message + // is already deserialized virtual void* GetRecvMessage() = 0; + // Returns a modifiable multimap of the received initial metadata virtual std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() = 0; + // Returns a modifiable view of the received status virtual Status* GetRecvStatus() = 0; + // Returns a modifiable multimap of the received trailing metadata virtual std::multimap<grpc::string_ref, grpc::string_ref>* 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 { diff --git a/include/grpcpp/impl/codegen/server_interceptor.h b/include/grpcpp/impl/codegen/server_interceptor.h index 9eb1a61385..14b786cef9 100644 --- a/include/grpcpp/impl/codegen/server_interceptor.h +++ b/include/grpcpp/impl/codegen/server_interceptor.h @@ -30,8 +30,7 @@ namespace grpc { class ServerContext; namespace internal { -template <int I> -class CallNoOp; +class InterceptorBatchMethodsImpl; } namespace experimental { @@ -66,8 +65,7 @@ class ServerRpcInfo { grpc::ServerContext* server_context() { return ctx_; } public: - /* Runs interceptor at pos \a pos. If \a reverse is set, the interceptor order - * is the reverse */ + // Runs interceptor at pos \a pos. void RunInterceptor( experimental::InterceptorBatchMethods* interceptor_methods, unsigned int pos) { @@ -78,9 +76,9 @@ class ServerRpcInfo { private: grpc::ServerContext* ctx_ = nullptr; const char* method_ = nullptr; - - public: std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; + + friend class internal::InterceptorBatchMethodsImpl; }; } // namespace experimental |