Patch Detail
Show a patch.
GET /api/patches/2352/?format=api
{ "id": 2352, "url": "https://patchwork.libcamera.org/api/patches/2352/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2352/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20191126233620.1695316-5-niklas.soderlund@ragnatech.se>", "date": "2019-11-26T23:35:54", "name": "[libcamera-devel,04/30] libcamera: buffer: Add FileDecriptor to help deal with file descriptors", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "173e2484af60ac9ca255b0f01c4b896ddc5e9b7a", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/2352/mbox/", "series": [ { "id": 579, "url": "https://patchwork.libcamera.org/api/series/579/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=579", "date": "2019-11-26T23:35:50", "name": "libcamera: Rework buffer API", "version": 1, "mbox": "https://patchwork.libcamera.org/series/579/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2352/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2352/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 27AC860C3D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2019 00:39:28 +0100 (CET)", "from bismarck.berto.se (p54ac5865.dip0.t-ipconnect.de\n\t[84.172.88.101]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid fb9c075c-10a5-11ea-a0b9-005056917f90;\n\tWed, 27 Nov 2019 00:39:26 +0100 (CET)" ], "X-Halon-ID": "fb9c075c-10a5-11ea-a0b9-005056917f90", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 27 Nov 2019 00:35:54 +0100", "Message-Id": "<20191126233620.1695316-5-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.24.0", "In-Reply-To": "<20191126233620.1695316-1-niklas.soderlund@ragnatech.se>", "References": "<20191126233620.1695316-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 04/30] libcamera: buffer: Add\n\tFileDecriptor to help deal with file descriptors", "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": "Tue, 26 Nov 2019 23:39:29 -0000" }, "content": "Add a helper to make it easier to pass file descriptors around. The\nhelper class duplicates the fd which decouples it from the original fd\nwhich could be closed by its owner while the new FileDescriptor remains\nvalid.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n include/libcamera/buffer.h | 12 ++++++++++++\n src/libcamera/buffer.cpp | 40 ++++++++++++++++++++++++++++++++++++++\n 2 files changed, 52 insertions(+)", "diff": "diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\nindex 7302b9f32ce8c50d..33793b4ccf881eda 100644\n--- a/include/libcamera/buffer.h\n+++ b/include/libcamera/buffer.h\n@@ -46,6 +46,18 @@ private:\n \tstd::vector<Plane> planes_;\n };\n \n+class FileDescriptor final\n+{\n+public:\n+\tFileDescriptor(int fd);\n+\t~FileDescriptor();\n+\n+\tint fd() const { return fd_; }\n+\n+private:\n+\tint fd_;\n+};\n+\n class Plane final\n {\n public:\ndiff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\nindex 4acff216cafba484..0676586ae3be2a61 100644\n--- a/src/libcamera/buffer.cpp\n+++ b/src/libcamera/buffer.cpp\n@@ -115,6 +115,46 @@ void BufferInfo::update(Status status, unsigned int sequence,\n * \\return A array holding all plane information for the buffer\n */\n \n+/**\n+ * \\class FileDescriptor\n+ * \\brief Life time management of a file descriptor\n+ *\n+ * The managed file descriptor (fd) is duplicated from the original one and\n+ * is opened for the life time of the FileDescriptor object disregarding\n+ * if the original one is closed.\n+ */\n+\n+/**\n+ * \\brief Create a life time managed file descriptor\n+ * \\param[in] fd File descriptor\n+ */\n+FileDescriptor::FileDescriptor(int fd)\n+\t: fd_(-1)\n+{\n+\tif (fd < 0)\n+\t\treturn;\n+\n+\t/* Failing to dup() a fd should not happen and is fatal. */\n+\tfd_ = dup(fd);\n+\tif (fd_ == -1) {\n+\t\tint ret = -errno;\n+\t\tLOG(Buffer, Fatal)\n+\t\t\t<< \"Failed to dup() fd: \" << strerror(-ret);\n+\t}\n+}\n+\n+FileDescriptor::~FileDescriptor()\n+{\n+\tif (fd_ != -1)\n+\t\tclose(fd_);\n+}\n+\n+/**\n+ * \\fn FileDescriptor::fd()\n+ * \\brief Retrieve the file descriptor or\n+ * \\return A valid file descriptor or a negative error code\n+ */\n+\n /**\n * \\class Plane\n * \\brief A memory region to store a single plane of a frame\n", "prefixes": [ "libcamera-devel", "04/30" ] }