Skip to content

Commit

Permalink
rearrange Pipeline to have more functionality in PipelineBase
Browse files Browse the repository at this point in the history
Summary: This way, handlers can carry out more complex manipulations of the pipeline via ctx->getPipeline() without knowing the R/W types

Reviewed By: @djwatson

Differential Revision: D2158736
  • Loading branch information
James Sedgwick authored and sgolemon committed Jun 24, 2015
1 parent 6a2eb67 commit e4b8b76
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 283 deletions.
1 change: 1 addition & 0 deletions folly/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ libfolly_la_SOURCES = \
wangle/acceptor/SocketOptions.cpp \
wangle/acceptor/TransportInfo.cpp \
wangle/bootstrap/ServerBootstrap.cpp \
wangle/channel/Pipeline.cpp \
wangle/concurrent/CPUThreadPoolExecutor.cpp \
wangle/concurrent/Codel.cpp \
wangle/concurrent/IOThreadPoolExecutor.cpp \
Expand Down
46 changes: 25 additions & 21 deletions folly/wangle/channel/HandlerContext-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class OutboundLink {
virtual Future<void> close() = 0;
};

template <class P, class H, class Context>
template <class H, class Context>
class ContextImplBase : public PipelineContext {
public:
~ContextImplBase() = default;
Expand All @@ -68,7 +68,7 @@ class ContextImplBase : public PipelineContext {
return handler_.get();
}

void initialize(P* pipeline, std::shared_ptr<H> handler) {
void initialize(PipelineBase* pipeline, std::shared_ptr<H> handler) {
pipeline_ = pipeline;
handler_ = std::move(handler);
}
Expand Down Expand Up @@ -119,32 +119,32 @@ class ContextImplBase : public PipelineContext {

protected:
Context* impl_;
P* pipeline_;
PipelineBase* pipeline_;
std::shared_ptr<H> handler_;
InboundLink<typename H::rout>* nextIn_{nullptr};
OutboundLink<typename H::wout>* nextOut_{nullptr};

private:
bool attached_{false};
using DestructorGuard = typename P::DestructorGuard;
using DestructorGuard = typename DelayedDestruction::DestructorGuard;
};

template <class P, class H>
template <class H>
class ContextImpl
: public HandlerContext<typename H::rout,
typename H::wout>,
public InboundLink<typename H::rin>,
public OutboundLink<typename H::win>,
public ContextImplBase<P, H, HandlerContext<typename H::rout,
typename H::wout>> {
public ContextImplBase<H, HandlerContext<typename H::rout,
typename H::wout>> {
public:
typedef typename H::rin Rin;
typedef typename H::rout Rout;
typedef typename H::win Win;
typedef typename H::wout Wout;
static const HandlerDir dir = HandlerDir::BOTH;

explicit ContextImpl(P* pipeline, std::shared_ptr<H> handler) {
explicit ContextImpl(PipelineBase* pipeline, std::shared_ptr<H> handler) {
this->impl_ = this;
this->initialize(pipeline, std::move(handler));
}
Expand Down Expand Up @@ -278,22 +278,24 @@ class ContextImpl
}

private:
using DestructorGuard = typename P::DestructorGuard;
using DestructorGuard = typename DelayedDestruction::DestructorGuard;
};

template <class P, class H>
template <class H>
class InboundContextImpl
: public InboundHandlerContext<typename H::rout>,
public InboundLink<typename H::rin>,
public ContextImplBase<P, H, InboundHandlerContext<typename H::rout>> {
public ContextImplBase<H, InboundHandlerContext<typename H::rout>> {
public:
typedef typename H::rin Rin;
typedef typename H::rout Rout;
typedef typename H::win Win;
typedef typename H::wout Wout;
static const HandlerDir dir = HandlerDir::IN;

explicit InboundContextImpl(P* pipeline, std::shared_ptr<H> handler) {
explicit InboundContextImpl(
PipelineBase* pipeline,
std::shared_ptr<H> handler) {
this->impl_ = this;
this->initialize(pipeline, std::move(handler));
}
Expand Down Expand Up @@ -378,22 +380,24 @@ class InboundContextImpl
}

private:
using DestructorGuard = typename P::DestructorGuard;
using DestructorGuard = typename DelayedDestruction::DestructorGuard;
};

template <class P, class H>
template <class H>
class OutboundContextImpl
: public OutboundHandlerContext<typename H::wout>,
public OutboundLink<typename H::win>,
public ContextImplBase<P, H, OutboundHandlerContext<typename H::wout>> {
public ContextImplBase<H, OutboundHandlerContext<typename H::wout>> {
public:
typedef typename H::rin Rin;
typedef typename H::rout Rout;
typedef typename H::win Win;
typedef typename H::wout Wout;
static const HandlerDir dir = HandlerDir::OUT;

explicit OutboundContextImpl(P* pipeline, std::shared_ptr<H> handler) {
explicit OutboundContextImpl(
PipelineBase* pipeline,
std::shared_ptr<H> handler) {
this->impl_ = this;
this->initialize(pipeline, std::move(handler));
}
Expand Down Expand Up @@ -442,18 +446,18 @@ class OutboundContextImpl
}

private:
using DestructorGuard = typename P::DestructorGuard;
using DestructorGuard = typename DelayedDestruction::DestructorGuard;
};

template <class Handler, class Pipeline>
template <class Handler>
struct ContextType {
typedef typename std::conditional<
Handler::dir == HandlerDir::BOTH,
ContextImpl<Pipeline, Handler>,
ContextImpl<Handler>,
typename std::conditional<
Handler::dir == HandlerDir::IN,
InboundContextImpl<Pipeline, Handler>,
OutboundContextImpl<Pipeline, Handler>
InboundContextImpl<Handler>,
OutboundContextImpl<Handler>
>::type>::type
type;
};
Expand Down
Loading

0 comments on commit e4b8b76

Please sign in to comment.