{"id":10721,"url":"https://patchwork.libcamera.org/api/1.1/patches/10721/?format=json","web_url":"https://patchwork.libcamera.org/patch/10721/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20201224081534.41601-8-paul.elder@ideasonboard.com>","date":"2020-12-24T08:15:32","name":"[libcamera-devel,v6,7/9] libcamera: Add IPCPipe","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"73a9cad0ea4159b540bc362456da3dab223998c4","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/users/17/?format=json","username":"epaul","first_name":"Paul","last_name":"Elder","email":"paul.elder@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/10721/mbox/","series":[{"id":1546,"url":"https://patchwork.libcamera.org/api/1.1/series/1546/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1546","date":"2020-12-24T08:15:25","name":"IPA isolation: Part 1: Core components","version":6,"mbox":"https://patchwork.libcamera.org/series/1546/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10721/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10721/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 96337C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Dec 2020 08:16:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 640C9615B4;\n\tThu, 24 Dec 2020 09:16:05 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0203960525\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Dec 2020 09:16:04 +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 CC8AEA1D;\n\tThu, 24 Dec 2020 09:16:01 +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=\"RzwtDZFM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1608797763;\n\tbh=IrBVC9KT07HMJfwe2q//Wk3hCe9zaH1YBd2OoAkM0y0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=RzwtDZFMSsKXXvNebhSEIUzrzZmG4oZupAGZHUmD/CKN1BRWL3yLcVKRKwdMocFzo\n\tW55y/bVKtZUv3bAQcCIGq3KnhnvV+P1ZcQi+neUkFo297s24Itp48Je3gS3QgHybDU\n\tZXKLy9VHHOA7d71NWxScXtp58GBGEbYJs997QGCc=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 24 Dec 2020 17:15:32 +0900","Message-Id":"<20201224081534.41601-8-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20201224081534.41601-1-paul.elder@ideasonboard.com>","References":"<20201224081534.41601-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v6 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>\n\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 .../libcamera/internal/ipa_data_serializer.h  |   2 +-\n include/libcamera/internal/ipc_pipe.h         |  70 ++++++\n src/libcamera/ipc_pipe.cpp                    | 211 ++++++++++++++++++\n src/libcamera/meson.build                     |   1 +\n 4 files changed, 283 insertions(+), 1 deletion(-)\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/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h\nindex 5468a0b7..bde5eaf7 100644\n--- a/include/libcamera/internal/ipa_data_serializer.h\n+++ b/include/libcamera/internal/ipa_data_serializer.h\n@@ -286,7 +286,7 @@ public:\n \t\t\t\t\t\t\t\t\t  fdIter,\n \t\t\t\t\t\t\t\t\t  fdIter + sizeofFds,\n \t\t\t\t\t\t\t\t\t  cs);\n-\t\t\tret.insert({key, value});\n+\t\t\tret.insert({ key, value });\n \n \t\t\tdataIter += sizeofData;\n \t\t\tfdIter += sizeofFds;\ndiff --git a/include/libcamera/internal/ipc_pipe.h b/include/libcamera/internal/ipc_pipe.h\nnew file mode 100644\nindex 00000000..0232c3b5\n--- /dev/null\n+++ b/include/libcamera/internal/ipc_pipe.h\n@@ -0,0 +1,70 @@\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(const Header &header);\n+\tIPCMessage(const IPCUnixSocket::Payload &payload);\n+\n+\tconst IPCUnixSocket::Payload payload(const Header *header = nullptr) 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 &cheader() const { return header_; }\n+\tconst std::vector<uint8_t> &cdata() const { return data_; }\n+\tconst std::vector<int32_t> &cfds() 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(uint32_t cmd,\n+\t\t\t     const IPCMessage &in,\n+\t\t\t     IPCMessage *out) = 0;\n+\n+\tvirtual int sendAsync(uint32_t cmd,\n+\t\t\t      const IPCMessage &data) = 0;\n+\n+\tSignal<uint32_t, 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..eb439724\n--- /dev/null\n+++ b/src/libcamera/ipc_pipe.cpp\n@@ -0,0 +1,211 @@\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 idetify 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 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 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.begin(), sizeof(header_));\n+\tdata_ = std::vector<uint8_t>(payload.data.begin() + sizeof(header_),\n+\t\t\t\t     payload.data.end());\n+\tfds_ = std::vector<int32_t>(payload.fds.begin(), payload.fds.end());\n+}\n+\n+/**\n+ * \\brief Create an IPCUnixSocket payload from the IPCMessage\n+ * \\param[in] header Header to use when constructing the payload, if applicable\n+ *\n+ * This essentially converts the IPCMessage into an IPCUnixSocket payload. If\n+ * \\a header is not provided (ie. nullptr), then the header field that is\n+ * internal to the IPCMessage will be used.\n+ */\n+const IPCUnixSocket::Payload IPCMessage::payload(const Header *header) const\n+{\n+\tIPCUnixSocket::Payload message;\n+\n+\tmessage.data.resize(sizeof(Header) + data_.size());\n+\tmessage.fds.reserve(fds_.size());\n+\n+\tmemcpy(&*message.data.begin(), header ? header : &header_, sizeof(Header));\n+\n+\t/* \\todo Make this work without copy */\n+\tmemcpy(&*(message.data.begin() + sizeof(Header)), data_.data(), data_.size());\n+\tmessage.fds = const_cast<std::vector<int32_t> &>(fds_);\n+\n+\treturn message;\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::cheader()\n+ * \\brief Returns a const reference to the header\n+ */\n+\n+/**\n+ * \\fn IPCMessage::cdata()\n+ * \\brief Returns a const reference to the byte vector containing data\n+ */\n+\n+/**\n+ * \\fn IPCMessage::cfds()\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] cmd Command ID\n+ * \\param[in] in Data to send, as an IPCMessage\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+\n+/**\n+ * \\fn IPCPipe::sendAsync()\n+ * \\brief Send a message over IPC asynchronously\n+ * \\param[in] cmd Command ID\n+ * \\param[in] data Data to send, as an IPCMessage\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 data is received over IPC\n+ *\n+ * When data is received over IPC, this signal shall be emitted. Users must\n+ * connect to this to receive new data.\n+ *\n+ * The parameters of the signal are a vector of bytes and a vector of file\n+ * descriptors.\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+ * construction.\n+ */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 1291f1b3..b7cfe0c2 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -30,6 +30,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","v6","7/9"]}