proxygen
proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp > Class Template Reference

#include <FilterChain.h>

Inheritance diagram for proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >:
T1 T2 proxygen::PassThroughHTTPCodecFilter proxygen::PassThroughTransportFilter proxygen::FilterChain< HTTPCodec, HTTPCodec::Callback, PassThroughHTTPCodecFilter,&HTTPCodec::setCallback, true > proxygen::FlowControlFilter proxygen::HTTPChecks proxygen::HTTPCodecPrinter

Public Types

using Filter = GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >
 

Public Member Functions

 GenericFilter (bool calls, bool callbacks)
 
 ~GenericFilter () override
 
void append (Filter *nextFilter)
 

Public Attributes

const bool kWantsCalls_
 
const bool kWantsCallbacks_
 

Protected Member Functions

void setCallbackInternal (T2 *cb)
 
void drop ()
 

Protected Attributes

T1call_ {nullptr}
 
T2callback_ {nullptr}
 

Private Member Functions

void setCallbackInternalImpl (T2 *cb, T2 *sourceSet)
 

Private Attributes

Filternext_ {nullptr}
 
Filterprev_ {nullptr}
 
FiltercallSource_ {nullptr}
 
T1callbackSource_ {nullptr}
 

Friends

template<class A , class B , class F , void(A::*)(B *) fn, bool Own>
class FilterChain
 

Detailed Description

template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
class proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >

A generic two-way filter. That is, this filter intercepts calls from an object A to some object B on an interface T1. It also intercepts calls from B to A on an interface T2.

Subclass GenericFilter templatized on the appropriate interfaces to intercept calls between T1 and T2.

T2 must have the ability to tell T1 to call it back using a certain object. Many different callback patterns have a different name for this function, but this filter needs to be informed when the callback object changes. Therefore, when you subclass this object, you must call

void setCallbackInternal(T2*);

from the appropriate virtual function and not forward that function call along the chain, or the filter will not work and may have errors!

Definition at line 40 of file FilterChain.h.

Member Typedef Documentation

template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
using proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::Filter = GenericFilter<T1, T2, set_callback, TakeOwnership, Dp>

Definition at line 42 of file FilterChain.h.

Constructor & Destructor Documentation

template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::GenericFilter ( bool  calls,
bool  callbacks 
)
inline
Parameters
callsYou will intercept calls to T1 interface iff you pass true for this parameter.
callbacksYou will intercept calls to T2 interface iff you pass true for this parameter.

Definition at line 49 of file FilterChain.h.

49  :
50  kWantsCalls_(calls),
51  kWantsCallbacks_(callbacks) {}
const bool kWantsCallbacks_
Definition: FilterChain.h:104
template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::~GenericFilter ( )
inlineoverride

Definition at line 53 of file FilterChain.h.

53  {
54  if (TakeOwnership) {
55  callbackSource_ = nullptr;
56  }
57  // For the last filter in the chain, next_ is null, and call_ points
58  // to the concrete implementation object.
59  auto next = next_ ? next_ : call_;
60  drop();
61  if (TakeOwnership && next) {
62  Dp()(next);
63  }
64  }
def next(obj)
Definition: ast.py:58

Member Function Documentation

template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
void proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::append ( Filter nextFilter)
inline
Parameters
nextFilterthe new filter to insert after this filter

Definition at line 69 of file FilterChain.h.

69  {
70  nextFilter->next_ = next_;
71  nextFilter->prev_ = this;
72  nextFilter->call_ = call_;
73  nextFilter->callback_ = kWantsCallbacks_ ? this : callback_;
74  nextFilter->callSource_ = kWantsCalls_ ? this : callSource_;
75  nextFilter->callbackSource_ = callbackSource_;
76  if (next_) {
77  next_->prev_ = nextFilter;
78  }
79 
80  if (nextFilter->kWantsCalls_) {
81  if (kWantsCalls_) {
82  call_ = nextFilter;
83  } else {
84  callSource_->call_ = nextFilter;
85  }
86  if (next_) {
87  next_->callSource_ = nextFilter;
88  }
89  }
90  if (nextFilter->kWantsCallbacks_) {
91  // Find the first filter before this one that wants callbacks
92  auto cur = this;
93  while (cur->prev_ && !cur->kWantsCallbacks_) {
94  cur = cur->prev_;
95  }
96  cur->callbackSource_ = nextFilter;
97  // Make sure nextFilter gets callbacks
98  ((nextFilter->callbackSource_)->*(set_callback))(nextFilter);
99  }
100  next_ = nextFilter;
101  }
const bool kWantsCallbacks_
Definition: FilterChain.h:104
template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
void proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::drop ( )
inlineprotected

Removes this filter from the chain. For owning chains the caller must manually delete the filter

Definition at line 119 of file FilterChain.h.

119  {
120  if (prev_) {
121  prev_->next_ = next_;
122  }
123  if (next_) {
124  next_->prev_ = prev_;
125  }
126  // TODO: could call fn gated by std::enable_if
127  if (kWantsCalls_ && callSource_) {
129  if (call_) {
130  auto callFilter = dynamic_cast<Filter*>(call_);
131  if (callFilter) {
132  callFilter->callSource_ = callSource_;
133  }
134  }
135  }
136  // TODO: could call fn gated by std::enable_if
138  ((callbackSource_)->*(set_callback))(callback_);
139  if (callback_) {
140  auto callbackFilter = dynamic_cast<Filter*>(callback_);
141  if (callbackFilter) {
142  callbackFilter->callbackSource_ = callbackSource_;
143  }
144  }
145  }
146  call_ = callbackSource_ = nullptr;
147  callback_ = nullptr;
148  callSource_ = next_ = prev_ = nullptr;
149  }
GenericFilter< T1, T2, set_callback, TakeOwnership, Dp > Filter
Definition: FilterChain.h:42
const bool kWantsCallbacks_
Definition: FilterChain.h:104
template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
void proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::setCallbackInternal ( T2 cb)
inlineprotected

Note: you MUST override the set_callback function and call setCallbackInternal() from your derived class.

Definition at line 111 of file FilterChain.h.

Referenced by proxygen::PassThroughHTTPCodecFilter::setCallback().

111  {
112  setCallbackInternalImpl(cb, this);
113  }
void setCallbackInternalImpl(T2 *cb, T2 *sourceSet)
Definition: FilterChain.h:158
template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
void proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::setCallbackInternalImpl ( T2 cb,
T2 sourceSet 
)
inlineprivate

Definition at line 158 of file FilterChain.h.

158  {
159  if (callback_ != cb) {
160  callback_ = cb;
161  ((callbackSource_)->*(set_callback))(cb ? sourceSet : nullptr);
162  }
163  }

Friends And Related Function Documentation

template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
template<class A , class B , class F , void(A::*)(B *) fn, bool Own>
friend class FilterChain
friend

Definition at line 177 of file FilterChain.h.

Member Data Documentation

template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
T1* proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::call_ {nullptr}
protected

Definition at line 152 of file FilterChain.h.

Referenced by proxygen::PassThroughHTTPCodecFilter::addPriorityNodes(), proxygen::GenericFilter< TesterInterface, TesterInterface::Callback,&TesterInterface::setCallback, Owned >::append(), proxygen::PassThroughHTTPCodecFilter::closeOnEgressComplete(), proxygen::PassThroughHTTPCodecFilter::createStream(), proxygen::PassThroughHTTPCodecFilter::enableDoubleGoawayDrain(), proxygen::FlowControlFilter::generateBody(), proxygen::PassThroughHTTPCodecFilter::generateBody(), proxygen::PassThroughHTTPCodecFilter::generateCertificate(), proxygen::PassThroughHTTPCodecFilter::generateCertificateRequest(), proxygen::PassThroughHTTPCodecFilter::generateChunkHeader(), proxygen::PassThroughHTTPCodecFilter::generateChunkTerminator(), proxygen::PassThroughHTTPCodecFilter::generateConnectionPreface(), proxygen::PassThroughHTTPCodecFilter::generateEOM(), proxygen::PassThroughHTTPCodecFilter::generateExHeader(), proxygen::PassThroughHTTPCodecFilter::generateGoaway(), proxygen::HTTPChecks::generateHeader(), proxygen::PassThroughHTTPCodecFilter::generateHeader(), proxygen::PassThroughHTTPCodecFilter::generatePingReply(), proxygen::PassThroughHTTPCodecFilter::generatePingRequest(), proxygen::PassThroughHTTPCodecFilter::generatePriority(), proxygen::PassThroughHTTPCodecFilter::generatePushPromise(), proxygen::PassThroughHTTPCodecFilter::generateRstStream(), proxygen::PassThroughHTTPCodecFilter::generateSettings(), proxygen::PassThroughHTTPCodecFilter::generateSettingsAck(), proxygen::PassThroughHTTPCodecFilter::generateTrailers(), proxygen::FlowControlFilter::generateWindowUpdate(), proxygen::PassThroughHTTPCodecFilter::generateWindowUpdate(), proxygen::PassThroughHTTPCodecFilter::getDefaultWindowSize(), proxygen::PassThroughHTTPCodecFilter::getEgressSettings(), proxygen::PassThroughHTTPCodecFilter::getHPACKTableInfo(), proxygen::PassThroughHTTPCodecFilter::getIngressSettings(), proxygen::PassThroughHTTPCodecFilter::getLastIncomingStreamID(), proxygen::PassThroughHTTPCodecFilter::getProtocol(), proxygen::PassThroughHTTPCodecFilter::getTransportDirection(), proxygen::PassThroughHTTPCodecFilter::getUserAgent(), proxygen::FlowControlFilter::ingressBytesProcessed(), proxygen::PassThroughHTTPCodecFilter::isBusy(), proxygen::FlowControlFilter::isReusable(), proxygen::PassThroughHTTPCodecFilter::isReusable(), proxygen::PassThroughHTTPCodecFilter::isWaitingToDrain(), proxygen::PassThroughHTTPCodecFilter::mapDependencyToPriority(), proxygen::PassThroughHTTPCodecFilter::mapPriorityToDependency(), proxygen::HTTPCodecPrinter::onFrameHeader(), proxygen::PassThroughHTTPCodecFilter::onIngress(), proxygen::PassThroughHTTPCodecFilter::onIngressEOF(), proxygen::PassThroughHTTPCodecFilter::onIngressUpgradeMessage(), proxygen::FilterChain< HTTPCodec, HTTPCodec::Callback, PassThroughHTTPCodecFilter,&HTTPCodec::setCallback, true >::setDestination(), proxygen::PassThroughHTTPCodecFilter::setHeaderCodecStats(), proxygen::PassThroughHTTPCodecFilter::setParserPaused(), proxygen::FlowControlFilter::setReceiveWindowSize(), proxygen::PassThroughHTTPCodecFilter::supportsParallelRequests(), proxygen::PassThroughHTTPCodecFilter::supportsPushTransactions(), proxygen::PassThroughHTTPCodecFilter::supportsSessionFlowControl(), and proxygen::PassThroughHTTPCodecFilter::supportsStreamFlowControl().

template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
T2* proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::callback_ {nullptr}
protected

Definition at line 154 of file FilterChain.h.

Referenced by proxygen::GenericFilter< TesterInterface, TesterInterface::Callback,&TesterInterface::setCallback, Owned >::append(), proxygen::PassThroughHTTPCodecFilter::numIncomingStreams(), proxygen::PassThroughHTTPCodecFilter::numOutgoingStreams(), proxygen::HTTPCodecPrinter::onAbort(), proxygen::PassThroughHTTPCodecFilter::onAbort(), proxygen::HTTPCodecPrinter::onBody(), proxygen::PassThroughHTTPCodecFilter::onBody(), proxygen::FlowControlFilter::onBody(), proxygen::PassThroughHTTPCodecFilter::onCertificate(), proxygen::PassThroughHTTPCodecFilter::onCertificateRequest(), proxygen::PassThroughHTTPCodecFilter::onChunkComplete(), proxygen::PassThroughHTTPCodecFilter::onChunkHeader(), proxygen::HTTPCodecPrinter::onError(), proxygen::PassThroughHTTPCodecFilter::onError(), proxygen::PassThroughHTTPCodecFilter::onExMessageBegin(), proxygen::HTTPCodecPrinter::onFrameHeader(), proxygen::PassThroughHTTPCodecFilter::onFrameHeader(), proxygen::PassThroughHTTPCodecFilter::onGenerateFrameHeader(), proxygen::PassThroughHTTPCodecFilter::onGoaway(), proxygen::HTTPCodecPrinter::onGoaway(), proxygen::HTTPChecks::onHeadersComplete(), proxygen::PassThroughHTTPCodecFilter::onHeadersComplete(), proxygen::HTTPCodecPrinter::onHeadersComplete(), proxygen::PassThroughHTTPCodecFilter::onMessageBegin(), proxygen::HTTPCodecPrinter::onMessageComplete(), proxygen::PassThroughHTTPCodecFilter::onMessageComplete(), proxygen::PassThroughHTTPCodecFilter::onNativeProtocolUpgrade(), proxygen::PassThroughHTTPCodecFilter::onPingReply(), proxygen::HTTPCodecPrinter::onPingReply(), proxygen::PassThroughHTTPCodecFilter::onPingRequest(), proxygen::HTTPCodecPrinter::onPingRequest(), proxygen::PassThroughHTTPCodecFilter::onPriority(), proxygen::PassThroughHTTPCodecFilter::onPushMessageBegin(), proxygen::HTTPCodecPrinter::onSettings(), proxygen::PassThroughHTTPCodecFilter::onSettings(), proxygen::HTTPCodecPrinter::onSettingsAck(), proxygen::PassThroughHTTPCodecFilter::onSettingsAck(), proxygen::PassThroughHTTPCodecFilter::onTrailersComplete(), proxygen::HTTPCodecPrinter::onWindowUpdate(), proxygen::PassThroughHTTPCodecFilter::onWindowUpdate(), and proxygen::FlowControlFilter::onWindowUpdate().

template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
Filter* proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::callSource_ {nullptr}
private
template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
const bool proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::kWantsCallbacks_
template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
const bool proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::kWantsCalls_
template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
Filter* proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::next_ {nullptr}
private
template<typename T1, typename T2, void(T1::*)(T2 *) set_callback, bool TakeOwnership, typename Dp = std::default_delete<T1>>
Filter* proxygen::GenericFilter< T1, T2, set_callback, TakeOwnership, Dp >::prev_ {nullptr}
private

The documentation for this class was generated from the following file: