[{"id":2603,"web_url":"https://patchwork.libcamera.org/comment/2603/","msgid":"<20190904182325.GG5433@pendragon.ideasonboard.com>","date":"2019-09-04T18:23:25","subject":"Re: [libcamera-devel] [PATCH v2 07/14] libcamera: controls: Allow\n\tread only access to control values","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Fri, Aug 30, 2019 at 01:26:46AM +0200, Niklas Söderlund wrote:\n> Allow the control values in a ControlList to be examined from a const\n> environment.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  include/libcamera/controls.h |  1 +\n>  src/libcamera/controls.cpp   | 34 ++++++++++++++++++++++++++++++++++\n>  2 files changed, 35 insertions(+)\n> \n> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\n> index fbb3a62274c64259..eee5ef87b8fd2633 100644\n> --- a/include/libcamera/controls.h\n> +++ b/include/libcamera/controls.h\n> @@ -124,6 +124,7 @@ public:\n>  \tvoid clear() { controls_.clear(); }\n>  \n>  \tControlValue &operator[](ControlId id);\n> +\tconst ControlValue &operator[](ControlId id) const;\n>  \tControlValue &operator[](const ControlInfo *info) { return controls_[info]; }\n>  \n>  \tvoid update(const ControlList &list);\n> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> index 35861e27401d5241..12cbf778408ee8e7 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -521,6 +521,40 @@ ControlValue &ControlList::operator[](ControlId id)\n>  \treturn controls_[&iter->second];\n>  }\n>  \n> +/**\n> + * \\brief Access a control specified by \\a id\n\ns/a control/the control/ to match the non-const version.\n\n> + * \\param[in] id The control ID\n> + *\n> + * This method returns a reference to the control identified by \\a id, if it\n> + * exists or an empty control if it does not.\n\ns/, if it exists/ if it exists,/\n\nI would actually not use \"exist\" as thats ambiguous (where does it\nexist, in the control list or in the camera ?).\n\n * This method returns a const reference to the control identified by \\a id. If\n * no such controls is present in the list, a const reference to an empty\n * control value is returned.\n\n> + *\n> + * The behaviour is undefined if the control \\a id is not supported by the\n> + * camera that the ControlList refers to.\n> + *\n> + * \\return A reference to the value of the control identified by \\a id\n\ns/A reference/A const reference/\n\n> + */\n> +const ControlValue &ControlList::operator[](ControlId id) const\n> +{\n> +\tconst ControlInfoMap &controls = camera_->controls();\n> +\tstatic ControlValue empty;\n> +\n> +\tconst auto iter = controls.find(id);\n> +\tif (iter == controls.end()) {\n> +\t\tLOG(Controls, Error)\n> +\t\t\t<< \"Camera \" << camera_->name()\n> +\t\t\t<< \" does not support control \" << id;\n> +\t\treturn empty;\n> +\t}\n\nThis is common to the non-const version of the function, so I wonder if\nit should be moved to a separate private method. It could be a bit\noverkill.\n\n> +\n> +\tconst auto it = controls_.find(&iter->second);\n\niter and it isn't a good idea, please use more explicit names.\n\n> +\tif (it == controls_.end()) {\n> +\t\tLOG(Controls, Error) << \"list does not have control \" << id;\n> +\t\treturn empty;\n> +\t}\n> +\n> +\treturn it->second;\n> +}\n> +\n>  /**\n>   * \\fn ControlList::operator[](const ControlInfo *info)\n>   * \\brief Access or insert the control specified by \\a info","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C52760BB2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  4 Sep 2019 20:23:32 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 99A29440;\n\tWed,  4 Sep 2019 20:23:31 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1567621411;\n\tbh=0FwLEjyw2HQCf4ra2dj3lzxIGR4UPg90XgfOOhfCkA4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tHL4jtxB2bsp927ecMdlH/UKJ2gZRs8s/sxKi4974C8Oqb5eJSs2sn4Dr4pmJWKZ6\n\t7V8+MVjStJHiZssKEiwSQtFX38yyALwQAFHVxIag5UwNF17e8Wn6xbbE6L+RVEJcbw\n\tzyCc+NZuJdXMZ/7NJD7L2efgn3msuMHYP2eEHwjY=","Date":"Wed, 4 Sep 2019 21:23:25 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190904182325.GG5433@pendragon.ideasonboard.com>","References":"<20190829232653.13214-1-niklas.soderlund@ragnatech.se>\n\t<20190829232653.13214-8-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190829232653.13214-8-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2 07/14] libcamera: controls: Allow\n\tread only access to control values","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Wed, 04 Sep 2019 18:23:32 -0000"}}]