Commit 1137f4b8 authored by James Sedgwick's avatar James Sedgwick Committed by Sara Golemon

use Unit in Pipeline

Summary: Instead of the one-off Nothing struct

Reviewed By: @yfeldblum

Differential Revision: D2158621
parent ca1e87ed
......@@ -109,8 +109,8 @@ class InboundHandler : public HandlerBase<InboundHandlerContext<Rout>> {
typedef Rin rin;
typedef Rout rout;
typedef Nothing win;
typedef Nothing wout;
typedef Unit win;
typedef Unit wout;
typedef InboundHandlerContext<Rout> Context;
virtual ~InboundHandler() = default;
......@@ -134,8 +134,8 @@ class OutboundHandler : public HandlerBase<OutboundHandlerContext<Wout>> {
public:
static const HandlerDir dir = HandlerDir::OUT;
typedef Nothing rin;
typedef Nothing rout;
typedef Unit rin;
typedef Unit rout;
typedef Win win;
typedef Wout wout;
typedef OutboundHandlerContext<Wout> Context;
......
......@@ -59,7 +59,7 @@ std::pair<uint64_t, uint64_t> Pipeline<R, W>::getReadBufferSettings() {
template <class R, class W>
template <class T>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
Pipeline<R, W>::read(R msg) {
if (!front_) {
throw std::invalid_argument("read(): no inbound handler in Pipeline");
......@@ -69,7 +69,7 @@ Pipeline<R, W>::read(R msg) {
template <class R, class W>
template <class T>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
Pipeline<R, W>::readEOF() {
if (!front_) {
throw std::invalid_argument("readEOF(): no inbound handler in Pipeline");
......@@ -79,7 +79,7 @@ Pipeline<R, W>::readEOF() {
template <class R, class W>
template <class T>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
Pipeline<R, W>::transportActive() {
if (front_) {
front_->transportActive();
......@@ -88,7 +88,7 @@ Pipeline<R, W>::transportActive() {
template <class R, class W>
template <class T>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
Pipeline<R, W>::transportInactive() {
if (front_) {
front_->transportInactive();
......@@ -97,7 +97,7 @@ Pipeline<R, W>::transportInactive() {
template <class R, class W>
template <class T>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
Pipeline<R, W>::readException(exception_wrapper e) {
if (!front_) {
throw std::invalid_argument(
......@@ -108,7 +108,7 @@ Pipeline<R, W>::readException(exception_wrapper e) {
template <class R, class W>
template <class T>
typename std::enable_if<!std::is_same<T, Nothing>::value, Future<void>>::type
typename std::enable_if<!std::is_same<T, Unit>::value, Future<void>>::type
Pipeline<R, W>::write(W msg) {
if (!back_) {
throw std::invalid_argument("write(): no outbound handler in Pipeline");
......@@ -118,7 +118,7 @@ Pipeline<R, W>::write(W msg) {
template <class R, class W>
template <class T>
typename std::enable_if<!std::is_same<T, Nothing>::value, Future<void>>::type
typename std::enable_if<!std::is_same<T, Unit>::value, Future<void>>::type
Pipeline<R, W>::close() {
if (!back_) {
throw std::invalid_argument("close(): no outbound handler in Pipeline");
......@@ -250,12 +250,12 @@ H* Pipeline<R, W>::getHandler(int i) {
namespace detail {
template <class T>
inline void logWarningIfNotNothing(const std::string& warning) {
inline void logWarningIfNotUnit(const std::string& warning) {
LOG(WARNING) << warning;
}
template <>
inline void logWarningIfNotNothing<Nothing>(const std::string& warning) {
inline void logWarningIfNotUnit<Unit>(const std::string& warning) {
// do nothing
}
......@@ -283,12 +283,12 @@ void Pipeline<R, W>::finalize() {
}
if (!front_) {
detail::logWarningIfNotNothing<R>(
detail::logWarningIfNotUnit<R>(
"No inbound handler in Pipeline, inbound operations will throw "
"std::invalid_argument");
}
if (!back_) {
detail::logWarningIfNotNothing<W>(
detail::logWarningIfNotUnit<W>(
"No outbound handler in Pipeline, outbound operations will throw "
"std::invalid_argument");
}
......
......@@ -18,6 +18,7 @@
#include <folly/wangle/channel/HandlerContext.h>
#include <folly/futures/Future.h>
#include <folly/futures/Unit.h>
#include <folly/io/async/AsyncTransport.h>
#include <folly/io/async/DelayedDestruction.h>
#include <folly/ExceptionWrapper.h>
......@@ -58,17 +59,15 @@ class PipelineBase : public DelayedDestruction {
std::shared_ptr<AsyncTransport> transport_;
};
struct Nothing{};
/*
* R is the inbound type, i.e. inbound calls start with pipeline.read(R)
* W is the outbound type, i.e. outbound calls start with pipeline.write(W)
*
* Use Nothing for one of the types if your pipeline is unidirectional.
* If R is Nothing, read(), readEOF(), and readException() will be disabled.
* If W is Nothing, write() and close() will be disabled.
* Use Unit for one of the types if your pipeline is unidirectional.
* If R is Unit, read(), readEOF(), and readException() will be disabled.
* If W is Unit, write() and close() will be disabled.
*/
template <class R, class W = Nothing>
template <class R, class W = Unit>
class Pipeline : public PipelineBase {
public:
Pipeline();
......@@ -81,31 +80,31 @@ class Pipeline : public PipelineBase {
std::pair<uint64_t, uint64_t> getReadBufferSettings();
template <class T = R>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
read(R msg);
template <class T = R>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
readEOF();
template <class T = R>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
readException(exception_wrapper e);
template <class T = R>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
transportActive();
template <class T = R>
typename std::enable_if<!std::is_same<T, Nothing>::value>::type
typename std::enable_if<!std::is_same<T, Unit>::value>::type
transportInactive();
template <class T = W>
typename std::enable_if<!std::is_same<T, Nothing>::value, Future<void>>::type
typename std::enable_if<!std::is_same<T, Unit>::value, Future<void>>::type
write(W msg);
template <class T = W>
typename std::enable_if<!std::is_same<T, Nothing>::value, Future<void>>::type
typename std::enable_if<!std::is_same<T, Unit>::value, Future<void>>::type
close();
template <class H>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment