[{"id":2718,"web_url":"https://patchwork.libcamera.org/comment/2718/","msgid":"<20190928201451.GC22755@pendragon.ideasonboard.com>","date":"2019-09-28T20:14:51","subject":"Re: [libcamera-devel] [PATCH v3 03/13] 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, Sep 27, 2019 at 04:44:07AM +0200, Niklas Söderlund wrote:\n> Allow the control values in a ControlList to be examined from a const\n> environment.\n\nI think this patch and the next one can be dropped if you rebase on top\nof the control rework series I've just sent.\n\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  include/libcamera/controls.h |  1 +\n>  src/libcamera/controls.cpp   | 35 +++++++++++++++++++++++++++++++++++\n>  2 files changed, 36 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 44cb09d9102d93f6..6271a0bd7518dda5 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -523,6 +523,41 @@ ControlValue &ControlList::operator[](ControlId id)\n>  \treturn controls_[&iter->second];\n>  }\n>  \n> +/**\n> + * \\brief Access the control specified by \\a id\n> + * \\param[in] id The control ID\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> + * 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 const reference to the value of the control identified by \\a id\n> + */\n> +const ControlValue &ControlList::operator[](ControlId id) const\n> +{\n> +\tconst ControlInfoMap &controls = camera_->controls();\n> +\tstatic ControlValue empty;\n> +\n> +\tconst auto camctrl = controls.find(id);\n> +\tif (camctrl == 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> +\n> +\tconst auto ctrl = controls_.find(&camctrl->second);\n> +\tif (ctrl == controls_.end()) {\n> +\t\tLOG(Controls, Error) << \"list does not have control \" << id;\n> +\t\treturn empty;\n> +\t}\n> +\n> +\treturn ctrl->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[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E2F8160BBA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 28 Sep 2019 22:15:02 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 48BFF53B;\n\tSat, 28 Sep 2019 22:15:02 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1569701702;\n\tbh=UYEsZrJiE7t1z96iEoHjIzy5R4NavVffjwpM+dipt3s=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=AEHgn1fGGEqepn7TDf543jwV5OGK+4nBNt3jEuZ4N07LbnVuMDPTeArYX6OmDsaWG\n\t35739goNqEA3xd7DtESdq27sAh2BLQgt9WQ52Ny2V+pfAPTnBCyNw6sYkbx0h3AgHm\n\tqEEupCMbarlGHJPACBztqzDBat9Aie9WzVOhIajc=","Date":"Sat, 28 Sep 2019 23:14:51 +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":"<20190928201451.GC22755@pendragon.ideasonboard.com>","References":"<20190927024417.725906-1-niklas.soderlund@ragnatech.se>\n\t<20190927024417.725906-4-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":"<20190927024417.725906-4-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 03/13] libcamera: controls: Allow\n\tread only access to control values","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>","X-List-Received-Date":"Sat, 28 Sep 2019 20:15:03 -0000"}}]