From 621edb2367e81860f6b6e89243ad7cbe3e0b6b7f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 3 Jan 2020 20:56:05 +0200 Subject: libcamera: bound_method: Support bindings to non-void methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bound method implementation is restricted to binding to void methods as return values are not supported. This complicates usage of bound methods, as non-void methods used a slots or Object::invokeMethod() targets need to be wrapped in a void method. Simplify this by supporting arbitrary return types and ignoring the return value. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/signal.h | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'include/libcamera/signal.h') diff --git a/include/libcamera/signal.h b/include/libcamera/signal.h index 57598335..7fbe5a2c 100644 --- a/include/libcamera/signal.h +++ b/include/libcamera/signal.h @@ -54,27 +54,28 @@ public: } #ifndef __DOXYGEN__ - template::value>::type * = nullptr> - void connect(T *obj, void (T::*func)(Args...), + template::value>::type * = nullptr> + void connect(T *obj, R (T::*func)(Args...), ConnectionType type = ConnectionTypeAuto) { Object *object = static_cast(obj); object->connect(this); - slots_.push_back(new BoundMemberMethod(obj, object, func, type)); + slots_.push_back(new BoundMemberMethod(obj, object, func, type)); } - template::value>::type * = nullptr> + template::value>::type * = nullptr> #else - template + template #endif - void connect(T *obj, void (T::*func)(Args...)) + void connect(T *obj, R (T::*func)(Args...)) { - slots_.push_back(new BoundMemberMethod(obj, nullptr, func)); + slots_.push_back(new BoundMemberMethod(obj, nullptr, func)); } - void connect(void (*func)(Args...)) + template + void connect(R (*func)(Args...)) { - slots_.push_back(new BoundStaticMethod(func)); + slots_.push_back(new BoundStaticMethod(func)); } void disconnect() @@ -90,11 +91,12 @@ public: SignalBase::disconnect(obj); } - template - void disconnect(T *obj, void (T::*func)(Args...)) + template + void disconnect(T *obj, R (T::*func)(Args...)) { for (auto iter = slots_.begin(); iter != slots_.end(); ) { - BoundMethodArgs *slot = static_cast *>(*iter); + BoundMethodArgs *slot = + static_cast *>(*iter); /* * If the object matches the slot, the slot is * guaranteed to be a member slot, so we can safely @@ -102,7 +104,7 @@ public: * func. */ if (slot->match(obj) && - static_cast *>(slot)->match(func)) { + static_cast *>(slot)->match(func)) { iter = slots_.erase(iter); delete slot; } else { @@ -111,12 +113,13 @@ public: } } - void disconnect(void (*func)(Args...)) + template + void disconnect(R (*func)(Args...)) { for (auto iter = slots_.begin(); iter != slots_.end(); ) { - BoundMethodArgs *slot = *iter; + BoundMethodArgs *slot = *iter; if (slot->match(nullptr) && - static_cast *>(slot)->match(func)) { + static_cast *>(slot)->match(func)) { iter = slots_.erase(iter); delete slot; } else { @@ -133,7 +136,7 @@ public: */ std::vector slots{ slots_.begin(), slots_.end() }; for (BoundMethodBase *slot : slots) - static_cast *>(slot)->activate(args...); + static_cast *>(slot)->activate(args...); } }; -- cgit v1.2.1