mirror of
https://github.com/kasmtech/KasmVNC.git
synced 2024-11-21 23:53:24 +01:00
Support calling methods from timers
We can't safely use the normal timers in base classes as we cannot guarantee that subclasses will call the base class' handleTimeout() properly if the subclass overrides it.
This commit is contained in:
parent
1632f4888d
commit
a3c0ce55c9
@ -35,6 +35,8 @@ namespace rfb {
|
||||
dispatch elapsed Timer callbacks and to determine how long to wait in select() for
|
||||
the next timeout to occur.
|
||||
|
||||
For classes that can be derived it's best to use MethodTimer which can call a specific
|
||||
method on the class, thus avoiding conflicts when subclassing.
|
||||
*/
|
||||
|
||||
struct Timer {
|
||||
@ -101,6 +103,19 @@ namespace rfb {
|
||||
static std::list<Timer*> pending;
|
||||
};
|
||||
|
||||
template<class T> class MethodTimer
|
||||
: public Timer, public Timer::Callback {
|
||||
public:
|
||||
MethodTimer(T* obj_, bool (T::*cb_)(Timer*))
|
||||
: Timer(this), obj(obj_), cb(cb_) {}
|
||||
|
||||
virtual bool handleTimeout(Timer* t) { return (obj->*cb)(t); }
|
||||
|
||||
private:
|
||||
T* obj;
|
||||
bool (T::*cb)(Timer*);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user