From 5ffe3773d4a9b4726288b266725235d4c6f24b94 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 10 Mar 2016 22:37:33 +0100 Subject: [PATCH] event/MaskMonitor: add variant with bound method --- src/event/MaskMonitor.hxx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/event/MaskMonitor.hxx b/src/event/MaskMonitor.hxx index db6803bbf..3abb46ab2 100644 --- a/src/event/MaskMonitor.hxx +++ b/src/event/MaskMonitor.hxx @@ -22,6 +22,7 @@ #include "check.h" #include "DeferredMonitor.hxx" +#include "util/BoundMethod.hxx" #include @@ -50,4 +51,22 @@ protected: void RunDeferred() override; }; +/** + * A variant of #MaskMonitor which invokes a bound method. + */ +template +class CallbackMaskMonitor final : public MaskMonitor { + BoundMethod callback; + +public: + template + explicit CallbackMaskMonitor(EventLoop &_loop, Args&&... args) + :MaskMonitor(_loop), callback(std::forward(args)...) {} + +protected: + void HandleMask(unsigned mask) override { + callback(mask); + } +}; + #endif