From patchwork Tue Jan 13 00:08:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 25749 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 22310BDCBF for ; Tue, 13 Jan 2026 00:09:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C021E61FFE; Tue, 13 Jan 2026 01:09:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UfmjG6Is"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EAF361FFF for ; Tue, 13 Jan 2026 01:09:17 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-152.bb.dnainternet.fi [81.175.209.152]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 88A9FBCA for ; Tue, 13 Jan 2026 01:08:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1768262931; bh=Q4PkQX2DZj9WDuWPR7gu+NRUWPoKvmBZtKuMRMRT0t8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UfmjG6IsxRLXq81G2OIOs01e7XHMTzInC9eDRS2yUkLb7RuS5JtHXyMUAYYYHTHG9 dTxMvXD6QxRIEolPAR5CerNv+KJhho5/EgziCbm/F6ums26jTtRIXjOQumdKUZDK5W hOI+kQEXBcKM62G1x5vui2yUwKy53tUPox4HCB+o= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 29/36] libcamera: value_node: Support adding nested children in one operation Date: Tue, 13 Jan 2026 02:08:01 +0200 Message-ID: <20260113000808.15395-30-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260113000808.15395-1-laurent.pinchart@ideasonboard.com> References: <20260113000808.15395-1-laurent.pinchart@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" The GlobalConfiguration class will need to add nested children to a ValueNode. Add a new overload to the add() function for this purpose. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/value_node.h | 3 ++ src/libcamera/value_node.cpp | 56 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/libcamera/internal/value_node.h b/include/libcamera/internal/value_node.h index c285be4957ed..abb0991fd87e 100644 --- a/include/libcamera/internal/value_node.h +++ b/include/libcamera/internal/value_node.h @@ -8,6 +8,7 @@ #pragma once +#include #include #include #include @@ -237,6 +238,8 @@ public: ValueNode *add(std::unique_ptr child); ValueNode *add(std::string key, std::unique_ptr child); + ValueNode *add(std::initializer_list path, + std::unique_ptr child); private: LIBCAMERA_DISABLE_COPY_AND_MOVE(ValueNode) diff --git a/src/libcamera/value_node.cpp b/src/libcamera/value_node.cpp index 50b23284f930..1256adf8361d 100644 --- a/src/libcamera/value_node.cpp +++ b/src/libcamera/value_node.cpp @@ -13,6 +13,8 @@ #include #include +#include +#include #include /** @@ -22,6 +24,8 @@ namespace libcamera { +LOG_DEFINE_CATEGORY(ValueNode) + namespace { /* Empty static ValueNode as a safe result for invalid operations */ @@ -539,4 +543,56 @@ ValueNode *ValueNode::add(std::string key, std::unique_ptr child) return elem.value.get(); } +/** + * \brief Add a child node at the given path + * \param[in] path The path + * \param[in] child The child node + * + * Add the \a child node at the given \a path starting at this node. Missing + * nodes are created along the path. Nodes along the path must be empty, in + * which case they are converted to the Type::Dictionary type, be a dictionary, + * or be missing. Otherwise, the \a child is discarded and the function returns + * a nullptr. + * + * Path elements are unique in the context of a parent node. If a child with the + * same \a key already exist at the end of the path, the \a child is discarded + * and the function returns a nullptr. + * + * \return A pointer to the \a child node if successfully added, nullptr + * otherwise + */ +ValueNode *ValueNode::add(std::initializer_list path, + std::unique_ptr child) +{ + if (!path.size()) + return NULL; + + ValueNode *node = this; + + for (const auto [i, name] : utils::enumerate(path)) { + auto iter = node->dictionary_.find(name); + if (iter == node->dictionary_.end()) { + std::unique_ptr obj; + + if (i < path.size() - 1) + obj = std::make_unique(); + else + obj = std::move(child); + + node = node->add(std::string{ name }, std::move(obj)); + if (!node) { + Span pathName{ std::data(path), i + 1 }; + LOG(ValueNode, Error) + << "Failed to populate '" + << utils::join(pathName, "/") << "'"; + return nullptr; + } + } else { + node = iter->second; + } + } + + return node; +} + } /* namespace libcamera */