From patchwork Mon Aug 11 09:49:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 24089 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 55531BDCC1 for ; Mon, 11 Aug 2025 09:49:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C864969230; Mon, 11 Aug 2025 11:49:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BU5JXXQZ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CAFB761464 for ; Mon, 11 Aug 2025 11:49:29 +0200 (CEST) Received: from pb-laptop.local (185.221.140.182.nat.pool.zt.hu [185.221.140.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C997C10D4 for ; Mon, 11 Aug 2025 11:48:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1754905717; bh=+aU5QbLxj/hcBEzsskTkS6MZzydYuIlSDc5zFp7SyGc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BU5JXXQZGQJgfOscnKjEcmUQ2HbUfuTYN+wLBpRJBVCNB+gY1TOHV+hufPQGtTD/4 mGr3LGaP8RmJopGgUtTTxTG9QILoZ+fJ4dApmma/q6IWR9xUtuJeitZvXkYNCtLZWD HMee7xxhc98IlidXfSM7vi2I91bvKi6w82AIEhmQ= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v1 1/2] libcamera: base: object: Add `invokeMethod` for lamdas Date: Mon, 11 Aug 2025 11:49:25 +0200 Message-ID: <20250811094926.1308259-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250811094926.1308259-1-barnabas.pocze@ideasonboard.com> References: <20250811094926.1308259-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an overload of `invokeMethod` that works the same way as the already existing version but instead of invoking a particular member function, it runs a lambda. Signed-off-by: Barnabás Pőcze --- include/libcamera/base/object.h | 10 ++++++++++ src/libcamera/base/object.cpp | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/libcamera/base/object.h b/include/libcamera/base/object.h index a24f84ff9..3f004499f 100644 --- a/include/libcamera/base/object.h +++ b/include/libcamera/base/object.h @@ -43,6 +43,16 @@ public: return method->activate(std::forward(args)..., true); } + template> * = nullptr> + auto invokeMethod(Func func, ConnectionType type) + -> std::invoke_result_t + { + using R = std::invoke_result_t; + auto *method = new BoundMethodFunctor(this, this, std::move(func), type); + return method->activate(true); + } + Thread *thread() const { return thread_; } void moveToThread(Thread *thread); diff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp index 37d133cc7..98937784c 100644 --- a/src/libcamera/base/object.cpp +++ b/src/libcamera/base/object.cpp @@ -255,7 +255,7 @@ bool Object::assertThreadBound(const char *message) } /** - * \fn R Object::invokeMethod() + * \fn Object::invokeMethod(R (T::*func)(FuncArgs...), ConnectionType type, Args &&...args) * \brief Invoke a method asynchronously on an Object instance * \param[in] func The object method to invoke * \param[in] type Connection type for method invocation @@ -280,6 +280,28 @@ bool Object::assertThreadBound(const char *message) * connection type ConnectionTypeQueued, return a default-constructed R value. */ +/** + * \fn Object::invokeMethod(Func func, ConnectionType type) + * \brief Invoke a lambda in the thread of an Object instance + * \param[in] func The object method to invoke + * \param[in] type Connection type for method invocation + * + * This function invokes the lambda \a func without arguments, based on the + * connection \a type wrt. the Object instance. Depending on the type, the method + * will be called synchronously in the same thread or asynchronously in the + * object's thread. + * + * Due to the asynchronous nature of threads, asynchronous invocations with the + * ConnectionTypeQueued type are not guaranteed to be called before the thread + * is stopped. See \ref thread-stop for additional information. + * + * \context This function is \threadsafe. + * + * \return For connection types ConnectionTypeDirect and + * ConnectionTypeBlocking, return the return value of the invoked method. For + * connection type ConnectionTypeQueued, return a default-constructed R value. + */ + /** * \fn Object::thread() * \brief Retrieve the thread the object is bound to