diff options
author | Alexander Tkachev | 2016-05-21 21:30:25 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | e1109c0c328aaf671e2b03b3b4e6de1ae9061754 (patch) | |
tree | df4beeb28006b68c6d60953c164f53660f74b376 /common | |
parent | ca456a7241fb4b46f9c76c86eeecc273ca31d8f6 (diff) | |
download | scummvm-rg350-e1109c0c328aaf671e2b03b3b4e6de1ae9061754.tar.gz scummvm-rg350-e1109c0c328aaf671e2b03b3b4e6de1ae9061754.tar.bz2 scummvm-rg350-e1109c0c328aaf671e2b03b3b4e6de1ae9061754.zip |
CLOUD: Add CallbackBridge
This commit also adds GlobalFunctionCallback, because it was needed in
order to replace plain C pointers to functions (which were used in
Request) into our object-oriented BaseCallback pointers.
Diffstat (limited to 'common')
-rw-r--r-- | common/callback.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/common/callback.h b/common/callback.h index 4cfdd53fd9..4cc63ed346 100644 --- a/common/callback.h +++ b/common/callback.h @@ -32,6 +32,18 @@ public: virtual void operator()(void *ptr) = 0; }; +class GlobalFunctionCallback: public BaseCallback { + typedef void(*GlobalFunction)(void *result); + GlobalFunction _callback; + +public: + GlobalFunctionCallback(GlobalFunction cb): _callback(cb) {} + virtual ~GlobalFunctionCallback() {} + virtual void operator()(void *ptr) { + if (_callback) _callback(ptr); + } +}; + template<class T> class Callback: public BaseCallback { typedef void(T::*TMethod)(void *); T *_object; @@ -42,6 +54,18 @@ public: void operator()(void *ptr) { (_object->*_method)(ptr); } }; +template<class T> class CallbackBridge: public BaseCallback { + typedef void(T::*TCallbackMethod)(BaseCallback *, void *); + T *_object; + TCallbackMethod _method; + BaseCallback *_outerCallback; +public: + CallbackBridge(T *object, TCallbackMethod method, BaseCallback *outerCallback): + _object(object), _method(method), _outerCallback(outerCallback) {} + virtual ~CallbackBridge() {} + void operator()(void *ptr) { (_object->*_method)(_outerCallback, ptr); } +}; + } // End of namespace Common #endif |