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