From patchwork Sun Jul 25 17:18:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13114 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 CC33EC322C for ; Sun, 25 Jul 2021 17:18:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 80F0F687BC; Sun, 25 Jul 2021 19:18:43 +0200 (CEST) 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="GuvzE8zs"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CC24160273 for ; Sun, 25 Jul 2021 19:18:37 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 73B73DD for ; Sun, 25 Jul 2021 19:18:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627233517; bh=/PLHvP2Ge39FRPLwtEmA86ZEQGBBBoqCeq6llsOHW/k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GuvzE8zs5SOmM2ZL60SD3JpTMmTQel+XXfEtPtUd9+sDkcv4DD/9dfd1xy5e9tBLS 5YJAA+OFHylO2+pEjRjHMZA8AVHknjmOAAi5ec+fJvFFmHZlFd91JxgT9YpNS/Qz2G leyj1Ap+LSbdVUxZZIpKkwZrDgUa6sSvbmE+uWck= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 25 Jul 2021 20:18:25 +0300 Message-Id: <20210725171827.23643-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210725171827.23643-1-laurent.pinchart@ideasonboard.com> References: <20210725171827.23643-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/5] libcamera: file: Use Flags<> class for map flags 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" Use the newly introduced Flags<> class to store a bitfield of File::MapFlag in a type-safe way. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Changes since v1: - Use an unscoped enum --- include/libcamera/base/file.h | 5 ++++- src/libcamera/base/file.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/libcamera/base/file.h b/include/libcamera/base/file.h index 7dd1559d2285..452a658b409f 100644 --- a/include/libcamera/base/file.h +++ b/include/libcamera/base/file.h @@ -15,6 +15,7 @@ #include #include +#include #include namespace libcamera { @@ -27,6 +28,8 @@ public: MapPrivate = (1 << 0), }; + using MapFlags = Flags; + enum OpenMode { NotOpen = 0, ReadOnly = (1 << 0), @@ -57,7 +60,7 @@ public: ssize_t write(const Span &data); Span map(off_t offset = 0, ssize_t size = -1, - MapFlag flags = MapNoOption); + MapFlags flags = MapNoOption); bool unmap(uint8_t *addr); static bool exists(const std::string &name); diff --git a/src/libcamera/base/file.cpp b/src/libcamera/base/file.cpp index 073666fa6f66..e180c5479098 100644 --- a/src/libcamera/base/file.cpp +++ b/src/libcamera/base/file.cpp @@ -52,6 +52,11 @@ LOG_DEFINE_CATEGORY(File) * the file constents */ +/** + * \typedef File::MapFlags + * \brief An OR combination of File::MapFlag values + */ + /** * \enum File::OpenMode * \brief Mode in which a file is opened @@ -371,7 +376,7 @@ ssize_t File::write(const Span &data) * * \return The mapped memory on success, or an empty span otherwise */ -Span File::map(off_t offset, ssize_t size, enum File::MapFlag flags) +Span File::map(off_t offset, ssize_t size, File::MapFlags flags) { if (!isOpen()) { error_ = -EBADF;