From patchwork Wed Apr 21 10:26:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 12031 X-Patchwork-Delegate: paul.elder@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3B420BDB16 for ; Wed, 21 Apr 2021 10:27:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9EC6868843; Wed, 21 Apr 2021 12:27:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="iuxtg+Hh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9F19668840 for ; Wed, 21 Apr 2021 12:27:03 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F8233EE; Wed, 21 Apr 2021 12:27:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1619000823; bh=X8p+Vpjl68VaGlmv6LjeArMQXVGhuKuoGer7p0vm1YQ=; h=From:To:Cc:Subject:Date:From; b=iuxtg+HhCD6B5uUIeCC2WcbRd+DD3Dm5NkQrrO5A1x4PTaywHvWuybBvW7A59o8QL v5ijHlHqwWmI6jwJ7Hf60g0hXmiwUZf7alZreBw/Uvk2ifLMAdMzD0yuExgKAdASYq td5xgDizmo8k1NMkIk6pkglJTvltK2tP99P1DbMg= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 21 Apr 2021 19:26:47 +0900 Message-Id: <20210421102647.344784-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] utils: ipc: Support types defined in core.mojom with skipHeader only X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Previously, types that were defined in core.mojom with skipHeader only and no skipSerdes would cause serializer generation to fail due to the generated IPA namespace being used for mojom-defined types instead of the libcamera namespace. This doesn't work because skipHeader means that the type is defined in the libcamera (or some other) namespace elsewhere. Fix this by using "using namespace" in the generated serializer header, so that mojom-defined IPA types can be used without the full namespace qualifier. Signed-off-by: Paul Elder --- .../module_ipa_serializer.h.tmpl | 6 +++ .../libcamera_templates/serializer.tmpl | 38 +++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl index 64ae99dc..d0bac62d 100644 --- a/utils/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl +++ b/utils/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl @@ -27,6 +27,12 @@ namespace libcamera { +{%- if has_namespace %} +{% for ns in namespace -%} +using namespace {{ns}}; +{% endfor %} +{%- endif %} + LOG_DECLARE_CATEGORY(IPADataSerializer) {% for struct in structs_nonempty %} template<> diff --git a/utils/ipc/generators/libcamera_templates/serializer.tmpl b/utils/ipc/generators/libcamera_templates/serializer.tmpl index af35b9e3..afabd8e3 100644 --- a/utils/ipc/generators/libcamera_templates/serializer.tmpl +++ b/utils/ipc/generators/libcamera_templates/serializer.tmpl @@ -63,12 +63,10 @@ {%- else %} std::tie({{field.mojom_name}}, std::ignore) = {%- endif %} - {%- if field|is_array or field|is_map %} - IPADataSerializer<{{field|name}}>::serialize(data.{{field.mojom_name}}, cs); - {%- elif field|is_str %} + {%- if field|is_str %} IPADataSerializer<{{field|name}}>::serialize(data.{{field.mojom_name}}); {%- else %} - IPADataSerializer<{{field|name_full(namespace)}}>::serialize(data.{{field.mojom_name}}, cs); + IPADataSerializer<{{field|name}}>::serialize(data.{{field.mojom_name}}, cs); {%- endif %} appendPOD(retData, {{field.mojom_name}}.size()); {%- if field|has_fd %} @@ -97,7 +95,7 @@ {%- if field|is_pod %} ret.{{field.mojom_name}} = IPADataSerializer<{{field|name}}>::deserialize(m, m + {{field_size}}); {%- else %} - ret.{{field.mojom_name}} = static_cast<{{field|name_full(namespace)}}>(IPADataSerializer::deserialize(m, m + {{field_size}})); + ret.{{field.mojom_name}} = static_cast<{{field|name}}>(IPADataSerializer::deserialize(m, m + {{field_size}})); {%- endif %} {%- if not loop.last %} m += {{field_size}}; @@ -150,11 +148,11 @@ {%- elif field|has_fd and (field|is_array or field|is_map) %} IPADataSerializer<{{field|name}}>::deserialize(m, m + {{field.mojom_name}}Size, n, n + {{field.mojom_name}}FdsSize, cs); {%- elif field|has_fd and (not (field|is_array or field|is_map)) %} - IPADataSerializer<{{field|name_full(namespace)}}>::deserialize(m, m + {{field.mojom_name}}Size, n, n + {{field.mojom_name}}FdsSize, cs); + IPADataSerializer<{{field|name}}>::deserialize(m, m + {{field.mojom_name}}Size, n, n + {{field.mojom_name}}FdsSize, cs); {%- elif (not field|has_fd) and (field|is_array or field|is_map) %} IPADataSerializer<{{field|name}}>::deserialize(m, m + {{field.mojom_name}}Size, cs); {%- else %} - IPADataSerializer<{{field|name_full(namespace)}}>::deserialize(m, m + {{field.mojom_name}}Size, cs); + IPADataSerializer<{{field|name}}>::deserialize(m, m + {{field.mojom_name}}Size, cs); {%- endif %} {%- if not loop.last %} m += {{field_size}}; @@ -178,7 +176,7 @@ #} {%- macro serializer(struct, namespace) %} static std::tuple, std::vector> - serialize(const {{struct|name_full(namespace)}} &data, + serialize(const {{struct|name}} &data, {%- if struct|needs_control_serializer %} ControlSerializer *cs) {%- else %} @@ -208,7 +206,7 @@ # \a struct, in the case that \a struct has file descriptors. #} {%- macro deserializer_fd(struct, namespace) %} - static {{struct|name_full(namespace)}} + static {{struct|name}} deserialize(std::vector &data, std::vector &fds, {%- if struct|needs_control_serializer %} @@ -217,11 +215,11 @@ ControlSerializer *cs = nullptr) {%- endif %} { - return IPADataSerializer<{{struct|name_full(namespace)}}>::deserialize(data.cbegin(), data.cend(), fds.cbegin(), fds.cend(), cs); + return IPADataSerializer<{{struct|name}}>::deserialize(data.cbegin(), data.cend(), fds.cbegin(), fds.cend(), cs); } {# \todo Don't inline this function #} - static {{struct|name_full(namespace)}} + static {{struct|name}} deserialize(std::vector::const_iterator dataBegin, std::vector::const_iterator dataEnd, std::vector::const_iterator fdsBegin, @@ -232,7 +230,7 @@ [[maybe_unused]] ControlSerializer *cs = nullptr) {%- endif %} { - {{struct|name_full(namespace)}} ret; + {{struct|name}} ret; std::vector::const_iterator m = dataBegin; std::vector::const_iterator n = fdsBegin; @@ -253,22 +251,22 @@ # deserializers with file descriptors. #} {%- macro deserializer_fd_simple(struct, namespace) %} - static {{struct|name_full(namespace)}} + static {{struct|name}} deserialize(std::vector &data, [[maybe_unused]] std::vector &fds, ControlSerializer *cs = nullptr) { - return IPADataSerializer<{{struct|name_full(namespace)}}>::deserialize(data.cbegin(), data.cend(), cs); + return IPADataSerializer<{{struct|name}}>::deserialize(data.cbegin(), data.cend(), cs); } - static {{struct|name_full(namespace)}} + static {{struct|name}} deserialize(std::vector::const_iterator dataBegin, std::vector::const_iterator dataEnd, [[maybe_unused]] std::vector::const_iterator fdsBegin, [[maybe_unused]] std::vector::const_iterator fdsEnd, ControlSerializer *cs = nullptr) { - return IPADataSerializer<{{struct|name_full(namespace)}}>::deserialize(dataBegin, dataEnd, cs); + return IPADataSerializer<{{struct|name}}>::deserialize(dataBegin, dataEnd, cs); } {%- endmacro %} @@ -280,7 +278,7 @@ # \a struct, in the case that \a struct does not have file descriptors. #} {%- macro deserializer_no_fd(struct, namespace) %} - static {{struct|name_full(namespace)}} + static {{struct|name}} deserialize(std::vector &data, {%- if struct|needs_control_serializer %} ControlSerializer *cs) @@ -288,11 +286,11 @@ ControlSerializer *cs = nullptr) {%- endif %} { - return IPADataSerializer<{{struct|name_full(namespace)}}>::deserialize(data.cbegin(), data.cend(), cs); + return IPADataSerializer<{{struct|name}}>::deserialize(data.cbegin(), data.cend(), cs); } {# \todo Don't inline this function #} - static {{struct|name_full(namespace)}} + static {{struct|name}} deserialize(std::vector::const_iterator dataBegin, std::vector::const_iterator dataEnd, {%- if struct|needs_control_serializer %} @@ -301,7 +299,7 @@ [[maybe_unused]] ControlSerializer *cs = nullptr) {%- endif %} { - {{struct|name_full(namespace)}} ret; + {{struct|name}} ret; std::vector::const_iterator m = dataBegin; size_t dataSize = std::distance(dataBegin, dataEnd);