aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2018-10-30 02:09:11 -0700
committerGravatar Yash Tibrewal <yashkt@google.com>2018-10-30 02:43:01 -0700
commit0390b29e15e79acd1e84c511d5c20d8e20ee2eb6 (patch)
tree78b32178894fbac5f6aeb92eaffe59b4091e9adb
parent01313976e1a44b5c9625d3a349fffa55471beff4 (diff)
Register global interceptors functionality
-rw-r--r--BUILD1
-rw-r--r--CMakeLists.txt6
-rw-r--r--Makefile11
-rw-r--r--build.yaml1
-rw-r--r--gRPC-C++.podspec1
-rw-r--r--grpc.gyp4
-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.h27
-rw-r--r--include/grpcpp/impl/codegen/intercepted_channel.h4
-rw-r--r--src/cpp/client/channel_cc.cc2
-rw-r--r--src/cpp/codegen/client_interceptor.cc34
-rw-r--r--tools/doxygen/Doxyfile.c++.internal1
-rw-r--r--tools/run_tests/generated/sources_and_headers.json1
14 files changed, 91 insertions, 6 deletions
diff --git a/BUILD b/BUILD
index c8ad45a788..195e732d2c 100644
--- a/BUILD
+++ b/BUILD
@@ -2109,6 +2109,7 @@ grpc_cc_library(
name = "grpc++_codegen_base_src",
srcs = [
"src/cpp/codegen/codegen_init.cc",
+ "src/cpp/codegen/client_interceptor.cc",
],
language = "c++",
deps = [
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b41ec6c6e..6e8ffbaae3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2895,6 +2895,7 @@ add_library(grpc++
third_party/nanopb/pb_common.c
third_party/nanopb/pb_decode.c
third_party/nanopb/pb_encode.c
+ src/cpp/codegen/client_interceptor.cc
src/cpp/codegen/codegen_init.cc
)
@@ -3264,6 +3265,7 @@ add_library(grpc++_cronet
third_party/nanopb/pb_common.c
third_party/nanopb/pb_decode.c
third_party/nanopb/pb_encode.c
+ src/cpp/codegen/client_interceptor.cc
src/cpp/codegen/codegen_init.cc
src/core/ext/transport/chttp2/client/insecure/channel_create.cc
src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc
@@ -4015,6 +4017,7 @@ add_library(grpc++_test_util
test/cpp/util/string_ref_helper.cc
test/cpp/util/subprocess.cc
test/cpp/util/test_credentials_provider.cc
+ src/cpp/codegen/client_interceptor.cc
src/cpp/codegen/codegen_init.cc
)
@@ -4204,6 +4207,7 @@ add_library(grpc++_test_util_unsecure
test/cpp/util/byte_buffer_proto_helper.cc
test/cpp/util/string_ref_helper.cc
test/cpp/util/subprocess.cc
+ src/cpp/codegen/client_interceptor.cc
src/cpp/codegen/codegen_init.cc
)
@@ -4406,6 +4410,7 @@ add_library(grpc++_unsecure
third_party/nanopb/pb_common.c
third_party/nanopb/pb_decode.c
third_party/nanopb/pb_encode.c
+ src/cpp/codegen/client_interceptor.cc
src/cpp/codegen/codegen_init.cc
)
@@ -12631,6 +12636,7 @@ add_executable(codegen_test_minimal
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/stats.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/stats.grpc.pb.h
test/cpp/codegen/codegen_test_minimal.cc
+ src/cpp/codegen/client_interceptor.cc
src/cpp/codegen/codegen_init.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
diff --git a/Makefile b/Makefile
index aafdebb6ca..46d66c1dba 100644
--- a/Makefile
+++ b/Makefile
@@ -5277,6 +5277,7 @@ LIBGRPC++_SRC = \
third_party/nanopb/pb_common.c \
third_party/nanopb/pb_decode.c \
third_party/nanopb/pb_encode.c \
+ src/cpp/codegen/client_interceptor.cc \
src/cpp/codegen/codegen_init.cc \
PUBLIC_HEADERS_CXX += \
@@ -5656,6 +5657,7 @@ LIBGRPC++_CRONET_SRC = \
third_party/nanopb/pb_common.c \
third_party/nanopb/pb_decode.c \
third_party/nanopb/pb_encode.c \
+ src/cpp/codegen/client_interceptor.cc \
src/cpp/codegen/codegen_init.cc \
src/core/ext/transport/chttp2/client/insecure/channel_create.cc \
src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \
@@ -6409,6 +6411,7 @@ LIBGRPC++_TEST_UTIL_SRC = \
test/cpp/util/string_ref_helper.cc \
test/cpp/util/subprocess.cc \
test/cpp/util/test_credentials_provider.cc \
+ src/cpp/codegen/client_interceptor.cc \
src/cpp/codegen/codegen_init.cc \
PUBLIC_HEADERS_CXX += \
@@ -6560,6 +6563,7 @@ $(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/src/proto/grp
$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/subprocess.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/test_credentials_provider.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
+$(OBJDIR)/$(CONFIG)/src/cpp/codegen/client_interceptor.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
@@ -6572,6 +6576,7 @@ LIBGRPC++_TEST_UTIL_UNSECURE_SRC = \
test/cpp/util/byte_buffer_proto_helper.cc \
test/cpp/util/string_ref_helper.cc \
test/cpp/util/subprocess.cc \
+ src/cpp/codegen/client_interceptor.cc \
src/cpp/codegen/codegen_init.cc \
PUBLIC_HEADERS_CXX += \
@@ -6720,6 +6725,7 @@ $(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(GENDIR)/src/proto/gr
$(OBJDIR)/$(CONFIG)/test/cpp/util/byte_buffer_proto_helper.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/subprocess.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
+$(OBJDIR)/$(CONFIG)/src/cpp/codegen/client_interceptor.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
@@ -6763,6 +6769,7 @@ LIBGRPC++_UNSECURE_SRC = \
third_party/nanopb/pb_common.c \
third_party/nanopb/pb_decode.c \
third_party/nanopb/pb_encode.c \
+ src/cpp/codegen/client_interceptor.cc \
src/cpp/codegen/codegen_init.cc \
PUBLIC_HEADERS_CXX += \
@@ -17469,6 +17476,7 @@ CODEGEN_TEST_MINIMAL_SRC = \
$(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc \
$(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc \
test/cpp/codegen/codegen_test_minimal.cc \
+ src/cpp/codegen/client_interceptor.cc \
src/cpp/codegen/codegen_init.cc \
CODEGEN_TEST_MINIMAL_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CODEGEN_TEST_MINIMAL_SRC))))
@@ -17516,6 +17524,8 @@ $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/stats.o: $(LIBDIR)/$(CONFIG)/libgrpc
$(OBJDIR)/$(CONFIG)/test/cpp/codegen/codegen_test_minimal.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
+$(OBJDIR)/$(CONFIG)/src/cpp/codegen/client_interceptor.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
+
$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_codegen_test_minimal: $(CODEGEN_TEST_MINIMAL_OBJS:.o=.dep)
@@ -17526,6 +17536,7 @@ ifneq ($(NO_DEPS),true)
endif
endif
$(OBJDIR)/$(CONFIG)/test/cpp/codegen/codegen_test_minimal.o: $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc
+$(OBJDIR)/$(CONFIG)/src/cpp/codegen/client_interceptor.o: $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc
diff --git a/build.yaml b/build.yaml
index e5955007d4..26c50e0d84 100644
--- a/build.yaml
+++ b/build.yaml
@@ -1261,6 +1261,7 @@ filegroups:
- name: grpc++_codegen_base_src
language: c++
src:
+ - src/cpp/codegen/client_interceptor.cc
- src/cpp/codegen/codegen_init.cc
uses:
- grpc++_codegen_base
diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec
index 485646171c..f45cdc4764 100644
--- a/gRPC-C++.podspec
+++ b/gRPC-C++.podspec
@@ -223,6 +223,7 @@ Pod::Spec.new do |s|
'src/cpp/util/status.cc',
'src/cpp/util/string_ref.cc',
'src/cpp/util/time_cc.cc',
+ 'src/cpp/codegen/client_interceptor.cc',
'src/cpp/codegen/codegen_init.cc',
'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/arena.h',
diff --git a/grpc.gyp b/grpc.gyp
index 963b8b22b1..dfb97cb370 100644
--- a/grpc.gyp
+++ b/grpc.gyp
@@ -1420,6 +1420,7 @@
'third_party/nanopb/pb_common.c',
'third_party/nanopb/pb_decode.c',
'third_party/nanopb/pb_encode.c',
+ 'src/cpp/codegen/client_interceptor.cc',
'src/cpp/codegen/codegen_init.cc',
],
},
@@ -1500,6 +1501,7 @@
'test/cpp/util/string_ref_helper.cc',
'test/cpp/util/subprocess.cc',
'test/cpp/util/test_credentials_provider.cc',
+ 'src/cpp/codegen/client_interceptor.cc',
'src/cpp/codegen/codegen_init.cc',
],
},
@@ -1520,6 +1522,7 @@
'test/cpp/util/byte_buffer_proto_helper.cc',
'test/cpp/util/string_ref_helper.cc',
'test/cpp/util/subprocess.cc',
+ 'src/cpp/codegen/client_interceptor.cc',
'src/cpp/codegen/codegen_init.cc',
],
},
@@ -1570,6 +1573,7 @@
'third_party/nanopb/pb_common.c',
'third_party/nanopb/pb_decode.c',
'third_party/nanopb/pb_encode.c',
+ 'src/cpp/codegen/client_interceptor.cc',
'src/cpp/codegen/codegen_init.cc',
],
},
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;
};
diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc
index 15e3ccb3c9..d1dab5d115 100644
--- a/src/cpp/client/channel_cc.cc
+++ b/src/cpp/client/channel_cc.cc
@@ -115,7 +115,7 @@ void ChannelResetConnectionBackoff(Channel* channel) {
internal::Call Channel::CreateCallInternal(const internal::RpcMethod& method,
ClientContext* context,
CompletionQueue* cq,
- int interceptor_pos) {
+ size_t interceptor_pos) {
const bool kRegistered = method.channel_tag() && context->authority().empty();
grpc_call* c_call = nullptr;
if (kRegistered) {
diff --git a/src/cpp/codegen/client_interceptor.cc b/src/cpp/codegen/client_interceptor.cc
new file mode 100644
index 0000000000..3a5cac9830
--- /dev/null
+++ b/src/cpp/codegen/client_interceptor.cc
@@ -0,0 +1,34 @@
+/*
+ *
+ * Copyright 2018 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <grpcpp/impl/codegen/client_interceptor.h>
+
+namespace grpc {
+
+namespace internal {
+experimental::ClientInterceptorFactoryInterface*
+ g_global_client_interceptor_factory = nullptr;
+}
+
+namespace experimental {
+void RegisterGlobalClientInterceptorFactory(
+ ClientInterceptorFactoryInterface* factory) {
+ internal::g_global_client_interceptor_factory = factory;
+}
+} // namespace experimental
+} // namespace grpc
diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal
index 81d74cd972..e441ff9c66 100644
--- a/tools/doxygen/Doxyfile.c++.internal
+++ b/tools/doxygen/Doxyfile.c++.internal
@@ -1193,6 +1193,7 @@ src/cpp/client/generic_stub.cc \
src/cpp/client/insecure_credentials.cc \
src/cpp/client/secure_credentials.cc \
src/cpp/client/secure_credentials.h \
+src/cpp/codegen/client_interceptor.cc \
src/cpp/codegen/codegen_init.cc \
src/cpp/common/alarm.cc \
src/cpp/common/auth_property_iterator.cc \
diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json
index 9d7d487e0d..45d9ebe6e0 100644
--- a/tools/run_tests/generated/sources_and_headers.json
+++ b/tools/run_tests/generated/sources_and_headers.json
@@ -11298,6 +11298,7 @@
"language": "c++",
"name": "grpc++_codegen_base_src",
"src": [
+ "src/cpp/codegen/client_interceptor.cc",
"src/cpp/codegen/codegen_init.cc"
],
"third_party": false,