From patchwork Tue Oct 11 10:58:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17579 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 B164AC0DA4 for ; Tue, 11 Oct 2022 10:59:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6B5CF62D74; Tue, 11 Oct 2022 12:59:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485956; bh=WYM0INlaGtOuymy12t/4WjDb5+v30IdZbRkSjhURYGc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=k/yc8IP1p9u3mb7deqmBXtMi9oIADTKJ7qT4vIPVsvrdBvmA4u9c5OGe9iILjPTAV CPECff9ZElJtohRB3lOYOV5+dQmUSvS2geJzUO/XIz5FNZ9yGdub1gc7hG+1LVdrnl 9wmiCkZIccf2ML8NXSV52o7ABxtxERCzjS3kCVpHsc2L4MdtrAIx27ZwDGuDzElJF3 4gANrFoNSw/TfH7ooFr63MhM0s2iC00KLhhtYFfykQ74MKh5z9Z0DsGqqpCwFFiShu JbtBW7wOgjHQ7jWMVMrM3304Nk34fwTsEe15ZlMmTi4OihdRzAj7963CEJkzO04h2o EBeOyJsIHcbnw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D2A3162D4E for ; Tue, 11 Oct 2022 12:59:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oVgJtbYo"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C0829AFC; Tue, 11 Oct 2022 12:59:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485954; bh=WYM0INlaGtOuymy12t/4WjDb5+v30IdZbRkSjhURYGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oVgJtbYok/pqL34D8JbucgBL7V7NH6YdMBYo7EAbvtdyf/b0o2BtCLMVtcHVMUuNA +14Dtnyz9lYQTGeLobIO3koFgmT+81XWekBRNGo3aQbBXe9KniTh3VBsNIAva9bp+a UuV29Y7ocl6qVxRg8zw8dK7RkHFJ5uIu9DUrGcDU= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:51 +0900 Message-Id: <20221011105859.457567-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 1/9] test: generated_serializer: Test enum that is struct member 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an enum field to the test struct member to test serialization/deserialization of enums that are struct members. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- No change in v5 No change in v4 No change in v3 No change in v2 --- .../generated_serializer/generated_serializer_test.cpp | 4 ++++ .../generated_serializer/include/libcamera/ipa/test.mojom | 1 + 2 files changed, 5 insertions(+) diff --git a/test/serialization/generated_serializer/generated_serializer_test.cpp b/test/serialization/generated_serializer/generated_serializer_test.cpp index 698c81d6..a4639a80 100644 --- a/test/serialization/generated_serializer/generated_serializer_test.cpp +++ b/test/serialization/generated_serializer/generated_serializer_test.cpp @@ -51,6 +51,7 @@ if (struct1.field != struct2.field) { \ t.s2 = "goodbye"; t.s3 = "lorem ipsum"; t.i = 58527; + t.c = ipa::test::IPAOperationInit; std::vector serialized; @@ -69,6 +70,7 @@ if (struct1.field != struct2.field) { \ TEST_FIELD_EQUALITY(t, u, s2); TEST_FIELD_EQUALITY(t, u, s3); TEST_FIELD_EQUALITY(t, u, i); + TEST_FIELD_EQUALITY(t, u, c); /* Test vector of generated structs */ @@ -92,11 +94,13 @@ if (struct1.field != struct2.field) { \ TEST_FIELD_EQUALITY(v[0], w[0], s2); TEST_FIELD_EQUALITY(v[0], w[0], s3); TEST_FIELD_EQUALITY(v[0], w[0], i); + TEST_FIELD_EQUALITY(v[0], w[0], c); TEST_FIELD_EQUALITY(v[1], w[1], s1); TEST_FIELD_EQUALITY(v[1], w[1], s2); TEST_FIELD_EQUALITY(v[1], w[1], s3); TEST_FIELD_EQUALITY(v[1], w[1], i); + TEST_FIELD_EQUALITY(v[1], w[1], c); return TestPass; } diff --git a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom index 5f200885..73081b40 100644 --- a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom +++ b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom @@ -18,6 +18,7 @@ struct TestStruct { string s2; int32 i; string s3; + IPAOperationCode c; }; interface IPATestInterface { From patchwork Tue Oct 11 10:58:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17580 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 347E8C0DA4 for ; Tue, 11 Oct 2022 10:59:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D75A462D79; Tue, 11 Oct 2022 12:59:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485957; bh=KizrgP6O/mGAbSVLFZLKJWcEI65LDo/w8QgFS5JqgOw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QVhEtJKIK9MeNiXieZpi600wtyJlw/Kqw17C5WOqvqepUldMUEobofCs1OLZIg1qF w/89MVAWwV+PeYk5hhLFmQjCTMyYSZRp6fu0Niqc2excklKyP2Y/vN1GCXwr9EcYuf G/8E/s6bEkykjlFjdnw95B9Yd1IZ62XJE1tbuLLDp0L+c7pTPF9kp7ihw8EdIPvpHy Sa/SMUuZVBApQf0NRT3V6ZUhVDtbxR6wS2Z8hi8fTYvfl+iGHQjj+cHjcjeRUeUUP8 q1sC2Bg+YIKqA8Gwa7RVQZZZ6S5OEhLlLyfFwZ92HSnQoFgr/M/99jpMEL9QQPparL uxSq99p83m6dw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E739062D4E for ; Tue, 11 Oct 2022 12:59:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H0VsiKH9"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2D2E5143F; Tue, 11 Oct 2022 12:59:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485956; bh=KizrgP6O/mGAbSVLFZLKJWcEI65LDo/w8QgFS5JqgOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H0VsiKH9Bi8DqzlvRi50nEvldd9LQvjuLWO/l7J/iEyR0f18T0FDrLfwZllNyRFji qyBu+jQMghrOKU0a8+7GJyQZ+i7Ta5Y3pCWsZ3hO+fl9Oes8OiSskRXUskIPL1jNuF bNklv0+HIMG8mslJjalqz65FzY8SI5zU4qpN/BuE= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:52 +0900 Message-Id: <20221011105859.457567-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 2/9] utils: ipc: Add support for enums in function parameters 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" There is already support for enums as struct members, but there was no support for enums in function parameters. Add it. This does not add support for returning enums as direct return values. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- No change in v5 No change in v4 No change in v3 Changes in v2: - add static assertion to confirm that the enum type fits in int32_t --- .../libcamera_templates/proxy_functions.tmpl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl index bac826a7..cbcfb64a 100644 --- a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl +++ b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl @@ -52,6 +52,9 @@ #} {%- macro serialize_call(params, buf, fds) %} {%- for param in params %} +{%- if param|is_enum %} + static_assert(sizeof({{param|name_full}}) <= 4); +{%- endif %} std::vector {{param.mojom_name}}Buf; {%- if param|has_fd %} std::vector {{param.mojom_name}}Fds; @@ -59,7 +62,11 @@ {%- else %} std::tie({{param.mojom_name}}Buf, std::ignore) = {%- endif %} +{%- if param|is_enum %} + IPADataSerializer::serialize(static_cast({{param.mojom_name}}) +{%- else %} IPADataSerializer<{{param|name}}>::serialize({{param.mojom_name}} +{% endif -%} {{- ", &controlSerializer_" if param|needs_control_serializer -}} ); {%- endfor %} @@ -97,7 +104,12 @@ # This code is meant to be used by macro deserialize_call. #} {%- macro deserialize_param(param, pointer, loop, buf, fds, iter, data_size) -%} -{{"*" if pointer}}{{param.mojom_name}} = IPADataSerializer<{{param|name}}>::deserialize( +{{"*" if pointer}}{{param.mojom_name}} = +{%- if param|is_enum %} +static_cast<{{param|name_full}}>(IPADataSerializer::deserialize( +{%- else %} +IPADataSerializer<{{param|name}}>::deserialize( +{%- endif %} {{buf}}{{- ".cbegin()" if not iter}} + {{param.mojom_name}}Start, {%- if loop.last and not iter %} {{buf}}.cend() @@ -121,7 +133,7 @@ {%- if param|needs_control_serializer %} &controlSerializer_ {%- endif -%} -); +){{")" if param|is_enum}}; {%- endmacro -%} From patchwork Tue Oct 11 10:58:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17581 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 93365C0DA4 for ; Tue, 11 Oct 2022 10:59:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4EA6362D7E; Tue, 11 Oct 2022 12:59:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485960; bh=7PNSd1rNWaPCtaLZIWIxfkRODfiSBRN65VR0qRxbGVw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=szWtHwGo+/dRI0TRz9+lZhGftFW3bzqAuv8G60gvSIUHGTlzZi2c6D/LTB2ynLUxB GAXbz9mGFtqduB/QhFQuTCixtMD62AIRJQaukh9rxOpYlWZppC0eyDn102eHF72zC8 T4KjhTvv0yNCLakCQIL0P59Y0NZR+KGOcrNLuZwH/D3BQjTrh8eC+/aUGnYZnG36zh T3QgB6LL59lpbQSHVlAoFY5ZvsYIYW8N++0RB7+mJdXtGnaP7NIt+LaOuf3Ox3hCdz 3PAvRuvQJx+bgHFQlxy6NqRGGjo86tG0zkR8sdkAoQGsRFz1mWLZlUD6XEVfzjUSQ/ 4xlwmixnBQfHg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 02C2962D4E for ; Tue, 11 Oct 2022 12:59:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fh/xy85d"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 52111907; Tue, 11 Oct 2022 12:59:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485958; bh=7PNSd1rNWaPCtaLZIWIxfkRODfiSBRN65VR0qRxbGVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fh/xy85dShYnH40l/hZwSdHowPw52fmABuqbjfepx5L/N74UaQpS0eTOpx1QuxRCC ZIealsL7DKGlU558fkNOvYlrBZM/pw70EEM4ZJrGG/Mepm7APN5ZZX3p1oZHAQq5hd 7uymBlEMaRrG07CKhOgAiWs9TCmGdhlh7XNbbgzY= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:53 +0900 Message-Id: <20221011105859.457567-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 3/9] libcamera: ipa_data_serializer: Add serializer for Flags 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement an IPADataSerializer for Flags. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- No change in v5 No change in v4 No change in v3 Changes in v2: - use Flags's Type cast to avoid friend class --- .../libcamera/internal/ipa_data_serializer.h | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/include/libcamera/internal/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h index 30bdaebc..981d2f5c 100644 --- a/include/libcamera/internal/ipa_data_serializer.h +++ b/include/libcamera/internal/ipa_data_serializer.h @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -301,6 +302,51 @@ public: } }; +/* Serialization format for Flags is same as for PODs */ +template +class IPADataSerializer> +{ +public: + static std::tuple, std::vector> + serialize(const Flags &data, [[maybe_unused]] ControlSerializer *cs = nullptr) + { + std::vector dataVec; + dataVec.reserve(sizeof(Flags)); + appendPOD(dataVec, static_cast::Type>(data)); + + return { dataVec, {} }; + } + + static Flags deserialize(std::vector &data, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return deserialize(data.cbegin(), data.end()); + } + + static Flags deserialize(std::vector::const_iterator dataBegin, + std::vector::const_iterator dataEnd, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return Flags{ static_cast(readPOD(dataBegin, 0, dataEnd)) }; + } + + static Flags deserialize(std::vector &data, + [[maybe_unused]] std::vector &fds, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return deserialize(data.cbegin(), data.end()); + } + + static Flags 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, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return deserialize(dataBegin, dataEnd); + } +}; + #endif /* __DOXYGEN__ */ } /* namespace libcamera */ From patchwork Tue Oct 11 10:58:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17582 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 0FBE5C0DA4 for ; Tue, 11 Oct 2022 10:59:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B1BA162D81; Tue, 11 Oct 2022 12:59:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485961; bh=/EUTZZ3hMm47Ig/40fyi+ZPthIX8jsGzBMMY0s3Pt1o=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UcPVnRlzdyO7yZiajAwSztm99rln7pOJVGRHW0iIPujZOaOrO/ZepuinUmYbF93vS GVdf58CLVfUQkgu2+T6z3OUp8y6aVwbll4AMS6vfxwLGqguW7x3siGJhjEJVsh5zjW EN3xU0Sl1JLB03lF2Fy2q6CkgsVRNh5sdpMc9hpgkmuz18mOM3raZu2NkzAMSNUzv/ qG9yv8nm0s/fz8Wl3wkmYkxe3jQvMTxar7CCNgwM67oofl9gjFRjgDSQadjk/fHnCn Ufkh2DNphYRimx6hhh1I0QZtlMxHk+o8MN9BD3uaeNn21AVfWAW5k9drq4nZL6xUD/ mrqOr7Y0rrrFA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DCB6E62D4E for ; Tue, 11 Oct 2022 12:59:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lJi4FZAY"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 52307907; Tue, 11 Oct 2022 12:59:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485960; bh=/EUTZZ3hMm47Ig/40fyi+ZPthIX8jsGzBMMY0s3Pt1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lJi4FZAY/ss4edAEVdnggJJpAE3xZFnFVcdKWxzesx16xMWQLje1PFCUfR1rCbegS vgyLiFazdBUHSTfP1osAkXaiPZW7gUPkMcUWkz25M/M7TtF6mJOnoct4gaQHYbg3m6 sPE2a/9KZRDTSCEicO9Ony7M3DHjDK4F7ObtA4Mw= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:54 +0900 Message-Id: <20221011105859.457567-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 4/9] utils: ipc: Add support for Flags 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add Flags as a supported type in the IPA interface. It is used in mojom with the [flags] attribute. Any field or parameter type E that is prefixed with the [flags] attribute will direct the code generator to generate the type name "Flags" and appropriate serialization/deserialization code for Flags instead of for E. It is usable and has been tested in struct members, function input and output parameters, and Signal parameters. This does not add support for returning Flags as direct return values. Additionally, the [scopedEnum] attribute can be used on enum definitions, which will instruct the code generator to convert it to an enum class instead of a raw enum. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v5: - fix serialization of scoped enums that are struct members - IsScoped doesn't catch enums that are struct members; only the enum definition itself, so we have a separate IsEnumScoped now for struct members Changes in v4: - make flags also passed directly (as opposed to const references) Changes in v3.1: - add documentation of [scopedEnum] and [flags] to core.mojom - it's not the best place, but better somewhere than nowhere for now Changes in v3: - change flags attribute from [Flags] to [flags] - make it so that enum input parameters are passed directly (as opposed to const references) - to turn enum definitions in mojom to enum classes, use the [scopedEnum] attribute (as opposed to the [Flags] attribute in v2) - correspondingly, the function in the mojom generator python script is separated out from IsFlags() into IsScoped() - clean up IsFlags() - simplify GetFullNameForElement() for flags Question for reviewers (in v2): Should we use a different attribute name to specify that an enum should be an enum class? Answer (in v3): Yes; that attribute name is [scopedEnum] Changes in v2: - Use mojom attribute to specify that a field should be Flags, instead of using a magic type name format --- include/libcamera/ipa/core.mojom | 9 +++++ include/libcamera/ipa/ipa_interface.h | 1 + .../definition_functions.tmpl | 2 +- .../module_ipa_interface.h.tmpl | 2 +- .../module_ipa_proxy.h.tmpl | 2 +- .../libcamera_templates/proxy_functions.tmpl | 10 +++-- .../libcamera_templates/serializer.tmpl | 6 +++ .../generators/mojom_libcamera_generator.py | 37 +++++++++++++++++-- 8 files changed, 60 insertions(+), 9 deletions(-) diff --git a/include/libcamera/ipa/core.mojom b/include/libcamera/ipa/core.mojom index 74f3339e..ef28ff2d 100644 --- a/include/libcamera/ipa/core.mojom +++ b/include/libcamera/ipa/core.mojom @@ -33,6 +33,15 @@ module libcamera; * available for the type and there's no need to generate one * - hasFd - struct fields or empty structs only * - Designate that this field or empty struct contains a SharedFD + * - scopedEnum - enum definitions + * - Designate that this enum should be an enum class, as opposed to a pure + * enum + * - flags - struct fields or function parameters that are enums + * - Designate that this enum type E should be Flags in the generated C++ + * code + * - For example, if a struct field is defined as `[flags] ErrorFlag f;` + * (where ErrorFlag is defined as an enum elsewhere in mojom), then the + * generated code for this field will be `Flags f` * * Rules: * - If the type is defined in a libcamera C++ header *and* a (de)serializer is diff --git a/include/libcamera/ipa/ipa_interface.h b/include/libcamera/ipa/ipa_interface.h index 50ca0e7b..8afcfe21 100644 --- a/include/libcamera/ipa/ipa_interface.h +++ b/include/libcamera/ipa/ipa_interface.h @@ -13,6 +13,7 @@ #include #include +#include #include #include diff --git a/utils/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/ipc/generators/libcamera_templates/definition_functions.tmpl index 94bb4918..8b8509f3 100644 --- a/utils/ipc/generators/libcamera_templates/definition_functions.tmpl +++ b/utils/ipc/generators/libcamera_templates/definition_functions.tmpl @@ -9,7 +9,7 @@ # \param enum Enum object whose definition is to be generated #} {%- macro define_enum(enum) -%} -enum {{enum.mojom_name}} { +enum{{" class" if enum|is_scoped}} {{enum.mojom_name}} { {%- for field in enum.fields %} {{field.mojom_name}} = {{field.numeric_value}}, {%- endfor %} diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl index 415ec283..160601f7 100644 --- a/utils/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl +++ b/utils/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl @@ -69,7 +69,7 @@ public: {%- for method in interface_event.methods %} Signal< {%- for param in method.parameters -%} - {{"const " if not param|is_pod}}{{param|name}}{{" &" if not param|is_pod}} + {{"const " if not param|is_pod}}{{param|name}}{{" &" if not param|is_pod and not param|is_enum}} {{- ", " if not loop.last}} {%- endfor -%} > {{method.mojom_name}}; diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl index c308dd10..ed270f5c 100644 --- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl +++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl @@ -46,7 +46,7 @@ public: {%- for method in interface_event.methods %} Signal< {%- for param in method.parameters -%} - {{"const " if not param|is_pod}}{{param|name}}{{" &" if not param|is_pod}} + {{"const " if not param|is_pod}}{{param|name}}{{" &" if not param|is_pod and not param|is_enum}} {{- ", " if not loop.last}} {%- endfor -%} > {{method.mojom_name}}; diff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl index cbcfb64a..2be65d43 100644 --- a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl +++ b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl @@ -62,7 +62,9 @@ {%- else %} std::tie({{param.mojom_name}}Buf, std::ignore) = {%- endif %} -{%- if param|is_enum %} +{%- if param|is_flags %} + IPADataSerializer<{{param|name_full}}>::serialize({{param.mojom_name}} +{%- elif param|is_enum %} IPADataSerializer::serialize(static_cast({{param.mojom_name}}) {%- else %} IPADataSerializer<{{param|name}}>::serialize({{param.mojom_name}} @@ -105,7 +107,9 @@ #} {%- macro deserialize_param(param, pointer, loop, buf, fds, iter, data_size) -%} {{"*" if pointer}}{{param.mojom_name}} = -{%- if param|is_enum %} +{%- if param|is_flags %} +IPADataSerializer<{{param|name_full}}>::deserialize( +{%- elif param|is_enum %} static_cast<{{param|name_full}}>(IPADataSerializer::deserialize( {%- else %} IPADataSerializer<{{param|name}}>::deserialize( @@ -133,7 +137,7 @@ IPADataSerializer<{{param|name}}>::deserialize( {%- if param|needs_control_serializer %} &controlSerializer_ {%- endif -%} -){{")" if param|is_enum}}; +){{")" if param|is_enum and not param|is_flags}}; {%- endmacro -%} diff --git a/utils/ipc/generators/libcamera_templates/serializer.tmpl b/utils/ipc/generators/libcamera_templates/serializer.tmpl index 77bae36f..323e1293 100644 --- a/utils/ipc/generators/libcamera_templates/serializer.tmpl +++ b/utils/ipc/generators/libcamera_templates/serializer.tmpl @@ -34,6 +34,10 @@ std::tie({{field.mojom_name}}, std::ignore) = {%- if field|is_pod %} IPADataSerializer<{{field|name}}>::serialize(data.{{field.mojom_name}}); + {%- elif field|is_flags %} + IPADataSerializer<{{field|name_full}}>::serialize(data.{{field.mojom_name}}); + {%- elif field|is_enum_scoped %} + IPADataSerializer::serialize(static_cast(data.{{field.mojom_name}})); {%- elif field|is_enum %} IPADataSerializer::serialize(data.{{field.mojom_name}}); {%- endif %} @@ -96,6 +100,8 @@ {{- check_data_size(field_size, 'dataSize', field.mojom_name, 'data')}} {%- if field|is_pod %} ret.{{field.mojom_name}} = IPADataSerializer<{{field|name}}>::deserialize(m, m + {{field_size}}); + {%- elif field|is_flags %} + ret.{{field.mojom_name}} = IPADataSerializer<{{field|name_full}}>::deserialize(m, m + {{field_size}}); {%- else %} ret.{{field.mojom_name}} = static_cast<{{field|name_full}}>(IPADataSerializer::deserialize(m, m + {{field_size}})); {%- endif %} diff --git a/utils/ipc/generators/mojom_libcamera_generator.py b/utils/ipc/generators/mojom_libcamera_generator.py index 753bfc73..6c176aba 100644 --- a/utils/ipc/generators/mojom_libcamera_generator.py +++ b/utils/ipc/generators/mojom_libcamera_generator.py @@ -74,6 +74,8 @@ def GetDefaultValue(element): return element.default if type(element.kind) == mojom.Kind: return '0' + if IsFlags(element): + return '' if mojom.IsEnumKind(element.kind): return f'static_cast<{element.kind.mojom_name}>(0)' if isinstance(element.kind, mojom.Struct) and \ @@ -184,7 +186,7 @@ def MethodParameters(method): params = [] for param in method.parameters: params.append('const %s %s%s' % (GetNameForElement(param), - '&' if not IsPod(param) else '', + '' if IsPod(param) or IsEnum(param) else '&', param.mojom_name)) for param in MethodParamOutputs(method): params.append(f'{GetNameForElement(param)} *{param.mojom_name}') @@ -220,9 +222,28 @@ def IsControls(element): def IsEnum(element): return mojom.IsEnumKind(element.kind) +# Only works the enum definition, not types +def IsScoped(element): + attributes = getattr(element, 'attributes', None) + if not attributes: + return False + return 'scopedEnum' in attributes + + +def IsEnumScoped(element): + if not IsEnum(element): + return False + return IsScoped(element.kind) + def IsFd(element): return mojom.IsStructKind(element.kind) and element.kind.mojom_name == "SharedFD" +def IsFlags(element): + attributes = getattr(element, 'attributes', None) + if not attributes: + return False + return 'flags' in attributes + def IsMap(element): return mojom.IsMapKind(element.kind) @@ -251,9 +272,11 @@ def ByteWidthFromCppType(t): raise Exception('invalid type') return str(int(_bit_widths[key]) // 8) - # Get the type name for a given element def GetNameForElement(element): + # Flags + if IsFlags(element): + return f'Flags<{GetFullNameForElement(element.kind)}>' # structs if (mojom.IsEnumKind(element) or mojom.IsInterfaceKind(element) or @@ -302,7 +325,8 @@ def GetNameForElement(element): def GetFullNameForElement(element): name = GetNameForElement(element) namespace_str = '' - if mojom.IsStructKind(element): + if (mojom.IsStructKind(element) or + mojom.IsEnumKind(element)): namespace_str = element.module.mojom_namespace.replace('.', '::') elif (hasattr(element, 'kind') and (mojom.IsStructKind(element.kind) or @@ -311,6 +335,10 @@ def GetFullNameForElement(element): if namespace_str == '': return name + + if IsFlags(element): + return GetNameForElement(element) + return f'{namespace_str}::{name}' def ValidateZeroLength(l, s, cap=True): @@ -407,10 +435,13 @@ class Generator(generator.Generator): 'is_array': IsArray, 'is_controls': IsControls, 'is_enum': IsEnum, + 'is_enum_scoped': IsEnumScoped, 'is_fd': IsFd, + 'is_flags': IsFlags, 'is_map': IsMap, 'is_plain_struct': IsPlainStruct, 'is_pod': IsPod, + 'is_scoped': IsScoped, 'is_str': IsStr, 'method_input_has_fd': MethodInputHasFd, 'method_output_has_fd': MethodOutputHasFd, From patchwork Tue Oct 11 10:58:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17583 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 B2429C0DA4 for ; Tue, 11 Oct 2022 10:59:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 620EE62D85; Tue, 11 Oct 2022 12:59:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485964; bh=FQZp1R7GCguTvhcd4r9Ol4LNyOwEN4K5u13hidwZOMI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yLuU8+OUIwEkJoaPhTpkIwxm+mn0qlGN+r6HrDOOkaV8HW+JzJVZJ0RgfohTfOM8z twXbFCktb36fcomNxC9A6jj88jTYOEF2dpOCor0iOyYemKzVebT98ucjCLHFBqoU7X Me3XvrAr0MSY5g7SlQ2EIY61JWR93wOdcqOgSts09kV9GxBUKPZ2F9qk51DarVEuLc j/3TSoo5HhZ7ymNtEC9fOXzdsRKFVKlppfCQ8NPSSzmsc3rjMOQZUB74KNpcbXHgwK 9cRSMWrtuhs/JAS2pK7f2A2nPlkVYMhO5/DywuoP9GqZ/VutVMTLgzZBaz3BlOinpL WJBfurpjLsgpw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F247262D4E for ; Tue, 11 Oct 2022 12:59:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aCl2RTMk"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 523A0143F; Tue, 11 Oct 2022 12:59:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485962; bh=FQZp1R7GCguTvhcd4r9Ol4LNyOwEN4K5u13hidwZOMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aCl2RTMkX1CH9LjYlHLO1VYjkSbz4Inv6FPeDwzZtXbdkLysepvBthjLa77tjFQd9 50i2Rx7pBfNq37sTg5EzGpt4GeFd4N+rpu4Ah+OPPG6Cmn35v0NY/6pB7i72e38ZKb iTZ7tzmsT1Cu56gN77auYbJgGW9EmNZzDJ8YCIlg= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:55 +0900 Message-Id: <20221011105859.457567-6-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 5/9] test: generated_serializer: Test Flags that is struct member 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add fields to the test struct to test serialization/deserialization of scoped enums and flags that are struct members. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v5: - Add scoped enum to the test (basically the enum that the flag is created from) - This caught something that I missed in v4, which is why there is a v5 instead of just being merged... - Add a TEST_SCOPED_ENUM_EQUALITY macro No change in v4 Changes in v3: - add [scopedEnum] to enum ErrorFlags - s/[Flags]/[flags]/ Changes in v2: - use new attribute-based mojom definition for Flags --- .../generated_serializer_test.cpp | 21 +++++++++++++++++++ .../include/libcamera/ipa/test.mojom | 9 ++++++++ 2 files changed, 30 insertions(+) diff --git a/test/serialization/generated_serializer/generated_serializer_test.cpp b/test/serialization/generated_serializer/generated_serializer_test.cpp index a4639a80..4670fe46 100644 --- a/test/serialization/generated_serializer/generated_serializer_test.cpp +++ b/test/serialization/generated_serializer/generated_serializer_test.cpp @@ -35,6 +35,13 @@ if (struct1.field != struct2.field) { \ return TestFail; \ } +#define TEST_SCOPED_ENUM_EQUALITY(struct1, struct2, field) \ +if (struct1.field != struct2.field) { \ + cerr << #field << " field incorrect" << endl; \ + return TestFail; \ +} + + ipa::test::TestStruct t, u; t.m = { @@ -52,6 +59,12 @@ if (struct1.field != struct2.field) { \ t.s3 = "lorem ipsum"; t.i = 58527; t.c = ipa::test::IPAOperationInit; + t.e = ipa::test::ErrorFlags::Error1; + + Flags flags; + flags |= ipa::test::ErrorFlags::Error1; + flags |= ipa::test::ErrorFlags::Error2; + t.f = flags; std::vector serialized; @@ -72,6 +85,8 @@ if (struct1.field != struct2.field) { \ TEST_FIELD_EQUALITY(t, u, i); TEST_FIELD_EQUALITY(t, u, c); + TEST_SCOPED_ENUM_EQUALITY(t, u, e); + TEST_SCOPED_ENUM_EQUALITY(t, u, f); /* Test vector of generated structs */ std::vector v = { t, u }; @@ -96,12 +111,18 @@ if (struct1.field != struct2.field) { \ TEST_FIELD_EQUALITY(v[0], w[0], i); TEST_FIELD_EQUALITY(v[0], w[0], c); + TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], e); + TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], f); + TEST_FIELD_EQUALITY(v[1], w[1], s1); TEST_FIELD_EQUALITY(v[1], w[1], s2); TEST_FIELD_EQUALITY(v[1], w[1], s3); TEST_FIELD_EQUALITY(v[1], w[1], i); TEST_FIELD_EQUALITY(v[1], w[1], c); + TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], e); + TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], f); + return TestPass; } diff --git a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom index 73081b40..91c31642 100644 --- a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom +++ b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom @@ -9,6 +9,13 @@ enum IPAOperationCode { IPAOperationStop, }; +[scopedEnum] enum ErrorFlags { + Error1 = 0x1, + Error2 = 0x2, + Error3 = 0x4, + Error4 = 0x8, +}; + struct IPASettings {}; struct TestStruct { @@ -19,6 +26,8 @@ struct TestStruct { int32 i; string s3; IPAOperationCode c; + ErrorFlags e; + [flags] ErrorFlags f; }; interface IPATestInterface { From patchwork Tue Oct 11 10:58:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17584 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 321EFC0DA4 for ; Tue, 11 Oct 2022 10:59:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D9E9B62D87; Tue, 11 Oct 2022 12:59:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485965; bh=a0wSkQwqJRJh/McpXgjcVKoZ5Ge2YAV2j16pAVOYYIk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZfFPevY7HjzCXkll6N7zygS5ZEJnValBLmGxqo+JBiUDt12umPiPyFufvYUAMwRqh 2QSljwZHZ6FY1O8wTbxWcOsuSmP1MSLfjXomBfr63EkjvHYWlcElBlsX+kMXWzKyOI CjhUtnKXRdbFHUnDemTuhngbf0ATU6ieAOEi2EHO/A92K8g9e4hrDFBK1jZYQQbB8z yXlF5C3qXurUoRBIrYvVX2BMv6mTvyGU6vKkjdJsHGFxcUnC06b846X4ZWcJtgyCnj Tvf+MAMpEWdrM84UyDCguoEqS/o/xnmbBhQjUGNw8w2QBHA4P6MCYspiptWj+qKdtY tQlsOBl2lfEZQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E54C862D76 for ; Tue, 11 Oct 2022 12:59:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="udnrh5Bp"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4C80EAFC; Tue, 11 Oct 2022 12:59:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485964; bh=a0wSkQwqJRJh/McpXgjcVKoZ5Ge2YAV2j16pAVOYYIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=udnrh5Bpjc/6iFWsJ4SUwQeQ/u6mU3H33Kj6XUUrfvLcUZRaIoOePimmvHpwHugv4 m2VV3EbGqGOWpyIVSvWtyqg4lv4ZpF2GDo01mA362xbxQk4gK0T3OnJZnPTK/fgWuF K6L4CqJ/Df036cxhdGK65DvIPPiCQrxn9AAJBpZQ= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:56 +0900 Message-Id: <20221011105859.457567-7-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 6/9] ipa: vimc: Add IPAOperationCode to init() parameter list 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" For the purpose of testing serializing/deserializing enums in function parameters, add IPAOperationCode to the parameter list of init(). Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- No change in v5 Changes in v4: - remove [TEST] from commit subject Changes in v3: - pass enum by value as opposed to by const reference No changes in v2 --- include/libcamera/ipa/vimc.mojom | 2 +- src/ipa/vimc/vimc.cpp | 6 ++++-- src/libcamera/pipeline/vimc/vimc.cpp | 2 +- test/ipa/ipa_interface_test.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/libcamera/ipa/vimc.mojom b/include/libcamera/ipa/vimc.mojom index 718b9674..16149787 100644 --- a/include/libcamera/ipa/vimc.mojom +++ b/include/libcamera/ipa/vimc.mojom @@ -18,7 +18,7 @@ enum IPAOperationCode { }; interface IPAVimcInterface { - init(libcamera.IPASettings settings) => (int32 ret); + init(libcamera.IPASettings settings, IPAOperationCode code) => (int32 ret); configure(libcamera.IPACameraSensorInfo sensorInfo, map streamConfig, diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp index 85afb279..5d494b63 100644 --- a/src/ipa/vimc/vimc.cpp +++ b/src/ipa/vimc/vimc.cpp @@ -31,7 +31,7 @@ public: IPAVimc(); ~IPAVimc(); - int init(const IPASettings &settings) override; + int init(const IPASettings &settings, const ipa::vimc::IPAOperationCode code) override; int start() override; void stop() override; @@ -66,7 +66,7 @@ IPAVimc::~IPAVimc() ::close(fd_); } -int IPAVimc::init(const IPASettings &settings) +int IPAVimc::init(const IPASettings &settings, const ipa::vimc::IPAOperationCode code) { trace(ipa::vimc::IPAOperationInit); @@ -74,6 +74,8 @@ int IPAVimc::init(const IPASettings &settings) << "initializing vimc IPA with configuration file " << settings.configurationFile; + LOG(IPAVimc, Debug) << "Got opcode " << code; + File conf(settings.configurationFile); if (!conf.open(File::OpenModeFlag::ReadOnly)) { LOG(IPAVimc, Error) << "Failed to open configuration file"; diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index d2f2e460..df749bf7 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -471,7 +471,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) data->ipa_->paramsBufferReady.connect(data.get(), &VimcCameraData::paramsBufferReady); std::string conf = data->ipa_->configurationFile("vimc.conf"); - data->ipa_->init(IPASettings{ conf, data->sensor_->model() }); + data->ipa_->init(IPASettings{ conf, data->sensor_->model() }, ipa::vimc::IPAOperationInit); /* Create and register the camera. */ std::set streams{ &data->stream_ }; diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp index 6b93e976..cd20348a 100644 --- a/test/ipa/ipa_interface_test.cpp +++ b/test/ipa/ipa_interface_test.cpp @@ -106,7 +106,7 @@ protected: /* Test initialization of IPA module. */ std::string conf = ipa_->configurationFile("vimc.conf"); - int ret = ipa_->init(IPASettings{ conf, "vimc" }); + int ret = ipa_->init(IPASettings{ conf, "vimc" }, ipa::vimc::IPAOperationInit); if (ret < 0) { cerr << "IPA interface init() failed" << endl; return TestFail; From patchwork Tue Oct 11 10:58:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17585 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 CDF65C0DA4 for ; Tue, 11 Oct 2022 10:59:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 801C062D8C; Tue, 11 Oct 2022 12:59:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485968; bh=tKFHTURSlQvaDrHrXNj5/fCHdnYeOUzpiQ+L0XkayoY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Kau48gVwtfMzVyfd+q4nHFMEnxfgZL95xiLUAWdt8vc4WK/fOl8G5BJaPYGoFpP1s qwE8Y7QVkq32Mmz76ZTa/VWpWy98JnNBzSaLR8VTS2hL7P8zWZvr7KZaey6ao6QjVT 1zte+7la2/idAYIHkCkb+MQYb95aP+HVAK8Ohi0qYyR6/ybywdPl1XQ4gxFgVFt8SW 2XD+cwnCjQlu9xNd7CtENpzz7ya7axYGARbQo2O7syWeZWbABJFQ1oamjBb+qHuaP/ /tkxInidJdCcsWOUXxjS7E0JMy4a+dwnXS3hz3fCF6UR849NXdhvobtU0PGMKcHPUD lqrHBfWub4p8g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CC77862D89 for ; Tue, 11 Oct 2022 12:59:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HnyZKS+y"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 37C10143F; Tue, 11 Oct 2022 12:59:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485966; bh=tKFHTURSlQvaDrHrXNj5/fCHdnYeOUzpiQ+L0XkayoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HnyZKS+yAJjY+7mMo4Py9u6wyKDmwMe3AoTwvfT5EKA3VJAkw1Uwe9kbz8n1nfAGr PGSPAZghIJRghVq0MB6D3M+EJ7Csc88CGk2Bs5uogBdk8Lg0+HdxmTvMBca9CTZA+x IgUxnuvVXKkqQ2xc1E9v5xCv2idtx5sxsH4SUrU0= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:57 +0900 Message-Id: <20221011105859.457567-8-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 7/9] ipa: vimc: Add Flags to parameters 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" For the purpose of testing serializing/deserializing Flags in function parameters, add an enum class TestFlags and Flags to some function parameters, both for input and output and Signals. While at it, update the ipa_interface_test. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- No change in v5 Changes in v4: - make flags also passed directly (as opposed to const references) - remove [TEST] from commit subject Changes in v3: - s/TestFlags/TestFlag/ - add [scopedEnum] to enum Testflag Changes in v2: - use new attribute-based mojom definition for Flags --- include/libcamera/ipa/vimc.mojom | 14 ++++++++++++-- src/ipa/vimc/vimc.cpp | 20 +++++++++++++++++--- src/libcamera/pipeline/vimc/vimc.cpp | 15 ++++++++++++--- test/ipa/ipa_interface_test.cpp | 6 +++++- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/include/libcamera/ipa/vimc.mojom b/include/libcamera/ipa/vimc.mojom index 16149787..dd991f7e 100644 --- a/include/libcamera/ipa/vimc.mojom +++ b/include/libcamera/ipa/vimc.mojom @@ -17,8 +17,18 @@ enum IPAOperationCode { IPAOperationStop, }; +[scopedEnum] enum TestFlag { + Flag1 = 0x1, + Flag2 = 0x2, + Flag3 = 0x4, + Flag4 = 0x8, +}; + interface IPAVimcInterface { - init(libcamera.IPASettings settings, IPAOperationCode code) => (int32 ret); + init(libcamera.IPASettings settings, + IPAOperationCode code, + [flags] TestFlag inFlags) + => (int32 ret, [flags] TestFlag outFlags); configure(libcamera.IPACameraSensorInfo sensorInfo, map streamConfig, @@ -41,5 +51,5 @@ interface IPAVimcInterface { }; interface IPAVimcEventInterface { - paramsBufferReady(uint32 bufferId); + paramsBufferReady(uint32 bufferId, [flags] TestFlag flags); }; diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp index 5d494b63..9256bbba 100644 --- a/src/ipa/vimc/vimc.cpp +++ b/src/ipa/vimc/vimc.cpp @@ -31,7 +31,10 @@ public: IPAVimc(); ~IPAVimc(); - int init(const IPASettings &settings, const ipa::vimc::IPAOperationCode code) override; + int init(const IPASettings &settings, + const ipa::vimc::IPAOperationCode code, + const Flags inFlags, + Flags *outFlags) override; int start() override; void stop() override; @@ -66,7 +69,10 @@ IPAVimc::~IPAVimc() ::close(fd_); } -int IPAVimc::init(const IPASettings &settings, const ipa::vimc::IPAOperationCode code) +int IPAVimc::init(const IPASettings &settings, + const ipa::vimc::IPAOperationCode code, + const Flags inFlags, + Flags *outFlags) { trace(ipa::vimc::IPAOperationInit); @@ -76,6 +82,13 @@ int IPAVimc::init(const IPASettings &settings, const ipa::vimc::IPAOperationCode LOG(IPAVimc, Debug) << "Got opcode " << code; + LOG(IPAVimc, Debug) + << "Flag 2 was " + << (inFlags & ipa::vimc::TestFlag::Flag2 ? "" : "not ") + << "set"; + + *outFlags |= ipa::vimc::TestFlag::Flag1; + File conf(settings.configurationFile); if (!conf.open(File::OpenModeFlag::ReadOnly)) { LOG(IPAVimc, Error) << "Failed to open configuration file"; @@ -144,7 +157,8 @@ void IPAVimc::fillParamsBuffer([[maybe_unused]] uint32_t frame, uint32_t bufferI return; } - paramsBufferReady.emit(bufferId); + Flags flags; + paramsBufferReady.emit(bufferId, flags); } void IPAVimc::initTrace() diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index df749bf7..f85d05f7 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -54,7 +54,7 @@ public: int init(); int allocateMockIPABuffers(); void bufferReady(FrameBuffer *buffer); - void paramsBufferReady(unsigned int id); + void paramsBufferReady(unsigned int id, const Flags flags); MediaDevice *media_; std::unique_ptr sensor_; @@ -471,7 +471,15 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) data->ipa_->paramsBufferReady.connect(data.get(), &VimcCameraData::paramsBufferReady); std::string conf = data->ipa_->configurationFile("vimc.conf"); - data->ipa_->init(IPASettings{ conf, data->sensor_->model() }, ipa::vimc::IPAOperationInit); + Flags inFlags = ipa::vimc::TestFlag::Flag2; + Flags outFlags; + data->ipa_->init(IPASettings{ conf, data->sensor_->model() }, + ipa::vimc::IPAOperationInit, inFlags, &outFlags); + + LOG(VIMC, Debug) + << "Flag 1 was " + << (outFlags & ipa::vimc::TestFlag::Flag1 ? "" : "not ") + << "set"; /* Create and register the camera. */ std::set streams{ &data->stream_ }; @@ -608,7 +616,8 @@ int VimcCameraData::allocateMockIPABuffers() return video_->exportBuffers(kBufCount, &mockIPABufs_); } -void VimcCameraData::paramsBufferReady([[maybe_unused]] unsigned int id) +void VimcCameraData::paramsBufferReady([[maybe_unused]] unsigned int id, + [[maybe_unused]] const Flags flags) { } diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp index cd20348a..051ef96e 100644 --- a/test/ipa/ipa_interface_test.cpp +++ b/test/ipa/ipa_interface_test.cpp @@ -106,7 +106,11 @@ protected: /* Test initialization of IPA module. */ std::string conf = ipa_->configurationFile("vimc.conf"); - int ret = ipa_->init(IPASettings{ conf, "vimc" }, ipa::vimc::IPAOperationInit); + Flags inFlags; + Flags outFlags; + int ret = ipa_->init(IPASettings{ conf, "vimc" }, + ipa::vimc::IPAOperationInit, + inFlags, &outFlags); if (ret < 0) { cerr << "IPA interface init() failed" << endl; return TestFail; From patchwork Tue Oct 11 10:58:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17586 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 614BDC0DA4 for ; Tue, 11 Oct 2022 10:59:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0D73662D8E; Tue, 11 Oct 2022 12:59:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485970; bh=eUWxVu6zA8CheNezZiypVMsU5UjYnbSxlGieicPkHCU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Roe2wSViy4Mrc3M5Og/9DRa7Xqr7I9Fk15FD2gkFDAhQTo5wkyPtQUUn87v8ycNA8 bKCmDmLuUqlBm7+pYX/fIPlDdJZTLsqPnocwGYGwo0XeWViEz0mIityRUInII6cODi YHOGFcGzHKqLFh+eFIPKD12Af0EiSiKF9wOUq9ZnhiuPz8g+BO2LhOQ93CoVj4127R Zj1gT4DAu9ghfhTFYeBrHxu5IUAr0XuRHydZYOG0/ReXbtF8o/FoiYEaG+19V/RlHf +4N2IVompgc+ijYp8WtFajPrwj11FItEwQoGSl9NWNqVLW0KrGeDEw8Z/XBabCdTgu vp28UmywFjI9Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7D87762D8B for ; Tue, 11 Oct 2022 12:59:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ffs1ch6u"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3BD6F907; Tue, 11 Oct 2022 12:59:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485968; bh=eUWxVu6zA8CheNezZiypVMsU5UjYnbSxlGieicPkHCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ffs1ch6uBMj1EtJnX5KiN6GcdBSmSe53nZISrsAGtHVUel0oHAd3b3bemcmfM4ZwZ pp4w7nLupccXrmoZEEq8TtlzHf98GaUZ4fILvC6Mzyg80ygQ0CPwVqJfhShPaaJ7eW 1vSfMQitgfu+bejHN7jGdYRd7GTvw9a0eq8zjOuY= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:58 +0900 Message-Id: <20221011105859.457567-9-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 8/9] utils: ipc: Allow the skipHeader attribute on enums 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Currently, enums that are passed between pipeline handlers and their IPA must be defined in a mojom file. However, there is a use case for enum/flags to be defined in a C++ header, such that the enum can be used in a component other than the pipeline handler and its IPA. To support this, add support for the skipHeader attribute for enums. Like structs, it is only allowed in core.mojom. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- New in v5 --- include/libcamera/ipa/core.mojom | 4 +++- include/libcamera/ipa/ipa_interface.h | 4 ++-- .../generators/libcamera_templates/core_ipa_interface.h.tmpl | 2 +- utils/ipc/generators/mojom_libcamera_generator.py | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/libcamera/ipa/core.mojom b/include/libcamera/ipa/core.mojom index ef28ff2d..1ff674b0 100644 --- a/include/libcamera/ipa/core.mojom +++ b/include/libcamera/ipa/core.mojom @@ -14,7 +14,7 @@ module libcamera; * - structs * * Attributes: - * - skipHeader - structs only, and only in core.mojom + * - skipHeader - allowed only for structs and enums in core.mojom * - Do not generate a C++ definition for the structure * - Any type used in a mojom interface definition must have a corresponding * definition in a mojom file for the code generator to accept it, except @@ -52,6 +52,8 @@ module libcamera; * then the type definition in the core.mojom file should have the * [skipHeader] attribute only * - A (de)serializer will be generated for the type + * - enums that are defined in a libcamera C++ header also fall in this + * category * - If a type definition has [skipHeader], then the header where the type is * defined must be included in ipa_interface.h * - Types that are solely used as array/map members do not require a mojom diff --git a/include/libcamera/ipa/ipa_interface.h b/include/libcamera/ipa/ipa_interface.h index 8afcfe21..8884f0ed 100644 --- a/include/libcamera/ipa/ipa_interface.h +++ b/include/libcamera/ipa/ipa_interface.h @@ -23,8 +23,8 @@ namespace libcamera { /* - * Structs that are defined in core.mojom and have the skipHeader tag must be - * #included here. + * Structs and enums that are defined in core.mojom that have the skipHeader + * tag must be #included here. */ class IPAInterface diff --git a/utils/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl b/utils/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl index a565b59a..c60b99b8 100644 --- a/utils/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl +++ b/utils/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl @@ -26,7 +26,7 @@ namespace libcamera { static const {{const.kind|name}} {{const.mojom_name}} = {{const.value}}; {% endfor %} -{% for enum in enums %} +{% for enum in enums_gen_header %} {{funcs.define_enum(enum)}} {% endfor %} diff --git a/utils/ipc/generators/mojom_libcamera_generator.py b/utils/ipc/generators/mojom_libcamera_generator.py index 6c176aba..64987ccd 100644 --- a/utils/ipc/generators/mojom_libcamera_generator.py +++ b/utils/ipc/generators/mojom_libcamera_generator.py @@ -483,7 +483,7 @@ class Generator(generator.Generator): def _GetJinjaExportsForCore(self): return { 'consts': self.module.constants, - 'enums': self.module.enums, + 'enums_gen_header': [x for x in self.module.enums if x.attributes is None or 'skipHeader' not in x.attributes], 'has_array': len([x for x in self.module.kinds.keys() if x[0] == 'a']) > 0, 'has_map': len([x for x in self.module.kinds.keys() if x[0] == 'm']) > 0, 'structs_gen_header': [x for x in self.module.structs if x.attributes is None or 'skipHeader' not in x.attributes], From patchwork Tue Oct 11 10:58:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17587 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 08578C0DA4 for ; Tue, 11 Oct 2022 10:59:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C434462D74; Tue, 11 Oct 2022 12:59:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485972; bh=s9uknyDyrW6/tCcbTpz3ktrcMDk0rN/MVPr8Qg1iBfo=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=B7qMjspQtJSFiNFfnJdHD07KKZL6GVqMPFOepQzB3vQzVwytOPgpCdMP2Sg+8Yfc/ itdFgHqDFHzPzVrKTAk9bM2a3BgE6EpG7dcdFwPbcsokIaCCcnQ2RTxYtYEJqDM5EX Mxx51UvCa9XWrlbk9Phkl4Lj6p7TDOo6fPMr3g0ZJeBZPm6C3/A6UaKRWOgu9Lr2ab rjL2UAugp6H9Nifftbq4n7Xy9Q0mh5EDjY5bsr1xtxD3VJ85M3J/Y5cW/skB5kI0UU n2Xyo60mt5URmw2dkmJlgIqQWLtid60ZaguF2qWkxP/PgWu8uK16t7//k7iXmshCtE PRu/5iwUR/UXA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 21FFF62D91 for ; Tue, 11 Oct 2022 12:59:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="T64/GBfX"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CBA1F907; Tue, 11 Oct 2022 12:59:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485969; bh=s9uknyDyrW6/tCcbTpz3ktrcMDk0rN/MVPr8Qg1iBfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T64/GBfXSbdeF6Lg2o+CdtPxP1DpVQiH0DTmuf9bmHQL81Ad/uMjfE0c4b0cJB5Ae hw8Eszj9JW3D1uzXWuHfzbPAJhm9kxBQTdg6tDCdh/FpreshcteJypAGi+6G8UdkNp G8HB+h+S+XfnxJEk/pBLjJWaWKchVc/v0linrNhk= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:59 +0900 Message-Id: <20221011105859.457567-10-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 9/9] [RFC] test: generated_serializer: Test skipHeader enums and flags 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add fields to the test struct to test serialization/deserialization of scoped enums and flags of said scoped enums that are defined in a C++ header, which are thus designated by [skipHeader] in mojom. Signed-off-by: Paul Elder --- New in v5 RFC because this touches core stuff. This can be detached from the rest of the series. --- include/libcamera/ipa/core.mojom | 2 ++ include/libcamera/ipa/ipa_interface.h | 7 +++++++ .../generated_serializer_test.cpp | 11 +++++++++++ .../include/libcamera/ipa/test.mojom | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/include/libcamera/ipa/core.mojom b/include/libcamera/ipa/core.mojom index 1ff674b0..3438af93 100644 --- a/include/libcamera/ipa/core.mojom +++ b/include/libcamera/ipa/core.mojom @@ -84,6 +84,8 @@ module libcamera; [skipSerdes, skipHeader] struct ControlList {}; [skipSerdes, skipHeader] struct SharedFD {}; +[skipHeader, scopedEnum] enum TestEnum {}; + [skipHeader] struct Point { int32 x; int32 y; diff --git a/include/libcamera/ipa/ipa_interface.h b/include/libcamera/ipa/ipa_interface.h index 8884f0ed..96fb8344 100644 --- a/include/libcamera/ipa/ipa_interface.h +++ b/include/libcamera/ipa/ipa_interface.h @@ -27,6 +27,13 @@ namespace libcamera { * tag must be #included here. */ +enum class TestEnum { + TestEnumValueA, + TestEnumValueB, + TestEnumValueC, + TestEnumValueD, +}; + class IPAInterface { public: diff --git a/test/serialization/generated_serializer/generated_serializer_test.cpp b/test/serialization/generated_serializer/generated_serializer_test.cpp index 4670fe46..6f01c3d4 100644 --- a/test/serialization/generated_serializer/generated_serializer_test.cpp +++ b/test/serialization/generated_serializer/generated_serializer_test.cpp @@ -11,6 +11,8 @@ #include "test.h" +#include + #include "test_ipa_interface.h" #include "test_ipa_serializer.h" @@ -59,6 +61,9 @@ if (struct1.field != struct2.field) { \ t.s3 = "lorem ipsum"; t.i = 58527; t.c = ipa::test::IPAOperationInit; + t.ex = TestEnum::TestEnumValueA; + t.exf |= TestEnum::TestEnumValueB; + t.e = ipa::test::ErrorFlags::Error1; Flags flags; @@ -87,6 +92,8 @@ if (struct1.field != struct2.field) { \ TEST_SCOPED_ENUM_EQUALITY(t, u, e); TEST_SCOPED_ENUM_EQUALITY(t, u, f); + TEST_SCOPED_ENUM_EQUALITY(t, u, ex); + TEST_SCOPED_ENUM_EQUALITY(t, u, exf); /* Test vector of generated structs */ std::vector v = { t, u }; @@ -113,6 +120,8 @@ if (struct1.field != struct2.field) { \ TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], e); TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], f); + TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], ex); + TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], exf); TEST_FIELD_EQUALITY(v[1], w[1], s1); TEST_FIELD_EQUALITY(v[1], w[1], s2); @@ -122,6 +131,8 @@ if (struct1.field != struct2.field) { \ TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], e); TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], f); + TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], ex); + TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], exf); return TestPass; } diff --git a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom index 91c31642..1f1ba8dc 100644 --- a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom +++ b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom @@ -2,6 +2,8 @@ module ipa.test; +import "include/libcamera/ipa/core.mojom"; + enum IPAOperationCode { IPAOperationNone, IPAOperationInit, @@ -28,6 +30,8 @@ struct TestStruct { IPAOperationCode c; ErrorFlags e; [flags] ErrorFlags f; + libcamera.TestEnum ex; + [flags] libcamera.TestEnum exf; }; interface IPATestInterface {