diff options
author | Yash Tibrewal <yashkt@google.com> | 2018-10-30 02:09:11 -0700 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2018-10-30 02:43:01 -0700 |
commit | 0390b29e15e79acd1e84c511d5c20d8e20ee2eb6 (patch) | |
tree | 78b32178894fbac5f6aeb92eaffe59b4091e9adb /include/grpcpp | |
parent | 01313976e1a44b5c9625d3a349fffa55471beff4 (diff) |
Register global interceptors functionality
Diffstat (limited to 'include/grpcpp')
-rw-r--r-- | include/grpcpp/channel.h | 2 | ||||
-rw-r--r-- | include/grpcpp/impl/codegen/channel_interface.h | 2 | ||||
-rw-r--r-- | include/grpcpp/impl/codegen/client_interceptor.h | 27 | ||||
-rw-r--r-- | include/grpcpp/impl/codegen/intercepted_channel.h | 4 |
4 files changed, 30 insertions, 5 deletions
diff --git a/include/grpcpp/channel.h b/include/grpcpp/channel.h index 14209b85ee..4502b94b17 100644 --- a/include/grpcpp/channel.h +++ b/include/grpcpp/channel.h @@ -91,7 +91,7 @@ class Channel final : public ChannelInterface, internal::Call CreateCallInternal(const internal::RpcMethod& method, ClientContext* context, CompletionQueue* cq, - int interceptor_pos) override; + size_t interceptor_pos) override; const grpc::string host_; grpc_channel* const c_channel_; // owned diff --git a/include/grpcpp/impl/codegen/channel_interface.h b/include/grpcpp/impl/codegen/channel_interface.h index 6fd1dd1d9b..e8ed6a9805 100644 --- a/include/grpcpp/impl/codegen/channel_interface.h +++ b/include/grpcpp/impl/codegen/channel_interface.h @@ -133,7 +133,7 @@ class ChannelInterface { virtual internal::Call CreateCallInternal(const internal::RpcMethod& method, ClientContext* context, CompletionQueue* cq, - int interceptor_pos) { + size_t interceptor_pos) { return internal::Call(); } diff --git a/include/grpcpp/impl/codegen/client_interceptor.h b/include/grpcpp/impl/codegen/client_interceptor.h index 00113f04aa..f44a7c469c 100644 --- a/include/grpcpp/impl/codegen/client_interceptor.h +++ b/include/grpcpp/impl/codegen/client_interceptor.h @@ -19,6 +19,7 @@ #ifndef GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H #define GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H +#include <memory> #include <vector> #include <grpc/impl/codegen/log.h> @@ -42,7 +43,14 @@ class ClientInterceptorFactoryInterface { virtual ~ClientInterceptorFactoryInterface() {} virtual Interceptor* CreateClientInterceptor(ClientRpcInfo* info) = 0; }; +} // namespace experimental +namespace internal { +extern experimental::ClientInterceptorFactoryInterface* + g_global_client_interceptor_factory; +} + +namespace experimental { class ClientRpcInfo { public: ClientRpcInfo() {} @@ -72,12 +80,21 @@ class ClientRpcInfo { void RegisterInterceptors( const std::vector<std::unique_ptr< experimental::ClientInterceptorFactoryInterface>>& creators, - int interceptor_pos) { + size_t interceptor_pos) { + if (interceptor_pos > creators.size()) { + // No interceptors to register + return; + } for (auto it = creators.begin() + interceptor_pos; it != creators.end(); ++it) { interceptors_.push_back(std::unique_ptr<experimental::Interceptor>( (*it)->CreateClientInterceptor(this))); } + if (internal::g_global_client_interceptor_factory != nullptr) { + interceptors_.push_back(std::unique_ptr<experimental::Interceptor>( + internal::g_global_client_interceptor_factory + ->CreateClientInterceptor(this))); + } } grpc::ClientContext* ctx_ = nullptr; @@ -91,6 +108,14 @@ class ClientRpcInfo { friend class grpc::ClientContext; }; +// DO NOT USE THIS +// Registers a global client interceptor factory object. This should be +// registered before any channels are created. The application is responsible +// for maintaining the life of the object while gRPC is used. It is unsafe to +// try to register if gRPC operations have already started. +void RegisterGlobalClientInterceptorFactory( + ClientInterceptorFactoryInterface* factory); + } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/impl/codegen/intercepted_channel.h b/include/grpcpp/impl/codegen/intercepted_channel.h index 612e56d862..5255a6d147 100644 --- a/include/grpcpp/impl/codegen/intercepted_channel.h +++ b/include/grpcpp/impl/codegen/intercepted_channel.h @@ -42,7 +42,7 @@ class InterceptedChannel : public ChannelInterface { } private: - InterceptedChannel(ChannelInterface* channel, int pos) + InterceptedChannel(ChannelInterface* channel, size_t pos) : channel_(channel), interceptor_pos_(pos) {} Call CreateCall(const RpcMethod& method, ClientContext* context, @@ -70,7 +70,7 @@ class InterceptedChannel : public ChannelInterface { CompletionQueue* CallbackCQ() override { return channel_->CallbackCQ(); } ChannelInterface* channel_; - int interceptor_pos_; + size_t interceptor_pos_; friend class InterceptorBatchMethodsImpl; }; |