event/MaskMonitor: add variant with bound method
This commit is contained in:
parent
a7c68018a2
commit
5ffe3773d4
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user