[{"id":27298,"web_url":"https://patchwork.libcamera.org/comment/27298/","msgid":"<168613677788.2889415.7044326311221261545@Monstersaurus>","date":"2023-06-07T11:19:37","subject":"Re: [libcamera-devel] [PATCH v1 2/3] ipa: rpi: agc: Use std::string\n\tinstead of char arrays","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Naush,\n\nQuoting Naushir Patuck via libcamera-devel (2023-06-07 11:00:53)\n> Replace the char array strings in struct AgcStatus with std::string\n> objects. This simplifies the string handling in the source code.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\nThis seems better/cleaner indeed.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/ipa/rpi/controller/agc_status.h |  8 +++++---\n>  src/ipa/rpi/controller/rpi/agc.cpp  | 23 +++++++----------------\n>  2 files changed, 12 insertions(+), 19 deletions(-)\n> \n> diff --git a/src/ipa/rpi/controller/agc_status.h b/src/ipa/rpi/controller/agc_status.h\n> index 6abf09d9df57..6c112e76aa12 100644\n> --- a/src/ipa/rpi/controller/agc_status.h\n> +++ b/src/ipa/rpi/controller/agc_status.h\n> @@ -6,6 +6,8 @@\n>   */\n>  #pragma once\n>  \n> +#include <string>\n> +\n>  #include <libcamera/base/utils.h>\n>  \n>  /*\n> @@ -24,9 +26,9 @@ struct AgcStatus {\n>         libcamera::utils::Duration targetExposureValue; /* (unfiltered) target total exposure AGC is aiming for */\n>         libcamera::utils::Duration shutterTime;\n>         double analogueGain;\n> -       char exposureMode[32];\n> -       char constraintMode[32];\n> -       char meteringMode[32];\n> +       std::string exposureMode;\n> +       std::string constraintMode;\n> +       std::string meteringMode;\n>         double ev;\n>         libcamera::utils::Duration flickerPeriod;\n>         int floatingRegionEnable;\n> diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp\n> index e79c82e2e65b..b611157af1f0 100644\n> --- a/src/ipa/rpi/controller/rpi/agc.cpp\n> +++ b/src/ipa/rpi/controller/rpi/agc.cpp\n> @@ -226,7 +226,7 @@ Agc::Agc(Controller *controller)\n>          * Setting status_.totalExposureValue_ to zero initially tells us\n>          * it's not been calculated yet (i.e. Process hasn't yet run).\n>          */\n> -       memset(&status_, 0, sizeof(status_));\n> +       status_ = {};\n>         status_.ev = ev_;\n>  }\n>  \n> @@ -524,12 +524,6 @@ void Agc::updateLockStatus(DeviceStatus const &deviceStatus)\n>         status_.locked = lockCount_ == maxLockCount;\n>  }\n>  \n> -static void copyString(std::string const &s, char *d, size_t size)\n> -{\n> -       size_t length = s.copy(d, size - 1);\n> -       d[length] = '\\0';\n> -}\n> -\n>  void Agc::housekeepConfig()\n>  {\n>         /* First fetch all the up-to-date settings, so no one else has to do it. */\n> @@ -544,30 +538,27 @@ void Agc::housekeepConfig()\n>          * Make sure the \"mode\" pointers point to the up-to-date things, if\n>          * they've changed.\n>          */\n> -       if (strcmp(meteringModeName_.c_str(), status_.meteringMode)) {\n> +       if (meteringModeName_ != status_.meteringMode) {\n>                 auto it = config_.meteringModes.find(meteringModeName_);\n>                 if (it == config_.meteringModes.end())\n>                         LOG(RPiAgc, Fatal) << \"No metering mode \" << meteringModeName_;\n>                 meteringMode_ = &it->second;\n> -               copyString(meteringModeName_, status_.meteringMode,\n> -                          sizeof(status_.meteringMode));\n> +               status_.meteringMode = meteringModeName_;\n>         }\n> -       if (strcmp(exposureModeName_.c_str(), status_.exposureMode)) {\n> +       if (exposureModeName_ != status_.exposureMode) {\n>                 auto it = config_.exposureModes.find(exposureModeName_);\n>                 if (it == config_.exposureModes.end())\n>                         LOG(RPiAgc, Fatal) << \"No exposure profile \" << exposureModeName_;\n>                 exposureMode_ = &it->second;\n> -               copyString(exposureModeName_, status_.exposureMode,\n> -                          sizeof(status_.exposureMode));\n> +               status_.exposureMode = exposureModeName_;\n>         }\n> -       if (strcmp(constraintModeName_.c_str(), status_.constraintMode)) {\n> +       if (constraintModeName_ != status_.constraintMode) {\n>                 auto it =\n>                         config_.constraintModes.find(constraintModeName_);\n>                 if (it == config_.constraintModes.end())\n>                         LOG(RPiAgc, Fatal) << \"No constraint list \" << constraintModeName_;\n>                 constraintMode_ = &it->second;\n> -               copyString(constraintModeName_, status_.constraintMode,\n> -                          sizeof(status_.constraintMode));\n> +               status_.constraintMode = constraintModeName_;\n>         }\n>         LOG(RPiAgc, Debug) << \"exposureMode \"\n>                            << exposureModeName_ << \" constraintMode \"\n> -- \n> 2.34.1\n>","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 F21BEC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  7 Jun 2023 11:19:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B493662896;\n\tWed,  7 Jun 2023 13:19:42 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9856A62886\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  7 Jun 2023 13:19:40 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 96A792B6;\n\tWed,  7 Jun 2023 13:19:14 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1686136782;\n\tbh=tajXIeH6Cp0G7uGjRDC/IqJXJWZa7h0Ljc6JAGfJMws=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=ApYMyqlebR0Zib6rs+BqZtxI1XLzNmGQ4NjKxOUZxqppQhEomdH8DTQ1+3zHMn8ee\n\tON3IMyWBeSQXPnnu1dtqe5YRKdzZwPSZKYJDInkgM7iCS14/yffMgtPFU/QPbN6HnL\n\tHeRkqPqqOUVPGlKLJL727yqrG+/TF8TczRQ7IFDN/eW96gLNXfCayqy3grUPDgd9UV\n\t/hGo7yfP/KbXoqNzsERcNRz86ea75L7kb3hJOdXnYjJ0HnPOsCDMU6G5N744cSl86N\n\t7vrxceQsDca3dfNU9dwS/s+ATRTqn2Okuqup9V1NdYNAwuyiZEKSSyj3e7SdcjVetR\n\t1eTpt95mDyrhQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1686136754;\n\tbh=tajXIeH6Cp0G7uGjRDC/IqJXJWZa7h0Ljc6JAGfJMws=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=AOVpGU2bFYWcMX66elQun9df1eeiVzjN9mqVKvF3srbN4VwwnTB/cZrZfq/9WLpnM\n\t0x7CmOgEPUJpxboc8Ctr22fdjnEIo2rwGUHefyAs6n4420ULA2D36ZzI7XLMieHZux\n\tnE1KesExXgoVjvX4+AUaMFG+bCyWnnQN9zzeE9E4="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"AOVpGU2b\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20230607100054.4576-3-naush@raspberrypi.com>","References":"<20230607100054.4576-1-naush@raspberrypi.com>\n\t<20230607100054.4576-3-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 07 Jun 2023 12:19:37 +0100","Message-ID":"<168613677788.2889415.7044326311221261545@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v1 2/3] ipa: rpi: agc: Use std::string\n\tinstead of char arrays","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27304,"web_url":"https://patchwork.libcamera.org/comment/27304/","msgid":"<20230607150208.GD22127@pendragon.ideasonboard.com>","date":"2023-06-07T15:02:08","subject":"Re: [libcamera-devel] [PATCH v1 2/3] ipa: rpi: agc: Use std::string\n\tinstead of char arrays","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Naush,\n\nThank you for the patch.\n\nOn Wed, Jun 07, 2023 at 11:00:53AM +0100, Naushir Patuck via libcamera-devel wrote:\n> Replace the char array strings in struct AgcStatus with std::string\n> objects. This simplifies the string handling in the source code.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI wonder, however, if it wouldn't be even better to switch the Agc class\nAPI to using enums instead of strings for the modes. ipa_base.cpp\nconverts from enums to strings, the conversion would be better placed in\nagc.cpp I think. This would allow turning the cached mode names into\nenums too, taking up less space, and making the comparison operations\nmore effective.\n\n> ---\n>  src/ipa/rpi/controller/agc_status.h |  8 +++++---\n>  src/ipa/rpi/controller/rpi/agc.cpp  | 23 +++++++----------------\n>  2 files changed, 12 insertions(+), 19 deletions(-)\n> \n> diff --git a/src/ipa/rpi/controller/agc_status.h b/src/ipa/rpi/controller/agc_status.h\n> index 6abf09d9df57..6c112e76aa12 100644\n> --- a/src/ipa/rpi/controller/agc_status.h\n> +++ b/src/ipa/rpi/controller/agc_status.h\n> @@ -6,6 +6,8 @@\n>   */\n>  #pragma once\n>  \n> +#include <string>\n> +\n>  #include <libcamera/base/utils.h>\n>  \n>  /*\n> @@ -24,9 +26,9 @@ struct AgcStatus {\n>  \tlibcamera::utils::Duration targetExposureValue; /* (unfiltered) target total exposure AGC is aiming for */\n>  \tlibcamera::utils::Duration shutterTime;\n>  \tdouble analogueGain;\n> -\tchar exposureMode[32];\n> -\tchar constraintMode[32];\n> -\tchar meteringMode[32];\n> +\tstd::string exposureMode;\n> +\tstd::string constraintMode;\n> +\tstd::string meteringMode;\n>  \tdouble ev;\n>  \tlibcamera::utils::Duration flickerPeriod;\n>  \tint floatingRegionEnable;\n> diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp\n> index e79c82e2e65b..b611157af1f0 100644\n> --- a/src/ipa/rpi/controller/rpi/agc.cpp\n> +++ b/src/ipa/rpi/controller/rpi/agc.cpp\n> @@ -226,7 +226,7 @@ Agc::Agc(Controller *controller)\n>  \t * Setting status_.totalExposureValue_ to zero initially tells us\n>  \t * it's not been calculated yet (i.e. Process hasn't yet run).\n>  \t */\n> -\tmemset(&status_, 0, sizeof(status_));\n> +\tstatus_ = {};\n>  \tstatus_.ev = ev_;\n>  }\n>  \n> @@ -524,12 +524,6 @@ void Agc::updateLockStatus(DeviceStatus const &deviceStatus)\n>  \tstatus_.locked = lockCount_ == maxLockCount;\n>  }\n>  \n> -static void copyString(std::string const &s, char *d, size_t size)\n> -{\n> -\tsize_t length = s.copy(d, size - 1);\n> -\td[length] = '\\0';\n> -}\n> -\n>  void Agc::housekeepConfig()\n>  {\n>  \t/* First fetch all the up-to-date settings, so no one else has to do it. */\n> @@ -544,30 +538,27 @@ void Agc::housekeepConfig()\n>  \t * Make sure the \"mode\" pointers point to the up-to-date things, if\n>  \t * they've changed.\n>  \t */\n> -\tif (strcmp(meteringModeName_.c_str(), status_.meteringMode)) {\n> +\tif (meteringModeName_ != status_.meteringMode) {\n>  \t\tauto it = config_.meteringModes.find(meteringModeName_);\n>  \t\tif (it == config_.meteringModes.end())\n>  \t\t\tLOG(RPiAgc, Fatal) << \"No metering mode \" << meteringModeName_;\n>  \t\tmeteringMode_ = &it->second;\n> -\t\tcopyString(meteringModeName_, status_.meteringMode,\n> -\t\t\t   sizeof(status_.meteringMode));\n> +\t\tstatus_.meteringMode = meteringModeName_;\n>  \t}\n> -\tif (strcmp(exposureModeName_.c_str(), status_.exposureMode)) {\n> +\tif (exposureModeName_ != status_.exposureMode) {\n>  \t\tauto it = config_.exposureModes.find(exposureModeName_);\n>  \t\tif (it == config_.exposureModes.end())\n>  \t\t\tLOG(RPiAgc, Fatal) << \"No exposure profile \" << exposureModeName_;\n>  \t\texposureMode_ = &it->second;\n> -\t\tcopyString(exposureModeName_, status_.exposureMode,\n> -\t\t\t   sizeof(status_.exposureMode));\n> +\t\tstatus_.exposureMode = exposureModeName_;\n>  \t}\n> -\tif (strcmp(constraintModeName_.c_str(), status_.constraintMode)) {\n> +\tif (constraintModeName_ != status_.constraintMode) {\n>  \t\tauto it =\n>  \t\t\tconfig_.constraintModes.find(constraintModeName_);\n>  \t\tif (it == config_.constraintModes.end())\n>  \t\t\tLOG(RPiAgc, Fatal) << \"No constraint list \" << constraintModeName_;\n>  \t\tconstraintMode_ = &it->second;\n> -\t\tcopyString(constraintModeName_, status_.constraintMode,\n> -\t\t\t   sizeof(status_.constraintMode));\n> +\t\tstatus_.constraintMode = constraintModeName_;\n>  \t}\n>  \tLOG(RPiAgc, Debug) << \"exposureMode \"\n>  \t\t\t   << exposureModeName_ << \" constraintMode \"","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 CB967C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  7 Jun 2023 15:02:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3CB6F62896;\n\tWed,  7 Jun 2023 17:02:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F0B0162886\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  7 Jun 2023 17:02:11 +0200 (CEST)","from pendragon.ideasonboard.com (om126233170111.36.openmobile.ne.jp\n\t[126.233.170.111])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C30802B6;\n\tWed,  7 Jun 2023 17:01:44 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1686150133;\n\tbh=7A26Fw35ugCKE6uHvnJ0fDvPBciMK80oGKxCd37U1Hw=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=vn05TDUFUTDVM8pboUv0RupjxHp9aNeBur6psC+6IeKjbizgqMtoWLSpKKZIc2q8o\n\tXjOpVxcvBQvxCaHSkMeNmhIAY5wVAtNjtAWFWJpjkcX28mt57gAQ5FU96xtATf4fQh\n\tXWJZ/K1EKLskuQR/oHRZV2jVVytAppYTPk2gmyso08YSJFl+7V3n59uAgMS+E0CzCu\n\tK3ZCnfKPTO43LyU7QlkURhfm0jBQZmKLgWksm0Cd59QMKqVlnYfp2CKQeedI1e5JVw\n\tx9fPfDna36vzxQE76+g3svUEzwhlzJONGvdWmiCqeVMv6mtiPBKkN7NURwjWrmJEwH\n\tTERDhx0XomAiA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1686150105;\n\tbh=7A26Fw35ugCKE6uHvnJ0fDvPBciMK80oGKxCd37U1Hw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Zrm2w4u1ydbbd9bHvC0Dda2L+DKlSh5xMCcgQDEfjqb+9kiESQgnBzq6fHCQpQKeL\n\td6KaZIHLO6qna2plfcZdn5w6p+0FmvXDZh2AiV4TTVzDRcL6352mhdounInZAoQUdt\n\tvfYaZBSQqIeb5ZPuaIVDFGtVU+Iv+eJ8HXmrb+iQ="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Zrm2w4u1\"; dkim-atps=neutral","Date":"Wed, 7 Jun 2023 18:02:08 +0300","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<20230607150208.GD22127@pendragon.ideasonboard.com>","References":"<20230607100054.4576-1-naush@raspberrypi.com>\n\t<20230607100054.4576-3-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230607100054.4576-3-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v1 2/3] ipa: rpi: agc: Use std::string\n\tinstead of char arrays","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]