Show a patch.

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

{
    "id": 11276,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/11276/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11276/",
    "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": "<20210213042143.112361-8-paul.elder@ideasonboard.com>",
    "date": "2021-02-13T04:21:41",
    "name": "[libcamera-devel,v8,7/9] libcamera: Add IPCPipe",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "e8cd61f0b41fcc120f81c429ff2e09809a72b1c3",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11276/mbox/",
    "series": [
        {
            "id": 1687,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1687/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1687",
            "date": "2021-02-13T04:21:34",
            "name": "IPA isolation: Part 1: Core components",
            "version": 8,
            "mbox": "https://patchwork.libcamera.org/series/1687/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11276/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11276/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C0FC8BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 13 Feb 2021 04:22:15 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8CD8F637A3;\n\tSat, 13 Feb 2021 05:22:15 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 78E4F637A3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Feb 2021 05:22:14 +0100 (CET)",
            "from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BB73F564;\n\tSat, 13 Feb 2021 05:22:11 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"CxzLC2lq\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1613190134;\n\tbh=+gQtSb7qnK3bLpo8+qev1dNrGNJQL4iNZ1xHqqVuMEk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=CxzLC2lqe1CJ6u0an0Sc6gkqJxRyQsQaFekNqakalk24jp37jFkjx789gptTTBjki\n\t4t7N0mO6cWvVsMeDhSdPOFw7zT9BURo40ecka45kJ9bDuvsxzxaGxhL8vYOG0pDtNb\n\tz3n0EH99yuGsfsSDR3Mon+MLPGrqBnbWook2CKhc=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 13 Feb 2021 13:21:41 +0900",
        "Message-Id": "<20210213042143.112361-8-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20210213042143.112361-1-paul.elder@ideasonboard.com>",
        "References": "<20210213042143.112361-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v8 7/9] libcamera: Add IPCPipe",
        "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>",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "base64",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Create a virtual IPCPipe class that models an IPC/RPC system. IPA proxies\nand proxy workers will call into the IPCPipe, rather than implementing\nthe IPC themselves.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v8:\n- fix some docs wording\n\nChanges in v7:\n- add an IPCMessage construct that takes just a command code\n- remove 'c' from cheader, cdata, and cfds, and just overload them\n- implement new sendSync/sendAsync API, so that they only deal with\n  IPCMessages\n  - so the caller is responsible for populating the command code and the\n    sequence number\n- cosmetic changes, reword some docs, add some todos\n\nNo change in v6\n\nChanges in v5:\n- fix style\n- rename ipa_ipc.[(cpp)h] to ipc_pipe.[(cpp),h]\n- rename IPAIPC to IPCPipe\n- add IPCMessage to use in the IPCPipe\n\nChange in v4:\n- change snake_case to camelCase\n- remove ipaModulePath and ipaProxyWorkerPath from parameters in the\n  IPAIPC base contructor\n- include signal.h\n\nChanges in v3:\n- expand documentation a bit\n- move [[maybe_unused]] to after the parameters in the IPAIPC\n  constructor, to appease gcc <= 9.1\n\nChanges in v2:\n- add documentation\n---\n include/libcamera/internal/ipc_pipe.h |  69 ++++++++\n src/libcamera/ipc_pipe.cpp            | 218 ++++++++++++++++++++++++++\n src/libcamera/meson.build             |   1 +\n 3 files changed, 288 insertions(+)\n create mode 100644 include/libcamera/internal/ipc_pipe.h\n create mode 100644 src/libcamera/ipc_pipe.cpp",
    "diff": "diff --git a/include/libcamera/internal/ipc_pipe.h b/include/libcamera/internal/ipc_pipe.h\nnew file mode 100644\nindex 00000000..c9a84b78\n--- /dev/null\n+++ b/include/libcamera/internal/ipc_pipe.h\n@@ -0,0 +1,69 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * ipc_pipe.h - Image Processing Algorithm IPC module for IPA proxies\n+ */\n+#ifndef __LIBCAMERA_INTERNAL_IPA_IPC_H__\n+#define __LIBCAMERA_INTERNAL_IPA_IPC_H__\n+\n+#include <vector>\n+\n+#include \"libcamera/internal/ipc_unixsocket.h\"\n+\n+#include <libcamera/signal.h>\n+\n+namespace libcamera {\n+\n+class IPCMessage\n+{\n+public:\n+\tstruct Header {\n+\t\tuint32_t cmd;\n+\t\tuint32_t cookie;\n+\t};\n+\n+\tIPCMessage();\n+\tIPCMessage(uint32_t cmd);\n+\tIPCMessage(const Header &header);\n+\tIPCMessage(const IPCUnixSocket::Payload &payload);\n+\n+\tIPCUnixSocket::Payload payload() const;\n+\n+\tHeader &header() { return header_; }\n+\tstd::vector<uint8_t> &data() { return data_; }\n+\tstd::vector<int32_t> &fds() { return fds_; }\n+\n+\tconst Header &header() const { return header_; }\n+\tconst std::vector<uint8_t> &data() const { return data_; }\n+\tconst std::vector<int32_t> &fds() const { return fds_; }\n+\n+private:\n+\tHeader header_;\n+\n+\tstd::vector<uint8_t> data_;\n+\tstd::vector<int32_t> fds_;\n+};\n+\n+class IPCPipe\n+{\n+public:\n+\tIPCPipe();\n+\tvirtual ~IPCPipe();\n+\n+\tbool isConnected() const { return connected_; }\n+\n+\tvirtual int sendSync(const IPCMessage &in,\n+\t\t\t     IPCMessage *out) = 0;\n+\n+\tvirtual int sendAsync(const IPCMessage &data) = 0;\n+\n+\tSignal<const IPCMessage &> recv;\n+\n+protected:\n+\tbool connected_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_INTERNAL_IPA_IPC_H__ */\ndiff --git a/src/libcamera/ipc_pipe.cpp b/src/libcamera/ipc_pipe.cpp\nnew file mode 100644\nindex 00000000..c402c8d0\n--- /dev/null\n+++ b/src/libcamera/ipc_pipe.cpp\n@@ -0,0 +1,218 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * ipc_pipe.cpp - Image Processing Algorithm IPC module for IPA proxies\n+ */\n+\n+#include \"libcamera/internal/ipc_pipe.h\"\n+\n+#include \"libcamera/internal/log.h\"\n+\n+/**\n+ * \\file ipc_pipe.h\n+ * \\brief IPC mechanism for IPA isolation\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(IPCPipe)\n+\n+/**\n+ * \\struct IPCMessage::Header\n+ * \\brief Container for an IPCMessage header\n+ *\n+ * Holds a cmd code for the IPC message, and a cookie.\n+ */\n+\n+/**\n+ * \\var IPCMessage::Header::cmd\n+ * \\brief Type of IPCMessage\n+ *\n+ * Typically used to carry a command code for an RPC.\n+ */\n+\n+/**\n+ * \\var IPCMessage::Header::cookie\n+ * \\brief Cookie to identify the message and a corresponding reply.\n+ *\n+ * Populated and used by IPCPipe implementations for matching calls with\n+ * replies.\n+ */\n+\n+/**\n+ * \\class IPCMessage\n+ * \\brief IPC message to be passed through IPC message pipe\n+ */\n+\n+/**\n+ * \\brief Construct an empty IPCMessage instance\n+ */\n+IPCMessage::IPCMessage()\n+\t: header_(Header{ 0, 0 })\n+{\n+}\n+\n+/**\n+ * \\brief Construct an IPCMessage instance with a given command code\n+ * \\param[in] cmd The command code\n+ */\n+IPCMessage::IPCMessage(uint32_t cmd)\n+\t: header_(Header{ cmd, 0 })\n+{\n+}\n+\n+/**\n+ * \\brief Construct an IPCMessage instance with a given header\n+ * \\param[in] header The header that the constructed IPCMessage will contain\n+ */\n+IPCMessage::IPCMessage(const Header &header)\n+\t: header_(header)\n+{\n+}\n+\n+/**\n+ * \\brief Construct an IPCMessage instance from an IPC payload\n+ * \\param[in] payload The IPCUnixSocket payload to construct from\n+ *\n+ * This essentially converts an IPCUnixSocket payload into an IPCMessage.\n+ * The header is extracted from the payload into the IPCMessage's header field.\n+ */\n+IPCMessage::IPCMessage(const IPCUnixSocket::Payload &payload)\n+{\n+\tmemcpy(&header_, payload.data.data(), sizeof(header_));\n+\tdata_ = std::vector<uint8_t>(payload.data.begin() + sizeof(header_),\n+\t\t\t\t     payload.data.end());\n+\tfds_ = payload.fds;\n+}\n+\n+/**\n+ * \\brief Create an IPCUnixSocket payload from the IPCMessage\n+ *\n+ * This essentially converts the IPCMessage into an IPCUnixSocket payload.\n+ *\n+ * \\todo Resolve the layering violation (add other converters later?)\n+ */\n+IPCUnixSocket::Payload IPCMessage::payload() const\n+{\n+\tIPCUnixSocket::Payload payload;\n+\n+\tpayload.data.resize(sizeof(Header) + data_.size());\n+\tpayload.fds.reserve(fds_.size());\n+\n+\tmemcpy(payload.data.data(), &header_, sizeof(Header));\n+\n+\t/* \\todo Make this work without copy */\n+\tmemcpy(payload.data.data() + sizeof(Header), data_.data(), data_.size());\n+\tpayload.fds = fds_;\n+\n+\treturn payload;\n+}\n+\n+/**\n+ * \\fn IPCMessage::header()\n+ * \\brief Returns a reference to the header\n+ */\n+\n+/**\n+ * \\fn IPCMessage::data()\n+ * \\brief Returns a reference to the byte vector containing data\n+ */\n+\n+/**\n+ * \\fn IPCMessage::fds()\n+ * \\brief Returns a reference to the vector containing file descriptors\n+ */\n+\n+/**\n+ * \\fn IPCMessage::header() const\n+ * \\brief Returns a const reference to the header\n+ */\n+\n+/**\n+ * \\fn IPCMessage::data() const\n+ * \\brief Returns a const reference to the byte vector containing data\n+ */\n+\n+/**\n+ * \\fn IPCMessage::fds() const\n+ * \\brief Returns a const reference to the vector containing file descriptors\n+ */\n+\n+/**\n+ * \\class IPCPipe\n+ * \\brief IPC message pipe for IPA isolation\n+ *\n+ * Virtual class to model an IPC message pipe for use by IPA proxies for IPA\n+ * isolation. sendSync() and sendAsync() must be implemented, and the recvMessage\n+ * signal must be emitted whenever new data is available.\n+ */\n+\n+/**\n+ * \\brief Construct an IPCPipe instance\n+ */\n+IPCPipe::IPCPipe()\n+\t: connected_(false)\n+{\n+}\n+\n+IPCPipe::~IPCPipe()\n+{\n+}\n+\n+/**\n+ * \\fn IPCPipe::isConnected()\n+ * \\brief Check if the IPCPipe instance is connected\n+ *\n+ * An IPCPipe instance is connected if IPC is successfully set up.\n+ *\n+ * \\return True if the IPCPipe is connected, false otherwise\n+ */\n+\n+/**\n+ * \\fn IPCPipe::sendSync()\n+ * \\brief Send a message over IPC synchronously\n+ * \\param[in] in Data to send\n+ * \\param[in] out IPCMessage instance in which to receive data, if applicable\n+ *\n+ * This function will not return until a response is received. The event loop\n+ * will still continue to execute, however.\n+ *\n+ * \\return Zero on success, negative error code otherwise\n+ *\n+ * \\todo Determine if the event loop should limit the types of messages it\n+ * processes, to avoid reintrancy in the caller, and carefully document what\n+ * the caller needs to implement to make this safe.\n+ */\n+\n+/**\n+ * \\fn IPCPipe::sendAsync()\n+ * \\brief Send a message over IPC asynchronously\n+ * \\param[in] data Data to send\n+ *\n+ * This function will return immediately after sending the message.\n+ *\n+ * \\return Zero on success, negative error code otherwise\n+ */\n+\n+/**\n+ * \\var IPCPipe::recv\n+ * \\brief Signal to be emitted when a message is received over IPC\n+ *\n+ * When a message is received over IPC, this signal shall be emitted. Users must\n+ * connect to this to receive messages.\n+ */\n+\n+/**\n+ * \\var IPCPipe::connected_\n+ * \\brief Flag to indicate if the IPCPipe instance is connected\n+ *\n+ * An IPCPipe instance is connected if IPC is successfully set up.\n+ *\n+ * This flag can be read via IPCPipe::isConnected().\n+ *\n+ * Implementations of the IPCPipe class should set this flag upon successful\n+ * connection.\n+ */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex c3414ba2..a29fdca2 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -31,6 +31,7 @@ libcamera_sources = files([\n     'ipa_manager.cpp',\n     'ipa_module.cpp',\n     'ipa_proxy.cpp',\n+    'ipc_pipe.cpp',\n     'ipc_unixsocket.cpp',\n     'log.cpp',\n     'media_device.cpp',\n",
    "prefixes": [
        "libcamera-devel",
        "v8",
        "7/9"
    ]
}