aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/grpc++/channel_filter.h114
-rw-r--r--src/cpp/common/channel_filter.cc38
-rw-r--r--test/cpp/end2end/filter_end2end_test.cc8
3 files changed, 76 insertions, 84 deletions
diff --git a/include/grpc++/channel_filter.h b/include/grpc++/channel_filter.h
index 8731a5e965..f73abe8e6c 100644
--- a/include/grpc++/channel_filter.h
+++ b/include/grpc++/channel_filter.h
@@ -59,12 +59,12 @@ class ChannelData {
public:
virtual ~ChannelData() {}
- virtual void StartTransportOp(
- grpc_exec_ctx *exec_ctx, grpc_channel_element *elem,
- grpc_transport_op *op);
+ virtual void StartTransportOp(grpc_exec_ctx *exec_ctx,
+ grpc_channel_element *elem,
+ grpc_transport_op *op);
protected:
- explicit ChannelData(const grpc_channel_args&) {}
+ explicit ChannelData(const grpc_channel_args &) {}
};
// Represents call data.
@@ -73,80 +73,80 @@ class CallData {
public:
virtual ~CallData() {}
- virtual void StartTransportStreamOp(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- grpc_transport_stream_op *op);
+ virtual void StartTransportStreamOp(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ grpc_transport_stream_op *op);
- virtual void SetPollsetOrPollsetSet(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- grpc_polling_entity *pollent);
+ virtual void SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ grpc_polling_entity *pollent);
- virtual char* GetPeer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem);
+ virtual char *GetPeer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem);
protected:
- explicit CallData(const ChannelData&) {}
+ explicit CallData(const ChannelData &) {}
};
namespace internal {
// Defines static members for passing to C core.
-template<typename ChannelDataType, typename CallDataType>
+template <typename ChannelDataType, typename CallDataType>
class ChannelFilter {
public:
static const size_t channel_data_size = sizeof(ChannelDataType);
- static void InitChannelElement(
- grpc_exec_ctx *exec_ctx, grpc_channel_element *elem,
- grpc_channel_element_args *args) {
+ static void InitChannelElement(grpc_exec_ctx *exec_ctx,
+ grpc_channel_element *elem,
+ grpc_channel_element_args *args) {
// Construct the object in the already-allocated memory.
new (elem->channel_data) ChannelDataType(*args->channel_args);
}
- static void DestroyChannelElement(
- grpc_exec_ctx *exec_ctx, grpc_channel_element *elem) {
- reinterpret_cast<ChannelDataType*>(elem->channel_data)->~ChannelDataType();
+ static void DestroyChannelElement(grpc_exec_ctx *exec_ctx,
+ grpc_channel_element *elem) {
+ reinterpret_cast<ChannelDataType *>(elem->channel_data)->~ChannelDataType();
}
- static void StartTransportOp(
- grpc_exec_ctx *exec_ctx, grpc_channel_element *elem,
- grpc_transport_op *op) {
- ChannelDataType* channel_data = (ChannelDataType*)elem->channel_data;
+ static void StartTransportOp(grpc_exec_ctx *exec_ctx,
+ grpc_channel_element *elem,
+ grpc_transport_op *op) {
+ ChannelDataType *channel_data = (ChannelDataType *)elem->channel_data;
channel_data->StartTransportOp(exec_ctx, elem, op);
}
static const size_t call_data_size = sizeof(CallDataType);
- static void InitCallElement(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- grpc_call_element_args *args) {
- const ChannelDataType& channel_data = *(ChannelDataType*)elem->channel_data;
+ static void InitCallElement(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
+ grpc_call_element_args *args) {
+ const ChannelDataType &channel_data =
+ *(ChannelDataType *)elem->channel_data;
// Construct the object in the already-allocated memory.
new (elem->call_data) CallDataType(channel_data);
}
- static void DestroyCallElement(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- const grpc_call_stats *stats, void *and_free_memory) {
- reinterpret_cast<CallDataType*>(elem->call_data)->~CallDataType();
+ static void DestroyCallElement(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ const grpc_call_stats *stats,
+ void *and_free_memory) {
+ reinterpret_cast<CallDataType *>(elem->call_data)->~CallDataType();
}
- static void StartTransportStreamOp(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- grpc_transport_stream_op *op) {
- CallDataType* call_data = (CallDataType*)elem->call_data;
+ static void StartTransportStreamOp(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ grpc_transport_stream_op *op) {
+ CallDataType *call_data = (CallDataType *)elem->call_data;
call_data->StartTransportStreamOp(exec_ctx, elem, op);
}
- static void SetPollsetOrPollsetSet(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- grpc_polling_entity *pollent) {
- CallDataType* call_data = (CallDataType*)elem->call_data;
+ static void SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ grpc_polling_entity *pollent) {
+ CallDataType *call_data = (CallDataType *)elem->call_data;
call_data->SetPollsetOrPollsetSet(exec_ctx, elem, pollent);
}
- static char* GetPeer(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem) {
- CallDataType* call_data = (CallDataType*)elem->call_data;
+ static char *GetPeer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) {
+ CallDataType *call_data = (CallDataType *)elem->call_data;
return call_data->GetPeer(exec_ctx, elem);
}
};
@@ -154,10 +154,10 @@ class ChannelFilter {
struct FilterRecord {
grpc_channel_stack_type stack_type;
int priority;
- std::function<bool(const grpc_channel_args&)> include_filter;
+ std::function<bool(const grpc_channel_args &)> include_filter;
grpc_channel_filter filter;
};
-extern std::vector<FilterRecord>* channel_filters;
+extern std::vector<FilterRecord> *channel_filters;
void ChannelFilterPluginInit();
void ChannelFilterPluginShutdown();
@@ -169,10 +169,10 @@ void ChannelFilterPluginShutdown();
// The include_filter argument specifies a function that will be called
// to determine at run-time whether or not to add the filter. If the
// value is nullptr, the filter will be added unconditionally.
-template<typename ChannelDataType, typename CallDataType>
+template <typename ChannelDataType, typename CallDataType>
void RegisterChannelFilter(
- const char* name, grpc_channel_stack_type stack_type, int priority,
- std::function<bool(const grpc_channel_args&)> include_filter) {
+ const char *name, grpc_channel_stack_type stack_type, int priority,
+ std::function<bool(const grpc_channel_args &)> include_filter) {
// If we haven't been called before, initialize channel_filters and
// call grpc_register_plugin().
if (internal::channel_filters == nullptr) {
@@ -184,18 +184,14 @@ void RegisterChannelFilter(
// C-core initialization code calls ChannelFilterPluginInit().
typedef internal::ChannelFilter<ChannelDataType, CallDataType> FilterType;
internal::FilterRecord filter_record = {
- stack_type, priority, include_filter, {
- FilterType::StartTransportStreamOp,
- FilterType::StartTransportOp,
- FilterType::call_data_size,
- FilterType::InitCallElement,
- FilterType::SetPollsetOrPollsetSet,
- FilterType::DestroyCallElement,
- FilterType::channel_data_size,
- FilterType::InitChannelElement,
- FilterType::DestroyChannelElement,
- FilterType::GetPeer,
- name}};
+ stack_type,
+ priority,
+ include_filter,
+ {FilterType::StartTransportStreamOp, FilterType::StartTransportOp,
+ FilterType::call_data_size, FilterType::InitCallElement,
+ FilterType::SetPollsetOrPollsetSet, FilterType::DestroyCallElement,
+ FilterType::channel_data_size, FilterType::InitChannelElement,
+ FilterType::DestroyChannelElement, FilterType::GetPeer, name}};
internal::channel_filters->push_back(filter_record);
}
diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc
index 77b2a26e8c..86df47903f 100644
--- a/src/cpp/common/channel_filter.cc
+++ b/src/cpp/common/channel_filter.cc
@@ -41,20 +41,19 @@ namespace grpc {
// CallData
//
-void CallData::StartTransportStreamOp(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- grpc_transport_stream_op *op) {
+void CallData::StartTransportStreamOp(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ grpc_transport_stream_op *op) {
grpc_call_next_op(exec_ctx, elem, op);
}
-void CallData::SetPollsetOrPollsetSet(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- grpc_polling_entity *pollent) {
+void CallData::SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ grpc_polling_entity *pollent) {
grpc_call_stack_ignore_set_pollset_or_pollset_set(exec_ctx, elem, pollent);
}
-char* CallData::GetPeer(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem) {
+char *CallData::GetPeer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) {
return grpc_call_next_get_peer(exec_ctx, elem);
}
@@ -62,9 +61,9 @@ char* CallData::GetPeer(
// ChannelData
//
-void ChannelData::StartTransportOp(
- grpc_exec_ctx *exec_ctx, grpc_channel_element *elem,
- grpc_transport_op *op) {
+void ChannelData::StartTransportOp(grpc_exec_ctx *exec_ctx,
+ grpc_channel_element *elem,
+ grpc_transport_op *op) {
grpc_channel_next_op(exec_ctx, elem, op);
}
@@ -74,29 +73,28 @@ void ChannelData::StartTransportOp(
namespace internal {
-std::vector<FilterRecord>* channel_filters = nullptr;
+std::vector<FilterRecord> *channel_filters = nullptr;
namespace {
-bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* arg) {
- const FilterRecord& filter = *(FilterRecord*)arg;
+bool MaybeAddFilter(grpc_channel_stack_builder *builder, void *arg) {
+ const FilterRecord &filter = *(FilterRecord *)arg;
if (filter.include_filter != nullptr) {
const grpc_channel_args *args =
grpc_channel_stack_builder_get_channel_arguments(builder);
- if (!filter.include_filter(*args))
- return true;
+ if (!filter.include_filter(*args)) return true;
}
- return grpc_channel_stack_builder_prepend_filter(
- builder, &filter.filter, nullptr, nullptr);
+ return grpc_channel_stack_builder_prepend_filter(builder, &filter.filter,
+ nullptr, nullptr);
}
} // namespace
void ChannelFilterPluginInit() {
for (size_t i = 0; i < channel_filters->size(); ++i) {
- FilterRecord& filter = (*channel_filters)[i];
+ FilterRecord &filter = (*channel_filters)[i];
grpc_channel_init_register_stage(filter.stack_type, filter.priority,
- MaybeAddFilter, (void*)&filter);
+ MaybeAddFilter, (void *)&filter);
}
}
diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc
index 16151c21b8..d72e8100d7 100644
--- a/test/cpp/end2end/filter_end2end_test.cc
+++ b/test/cpp/end2end/filter_end2end_test.cc
@@ -107,11 +107,9 @@ class CallDataImpl : public CallData {
: CallData(channel_data) {}
virtual ~CallDataImpl() {}
- void StartTransportStreamOp(
- grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
- grpc_transport_stream_op *op) {
- if (op->recv_initial_metadata != nullptr)
- IncrementCounter();
+ void StartTransportStreamOp(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
+ grpc_transport_stream_op* op) {
+ if (op->recv_initial_metadata != nullptr) IncrementCounter();
grpc_call_next_op(exec_ctx, elem, op);
}
};