From patchwork Tue Nov 30 03:38:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 14861 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 535CEBF415 for ; Tue, 30 Nov 2021 03:39:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DC71F605C3; Tue, 30 Nov 2021 04:39:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Hbll/GVc"; 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 F1709605C1 for ; Tue, 30 Nov 2021 04:38:50 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7E0FB8F0; Tue, 30 Nov 2021 04:38:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1638243530; bh=AgBMBdKWljtF8MTtTz0SyFFV23uh+ZB8kLA+21V30ws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hbll/GVcD2N0hFyu1yL0TNT0Lr3cK0dyg749EBrzru23r2ftCDQy85Uy8T7cw9Pfe dQL1Rj2z/WhwXYxwXuazSPdqNCsxXjACmFesgwT70/AwILfxiMz9UImn1xZu5bDfNV wfJm0CP0crwBCZ05zT20LF4XuyWFp9L7PbP0alTA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 05:38:04 +0200 Message-Id: <20211130033820.18235-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211130033820.18235-1-laurent.pinchart@ideasonboard.com> References: <20211130033820.18235-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 06/22] libcamera: base: file_descriptor: Add constructor from UniqueFD 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" From: Hirokazu Honda Add a FileDescriptor constructor that takes a UniqueFD, transfering ownership of the file descriptor to the FileDescriptor. Signed-off-by: Hirokazu Honda Signed-off-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- Changes since v2: - Pass UniqueFD by value --- include/libcamera/base/file_descriptor.h | 3 +++ src/libcamera/base/file_descriptor.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/base/file_descriptor.h b/include/libcamera/base/file_descriptor.h index 5d1594e80801..74292eba04f5 100644 --- a/include/libcamera/base/file_descriptor.h +++ b/include/libcamera/base/file_descriptor.h @@ -11,11 +11,14 @@ namespace libcamera { +class UniqueFD; + class FileDescriptor final { public: explicit FileDescriptor(const int &fd = -1); explicit FileDescriptor(int &&fd); + explicit FileDescriptor(UniqueFD fd); FileDescriptor(const FileDescriptor &other); FileDescriptor(FileDescriptor &&other); ~FileDescriptor(); diff --git a/src/libcamera/base/file_descriptor.cpp b/src/libcamera/base/file_descriptor.cpp index 98d4b4bfd24f..da696b2501cd 100644 --- a/src/libcamera/base/file_descriptor.cpp +++ b/src/libcamera/base/file_descriptor.cpp @@ -13,6 +13,7 @@ #include #include +#include /** * \file base/file_descriptor.h @@ -109,6 +110,18 @@ FileDescriptor::FileDescriptor(int &&fd) fd = -1; } +/** + * \brief Create a FileDescriptor taking ownership of a given UniqueFD \a fd + * \param[in] fd UniqueFD + * + * Construct a FileDescriptor from UniqueFD by taking ownership of the \a fd. + * The original \a fd becomes invalid. + */ +FileDescriptor::FileDescriptor(UniqueFD fd) + : FileDescriptor(fd.release()) +{ +} + /** * \brief Copy constructor, create a FileDescriptor from a copy of \a other * \param[in] other The other FileDescriptor