aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2018-11-02 08:56:16 -0700
committerGravatar GitHub <noreply@github.com>2018-11-02 08:56:16 -0700
commit3ac7f2d24c24c80b2e93b0e905f2cf6c92b6ff29 (patch)
tree0c19aa38531b51864f24e9bd71de340cdafac8c0 /include
parent53657b5de385ffc54e33899b3f2a87ff78d2952b (diff)
parent857e79ce005870332f0e44347e7c933747bd5d72 (diff)
Merge pull request #17053 from yashykt/global_interceptor
Add global client interceptor factory
Diffstat (limited to 'include')
-rw-r--r--include/grpcpp/channel.h2
-rw-r--r--include/grpcpp/impl/codegen/channel_interface.h2
-rw-r--r--include/grpcpp/impl/codegen/client_interceptor.h33
-rw-r--r--include/grpcpp/impl/codegen/intercepted_channel.h4
4 files changed, 36 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 39805a0ef5..6ec1ffb8c7 100644
--- a/include/grpcpp/impl/codegen/channel_interface.h
+++ b/include/grpcpp/impl/codegen/channel_interface.h
@@ -134,7 +134,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 0e08a7ce01..f69c99ab22 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 <grpcpp/impl/codegen/interceptor.h>
@@ -41,7 +42,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() {}
@@ -71,12 +79,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;
@@ -90,6 +107,20 @@ class ClientRpcInfo {
friend class grpc::ClientContext;
};
+// PLEASE DO NOT USE THIS. ALWAYS PREFER PER CHANNEL INTERCEPTORS OVER A GLOBAL
+// INTERCEPTOR. IF USAGE IS ABSOLUTELY NECESSARY, PLEASE READ THE SAFETY NOTES.
+// Registers a global client interceptor factory object, which is used for all
+// RPCs made in this process. If the argument is nullptr, the global
+// interceptor factory is deregistered. The application is responsible for
+// maintaining the life of the object while gRPC operations are in progress. It
+// is unsafe to try to register/deregister if any gRPC operation is in progress.
+// For safety, it is in the best interests of the developer to register the
+// global interceptor factory once at the start of the process before any gRPC
+// operations have begun. Deregistration is optional since gRPC does not
+// maintain any references to the object.
+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;
};