@ -1841,6 +1841,15 @@ struct BaseCallDataMethods {
}
}
} ;
} ;
// The type of object returned by a filter's Create method.
template < typename T >
using CreatedType = typename decltype ( T : : Create ( ChannelArgs ( ) , { } ) ) : : value_type ;
template < typename GrpcChannelOrCallElement >
inline ChannelFilter * ChannelFilterFromElem ( GrpcChannelOrCallElement * elem ) {
return * static_cast < ChannelFilter * * > ( elem - > channel_data ) ;
}
template < typename CallData , uint8_t kFlags >
template < typename CallData , uint8_t kFlags >
struct CallDataFilterWithFlagsMethods {
struct CallDataFilterWithFlagsMethods {
static absl : : Status InitCallElem ( grpc_call_element * elem ,
static absl : : Status InitCallElem ( grpc_call_element * elem ,
@ -1865,32 +1874,25 @@ struct ChannelFilterMethods {
static ArenaPromise < ServerMetadataHandle > MakeCallPromise (
static ArenaPromise < ServerMetadataHandle > MakeCallPromise (
grpc_channel_element * elem , CallArgs call_args ,
grpc_channel_element * elem , CallArgs call_args ,
NextPromiseFactory next_promise_factory ) {
NextPromiseFactory next_promise_factory ) {
return static_cast < ChannelFilter * > ( elem - > channel_data )
return ChannelFilterFromElem ( elem ) - > MakeCallPromise (
- > MakeCallPromise ( std : : move ( call_args ) ,
std : : move ( call_args ) , std : : move ( next_promise_factory ) ) ;
std : : move ( next_promise_factory ) ) ;
}
}
static void StartTransportOp ( grpc_channel_element * elem ,
static void StartTransportOp ( grpc_channel_element * elem ,
grpc_transport_op * op ) {
grpc_transport_op * op ) {
if ( ! static_cast < ChannelFilter * > ( elem - > channel_data )
if ( ! ChannelFilterFromElem ( elem ) - > StartTransportOp ( op ) ) {
- > StartTransportOp ( op ) ) {
grpc_channel_next_op ( elem , op ) ;
grpc_channel_next_op ( elem , op ) ;
}
}
}
}
static void PostInitChannelElem ( grpc_channel_stack * ,
static void PostInitChannelElem ( grpc_channel_stack * ,
grpc_channel_element * elem ) {
grpc_channel_element * elem ) {
static_cast < ChannelFilter * > ( elem - > channel_data ) - > PostInit ( ) ;
ChannelFilterFromElem ( elem ) - > PostInit ( ) ;
}
static void DestroyChannelElem ( grpc_channel_element * elem ) {
static_cast < ChannelFilter * > ( elem - > channel_data ) - > ~ ChannelFilter ( ) ;
}
}
static void GetChannelInfo ( grpc_channel_element * elem ,
static void GetChannelInfo ( grpc_channel_element * elem ,
const grpc_channel_info * info ) {
const grpc_channel_info * info ) {
if ( ! static_cast < ChannelFilter * > ( elem - > channel_data )
if ( ! ChannelFilterFromElem ( elem ) - > GetChannelInfo ( info ) ) {
- > GetChannelInfo ( info ) ) {
grpc_channel_next_get_info ( elem , info ) ;
grpc_channel_next_get_info ( elem , info ) ;
}
}
}
}
@ -1904,15 +1906,16 @@ struct ChannelFilterWithFlagsMethods {
auto status = F : : Create ( args - > channel_args ,
auto status = F : : Create ( args - > channel_args ,
ChannelFilter : : Args ( args - > channel_stack , elem ) ) ;
ChannelFilter : : Args ( args - > channel_stack , elem ) ) ;
if ( ! status . ok ( ) ) {
if ( ! status . ok ( ) ) {
static_assert (
new ( elem - > channel_data ) F * ( nullptr ) ;
sizeof ( promise_filter_detail : : InvalidChannelFilter ) < = sizeof ( F ) ,
" InvalidChannelFilter must fit in F " ) ;
new ( elem - > channel_data ) promise_filter_detail : : InvalidChannelFilter ( ) ;
return absl_status_to_grpc_error ( status . status ( ) ) ;
return absl_status_to_grpc_error ( status . status ( ) ) ;
}
}
new ( elem - > channel_data ) F ( std : : move ( * status ) ) ;
new ( elem - > channel_data ) F * ( status - > release ( ) ) ;
return absl : : OkStatus ( ) ;
return absl : : OkStatus ( ) ;
}
}
static void DestroyChannelElem ( grpc_channel_element * elem ) {
CreatedType < F > channel_elem ( DownCast < F * > ( ChannelFilterFromElem ( elem ) ) ) ;
}
} ;
} ;
} // namespace promise_filter_detail
} // namespace promise_filter_detail
@ -1958,7 +1961,8 @@ MakePromiseBasedFilter(const char* name) {
// post_init_channel_elem
// post_init_channel_elem
promise_filter_detail : : ChannelFilterMethods : : PostInitChannelElem ,
promise_filter_detail : : ChannelFilterMethods : : PostInitChannelElem ,
// destroy_channel_elem
// destroy_channel_elem
promise_filter_detail : : ChannelFilterMethods : : DestroyChannelElem ,
promise_filter_detail : : ChannelFilterWithFlagsMethods <
F , kFlags > : : DestroyChannelElem ,
// get_channel_info
// get_channel_info
promise_filter_detail : : ChannelFilterMethods : : GetChannelInfo ,
promise_filter_detail : : ChannelFilterMethods : : GetChannelInfo ,
// name
// name
@ -2004,7 +2008,8 @@ MakePromiseBasedFilter(const char* name) {
// post_init_channel_elem
// post_init_channel_elem
promise_filter_detail : : ChannelFilterMethods : : PostInitChannelElem ,
promise_filter_detail : : ChannelFilterMethods : : PostInitChannelElem ,
// destroy_channel_elem
// destroy_channel_elem
promise_filter_detail : : ChannelFilterMethods : : DestroyChannelElem ,
promise_filter_detail : : ChannelFilterWithFlagsMethods <
F , kFlags > : : DestroyChannelElem ,
// get_channel_info
// get_channel_info
promise_filter_detail : : ChannelFilterMethods : : GetChannelInfo ,
promise_filter_detail : : ChannelFilterMethods : : GetChannelInfo ,
// name
// name
@ -2046,7 +2051,8 @@ MakePromiseBasedFilter(const char* name) {
// post_init_channel_elem
// post_init_channel_elem
promise_filter_detail : : ChannelFilterMethods : : PostInitChannelElem ,
promise_filter_detail : : ChannelFilterMethods : : PostInitChannelElem ,
// destroy_channel_elem
// destroy_channel_elem
promise_filter_detail : : ChannelFilterMethods : : DestroyChannelElem ,
promise_filter_detail : : ChannelFilterWithFlagsMethods <
F , kFlags > : : DestroyChannelElem ,
// get_channel_info
// get_channel_info
promise_filter_detail : : ChannelFilterMethods : : GetChannelInfo ,
promise_filter_detail : : ChannelFilterMethods : : GetChannelInfo ,
// name
// name