Show a patch.

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

{
    "id": 11277,
    "url": "https://patchwork.libcamera.org/api/patches/11277/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11277/",
    "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": "<20210213042143.112361-9-paul.elder@ideasonboard.com>",
    "date": "2021-02-13T04:21:42",
    "name": "[libcamera-devel,v8,8/9] libcamera: Add IPCPipe implementation based on unix socket",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "7284a6afba95d154415128d864ef8ecf5ab4f078",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11277/mbox/",
    "series": [
        {
            "id": 1687,
            "url": "https://patchwork.libcamera.org/api/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/11277/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11277/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 4410CBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 13 Feb 2021 04:22:20 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ECD2C637A8;\n\tSat, 13 Feb 2021 05:22:19 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8DEB26379D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Feb 2021 05:22:18 +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 E76DEBC0;\n\tSat, 13 Feb 2021 05:22:14 +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=\"ZaDQdEs4\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1613190136;\n\tbh=DG7jZ1X68ynE6s6eDZpCMrcHulYVQ9op/UtiGFyK8kk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ZaDQdEs4gAIBaRbpwI8nYAHhUwLnVMhPUeh7lHTZfuUBJpai6/h1LmYIjKJ+J8v4u\n\t6qSKucASJhgWhwvqd884SLluk7GJp2IyjAzjRgyv8lkFJ5Dh04McwibYfVB/j/jOXf\n\trdOUtDa1yL9BsTrZSa785Y8Ez7qN34YBwvQjoIQ4=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 13 Feb 2021 13:21:42 +0900",
        "Message-Id": "<20210213042143.112361-9-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 8/9] libcamera: Add IPCPipe\n\timplementation based on unix socket",
        "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": "Add an implementation of IPCPipe using unix socket.\n\n[Original patch]\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n[Error fix from Niklas]\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v8:\n- minor code movement\n- change success error check (for call()) to get result -> get iterator\n\nChanges in v7:\n- implement new sendSync/sendAsync that only deals with IPCMessages\n- remove sequence number (the called of sendSync/sendAsync deals with it\n  now)\n- add underflow check on receive\n- cosmetic changes\n\nChanges in v6:\n- remove explicit nullptr intializations for unique_ptr members\n- move callData_.erase() to the call() error path\n\nChanges in v5:\n- rename IPAIPCUnixSocket to IPCPipeUnixSocket\n- rename ipa_ipc_unisocket.[(cpp),h] ipc_pipe_unixsocket.[(cpp),h]\n\nChanges in v4:\n- change snake_case to camelCase\n- change proc_ and socket_ to unique pointers\n- move inclusion of corresponding header to first in the include list\n- reserve message data and fds size (for sending)\n\nChanges in v3:\n- remove unused writeUInt32() and readUInt32()\n- remove redundant definition of IPAIPCUnixSocket::isValid()\n- remove & 0xff in writeHeader()\n- make readHeader, writeHeader, and eraseHeader static class functions\n  of IPAIPCUnixSocket instead of globals\n\nChanges in v2:\n- specify in doxygen to skip generating documentation for\n  IPAIPCUnixSocket\n---\n Documentation/Doxyfile.in                     |   2 +\n .../libcamera/internal/ipc_pipe_unixsocket.h  |  49 ++++++\n src/libcamera/ipc_pipe_unixsocket.cpp         | 144 ++++++++++++++++++\n src/libcamera/meson.build                     |   1 +\n 4 files changed, 196 insertions(+)\n create mode 100644 include/libcamera/internal/ipc_pipe_unixsocket.h\n create mode 100644 src/libcamera/ipc_pipe_unixsocket.cpp",
    "diff": "diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\nindex 5b64f705..e0de6c6d 100644\n--- a/Documentation/Doxyfile.in\n+++ b/Documentation/Doxyfile.in\n@@ -837,8 +837,10 @@ RECURSIVE              = YES\n EXCLUDE                = @TOP_SRCDIR@/include/libcamera/span.h \\\n \t\t\t @TOP_SRCDIR@/include/libcamera/internal/device_enumerator_sysfs.h \\\n \t\t\t @TOP_SRCDIR@/include/libcamera/internal/device_enumerator_udev.h \\\n+\t\t\t @TOP_SRCDIR@/include/libcamera/internal/ipc_pipe_unixsocket.h \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/device_enumerator_sysfs.cpp \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/device_enumerator_udev.cpp \\\n+\t\t\t @TOP_SRCDIR@/src/libcamera/ipc_pipe_unixsocket.cpp \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/pipeline/ \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/proxy/ \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/tracepoints.cpp \\\ndiff --git a/include/libcamera/internal/ipc_pipe_unixsocket.h b/include/libcamera/internal/ipc_pipe_unixsocket.h\nnew file mode 100644\nindex 00000000..4ffdddcc\n--- /dev/null\n+++ b/include/libcamera/internal/ipc_pipe_unixsocket.h\n@@ -0,0 +1,49 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * ipc_pipe_unixsocket.h - Image Processing Algorithm IPC module using unix socket\n+ */\n+#ifndef __LIBCAMERA_INTERNAL_IPA_IPC_UNIXSOCKET_H__\n+#define __LIBCAMERA_INTERNAL_IPA_IPC_UNIXSOCKET_H__\n+\n+#include <map>\n+#include <memory>\n+#include <vector>\n+\n+#include \"libcamera/internal/ipc_pipe.h\"\n+#include \"libcamera/internal/ipc_unixsocket.h\"\n+\n+namespace libcamera {\n+\n+class Process;\n+\n+class IPCPipeUnixSocket : public IPCPipe\n+{\n+public:\n+\tIPCPipeUnixSocket(const char *ipaModulePath, const char *ipaProxyWorkerPath);\n+\t~IPCPipeUnixSocket();\n+\n+\tint sendSync(const IPCMessage &in,\n+\t\t     IPCMessage *out = nullptr) override;\n+\n+\tint sendAsync(const IPCMessage &data) override;\n+\n+private:\n+\tstruct CallData {\n+\t\tIPCUnixSocket::Payload *response;\n+\t\tbool done;\n+\t};\n+\n+\tvoid readyRead(IPCUnixSocket *socket);\n+\tint call(const IPCUnixSocket::Payload &message,\n+\t\t IPCUnixSocket::Payload *response, uint32_t seq);\n+\n+\tstd::unique_ptr<Process> proc_;\n+\tstd::unique_ptr<IPCUnixSocket> socket_;\n+\tstd::map<uint32_t, CallData> callData_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_INTERNAL_IPA_IPC_UNIXSOCKET_H__ */\ndiff --git a/src/libcamera/ipc_pipe_unixsocket.cpp b/src/libcamera/ipc_pipe_unixsocket.cpp\nnew file mode 100644\nindex 00000000..db0e260f\n--- /dev/null\n+++ b/src/libcamera/ipc_pipe_unixsocket.cpp\n@@ -0,0 +1,144 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * ipc_pipe_unixsocket.cpp - Image Processing Algorithm IPC module using unix socket\n+ */\n+\n+#include \"libcamera/internal/ipc_pipe_unixsocket.h\"\n+\n+#include <vector>\n+\n+#include \"libcamera/internal/event_dispatcher.h\"\n+#include \"libcamera/internal/ipc_pipe.h\"\n+#include \"libcamera/internal/ipc_unixsocket.h\"\n+#include \"libcamera/internal/log.h\"\n+#include \"libcamera/internal/process.h\"\n+#include \"libcamera/internal/thread.h\"\n+#include \"libcamera/internal/timer.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(IPCPipe)\n+\n+IPCPipeUnixSocket::IPCPipeUnixSocket(const char *ipaModulePath,\n+\t\t\t\t     const char *ipaProxyWorkerPath)\n+\t: IPCPipe()\n+{\n+\tstd::vector<int> fds;\n+\tstd::vector<std::string> args;\n+\targs.push_back(ipaModulePath);\n+\n+\tsocket_ = std::make_unique<IPCUnixSocket>();\n+\tint fd = socket_->create();\n+\tif (fd < 0) {\n+\t\tLOG(IPCPipe, Error) << \"Failed to create socket\";\n+\t\treturn;\n+\t}\n+\tsocket_->readyRead.connect(this, &IPCPipeUnixSocket::readyRead);\n+\targs.push_back(std::to_string(fd));\n+\tfds.push_back(fd);\n+\n+\tproc_ = std::make_unique<Process>();\n+\tint ret = proc_->start(ipaProxyWorkerPath, args, fds);\n+\tif (ret) {\n+\t\tLOG(IPCPipe, Error)\n+\t\t\t<< \"Failed to start proxy worker process\";\n+\t\treturn;\n+\t}\n+\n+\tconnected_ = true;\n+}\n+\n+IPCPipeUnixSocket::~IPCPipeUnixSocket()\n+{\n+}\n+\n+int IPCPipeUnixSocket::sendSync(const IPCMessage &in, IPCMessage *out)\n+{\n+\tIPCUnixSocket::Payload response;\n+\n+\tint ret = call(in.payload(), &response, in.header().cookie);\n+\tif (ret) {\n+\t\tLOG(IPCPipe, Error) << \"Failed to call sync\";\n+\t\treturn ret;\n+\t}\n+\n+\tif (out)\n+\t\t*out = IPCMessage(response);\n+\n+\treturn 0;\n+}\n+\n+int IPCPipeUnixSocket::sendAsync(const IPCMessage &data)\n+{\n+\tint ret = socket_->send(data.payload());\n+\tif (ret) {\n+\t\tLOG(IPCPipe, Error) << \"Failed to call async\";\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void IPCPipeUnixSocket::readyRead(IPCUnixSocket *socket)\n+{\n+\tIPCUnixSocket::Payload payload;\n+\tint ret = socket->receive(&payload);\n+\tif (ret) {\n+\t\tLOG(IPCPipe, Error) << \"Receive message failed\" << ret;\n+\t\treturn;\n+\t}\n+\n+\t/* \\todo Use span to avoid the double copy when callData is found. */\n+\tif (payload.data.size() < sizeof(IPCMessage::Header)) {\n+\t\tLOG(IPCPipe, Error) << \"Not enough data received\";\n+\t\treturn;\n+\t}\n+\n+\tIPCMessage ipcMessage(payload);\n+\n+\tauto callData = callData_.find(ipcMessage.header().cookie);\n+\tif (callData != callData_.end()) {\n+\t\t*callData->second.response = std::move(payload);\n+\t\tcallData->second.done = true;\n+\t\treturn;\n+\t}\n+\n+\t/* Received unexpected data, this means it's a call from the IPA. */\n+\trecv.emit(ipcMessage);\n+}\n+\n+int IPCPipeUnixSocket::call(const IPCUnixSocket::Payload &message,\n+\t\t\t    IPCUnixSocket::Payload *response, uint32_t cookie)\n+{\n+\tTimer timeout;\n+\tint ret;\n+\n+\tconst auto result = callData_.insert({ cookie, { response, false } });\n+\tconst auto &iter = result.first;\n+\n+\tret = socket_->send(message);\n+\tif (ret) {\n+\t\tcallData_.erase(iter);\n+\t\treturn ret;\n+\t}\n+\n+\t/* \\todo Make this less dangerous, see IPCPipe::sendSync() */\n+\ttimeout.start(2000);\n+\twhile (!iter->second.done) {\n+\t\tif (!timeout.isRunning()) {\n+\t\t\tLOG(IPCPipe, Error) << \"Call timeout!\";\n+\t\t\tcallData_.erase(iter);\n+\t\t\treturn -ETIMEDOUT;\n+\t\t}\n+\n+\t\tThread::current()->eventDispatcher()->processEvents();\n+\t}\n+\n+\tcallData_.erase(iter);\n+\n+\treturn 0;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex a29fdca2..f5d3931c 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -32,6 +32,7 @@ libcamera_sources = files([\n     'ipa_module.cpp',\n     'ipa_proxy.cpp',\n     'ipc_pipe.cpp',\n+    'ipc_pipe_unixsocket.cpp',\n     'ipc_unixsocket.cpp',\n     'log.cpp',\n     'media_device.cpp',\n",
    "prefixes": [
        "libcamera-devel",
        "v8",
        "8/9"
    ]
}