[libcamera-devel] [RFC 2/4] Add BoundMethodFunction
Tomi Valkeinen
tomi.valkeinen at iki.fi
Fri Sep 18 17:20:17 CEST 2020
Note: no way to disconnect, except disconnect all.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen at iki.fi>
---
include/libcamera/bound_method.h | 25 +++++++++++++++++++++++++
include/libcamera/signal.h | 6 ++++++
2 files changed, 31 insertions(+)
diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h
index d1e4448..d720199 100644
--- a/include/libcamera/bound_method.h
+++ b/include/libcamera/bound_method.h
@@ -11,6 +11,7 @@
#include <tuple>
#include <type_traits>
#include <utility>
+#include <functional>
namespace libcamera {
@@ -228,6 +229,30 @@ private:
R (*func_)(Args...);
};
+template<typename R, typename... Args>
+class BoundMethodFunction : public BoundMethodArgs<R, Args...>
+{
+public:
+ BoundMethodFunction(std::function<R(Args...)> func)
+ : BoundMethodArgs<R, Args...>(nullptr, nullptr, ConnectionTypeAuto),
+ func_(func)
+ {
+ }
+
+ R activate(Args... args, [[maybe_unused]] bool deleteMethod = false) override
+ {
+ return func_(args...);
+ }
+
+ R invoke(Args...) override
+ {
+ return R();
+ }
+
+private:
+ std::function<R(Args...)> func_;
+};
+
} /* namespace libcamera */
#endif /* __LIBCAMERA_BOUND_METHOD_H__ */
diff --git a/include/libcamera/signal.h b/include/libcamera/signal.h
index accb797..939169f 100644
--- a/include/libcamera/signal.h
+++ b/include/libcamera/signal.h
@@ -68,6 +68,12 @@ public:
SignalBase::connect(new BoundMethodStatic<R, Args...>(func));
}
+ template<typename R>
+ void connect(std::function<R(Args...)> func)
+ {
+ SignalBase::connect(new BoundMethodFunction<R, Args...>(func));
+ }
+
void disconnect()
{
SignalBase::disconnect([]([[maybe_unused]] SlotList::iterator &iter) {
--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
More information about the libcamera-devel
mailing list