diff options
Diffstat (limited to 'src/cpp/common/channel_filter.h')
-rw-r--r-- | src/cpp/common/channel_filter.h | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index ae32e02f69..c9f50df732 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -216,23 +216,24 @@ class TransportStreamOp { /// Represents channel data. class ChannelData { public: - virtual ~ChannelData() { - if (peer_) gpr_free((void *)peer_); - } + virtual ~ChannelData() {} - /// Caller does NOT take ownership of result. - const char *peer() const { return peer_; } + /// Initializes the call data. + virtual grpc_error *Init(grpc_exec_ctx *exec_ctx, + grpc_channel_element_args *args) { + return GRPC_ERROR_NONE; + } // TODO(roth): Find a way to avoid passing elem into these methods. + virtual void StartTransportOp(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, TransportOp *op); - protected: - /// Takes ownership of \a peer. - ChannelData(const grpc_channel_args &args, const char *peer) : peer_(peer) {} + virtual void GetInfo(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, + const grpc_channel_info *channel_info); - private: - const char *peer_; + protected: + ChannelData() {} }; /// Represents call data. @@ -241,7 +242,10 @@ class CallData { virtual ~CallData() {} /// Initializes the call data. - virtual grpc_error *Init() { return GRPC_ERROR_NONE; } + virtual grpc_error *Init(grpc_exec_ctx *exec_ctx, ChannelData *channel_data, + grpc_call_element_args *args) { + return GRPC_ERROR_NONE; + } // TODO(roth): Find a way to avoid passing elem into these methods. @@ -259,7 +263,7 @@ class CallData { virtual char *GetPeer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem); protected: - explicit CallData(const ChannelData &) {} + CallData() {} }; namespace internal { @@ -268,19 +272,15 @@ namespace internal { // Members of this class correspond to the members of the C // grpc_channel_filter struct. template <typename ChannelDataType, typename CallDataType> -class ChannelFilter GRPC_FINAL { +class ChannelFilter final { 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) { - const char *peer = - args->optional_transport - ? grpc_transport_get_peer(exec_ctx, args->optional_transport) - : nullptr; - // Construct the object in the already-allocated memory. - new (elem->channel_data) ChannelDataType(*args->channel_args, peer); + static grpc_error *InitChannelElement(grpc_exec_ctx *exec_ctx, + grpc_channel_element *elem, + grpc_channel_element_args *args) { + ChannelDataType *channel_data = new (elem->channel_data) ChannelDataType(); + return channel_data->Init(exec_ctx, args); } static void DestroyChannelElement(grpc_exec_ctx *exec_ctx, @@ -296,16 +296,22 @@ class ChannelFilter GRPC_FINAL { channel_data->StartTransportOp(exec_ctx, elem, &op_wrapper); } + static void GetChannelInfo(grpc_exec_ctx *exec_ctx, + grpc_channel_element *elem, + const grpc_channel_info *channel_info) { + ChannelDataType *channel_data = (ChannelDataType *)elem->channel_data; + channel_data->GetInfo(exec_ctx, elem, channel_info); + } + static const size_t call_data_size = sizeof(CallDataType); static grpc_error *InitCallElement(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_call_element_args *args) { - const ChannelDataType &channel_data = - *(ChannelDataType *)elem->channel_data; + ChannelDataType *channel_data = (ChannelDataType *)elem->channel_data; // Construct the object in the already-allocated memory. - CallDataType *call_data = new (elem->call_data) CallDataType(channel_data); - return call_data->Init(); + CallDataType *call_data = new (elem->call_data) CallDataType(); + return call_data->Init(exec_ctx, channel_data, args); } static void DestroyCallElement(grpc_exec_ctx *exec_ctx, @@ -376,7 +382,8 @@ void RegisterChannelFilter( FilterType::call_data_size, FilterType::InitCallElement, FilterType::SetPollsetOrPollsetSet, FilterType::DestroyCallElement, FilterType::channel_data_size, FilterType::InitChannelElement, - FilterType::DestroyChannelElement, FilterType::GetPeer, name}}; + FilterType::DestroyChannelElement, FilterType::GetPeer, + FilterType::GetChannelInfo, name}}; internal::channel_filters->push_back(filter_record); } |