event/MaskMonitor: add variant with bound method

This commit is contained in:
Max Kellermann 2016-03-10 22:37:33 +01:00
parent a7c68018a2
commit 5ffe3773d4

View File

@ -22,6 +22,7 @@
#include "check.h"
#include "DeferredMonitor.hxx"
#include "util/BoundMethod.hxx"
#include <atomic>
@ -50,4 +51,22 @@ protected:
void RunDeferred() override;
};
/**
* A variant of #MaskMonitor which invokes a bound method.
*/
template<typename T>
class CallbackMaskMonitor final : public MaskMonitor {
BoundMethod<T, void, unsigned> callback;
public:
template<typename... Args>
explicit CallbackMaskMonitor(EventLoop &_loop, Args&&... args)
:MaskMonitor(_loop), callback(std::forward<Args>(args)...) {}
protected:
void HandleMask(unsigned mask) override {
callback(mask);
}
};
#endif