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