{"id":11506,"url":"https://patchwork.libcamera.org/api/patches/11506/?format=json","web_url":"https://patchwork.libcamera.org/patch/11506/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20210308074828.13228-3-paul.elder@ideasonboard.com>","date":"2021-03-08T07:48:27","name":"[libcamera-devel,v2,2/3] utils: ipc: Make first output parameter direct return if int32","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"60b440ef49f31383997b4165eae3de18e21e0176","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11506/mbox/","series":[{"id":1765,"url":"https://patchwork.libcamera.org/api/series/1765/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1765","date":"2021-03-08T07:48:25","name":"Expand mojom-based code generator","version":2,"mbox":"https://patchwork.libcamera.org/series/1765/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11506/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11506/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 A05F1BD80C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Mar 2021 07:48:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 602F360520;\n\tMon,  8 Mar 2021 08:48:44 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9A0EA60106\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Mar 2021 08:48:42 +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 9097010C5;\n\tMon,  8 Mar 2021 08:48:40 +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=\"D0zn2y8i\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1615189722;\n\tbh=V7wBRWSRHRE1LmT6sXZiXSIfi9FnofByVc+8lMlwdqM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=D0zn2y8iw8ZsINC0v9x7rW9caApr/7Nc9kkXqIUg/u8YhBzQQkHg0ZctY/CGC3MvA\n\tUKm7XmRtH8yWjlAyJOHRCo8hTFTTCQjD0e3k8Uq7/tBxu5SJeMVyd1byb9Kfn4wOO9\n\tU4wBeyHibTuPUgNv9pAtVosY+ynkycuJYQtOF8y0=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  8 Mar 2021 16:48:27 +0900","Message-Id":"<20210308074828.13228-3-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20210308074828.13228-1-paul.elder@ideasonboard.com>","References":"<20210308074828.13228-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 2/3] utils: ipc: Make first output\n\tparameter direct return if int32","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=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"To make it more convenient for synchronous IPA calls to return a status,\nconvert the first output into a direct return if it is an int32.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nAcked-by: Naushir Patuck <naush@raspberrypi.com>\n\n---\nChanges in v2:\n- cosmetic changes\n---\n .../module_ipa_proxy.cpp.tmpl                 |  7 ++-\n .../module_ipa_proxy_worker.cpp.tmpl          |  8 ++--\n .../libcamera_templates/proxy_functions.tmpl  |  4 +-\n .../generators/mojom_libcamera_generator.py   | 45 ++++++++++++-------\n 4 files changed, 40 insertions(+), 24 deletions(-)","diff":"diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\nindex 3eb3dced..f75b1206 100644\n--- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n+++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n@@ -209,7 +209,12 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data)\n {%- endif %}\n \t}\n {% if method|method_return_value != \"void\" %}\n-\treturn IPADataSerializer<{{method.response_parameters|first|name}}>::deserialize(_ipcOutputBuf.data(), 0);\n+\t{{method|method_return_value}} _retValue = IPADataSerializer<{{method|method_return_value}}>::deserialize(_ipcOutputBuf.data(), 0);\n+\n+{{proxy_funcs.deserialize_call(method|method_param_outputs, '_ipcOutputBuf.data()', '_ipcOutputBuf.fds()', init_offset = method|method_return_value|byte_width|int)}}\n+\n+\treturn _retValue;\n+\n {% elif method|method_param_outputs|length > 0 %}\n {{proxy_funcs.deserialize_call(method|method_param_outputs, '_ipcOutputBuf.data()', '_ipcOutputBuf.fds()')}}\n {% endif -%}\ndiff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl\nindex ac037fa1..8a57b6cc 100644\n--- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl\n+++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl\n@@ -83,15 +83,14 @@ public:\n \t\t\t{{param|name}} {{param.mojom_name}};\n {% endfor %}\n {%- if method|method_return_value != \"void\" %}\n-\t\t\t{{method|method_return_value}} _callRet = ipa_->{{method.mojom_name}}({{method.parameters|params_comma_sep}});\n-{%- else %}\n+\t\t\t{{method|method_return_value}} _callRet =\n+{%- endif -%}\n \t\t\tipa_->{{method.mojom_name}}({{method.parameters|params_comma_sep}}\n {{- \", \" if method|method_param_outputs|params_comma_sep -}}\n {%- for param in method|method_param_outputs -%}\n &{{param.mojom_name}}{{\", \" if not loop.last}}\n {%- endfor -%}\n );\n-{%- endif %}\n {% if not method|is_async %}\n \t\t\tIPCMessage::Header header = { _ipcMessage.header().cmd, _ipcMessage.header().cookie };\n \t\t\tIPCMessage _response(header);\n@@ -100,9 +99,8 @@ public:\n \t\t\tstd::tie(_callRetBuf, std::ignore) =\n \t\t\t\tIPADataSerializer<{{method|method_return_value}}>::serialize(_callRet);\n \t\t\t_response.data().insert(_response.data().end(), _callRetBuf.cbegin(), _callRetBuf.cend());\n-{%- else %}\n-\t\t{{proxy_funcs.serialize_call(method|method_param_outputs, \"_response.data()\", \"_response.fds()\")|indent(16, true)}}\n {%- endif %}\n+\t\t{{proxy_funcs.serialize_call(method|method_param_outputs, \"_response.data()\", \"_response.fds()\")|indent(16, true)}}\n \t\t\tint _ret = socket_.send(_response.payload());\n \t\t\tif (_ret < 0) {\n \t\t\t\tLOG({{proxy_worker_name}}, Error)\ndiff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\nindex f2d86b67..c2ac42fc 100644\n--- a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\n+++ b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\n@@ -135,8 +135,8 @@\n  #\n  # \\todo Avoid intermediate vectors\n  #}\n-{%- macro deserialize_call(params, buf, fds, pointer = true, declare = false, iter = false, data_size = '') -%}\n-{% set ns = namespace(size_offset = 0) %}\n+{%- macro deserialize_call(params, buf, fds, pointer = true, declare = false, iter = false, data_size = '', init_offset = 0) -%}\n+{% set ns = namespace(size_offset = init_offset) %}\n {%- if params|length > 1 %}\n {%- for param in params %}\n \t[[maybe_unused]] const size_t {{param.mojom_name}}BufSize = readPOD<uint32_t>({{buf}}, {{ns.size_offset}}\ndiff --git a/utils/ipc/generators/mojom_libcamera_generator.py b/utils/ipc/generators/mojom_libcamera_generator.py\nindex fa0c21a2..db9e28a6 100644\n--- a/utils/ipc/generators/mojom_libcamera_generator.py\n+++ b/utils/ipc/generators/mojom_libcamera_generator.py\n@@ -149,10 +149,16 @@ def MethodParamInputs(method):\n     return method.parameters\n \n def MethodParamOutputs(method):\n-    if (MethodReturnValue(method) != 'void' or\n-        method.response_parameters is None):\n+    if method.response_parameters is None:\n+        return []\n+\n+    if MethodReturnValue(method) == 'void':\n+        return method.response_parameters\n+\n+    if len(method.response_parameters) <= 1:\n         return []\n-    return method.response_parameters\n+\n+    return method.response_parameters[1:]\n \n def MethodParamsHaveFd(parameters):\n     return len([x for x in parameters if HasFd(x)]) > 0\n@@ -167,11 +173,8 @@ def MethodParamNames(method):\n     params = []\n     for param in method.parameters:\n         params.append(param.mojom_name)\n-    if MethodReturnValue(method) == 'void':\n-        if method.response_parameters is None:\n-            return params\n-        for param in method.response_parameters:\n-            params.append(param.mojom_name)\n+    for param in MethodParamOutputs(method):\n+        params.append(param.mojom_name)\n     return params\n \n def MethodParameters(method):\n@@ -180,18 +183,17 @@ def MethodParameters(method):\n         params.append('const %s %s%s' % (GetNameForElement(param),\n                                          '&' if not IsPod(param) else '',\n                                          param.mojom_name))\n-    if MethodReturnValue(method) == 'void':\n-        if method.response_parameters is None:\n-            return params\n-        for param in method.response_parameters:\n-            params.append(f'{GetNameForElement(param)} *{param.mojom_name}')\n+    for param in MethodParamOutputs(method):\n+        params.append(f'{GetNameForElement(param)} *{param.mojom_name}')\n     return params\n \n def MethodReturnValue(method):\n-    if method.response_parameters is None:\n+    if method.response_parameters is None or len(method.response_parameters) == 0:\n         return 'void'\n-    if len(method.response_parameters) == 1 and IsPod(method.response_parameters[0]):\n-        return GetNameForElement(method.response_parameters[0])\n+    first_output = method.response_parameters[0]\n+    if ((len(method.response_parameters) == 1 and IsPod(first_output)) or\n+        first_output.kind == mojom.INT32):\n+        return GetNameForElement(first_output)\n     return 'void'\n \n def IsAsync(method):\n@@ -237,6 +239,16 @@ def BitWidth(element):\n         return '32'\n     return ''\n \n+def ByteWidthFromCppType(t):\n+    key = None\n+    for mojo_type, cpp_type in _kind_to_cpp_type.items():\n+        if t == cpp_type:\n+            key = mojo_type\n+    if key is None:\n+        raise Exception('invalid type')\n+    return str(int(_bit_widths[key]) // 8)\n+\n+\n # Get the type name for a given element\n def GetNameForElement(element):\n     # structs\n@@ -373,6 +385,7 @@ class Generator(generator.Generator):\n         libcamera_filters = {\n             'all_types': GetAllTypes,\n             'bit_width': BitWidth,\n+            'byte_width' : ByteWidthFromCppType,\n             'cap': Capitalize,\n             'choose': Choose,\n             'comma_sep': CommaSep,\n","prefixes":["libcamera-devel","v2","2/3"]}