Patch Detail
Show a patch.
GET /api/patches/24108/?format=api
{ "id": 24108, "url": "https://patchwork.libcamera.org/api/patches/24108/?format=api", "web_url": "https://patchwork.libcamera.org/patch/24108/", "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": "<20250815085114.2188604-1-barnabas.pocze@ideasonboard.com>", "date": "2025-08-15T08:51:14", "name": "[RFC,v2] utils: codegen: ipc: Split proxy types", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "8e3c8ad687b07f6aebe93fa66a309008646ed417", "submitter": { "id": 216, "url": "https://patchwork.libcamera.org/api/people/216/?format=api", "name": "Barnabás Pőcze", "email": "barnabas.pocze@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/24108/mbox/", "series": [ { "id": 5380, "url": "https://patchwork.libcamera.org/api/series/5380/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5380", "date": "2025-08-15T08:51:14", "name": "[RFC,v2] utils: codegen: ipc: Split proxy types", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5380/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/24108/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/24108/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 9164DBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Aug 2025 08:51:20 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8802B69257;\n\tFri, 15 Aug 2025 10:51:19 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7DB9969244\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Aug 2025 10:51:17 +0200 (CEST)", "from pb-laptop.local (185.221.141.188.nat.pool.zt.hu\n\t[185.221.141.188])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6469763B;\n\tFri, 15 Aug 2025 10:50:22 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"A/0558Fj\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755247822;\n\tbh=PiBJW8Z8JkkVJLTGvi0ov/pj9JvYcU9JJzTpmMybaGk=;\n\th=From:To:Subject:Date:From;\n\tb=A/0558FjA2BMlIKydR93vkoLfXWCfr8r3m9n6i9f0SSs5l3GdXwhBoTRyhWjTi75M\n\twDgRdlCryDzSHC0N1521QBmfZt2yF1kv/JbweewkiDuPPVyigcA+crXuOpRE4Aw2UT\n\tDQmTX2S3ACjWKOU2bt6nr9l1QNWAJmn0c8M6RnkA=", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org,\n\tPaul Elder <paul.elder@ideasonboard.com>", "Subject": "[RFC PATCH v2] utils: codegen: ipc: Split proxy types", "Date": "Fri, 15 Aug 2025 10:51:14 +0200", "Message-ID": "<20250815085114.2188604-1-barnabas.pocze@ideasonboard.com>", "X-Mailer": "git-send-email 2.50.1", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Even though there is an abstract class to represent the interface of an IPA,\nthe threaded and IPC versions are still multiplexed using the same type,\nwhich uses a boolean to actually dispatch to the right function.\n\nInstead of doing that, split the classes into \"threaded\" and \"isolated\"\nvariants, and make `IPAManager` choose accordingly.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\nchanges in v2:\n * fix typo\n * rename local -> threaded, remote -> isolated\n * have different log messages in the two variants\n\nv1: https://patchwork.libcamera.org/patch/24056/\n---\n include/libcamera/internal/ipa_manager.h | 8 +-\n .../module_ipa_proxy.cpp.tmpl | 151 +++++++++---------\n .../module_ipa_proxy.h.tmpl | 56 +++++--\n 3 files changed, 119 insertions(+), 96 deletions(-)\n\n--\n2.50.1", "diff": "diff --git a/include/libcamera/internal/ipa_manager.h b/include/libcamera/internal/ipa_manager.h\nindex a0d448cf9..ae832b645 100644\n--- a/include/libcamera/internal/ipa_manager.h\n+++ b/include/libcamera/internal/ipa_manager.h\n@@ -42,7 +42,13 @@ public:\n \t\tif (!m)\n \t\t\treturn nullptr;\n\n-\t\tstd::unique_ptr<T> proxy = std::make_unique<T>(m, !self->isSignatureValid(m));\n+\t\tauto proxy = [&]() -> std::unique_ptr<T> {\n+\t\t\tif (self->isSignatureValid(m))\n+\t\t\t\treturn std::make_unique<typename T::Threaded>(m);\n+\t\t\telse\n+\t\t\t\treturn std::make_unique<typename T::Isolated>(m);\n+\t\t}();\n+\n \t\tif (!proxy->isValid()) {\n \t\t\tLOG(IPAManager, Error) << \"Failed to load proxy\";\n \t\t\treturn nullptr;\ndiff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\nindex beb646e2d..7ccde1d56 100644\n--- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n+++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n@@ -45,36 +45,13 @@ namespace {{ns}} {\n {% endfor %}\n {%- endif %}\n\n-{{proxy_name}}::{{proxy_name}}(IPAModule *ipam, bool isolate)\n-\t: IPAProxy(ipam), isolate_(isolate),\n-\t controlSerializer_(ControlSerializer::Role::Proxy), seq_(0)\n+{{proxy_name}}Threaded::{{proxy_name}}Threaded(IPAModule *ipam)\n+\t: {{proxy_name}}(ipam)\n {\n \tLOG(IPAProxy, Debug)\n-\t\t<< \"initializing {{module_name}} proxy: loading IPA from \"\n+\t\t<< \"initializing {{module_name}} proxy in thread: loading IPA from \"\n \t\t<< ipam->path();\n\n-\tif (isolate_) {\n-\t\tconst std::string proxyWorkerPath = resolvePath(\"{{module_name}}_ipa_proxy\");\n-\t\tif (proxyWorkerPath.empty()) {\n-\t\t\tLOG(IPAProxy, Error)\n-\t\t\t\t<< \"Failed to get proxy worker path\";\n-\t\t\treturn;\n-\t\t}\n-\n-\t\tauto ipc = std::make_unique<IPCPipeUnixSocket>(ipam->path().c_str(),\n-\t\t\t\t\t\t\t proxyWorkerPath.c_str());\n-\t\tif (!ipc->isConnected()) {\n-\t\t\tLOG(IPAProxy, Error) << \"Failed to create IPCPipe\";\n-\t\t\treturn;\n-\t\t}\n-\n-\t\tipc->recv.connect(this, &{{proxy_name}}::recvMessage);\n-\n-\t\tipc_ = std::move(ipc);\n-\t\tvalid_ = true;\n-\t\treturn;\n-\t}\n-\n \tif (!ipam->load())\n \t\treturn;\n\n@@ -89,59 +66,16 @@ namespace {{ns}} {\n \tproxy_.setIPA(ipa_.get());\n\n {% for method in interface_event.methods %}\n-\tipa_->{{method.mojom_name}}.connect(this, &{{proxy_name}}::{{method.mojom_name}}Thread);\n+\tipa_->{{method.mojom_name}}.connect(this, &{{proxy_name}}Threaded::{{method.mojom_name}}Handler);\n {%- endfor %}\n\n \tvalid_ = true;\n }\n\n-{{proxy_name}}::~{{proxy_name}}()\n-{\n-\tif (ipc_) {\n-\t\tIPCMessage::Header header =\n-\t\t\t{ static_cast<uint32_t>({{cmd_enum_name}}::Exit), seq_++ };\n-\t\tIPCMessage msg(header);\n-\t\tipc_->sendAsync(msg);\n-\t}\n-}\n-\n-{% if interface_event.methods|length > 0 %}\n-void {{proxy_name}}::recvMessage(const IPCMessage &data)\n-{\n-\tsize_t dataSize = data.data().size();\n-\t{{cmd_event_enum_name}} _cmd = static_cast<{{cmd_event_enum_name}}>(data.header().cmd);\n-\n-\tswitch (_cmd) {\n-{%- for method in interface_event.methods %}\n-\tcase {{cmd_event_enum_name}}::{{method.mojom_name|cap}}: {\n-\t\t{{method.mojom_name}}IPC(data.data().cbegin(), dataSize, data.fds());\n-\t\tbreak;\n-\t}\n-{%- endfor %}\n-\tdefault:\n-\t\tLOG(IPAProxy, Error) << \"Unknown command \" << static_cast<uint32_t>(_cmd);\n-\t}\n-}\n-{%- endif %}\n+{{proxy_name}}Threaded::~{{proxy_name}}Threaded() = default;\n\n {% for method in interface_main.methods %}\n-{{proxy_funcs.func_sig(proxy_name, method)}}\n-{\n-\tif (isolate_)\n-\t\treturn {{method.mojom_name}}IPC(\n-{%- for param in method|method_param_names -%}\n-\t\t{{param}}{{- \", \" if not loop.last}}\n-{%- endfor -%}\n-);\n-\telse\n-\t\treturn {{method.mojom_name}}Thread(\n-{%- for param in method|method_param_names -%}\n-\t\t{{param}}{{- \", \" if not loop.last}}\n-{%- endfor -%}\n-);\n-}\n-\n-{{proxy_funcs.func_sig(proxy_name, method, \"Thread\")}}\n+{{proxy_funcs.func_sig(proxy_name + \"Threaded\", method)}}\n {\n {%- if method.mojom_name == \"stop\" %}\n \t{{proxy_funcs.stop_thread_body()}}\n@@ -181,8 +115,58 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data)\n );\n {%- endif %}\n }\n+{% endfor %}\n+\n+{% for method in interface_event.methods %}\n+{{proxy_funcs.func_sig(proxy_name + \"Threaded\", method, \"Handler\")}}\n+{\n+\tASSERT(state_ != ProxyStopped);\n+\t{{method.mojom_name}}.emit({{method.parameters|params_comma_sep}});\n+}\n+{% endfor %}\n+\n+/* ========================================================================== */\n+\n+{{proxy_name}}Isolated::{{proxy_name}}Isolated(IPAModule *ipam)\n+\t: {{proxy_name}}(ipam),\n+\t controlSerializer_(ControlSerializer::Role::Proxy), seq_(0)\n+{\n+\tLOG(IPAProxy, Debug)\n+\t\t<< \"initializing {{module_name}} proxy in isolation: loading IPA from \"\n+\t\t<< ipam->path();\n+\n+\tconst std::string proxyWorkerPath = resolvePath(\"{{module_name}}_ipa_proxy\");\n+\tif (proxyWorkerPath.empty()) {\n+\t\tLOG(IPAProxy, Error)\n+\t\t\t<< \"Failed to get proxy worker path\";\n+\t\treturn;\n+\t}\n+\n+\tauto ipc = std::make_unique<IPCPipeUnixSocket>(ipam->path().c_str(),\n+\t\t\t\t\t\t proxyWorkerPath.c_str());\n+\tif (!ipc->isConnected()) {\n+\t\tLOG(IPAProxy, Error) << \"Failed to create IPCPipe\";\n+\t\treturn;\n+\t}\n+\n+\tipc->recv.connect(this, &{{proxy_name}}Isolated::recvMessage);\n+\n+\tipc_ = std::move(ipc);\n+\tvalid_ = true;\n+}\n\n-{{proxy_funcs.func_sig(proxy_name, method, \"IPC\")}}\n+{{proxy_name}}Isolated::~{{proxy_name}}Isolated()\n+{\n+\tif (ipc_) {\n+\t\tIPCMessage::Header header =\n+\t\t\t{ static_cast<uint32_t>({{cmd_enum_name}}::Exit), seq_++ };\n+\t\tIPCMessage msg(header);\n+\t\tipc_->sendAsync(msg);\n+\t}\n+}\n+\n+{% for method in interface_main.methods %}\n+{{proxy_funcs.func_sig(proxy_name + \"Isolated\", method)}}\n {\n {%- if method.mojom_name == \"configure\" %}\n \tcontrolSerializer_.reset();\n@@ -226,14 +210,25 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data)\n\n {% endfor %}\n\n-{% for method in interface_event.methods %}\n-{{proxy_funcs.func_sig(proxy_name, method, \"Thread\")}}\n+void {{proxy_name}}Isolated::recvMessage(const IPCMessage &data)\n {\n-\tASSERT(state_ != ProxyStopped);\n-\t{{method.mojom_name}}.emit({{method.parameters|params_comma_sep}});\n+\tsize_t dataSize = data.data().size();\n+\t{{cmd_event_enum_name}} _cmd = static_cast<{{cmd_event_enum_name}}>(data.header().cmd);\n+\n+\tswitch (_cmd) {\n+{%- for method in interface_event.methods %}\n+\tcase {{cmd_event_enum_name}}::{{method.mojom_name|cap}}: {\n+\t\t{{method.mojom_name}}Handler(data.data().cbegin(), dataSize, data.fds());\n+\t\tbreak;\n+\t}\n+{%- endfor %}\n+\tdefault:\n+\t\tLOG(IPAProxy, Error) << \"Unknown command \" << static_cast<uint32_t>(_cmd);\n+\t}\n }\n\n-void {{proxy_name}}::{{method.mojom_name}}IPC(\n+{% for method in interface_event.methods %}\n+void {{proxy_name}}Isolated::{{method.mojom_name}}Handler(\n \t[[maybe_unused]] std::vector<uint8_t>::const_iterator data,\n \t[[maybe_unused]] size_t dataSize,\n \t[[maybe_unused]] const std::vector<SharedFD> &fds)\ndiff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl\nindex a0312a7c1..caf8392da 100644\n--- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl\n+++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl\n@@ -34,29 +34,32 @@ namespace {{ns}} {\n {% endfor %}\n {%- endif %}\n\n+class {{proxy_name}}Threaded;\n+class {{proxy_name}}Isolated;\n+\n class {{proxy_name}} : public IPAProxy, public {{interface_name}}, public Object\n {\n public:\n-\t{{proxy_name}}(IPAModule *ipam, bool isolate);\n-\t~{{proxy_name}}();\n+\tusing Threaded = {{proxy_name}}Threaded;\n+\tusing Isolated = {{proxy_name}}Isolated;\n\n-{% for method in interface_main.methods %}\n-{{proxy_funcs.func_sig(proxy_name, method, \"\", false, true)|indent(8, true)}};\n-{% endfor %}\n+protected:\n+\tusing IPAProxy::IPAProxy;\n+};\n\n-private:\n-\tvoid recvMessage(const IPCMessage &data);\n+class {{proxy_name}}Threaded : public {{proxy_name}}\n+{\n+public:\n+\t{{proxy_name}}Threaded(IPAModule *ipam);\n+\t~{{proxy_name}}Threaded();\n\n {% for method in interface_main.methods %}\n-{{proxy_funcs.func_sig(proxy_name, method, \"Thread\", false)|indent(8, true)}};\n-{{proxy_funcs.func_sig(proxy_name, method, \"IPC\", false)|indent(8, true)}};\n+{{proxy_funcs.func_sig(proxy_name + \"Threaded\", method, \"\", false, true)|indent(8, true)}};\n {% endfor %}\n+\n+private:\n {% for method in interface_event.methods %}\n-{{proxy_funcs.func_sig(proxy_name, method, \"Thread\", false)|indent(8, true)}};\n-\tvoid {{method.mojom_name}}IPC(\n-\t\tstd::vector<uint8_t>::const_iterator data,\n-\t\tsize_t dataSize,\n-\t\tconst std::vector<SharedFD> &fds);\n+{{proxy_funcs.func_sig(proxy_name + \"Threaded\", method, \"Handler\", false)|indent(8, true)}};\n {% endfor %}\n\n \t/* Helper class to invoke async functions in another thread. */\n@@ -79,12 +82,12 @@ private:\n \t\t}\n {% for method in interface_main.methods %}\n {%- if method|is_async %}\n-\t\t{{proxy_funcs.func_sig(proxy_name, method, \"\", false)|indent(16)}}\n+\t\t{{proxy_funcs.func_sig(proxy_name + \"Threaded\", method, \"\", false)|indent(16)}}\n \t\t{\n \t\t\tipa_->{{method.mojom_name}}({{method.parameters|params_comma_sep}});\n \t\t}\n {%- elif method.mojom_name == \"start\" %}\n-\t\t{{proxy_funcs.func_sig(proxy_name, method, \"\", false)|indent(16)}}\n+\t\t{{proxy_funcs.func_sig(proxy_name + \"Threaded\", method, \"\", false)|indent(16)}}\n \t\t{\n {%- if method|method_return_value != \"void\" %}\n \t\t\treturn ipa_->{{method.mojom_name}}({{method.parameters|params_comma_sep}});\n@@ -104,8 +107,27 @@ private:\n \tThread thread_;\n \tThreadProxy proxy_;\n \tstd::unique_ptr<{{interface_name}}> ipa_;\n+};\n\n-\tconst bool isolate_;\n+class {{proxy_name}}Isolated : public {{proxy_name}}\n+{\n+public:\n+\t{{proxy_name}}Isolated(IPAModule *ipam);\n+\t~{{proxy_name}}Isolated();\n+\n+{% for method in interface_main.methods %}\n+{{proxy_funcs.func_sig(proxy_name + \"Isolated\", method, \"\", false, true)|indent(8, true)}};\n+{% endfor %}\n+\n+private:\n+\tvoid recvMessage(const IPCMessage &data);\n+\n+{% for method in interface_event.methods %}\n+\tvoid {{method.mojom_name}}Handler(\n+\t\tstd::vector<uint8_t>::const_iterator data,\n+\t\tsize_t dataSize,\n+\t\tconst std::vector<SharedFD> &fds);\n+{% endfor %}\n\n \tstd::unique_ptr<IPCPipeUnixSocket> ipc_;\n\n", "prefixes": [ "RFC", "v2" ] }