Show a patch.

GET /api/1.1/patches/2548/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2548,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/2548/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2548/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20200110193808.2266294-2-niklas.soderlund@ragnatech.se>",
    "date": "2020-01-10T19:37:36",
    "name": "[libcamera-devel,v3,01/33] libcamera: Add FileDescriptor to help pass numerical fds around",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "e0b33c757516d53878078a6910a2ca19f33db4e0",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2548/mbox/",
    "series": [
        {
            "id": 615,
            "url": "https://patchwork.libcamera.org/api/1.1/series/615/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=615",
            "date": "2020-01-10T19:37:35",
            "name": "libcamera: Rework buffer API",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/615/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2548/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2548/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 2540F60673\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Jan 2020 20:38:37 +0100 (CET)",
            "from bismarck.berto.se (p54ac5d7b.dip0.t-ipconnect.de\n\t[84.172.93.123]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid c944fae5-33e0-11ea-b6d8-005056917f90;\n\tFri, 10 Jan 2020 20:38:33 +0100 (CET)"
        ],
        "X-Halon-ID": "c944fae5-33e0-11ea-b6d8-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": "Fri, 10 Jan 2020 20:37:36 +0100",
        "Message-Id": "<20200110193808.2266294-2-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.24.1",
        "In-Reply-To": "<20200110193808.2266294-1-niklas.soderlund@ragnatech.se>",
        "References": "<20200110193808.2266294-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 01/33] libcamera: Add FileDescriptor to\n\thelp pass numerical fds around",
        "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": "Fri, 10 Jan 2020 19:38:37 -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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/file_descriptor.h |  46 ++++++++\n include/libcamera/meson.build       |   1 +\n src/libcamera/file_descriptor.cpp   | 170 ++++++++++++++++++++++++++++\n src/libcamera/meson.build           |   1 +\n 4 files changed, 218 insertions(+)\n create mode 100644 include/libcamera/file_descriptor.h\n create mode 100644 src/libcamera/file_descriptor.cpp",
    "diff": "diff --git a/include/libcamera/file_descriptor.h b/include/libcamera/file_descriptor.h\nnew file mode 100644\nindex 0000000000000000..f08c105998cc7559\n--- /dev/null\n+++ b/include/libcamera/file_descriptor.h\n@@ -0,0 +1,46 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * file_descriptor.h - File descriptor wrapper\n+ */\n+#ifndef __LIBCAMERA_FILE_DESCRIPTOR_H__\n+#define __LIBCAMERA_FILE_DESCRIPTOR_H__\n+\n+#include <memory>\n+\n+namespace libcamera {\n+\n+class FileDescriptor final\n+{\n+public:\n+\texplicit FileDescriptor(int fd = -1);\n+\tFileDescriptor(const FileDescriptor &other);\n+\tFileDescriptor(FileDescriptor &&other);\n+\t~FileDescriptor();\n+\n+\tFileDescriptor &operator=(const FileDescriptor &other);\n+\tFileDescriptor &operator=(FileDescriptor &&other);\n+\n+\tint fd() const { return fd_ ? fd_->fd() : -1; }\n+\tFileDescriptor dup() const;\n+\n+private:\n+\tclass Storage\n+\t{\n+\tpublic:\n+\t\tStorage(int fd);\n+\t\t~Storage();\n+\n+\t\tint fd() const { return fd_; }\n+\n+\tprivate:\n+\t\tint fd_;\n+\t};\n+\n+\tstd::shared_ptr<Storage> fd_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_FILE_DESCRIPTOR_H__ */\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 99abf06099407c1f..543e6773cc5158a0 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -6,6 +6,7 @@ libcamera_api = files([\n     'controls.h',\n     'event_dispatcher.h',\n     'event_notifier.h',\n+    'file_descriptor.h',\n     'geometry.h',\n     'logging.h',\n     'object.h',\ndiff --git a/src/libcamera/file_descriptor.cpp b/src/libcamera/file_descriptor.cpp\nnew file mode 100644\nindex 0000000000000000..2e531f40696be16c\n--- /dev/null\n+++ b/src/libcamera/file_descriptor.cpp\n@@ -0,0 +1,170 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * file_descriptor.cpp - File descriptor wrapper\n+ */\n+\n+#include <libcamera/file_descriptor.h>\n+\n+#include <string.h>\n+#include <unistd.h>\n+#include <utility>\n+\n+#include \"log.h\"\n+\n+/**\n+ * \\file file_descriptor.h\n+ * \\brief File descriptor wrapper\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(FileDescriptor)\n+\n+/**\n+ * \\class FileDescriptor\n+ * \\brief RAII-style wrapper for file descriptors\n+ *\n+ * The FileDescriptor class wraps a file descriptor (expressed as a signed\n+ * integer) to provide an RAII-style mechanism for owning the file descriptor.\n+ * When constructed, the FileDescriptor instance duplicates a given file\n+ * descriptor and takes ownership of the duplicate as a resource. The copy\n+ * constructor and assignment operator duplicate the file descriptor, while the\n+ * move versions of those methods move the resource and make the original\n+ * FileDescriptor invalid. When the FileDescriptor is deleted, it closes the\n+ * file descriptor it owns, if any.\n+ */\n+\n+/**\n+ * \\brief Create a FileDescriptor wrapping a copy of a given \\a fd\n+ * \\param[in] fd File descriptor\n+ *\n+ * Construct a FileDescriptor from a numerical file descriptor duplicates the\n+ * \\a fd and takes ownership of the copy. The original \\a fd is left untouched,\n+ * and the caller is responsible for closing it when appropriate. The duplicated\n+ * file descriptor will be closed automatically when the FileDescriptor instance\n+ * is destroyed.\n+ */\n+FileDescriptor::FileDescriptor(int fd)\n+{\n+\tfd_ = std::make_shared<Storage>(fd);\n+}\n+\n+/**\n+ * \\brief Copy constructor, create a FileDescriptor from a copy of \\a other\n+ * \\param[in] other The other FileDescriptor\n+ *\n+ * Construct a FileDescriptor from another FileDescriptor duplicates the\n+ * wrapped numerical file descriptor and takes ownership of the copy. The\n+ * original FileDescriptor is left untouched, and the caller is responsible for\n+ * closing it when appropriate. The duplicated file descriptor will be closed\n+ * automatically when this FileDescriptor instance is destroyed.\n+ */\n+FileDescriptor::FileDescriptor(const FileDescriptor &other)\n+\t: fd_(other.fd_)\n+{\n+}\n+\n+/**\n+ * \\brief Move constructor, create a FileDescriptor by taking over \\a other\n+ * \\param[in] other The other FileDescriptor\n+ *\n+ * Construct a FileDescriptor by taking over a wrapped numerical file\n+ * descriptor and taking ownership of it. The \\a other FileDescriptor is\n+ * invalidated and set to -1. The taken over file descriptor will be closed\n+ * automatically when this FileDescriptor instance is destroyed.\n+ */\n+FileDescriptor::FileDescriptor(FileDescriptor &&other)\n+\t: fd_(std::move(other.fd_))\n+{\n+}\n+\n+/**\n+ * \\brief Destroy the managed file descriptor\n+ *\n+ * If the managed file descriptor, as returned by fd(), is not equal to -1, the\n+ * file descriptor is closed.\n+ */\n+FileDescriptor::~FileDescriptor()\n+{\n+}\n+\n+/**\n+ * \\brief Copy assignment operator, replace the wrapped file descriptor with a\n+ * duplicate from \\a other\n+ * \\param[in] other The other FileDescriptor\n+ *\n+ * Close the wrapped file descriptor (if any) and duplicate the file descriptor\n+ * from \\a other. The \\a other FileDescriptor is left untouched, and the caller\n+ * is responsible for destroying it when appropriate. The duplicated file\n+ * descriptor will be closed automatically when this FileDescriptor instance is\n+ * destroyed.\n+ *\n+ * \\return A reference to this FileDescriptor\n+ */\n+FileDescriptor &FileDescriptor::operator=(const FileDescriptor &other)\n+{\n+\tfd_ = other.fd_;\n+\n+\treturn *this;\n+}\n+\n+/**\n+ * \\brief Move assignment operator, replace the wrapped file descriptor by\n+ * taking over \\a other\n+ * \\param[in] other The other FileDescriptor\n+ *\n+ * Close the wrapped file descriptor (if any) and take over the file descriptor\n+ * from \\a other. The \\a other FileDescriptor is invalidated and set to -1. The\n+ * taken over file descriptor will be closed automatically when this\n+ * FileDescriptor instance is destroyed.\n+ *\n+ * \\return A reference to this FileDescriptor\n+ */\n+FileDescriptor &FileDescriptor::operator=(FileDescriptor &&other)\n+{\n+\tfd_ = std::move(other.fd_);\n+\n+\treturn *this;\n+}\n+\n+/**\n+ * \\fn FileDescriptor::fd()\n+ * \\brief Retrieve the numerical file descriptor\n+ * \\return The numerical file descriptor, which may be -1 if the FileDescriptor\n+ * instance doesn't own a file descriptor\n+ */\n+\n+/**\n+ * \\brief Duplicate a FileDescriptor\n+ * \\return A new FileDescriptor instance wrapping a duplicate of the original\n+ * file descriptor\n+ */\n+FileDescriptor FileDescriptor::dup() const\n+{\n+\treturn FileDescriptor(fd_ ? fd_->fd() : -1);\n+}\n+\n+FileDescriptor::Storage::Storage(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(FileDescriptor, Fatal)\n+\t\t\t<< \"Failed to dup() fd: \" << strerror(-ret);\n+\t}\n+}\n+\n+FileDescriptor::Storage::~Storage()\n+{\n+\tif (fd_ != -1)\n+\t\tclose(fd_);\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex c4f965bd7413b37e..722c5bc15afe52ef 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -14,6 +14,7 @@ libcamera_sources = files([\n     'event_dispatcher.cpp',\n     'event_dispatcher_poll.cpp',\n     'event_notifier.cpp',\n+    'file_descriptor.cpp',\n     'formats.cpp',\n     'geometry.cpp',\n     'ipa_context_wrapper.cpp',\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "01/33"
    ]
}