proxygen
wangle::PipelineBase Class Referenceabstract

#include <Pipeline.h>

Inheritance diagram for wangle::PipelineBase:
wangle::Pipeline< int > wangle::Pipeline< R, W > wangle::StaticPipeline< R, W >

Public Member Functions

virtual ~PipelineBase ()=default
 
void setPipelineManager (PipelineManager *manager)
 
PipelineManagergetPipelineManager ()
 
void deletePipeline ()
 
void setTransport (std::shared_ptr< folly::AsyncTransport > transport)
 
std::shared_ptr< folly::AsyncTransportgetTransport ()
 
void setWriteFlags (folly::WriteFlags flags)
 
folly::WriteFlags getWriteFlags ()
 
void setReadBufferSettings (uint64_t minAvailable, uint64_t allocationSize)
 
std::pair< uint64_t, uint64_tgetReadBufferSettings ()
 
void setTransportInfo (std::shared_ptr< TransportInfo > tInfo)
 
std::shared_ptr< TransportInfogetTransportInfo ()
 
template<class H >
PipelineBaseaddBack (std::shared_ptr< H > handler)
 
template<class H >
PipelineBaseaddBack (H &&handler)
 
template<class H >
PipelineBaseaddBack (H *handler)
 
template<class H >
PipelineBaseaddFront (std::shared_ptr< H > handler)
 
template<class H >
PipelineBaseaddFront (H &&handler)
 
template<class H >
PipelineBaseaddFront (H *handler)
 
template<class H >
PipelineBaseremove (H *handler)
 
template<class H >
PipelineBaseremove ()
 
PipelineBaseremoveFront ()
 
PipelineBaseremoveBack ()
 
template<class H >
H * getHandler (int i)
 
template<class H >
H * getHandler ()
 
template<class H >
ContextType< H >::typegetContext (int i)
 
template<class H >
ContextType< H >::typegetContext ()
 
template<class H >
bool setOwner (H *handler)
 
virtual void finalize ()=0
 
size_t numHandlers () const
 

Protected Member Functions

template<class Context >
void addContextFront (Context *ctx)
 
void detachHandlers ()
 

Protected Attributes

std::vector< std::shared_ptr< PipelineContext > > ctxs_
 
std::vector< PipelineContext * > inCtxs_
 
std::vector< PipelineContext * > outCtxs_
 

Private Types

typedef std::vector< std::shared_ptr< PipelineContext > >::iterator ContextIterator
 

Private Member Functions

template<class Context >
PipelineBaseaddHelper (std::shared_ptr< Context > &&ctx, bool front)
 
template<class H >
PipelineBaseremoveHelper (H *handler, bool checkEqual)
 
ContextIterator removeAt (const ContextIterator &it)
 

Private Attributes

PipelineManagermanager_ {nullptr}
 
std::shared_ptr< folly::AsyncTransporttransport_
 
std::shared_ptr< TransportInfotransportInfo_
 
folly::WriteFlags writeFlags_ {folly::WriteFlags::NONE}
 
std::pair< uint64_t, uint64_treadBufferSettings_ {2048, 2048}
 
std::shared_ptr< PipelineContextowner_
 

Detailed Description

Definition at line 43 of file Pipeline.h.

Member Typedef Documentation

typedef std::vector<std::shared_ptr<PipelineContext> >::iterator wangle::PipelineBase::ContextIterator
private

Definition at line 151 of file Pipeline.h.

Constructor & Destructor Documentation

virtual wangle::PipelineBase::~PipelineBase ( )
virtualdefault

Member Function Documentation

template<class H >
PipelineBase & wangle::PipelineBase::addBack ( std::shared_ptr< H >  handler)

Definition at line 39 of file Pipeline-inl.h.

References addHelper(), and folly::gen::move.

Referenced by addBack(), and wangle::ClientDispatcherBase< wangle::Pipeline, folly::Req, Resp >::setPipeline().

39  {
40  typedef typename ContextType<H>::type Context;
41  return addHelper(
42  std::make_shared<Context>(shared_from_this(), std::move(handler)),
43  false);
44 }
PipelineBase & addHelper(std::shared_ptr< Context > &&ctx, bool front)
Definition: Pipeline-inl.h:155
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::conditional< Handler::dir==HandlerDir::BOTH, ContextImpl< Handler >, typename std::conditional< Handler::dir==HandlerDir::IN, InboundContextImpl< Handler >, OutboundContextImpl< Handler > >::type >::type type
template<class H >
PipelineBase & wangle::PipelineBase::addBack ( H &&  handler)

Definition at line 47 of file Pipeline-inl.h.

References addBack(), and handler().

47  {
48  return addBack(std::make_shared<H>(std::forward<H>(handler)));
49 }
void handler(int, siginfo_t *, void *)
PipelineBase & addBack(std::shared_ptr< H > handler)
Definition: Pipeline-inl.h:39
template<class H >
PipelineBase & wangle::PipelineBase::addBack ( H *  handler)

Definition at line 52 of file Pipeline-inl.h.

References addBack().

52  {
53  return addBack(std::shared_ptr<H>(handler, [](H*){}));
54 }
void handler(int, siginfo_t *, void *)
PipelineBase & addBack(std::shared_ptr< H > handler)
Definition: Pipeline-inl.h:39
template<class Context >
void wangle::PipelineBase::addContextFront ( Context *  ctx)
protected

Definition at line 150 of file Pipeline-inl.h.

References addHelper().

Referenced by wangle::StaticPipeline< R, W, Handler, Handlers... >::StaticPipeline().

150  {
151  addHelper(std::shared_ptr<Context>(ctx, [](Context*){}), true);
152 }
PipelineBase & addHelper(std::shared_ptr< Context > &&ctx, bool front)
Definition: Pipeline-inl.h:155
template<class H >
PipelineBase & wangle::PipelineBase::addFront ( std::shared_ptr< H >  handler)

Definition at line 57 of file Pipeline-inl.h.

References addHelper(), and folly::gen::move.

Referenced by addFront().

57  {
58  typedef typename ContextType<H>::type Context;
59  return addHelper(
60  std::make_shared<Context>(shared_from_this(), std::move(handler)),
61  true);
62 }
PipelineBase & addHelper(std::shared_ptr< Context > &&ctx, bool front)
Definition: Pipeline-inl.h:155
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::conditional< Handler::dir==HandlerDir::BOTH, ContextImpl< Handler >, typename std::conditional< Handler::dir==HandlerDir::IN, InboundContextImpl< Handler >, OutboundContextImpl< Handler > >::type >::type type
template<class H >
PipelineBase & wangle::PipelineBase::addFront ( H &&  handler)

Definition at line 65 of file Pipeline-inl.h.

References addFront(), and handler().

65  {
66  return addFront(std::make_shared<H>(std::forward<H>(handler)));
67 }
PipelineBase & addFront(std::shared_ptr< H > handler)
Definition: Pipeline-inl.h:57
void handler(int, siginfo_t *, void *)
template<class H >
PipelineBase & wangle::PipelineBase::addFront ( H *  handler)

Definition at line 70 of file Pipeline-inl.h.

References addFront().

70  {
71  return addFront(std::shared_ptr<H>(handler, [](H*){}));
72 }
PipelineBase & addFront(std::shared_ptr< H > handler)
Definition: Pipeline-inl.h:57
void handler(int, siginfo_t *, void *)
template<class Context >
PipelineBase & wangle::PipelineBase::addHelper ( std::shared_ptr< Context > &&  ctx,
bool  front 
)
private

Definition at line 155 of file Pipeline-inl.h.

References wangle::BOTH, ctxs_, wangle::IN, inCtxs_, wangle::OUT, and outCtxs_.

Referenced by addBack(), addContextFront(), and addFront().

157  {
158  ctxs_.insert(front ? ctxs_.begin() : ctxs_.end(), ctx);
159  if (Context::dir == HandlerDir::BOTH || Context::dir == HandlerDir::IN) {
160  inCtxs_.insert(front ? inCtxs_.begin() : inCtxs_.end(), ctx.get());
161  }
162  if (Context::dir == HandlerDir::BOTH || Context::dir == HandlerDir::OUT) {
163  outCtxs_.insert(front ? outCtxs_.begin() : outCtxs_.end(), ctx.get());
164  }
165  return *this;
166 }
std::vector< PipelineContext * > outCtxs_
Definition: Pipeline.h:137
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
std::vector< PipelineContext * > inCtxs_
Definition: Pipeline.h:136
void wangle::PipelineBase::deletePipeline ( )
inline

Definition at line 55 of file Pipeline.h.

55  {
56  if (manager_) {
57  manager_->deletePipeline(this);
58  }
59  }
PipelineManager * manager_
Definition: Pipeline.h:140
virtual void deletePipeline(PipelineBase *pipeline)=0
void wangle::PipelineBase::detachHandlers ( )
protected

Definition at line 85 of file Pipeline.cpp.

References ctxs_, and owner_.

Referenced by wangle::Pipeline< R, W >::~Pipeline(), and wangle::StaticPipeline< R, W, Handler, Handlers... >::~StaticPipeline().

85  {
86  for (auto& ctx : ctxs_) {
87  if (ctx != owner_) {
88  ctx->detachPipeline();
89  }
90  }
91 }
std::shared_ptr< PipelineContext > owner_
Definition: Pipeline.h:158
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
virtual void wangle::PipelineBase::finalize ( )
pure virtual
template<class H >
ContextType< H >::type * wangle::PipelineBase::getContext ( int  i)

Definition at line 119 of file Pipeline-inl.h.

References ctxs_, and i.

119  {
120  auto ctx = dynamic_cast<typename ContextType<H>::type*>(ctxs_[i].get());
121  CHECK(ctx);
122  return ctx;
123 }
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
std::conditional< Handler::dir==HandlerDir::BOTH, ContextImpl< Handler >, typename std::conditional< Handler::dir==HandlerDir::IN, InboundContextImpl< Handler >, OutboundContextImpl< Handler > >::type >::type type
template<class H >
ContextType< H >::type * wangle::PipelineBase::getContext ( )

Definition at line 126 of file Pipeline-inl.h.

References ctxs_.

126  {
127  for (auto pipelineCtx : ctxs_) {
128  auto ctx = dynamic_cast<typename ContextType<H>::type*>(pipelineCtx.get());
129  if (ctx) {
130  return ctx;
131  }
132  }
133  return nullptr;
134 }
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
std::conditional< Handler::dir==HandlerDir::BOTH, ContextImpl< Handler >, typename std::conditional< Handler::dir==HandlerDir::IN, InboundContextImpl< Handler >, OutboundContextImpl< Handler > >::type >::type type
template<class H >
H * wangle::PipelineBase::getHandler ( int  i)

Definition at line 108 of file Pipeline-inl.h.

References getHandler(), and i.

108  {
109  return getContext<H>(i)->getHandler();
110 }
template<class H >
H * wangle::PipelineBase::getHandler ( )

Definition at line 113 of file Pipeline-inl.h.

Referenced by getHandler().

113  {
114  auto ctx = getContext<H>();
115  return ctx ? ctx->getHandler() : nullptr;
116 }
PipelineManager* wangle::PipelineBase::getPipelineManager ( )
inline

Definition at line 51 of file Pipeline.h.

Referenced by wangle::AsyncSocketHandler::refreshTimeout().

51  {
52  return manager_;
53  }
PipelineManager * manager_
Definition: Pipeline.h:140
std::pair< uint64_t, uint64_t > wangle::PipelineBase::getReadBufferSettings ( )

Definition at line 37 of file Pipeline.cpp.

References readBufferSettings_.

37  {
38  return readBufferSettings_;
39 }
std::pair< uint64_t, uint64_t > readBufferSettings_
Definition: Pipeline.h:156
std::shared_ptr<folly::AsyncTransport> wangle::PipelineBase::getTransport ( )
inline
std::shared_ptr< TransportInfo > wangle::PipelineBase::getTransportInfo ( )

Definition at line 45 of file Pipeline.cpp.

References transportInfo_.

45  {
46  return transportInfo_;
47 }
std::shared_ptr< TransportInfo > transportInfo_
Definition: Pipeline.h:142
WriteFlags wangle::PipelineBase::getWriteFlags ( )

Definition at line 27 of file Pipeline.cpp.

References writeFlags_.

27  {
28  return writeFlags_;
29 }
folly::WriteFlags writeFlags_
Definition: Pipeline.h:155
size_t wangle::PipelineBase::numHandlers ( ) const

Definition at line 93 of file Pipeline.cpp.

References ctxs_.

93  {
94  return ctxs_.size();
95 }
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
template<class H >
PipelineBase & wangle::PipelineBase::remove ( H *  handler)

Definition at line 103 of file Pipeline-inl.h.

References handler().

Referenced by wangle::ClientDispatcherBase< wangle::Pipeline, folly::Req, Resp >::~ClientDispatcherBase().

103  {
104  return removeHelper<H>(handler, true);
105 }
void handler(int, siginfo_t *, void *)
template<class H >
PipelineBase & wangle::PipelineBase::remove ( )

Definition at line 98 of file Pipeline-inl.h.

98  {
99  return removeHelper<H>(nullptr, false);
100 }
PipelineBase::ContextIterator wangle::PipelineBase::removeAt ( const ContextIterator it)
private

Definition at line 49 of file Pipeline.cpp.

References wangle::BOTH, ctxs_, wangle::IN, inCtxs_, wangle::OUT, and outCtxs_.

Referenced by removeBack(), removeFront(), and removeHelper().

50  {
51  (*it)->detachPipeline();
52 
53  const auto dir = (*it)->getDirection();
54  if (dir == HandlerDir::BOTH || dir == HandlerDir::IN) {
55  auto it2 = std::find(inCtxs_.begin(), inCtxs_.end(), it->get());
56  CHECK(it2 != inCtxs_.end());
57  inCtxs_.erase(it2);
58  }
59 
60  if (dir == HandlerDir::BOTH || dir == HandlerDir::OUT) {
61  auto it2 = std::find(outCtxs_.begin(), outCtxs_.end(), it->get());
62  CHECK(it2 != outCtxs_.end());
63  outCtxs_.erase(it2);
64  }
65 
66  return ctxs_.erase(it);
67 }
std::vector< PipelineContext * > outCtxs_
Definition: Pipeline.h:137
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
std::vector< PipelineContext * > inCtxs_
Definition: Pipeline.h:136
PipelineBase & wangle::PipelineBase::removeBack ( )

Definition at line 77 of file Pipeline.cpp.

References ctxs_, and removeAt().

77  {
78  if (ctxs_.empty()) {
79  throw std::invalid_argument("No handlers in pipeline");
80  }
81  removeAt(--ctxs_.end());
82  return *this;
83 }
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
ContextIterator removeAt(const ContextIterator &it)
Definition: Pipeline.cpp:49
PipelineBase & wangle::PipelineBase::removeFront ( )

Definition at line 69 of file Pipeline.cpp.

References ctxs_, and removeAt().

69  {
70  if (ctxs_.empty()) {
71  throw std::invalid_argument("No handlers in pipeline");
72  }
73  removeAt(ctxs_.begin());
74  return *this;
75 }
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
ContextIterator removeAt(const ContextIterator &it)
Definition: Pipeline.cpp:49
template<class H >
PipelineBase & wangle::PipelineBase::removeHelper ( H *  handler,
bool  checkEqual 
)
private

Definition at line 75 of file Pipeline-inl.h.

References ctxs_, handler(), and removeAt().

75  {
76  typedef typename ContextType<H>::type Context;
77  bool removed = false;
78 
79  auto it = ctxs_.begin();
80  while (it != ctxs_.end()) {
81  auto ctx = std::dynamic_pointer_cast<Context>(*it);
82  if (ctx && (!checkEqual || ctx->getHandler() == handler)) {
83  it = removeAt(it);
84  removed = true;
85  } else {
86  it++;
87  }
88  }
89 
90  if (!removed) {
91  throw std::invalid_argument("No such handler in pipeline");
92  }
93 
94  return *this;
95 }
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
ContextIterator removeAt(const ContextIterator &it)
Definition: Pipeline.cpp:49
void handler(int, siginfo_t *, void *)
std::conditional< Handler::dir==HandlerDir::BOTH, ContextImpl< Handler >, typename std::conditional< Handler::dir==HandlerDir::IN, InboundContextImpl< Handler >, OutboundContextImpl< Handler > >::type >::type type
template<class H >
bool wangle::PipelineBase::setOwner ( H *  handler)

Definition at line 137 of file Pipeline-inl.h.

References ctxs_, handler(), and owner_.

137  {
138  typedef typename ContextType<H>::type Context;
139  for (auto& ctx : ctxs_) {
140  auto ctxImpl = dynamic_cast<Context*>(ctx.get());
141  if (ctxImpl && ctxImpl->getHandler() == handler) {
142  owner_ = ctx;
143  return true;
144  }
145  }
146  return false;
147 }
std::shared_ptr< PipelineContext > owner_
Definition: Pipeline.h:158
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
void handler(int, siginfo_t *, void *)
std::conditional< Handler::dir==HandlerDir::BOTH, ContextImpl< Handler >, typename std::conditional< Handler::dir==HandlerDir::IN, InboundContextImpl< Handler >, OutboundContextImpl< Handler > >::type >::type type
void wangle::PipelineBase::setPipelineManager ( PipelineManager manager)
inline

Definition at line 47 of file Pipeline.h.

Referenced by wangle::BroadcastPool< T, R, P >::BroadcastManager::getHandler().

47  {
48  manager_ = manager;
49  }
PipelineManager * manager_
Definition: Pipeline.h:140
void wangle::PipelineBase::setReadBufferSettings ( uint64_t  minAvailable,
uint64_t  allocationSize 
)

Definition at line 31 of file Pipeline.cpp.

References readBufferSettings_.

33  {
34  readBufferSettings_ = std::make_pair(minAvailable, allocationSize);
35 }
std::pair< uint64_t, uint64_t > readBufferSettings_
Definition: Pipeline.h:156
void wangle::PipelineBase::setTransport ( std::shared_ptr< folly::AsyncTransport transport)
inline

Definition at line 61 of file Pipeline.h.

References transport_.

61  {
62  transport_ = transport;
63  }
std::shared_ptr< folly::AsyncTransport > transport_
Definition: Pipeline.h:141
void wangle::PipelineBase::setTransportInfo ( std::shared_ptr< TransportInfo tInfo)

Definition at line 41 of file Pipeline.cpp.

References transportInfo_.

41  {
42  transportInfo_ = tInfo;
43 }
std::shared_ptr< TransportInfo > transportInfo_
Definition: Pipeline.h:142
void wangle::PipelineBase::setWriteFlags ( folly::WriteFlags  flags)

Definition at line 23 of file Pipeline.cpp.

References writeFlags_.

23  {
25 }
flags
Definition: http_parser.h:127
folly::WriteFlags writeFlags_
Definition: Pipeline.h:155

Member Data Documentation

std::vector<std::shared_ptr<PipelineContext> > wangle::PipelineBase::ctxs_
protected
std::vector<PipelineContext*> wangle::PipelineBase::inCtxs_
protected

Definition at line 136 of file Pipeline.h.

Referenced by addHelper(), wangle::Pipeline< R, W >::finalize(), and removeAt().

PipelineManager* wangle::PipelineBase::manager_ {nullptr}
private

Definition at line 140 of file Pipeline.h.

std::vector<PipelineContext*> wangle::PipelineBase::outCtxs_
protected

Definition at line 137 of file Pipeline.h.

Referenced by addHelper(), wangle::Pipeline< R, W >::finalize(), and removeAt().

std::shared_ptr<PipelineContext> wangle::PipelineBase::owner_
private

Definition at line 158 of file Pipeline.h.

Referenced by detachHandlers(), and setOwner().

std::pair<uint64_t, uint64_t> wangle::PipelineBase::readBufferSettings_ {2048, 2048}
private

Definition at line 156 of file Pipeline.h.

Referenced by getReadBufferSettings(), and setReadBufferSettings().

std::shared_ptr<folly::AsyncTransport> wangle::PipelineBase::transport_
private

Definition at line 141 of file Pipeline.h.

std::shared_ptr<TransportInfo> wangle::PipelineBase::transportInfo_
private

Definition at line 142 of file Pipeline.h.

Referenced by getTransportInfo(), and setTransportInfo().

folly::WriteFlags wangle::PipelineBase::writeFlags_ {folly::WriteFlags::NONE}
private

Definition at line 155 of file Pipeline.h.

Referenced by getWriteFlags(), and setWriteFlags().


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