{"id":2504,"url":"https://patchwork.libcamera.org/api/patches/2504/?format=json","web_url":"https://patchwork.libcamera.org/patch/2504/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200104050947.7673-9-laurent.pinchart@ideasonboard.com>","date":"2020-01-04T05:09:41","name":"[libcamera-devel,08/14] libcamera: bound_method: Support bindings to non-void methods","commit_ref":"621edb2367e81860f6b6e89243ad7cbe3e0b6b7f","pull_url":null,"state":"accepted","archived":false,"hash":"ccc67e02107cedd1e1c37bdec1638f95b1c79089","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2504/mbox/","series":[{"id":600,"url":"https://patchwork.libcamera.org/api/series/600/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=600","date":"2020-01-04T05:09:33","name":"object: Propagate return value of invoked method","version":1,"mbox":"https://patchwork.libcamera.org/series/600/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2504/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2504/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9404060605\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  4 Jan 2020 06:10:05 +0100 (CET)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3982630F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  4 Jan 2020 06:10:05 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1578114605;\n\tbh=WsJUHEKFZpMwIW/SZ2KfP9yBOqYhlIcjE1nKxAa3TBk=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=jTjG/eMdnaLUaxTeSc5yqkH//C06u7qxafgF6fYKGDYTK6WteBLqSkCMUBRAPnIYU\n\tRy/JlZsRHHTs0V0s1MO0WLDjT0ockfIqwIF//2VYvTrteJohYkve3p8pVGF8wBTKMD\n\teWPZebzBuisuvICBdyo/GCEGMVJSxajBkd7aZUkU=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat,  4 Jan 2020 07:09:41 +0200","Message-Id":"<20200104050947.7673-9-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200104050947.7673-1-laurent.pinchart@ideasonboard.com>","References":"<20200104050947.7673-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 08/14] libcamera: bound_method: Support\n\tbindings to non-void methods","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 04 Jan 2020 05:10:07 -0000"},"content":"The bound method implementation is restricted to binding to void methods\nas return values are not supported. This complicates usage of bound\nmethods, as non-void methods used a slots or Object::invokeMethod()\ntargets need to be wrapped in a void method. Simplify this by supporting\narbitrary return types and ignoring the return value.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/bound_method.h | 28 ++++++++++++------------\n include/libcamera/object.h       |  6 +++---\n include/libcamera/signal.h       | 37 +++++++++++++++++---------------\n src/libcamera/signal.cpp         |  8 +++----\n 4 files changed, 41 insertions(+), 38 deletions(-)","diff":"diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h\nindex d194cd4133bb..b50072ffc098 100644\n--- a/include/libcamera/bound_method.h\n+++ b/include/libcamera/bound_method.h\n@@ -79,7 +79,7 @@ public:\n \tstd::tuple<typename std::remove_reference<Args>::type...> args_;\n };\n \n-template<typename... Args>\n+template<typename R, typename... Args>\n class BoundMethodArgs : public BoundMethodBase\n {\n public:\n@@ -107,19 +107,19 @@ public:\n \tvirtual void invoke(Args... args) = 0;\n };\n \n-template<typename T, typename... Args>\n-class BoundMemberMethod : public BoundMethodArgs<Args...>\n+template<typename T, typename R, typename... Args>\n+class BoundMemberMethod : public BoundMethodArgs<R, Args...>\n {\n public:\n-\tusing PackType = typename BoundMethodArgs<Args...>::PackType;\n+\tusing PackType = typename BoundMethodArgs<R, Args...>::PackType;\n \n-\tBoundMemberMethod(T *obj, Object *object, void (T::*func)(Args...),\n+\tBoundMemberMethod(T *obj, Object *object, R (T::*func)(Args...),\n \t\t\t  ConnectionType type = ConnectionTypeAuto)\n-\t\t: BoundMethodArgs<Args...>(obj, object, type), func_(func)\n+\t\t: BoundMethodArgs<R, Args...>(obj, object, type), func_(func)\n \t{\n \t}\n \n-\tbool match(void (T::*func)(Args...)) const { return func == func_; }\n+\tbool match(R (T::*func)(Args...)) const { return func == func_; }\n \n \tvoid activate(Args... args, bool deleteMethod = false) override\n \t{\n@@ -135,20 +135,20 @@ public:\n \t}\n \n private:\n-\tvoid (T::*func_)(Args...);\n+\tR (T::*func_)(Args...);\n };\n \n-template<typename... Args>\n-class BoundStaticMethod : public BoundMethodArgs<Args...>\n+template<typename R, typename... Args>\n+class BoundStaticMethod : public BoundMethodArgs<R, Args...>\n {\n public:\n-\tBoundStaticMethod(void (*func)(Args...))\n-\t\t: BoundMethodArgs<Args...>(nullptr, nullptr, ConnectionTypeAuto),\n+\tBoundStaticMethod(R (*func)(Args...))\n+\t\t: BoundMethodArgs<R, Args...>(nullptr, nullptr, ConnectionTypeAuto),\n \t\t  func_(func)\n \t{\n \t}\n \n-\tbool match(void (*func)(Args...)) const { return func == func_; }\n+\tbool match(R (*func)(Args...)) const { return func == func_; }\n \n \tvoid activate(Args... args, bool deleteMethod = false) override\n \t{\n@@ -158,7 +158,7 @@ public:\n \tvoid invoke(Args...) override {}\n \n private:\n-\tvoid (*func_)(Args...);\n+\tR (*func_)(Args...);\n };\n \n } /* namespace libcamera */\ndiff --git a/include/libcamera/object.h b/include/libcamera/object.h\nindex c45165dec8ef..586c2cf6fc70 100644\n--- a/include/libcamera/object.h\n+++ b/include/libcamera/object.h\n@@ -29,13 +29,13 @@ public:\n \n \tvoid postMessage(std::unique_ptr<Message> msg);\n \n-\ttemplate<typename T, typename... FuncArgs, typename... Args,\n+\ttemplate<typename T, typename R, typename... FuncArgs, typename... Args,\n \t\t typename std::enable_if<std::is_base_of<Object, T>::value>::type * = nullptr>\n-\tvoid invokeMethod(void (T::*func)(FuncArgs...), ConnectionType type,\n+\tvoid invokeMethod(R (T::*func)(FuncArgs...), ConnectionType type,\n \t\t\t  Args... args)\n \t{\n \t\tT *obj = static_cast<T *>(this);\n-\t\tauto *method = new BoundMemberMethod<T, FuncArgs...>(obj, this, func, type);\n+\t\tauto *method = new BoundMemberMethod<T, R, FuncArgs...>(obj, this, func, type);\n \t\tmethod->activate(args..., true);\n \t}\n \ndiff --git a/include/libcamera/signal.h b/include/libcamera/signal.h\nindex 57598335932c..7fbe5a2c528f 100644\n--- a/include/libcamera/signal.h\n+++ b/include/libcamera/signal.h\n@@ -54,27 +54,28 @@ public:\n \t}\n \n #ifndef __DOXYGEN__\n-\ttemplate<typename T, typename std::enable_if<std::is_base_of<Object, T>::value>::type * = nullptr>\n-\tvoid connect(T *obj, void (T::*func)(Args...),\n+\ttemplate<typename T, typename R, typename std::enable_if<std::is_base_of<Object, T>::value>::type * = nullptr>\n+\tvoid connect(T *obj, R (T::*func)(Args...),\n \t\t     ConnectionType type = ConnectionTypeAuto)\n \t{\n \t\tObject *object = static_cast<Object *>(obj);\n \t\tobject->connect(this);\n-\t\tslots_.push_back(new BoundMemberMethod<T, Args...>(obj, object, func, type));\n+\t\tslots_.push_back(new BoundMemberMethod<T, void, Args...>(obj, object, func, type));\n \t}\n \n-\ttemplate<typename T, typename std::enable_if<!std::is_base_of<Object, T>::value>::type * = nullptr>\n+\ttemplate<typename T, typename R, typename std::enable_if<!std::is_base_of<Object, T>::value>::type * = nullptr>\n #else\n-\ttemplate<typename T>\n+\ttemplate<typename T, typename R>\n #endif\n-\tvoid connect(T *obj, void (T::*func)(Args...))\n+\tvoid connect(T *obj, R (T::*func)(Args...))\n \t{\n-\t\tslots_.push_back(new BoundMemberMethod<T, Args...>(obj, nullptr, func));\n+\t\tslots_.push_back(new BoundMemberMethod<T, R, Args...>(obj, nullptr, func));\n \t}\n \n-\tvoid connect(void (*func)(Args...))\n+\ttemplate<typename R>\n+\tvoid connect(R (*func)(Args...))\n \t{\n-\t\tslots_.push_back(new BoundStaticMethod<Args...>(func));\n+\t\tslots_.push_back(new BoundStaticMethod<R, Args...>(func));\n \t}\n \n \tvoid disconnect()\n@@ -90,11 +91,12 @@ public:\n \t\tSignalBase::disconnect(obj);\n \t}\n \n-\ttemplate<typename T>\n-\tvoid disconnect(T *obj, void (T::*func)(Args...))\n+\ttemplate<typename T, typename R>\n+\tvoid disconnect(T *obj, R (T::*func)(Args...))\n \t{\n \t\tfor (auto iter = slots_.begin(); iter != slots_.end(); ) {\n-\t\t\tBoundMethodArgs<Args...> *slot = static_cast<BoundMethodArgs<Args...> *>(*iter);\n+\t\t\tBoundMethodArgs<R, Args...> *slot =\n+\t\t\t\tstatic_cast<BoundMethodArgs<R, Args...> *>(*iter);\n \t\t\t/*\n \t\t\t * If the object matches the slot, the slot is\n \t\t\t * guaranteed to be a member slot, so we can safely\n@@ -102,7 +104,7 @@ public:\n \t\t\t * func.\n \t\t\t */\n \t\t\tif (slot->match(obj) &&\n-\t\t\t    static_cast<BoundMemberMethod<T, Args...> *>(slot)->match(func)) {\n+\t\t\t    static_cast<BoundMemberMethod<T, R, Args...> *>(slot)->match(func)) {\n \t\t\t\titer = slots_.erase(iter);\n \t\t\t\tdelete slot;\n \t\t\t} else {\n@@ -111,12 +113,13 @@ public:\n \t\t}\n \t}\n \n-\tvoid disconnect(void (*func)(Args...))\n+\ttemplate<typename R>\n+\tvoid disconnect(R (*func)(Args...))\n \t{\n \t\tfor (auto iter = slots_.begin(); iter != slots_.end(); ) {\n-\t\t\tBoundMethodArgs<Args...> *slot = *iter;\n+\t\t\tBoundMethodArgs<R, Args...> *slot = *iter;\n \t\t\tif (slot->match(nullptr) &&\n-\t\t\t    static_cast<BoundStaticMethod<Args...> *>(slot)->match(func)) {\n+\t\t\t    static_cast<BoundStaticMethod<R, Args...> *>(slot)->match(func)) {\n \t\t\t\titer = slots_.erase(iter);\n \t\t\t\tdelete slot;\n \t\t\t} else {\n@@ -133,7 +136,7 @@ public:\n \t\t */\n \t\tstd::vector<BoundMethodBase *> slots{ slots_.begin(), slots_.end() };\n \t\tfor (BoundMethodBase *slot : slots)\n-\t\t\tstatic_cast<BoundMethodArgs<Args...> *>(slot)->activate(args...);\n+\t\t\tstatic_cast<BoundMethodArgs<void, Args...> *>(slot)->activate(args...);\n \t}\n };\n \ndiff --git a/src/libcamera/signal.cpp b/src/libcamera/signal.cpp\nindex 6ee348acc8d4..190033317c72 100644\n--- a/src/libcamera/signal.cpp\n+++ b/src/libcamera/signal.cpp\n@@ -54,7 +54,7 @@ namespace libcamera {\n  */\n \n /**\n- * \\fn Signal::connect(T *object, void(T::*func)(Args...))\n+ * \\fn Signal::connect(T *object, R (T::*func)(Args...))\n  * \\brief Connect the signal to a member function slot\n  * \\param[in] object The slot object pointer\n  * \\param[in] func The slot member function\n@@ -66,7 +66,7 @@ namespace libcamera {\n  */\n \n /**\n- * \\fn Signal::connect(void(*func)(Args...))\n+ * \\fn Signal::connect(R (*func)(Args...))\n  * \\brief Connect the signal to a static function slot\n  * \\param[in] func The slot static function\n  */\n@@ -83,14 +83,14 @@ namespace libcamera {\n  */\n \n /**\n- * \\fn Signal::disconnect(T *object, void(T::*func)(Args...))\n+ * \\fn Signal::disconnect(T *object, R (T::*func)(Args...))\n  * \\brief Disconnect the signal from the \\a object slot member function \\a func\n  * \\param[in] object The object pointer whose slots to disconnect\n  * \\param[in] func The slot member function to disconnect\n  */\n \n /**\n- * \\fn Signal::disconnect(void(*func)(Args...))\n+ * \\fn Signal::disconnect(R (*func)(Args...))\n  * \\brief Disconnect the signal from the slot static function \\a func\n  * \\param[in] func The slot static function to disconnect\n  */\n","prefixes":["libcamera-devel","08/14"]}