aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-21 21:30:25 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commite1109c0c328aaf671e2b03b3b4e6de1ae9061754 (patch)
treedf4beeb28006b68c6d60953c164f53660f74b376 /common
parentca456a7241fb4b46f9c76c86eeecc273ca31d8f6 (diff)
downloadscummvm-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.h24
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