19 #include <glog/logging.h> 23 template <
class R,
class W>
26 template <
class R,
class W>
31 template <
class R,
class W>
42 std::make_shared<Context>(shared_from_this(),
std::move(handler)),
53 return addBack(std::shared_ptr<H>(handler, [](H*){}));
60 std::make_shared<Context>(shared_from_this(),
std::move(handler)),
71 return addFront(std::shared_ptr<H>(handler, [](H*){}));
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)) {
91 throw std::invalid_argument(
"No such handler in pipeline");
99 return removeHelper<H>(
nullptr,
false);
104 return removeHelper<H>(
handler,
true);
114 auto ctx = getContext<H>();
115 return ctx ? ctx->getHandler() :
nullptr;
127 for (
auto pipelineCtx :
ctxs_) {
139 for (
auto& ctx :
ctxs_) {
140 auto ctxImpl =
dynamic_cast<Context*
>(ctx.get());
141 if (ctxImpl && ctxImpl->getHandler() ==
handler) {
149 template <
class Context>
151 addHelper(std::shared_ptr<Context>(ctx, [](Context*){}),
true);
154 template <
class Context>
156 std::shared_ptr<Context>&& ctx,
176 inline void logWarningIfNotUnit<folly::Unit>(
const std::string& ) {
182 template <
class R,
class W>
187 throw std::invalid_argument(
"read(): no inbound handler in Pipeline");
192 template <
class R,
class W>
197 throw std::invalid_argument(
"readEOF(): no inbound handler in Pipeline");
202 template <
class R,
class W>
211 template <
class R,
class W>
220 template <
class R,
class W>
225 throw std::invalid_argument(
226 "readException(): no inbound handler in Pipeline");
231 template <
class R,
class W>
237 throw std::invalid_argument(
"write(): no outbound handler in Pipeline");
242 template <
class R,
class W>
248 throw std::invalid_argument(
249 "writeException(): no outbound handler in Pipeline");
254 template <
class R,
class W>
260 throw std::invalid_argument(
"close(): no outbound handler in Pipeline");
266 template <
class R,
class W>
271 for (
size_t i = 0;
i <
inCtxs_.size() - 1;
i++) {
274 inCtxs_.back()->setNextIn(
nullptr);
283 outCtxs_.front()->setNextOut(
nullptr);
287 detail::logWarningIfNotUnit<R>(
288 "No inbound handler in Pipeline, inbound operations will throw " 289 "std::invalid_argument");
292 detail::logWarningIfNotUnit<W>(
293 "No outbound handler in Pipeline, outbound operations will throw " 294 "std::invalid_argument");
297 for (
auto it =
ctxs_.rbegin(); it !=
ctxs_.rend(); it++) {
298 (*it)->attachPipeline();
InboundLink< R > * front_
PipelineBase & addHelper(std::shared_ptr< Context > &&ctx, bool front)
std::vector< PipelineContext * > outCtxs_
std::shared_ptr< PipelineContext > owner_
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type close()
std::enable_if<!std::is_same< T, folly::Unit >::value >::type transportInactive()
PipelineBase & addFront(std::shared_ptr< H > handler)
void addContextFront(Context *ctx)
std::vector< std::shared_ptr< PipelineContext > > ctxs_
constexpr detail::Map< Move > move
ContextType< H >::type * getContext()
std::enable_if<!std::is_same< T, folly::Unit >::value >::type readEOF()
ContextIterator removeAt(const ContextIterator &it)
virtual void transportActive()=0
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
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type write(W msg)
virtual void transportInactive()=0
virtual folly::Future< folly::Unit > close()=0
std::enable_if<!std::is_same< T, folly::Unit >::value >::type transportActive()
std::enable_if<!std::is_same< T, folly::Unit >::value >::type read(R msg)
virtual void read(In msg)=0
PipelineBase & removeHelper(H *handler, bool checkEqual)
PipelineBase & addBack(std::shared_ptr< H > handler)
static const char *const value
void logWarningIfNotUnit(const std::string &warning)
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type writeException(folly::exception_wrapper e)
virtual void readException(folly::exception_wrapper e)=0
std::enable_if<!std::is_same< T, folly::Unit >::value >::type readException(folly::exception_wrapper e)
virtual folly::Future< folly::Unit > write(Out msg)=0
std::vector< PipelineContext * > inCtxs_
OutboundLink< W > * back_
bool setOwner(H *handler)
virtual folly::Future< folly::Unit > writeException(folly::exception_wrapper e)=0