[{"id":2523,"web_url":"https://patchwork.libcamera.org/comment/2523/","msgid":"<20190828162013.rp6rxf3baaqbm3b5@uno.localdomain>","date":"2019-08-28T16:20:13","subject":"Re: [libcamera-devel] [PATCH 06/13] libcamera: controls: Allow read\n\tonly access to control values","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Wed, Aug 28, 2019 at 03:17:03AM +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 54efef1bb337e945..424fe515fa69f8d8 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -517,6 +517,40 @@ ControlValue &ControlList::operator[](ControlId id)\n>  \treturn controls_[&iter->second];\n>  }\n>\n> +/**\n> + * \\brief Access a control specified by \\a id\n> + * \\param[in] id The control ID\n> + *\n> + * This method returns a reference to the control identified by \\a id, if it\n> + * exsists or an empty control if it does not.\n\ns/exsists/exists\n\nI would rather return nullptr, both here and in the existing version\nof operator[], it would save creating the static empty control,\ndoesn't it?\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\nIf the control is not in the InfoMap returned by camera_->controls()\nwon't iter be == controls.end() ?\n\n> + *\n> + * \\return A 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 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> +\n> +\tconst auto it = controls_.find(&iter->second);\n> +\tif (it == controls_.end()) {\n> +\t\tLOG(Controls, Error) << \"list does not have control \" << id;\n> +\t\treturn empty;\n> +\t}\n\nNot on your patch, but why do we keep two lists of controls ??\n\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\n> --\n> 2.22.1\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 16FEA60BF6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Aug 2019 18:18:42 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 84E0640003;\n\tWed, 28 Aug 2019 16:18:41 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Wed, 28 Aug 2019 18:20:13 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190828162013.rp6rxf3baaqbm3b5@uno.localdomain>","References":"<20190828011710.32128-1-niklas.soderlund@ragnatech.se>\n\t<20190828011710.32128-7-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"szjjwtn37kijdiq7\"","Content-Disposition":"inline","In-Reply-To":"<20190828011710.32128-7-niklas.soderlund@ragnatech.se>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 06/13] libcamera: controls: Allow read\n\tonly 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, 28 Aug 2019 16:18:42 -0000"}},{"id":2529,"web_url":"https://patchwork.libcamera.org/comment/2529/","msgid":"<e21b0d86-c55c-ff9f-a3d6-ed3e9fa3e153@ideasonboard.com>","date":"2019-08-28T22:04:28","subject":"Re: [libcamera-devel] [PATCH 06/13] libcamera: controls: Allow read\n\tonly access to control values","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn 28/08/2019 17:20, Jacopo Mondi wrote:\n> Hi Niklas,\n> \n> On Wed, Aug 28, 2019 at 03:17:03AM +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 54efef1bb337e945..424fe515fa69f8d8 100644\n>> --- a/src/libcamera/controls.cpp\n>> +++ b/src/libcamera/controls.cpp\n>> @@ -517,6 +517,40 @@ ControlValue &ControlList::operator[](ControlId id)\n>>  \treturn controls_[&iter->second];\n>>  }\n>>\n>> +/**\n>> + * \\brief Access a control specified by \\a id\n>> + * \\param[in] id The control ID\n>> + *\n>> + * This method returns a reference to the control identified by \\a id, if it\n>> + * exsists or an empty control if it does not.\n> \n> s/exsists/exists\n> \n> I would rather return nullptr, both here and in the existing version\n> of operator[], it would save creating the static empty control,\n> doesn't it?\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> If the control is not in the InfoMap returned by camera_->controls()\n> won't iter be == controls.end() ?\n\nI think this refers to the fact that if you try to have a control in a\nControlList which is not supported by the Controls on the Camera then it\nis not valid.\n\n> \n>> + *\n>> + * \\return A 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 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>> +\n>> +\tconst auto it = controls_.find(&iter->second);\n>> +\tif (it == controls_.end()) {\n>> +\t\tLOG(Controls, Error) << \"list does not have control \" << id;\n>> +\t\treturn empty;\n>> +\t}\n> \n> Not on your patch, but why do we keep two lists of controls ??\n\nThis is a ControlList, which stores a list of controls as controls_.\n\nBut those Controls are required to be supported by the list of\ncamera_->controls(), as the ControlInfo data is specific to a camera.\n\nIOW, you can't generate a controllist from one camera and apply it to\nanother.\n\n--\nKieran\n\n\n> \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\n>> --\n>> 2.22.1\n>>\n>> _______________________________________________\n>> libcamera-devel mailing list\n>> libcamera-devel@lists.libcamera.org\n>> https://lists.libcamera.org/listinfo/libcamera-devel\n>>\n>> _______________________________________________\n>> libcamera-devel mailing list\n>> libcamera-devel@lists.libcamera.org\n>> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<kieran.bingham@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 861B260BF6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Aug 2019 00:04:31 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C06DD33E;\n\tThu, 29 Aug 2019 00:04:30 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1567029871;\n\tbh=ylcRcx+SEpDCYD7DhDrnjhAT9S1zXmWjh9fMThgOFho=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=ZWhkfzj/0o0Vi+XLRZvbuCECXRjJRz8BpxIvirOVQ6e6v7uOsopHatwFT+MSILEIk\n\tTtLLhCeUhx0sXEVUq3r/YWmCf7yqpmI3b86vYeC4nekPtgfKdGHhvV/5sZNVhTpbRJ\n\teVlo9GHukQ7XEuPswghZPUWIVoFeMvdmoaY9IzgQ=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Jacopo Mondi <jacopo@jmondi.org>, =?utf-8?q?Niklas_S=C3=B6derlund?=\n\t<niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","References":"<20190828011710.32128-1-niklas.soderlund@ragnatech.se>\n\t<20190828011710.32128-7-niklas.soderlund@ragnatech.se>\n\t<20190828162013.rp6rxf3baaqbm3b5@uno.localdomain>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDR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hA5qDUGEcKGCphpQffKhTNo/BP99jvmJUj7IPSKH97qPypi8/ym8bAxB+uY31\n\tgHTMHf1jMJJ1pRo2tYYPeIIHGDqXBI4sp5GHHF+JcIhgR/e/A6w/dgzHYmQPl2ix5eZYEZbV\n\tTRP+gkX4NV8oHqa/lR+xPOlWElGB57viOSOoWriqxQbFy8XbG1GR8cWlkNtGBGVWaJaSoORP\n\tiowD7irXL91bCyFIqL+7BVk3Jy4uzP744PzE80KwxOp5SQAp9sPzFbgsJrLev90PZySjFHG0\n\twP144DK7nBjOj/J0g9OHVASP1JjK+nw7SDoKnETDIdRC0XmiHXk7TXzPdkvO0UkpHdEPjZUp\n\tWyuc0MqehjR/hTTPt4m/Y14XzEcy6JREIjOrFfUZVho2QpOdv9CNryGdieRTNjUtz463CIaZ\n\tdPBiw9mOMBoNffkn9FIoCjLnAaj9gUAnEHWBZOEviQ5NuyqpeP0YtzI4iaRbSUkYZHej99X3\n\tVmHrdLlMqd/ZgYYbPGSL4AN3FVACb5CxuxEHwo029VcE5U3CSjzqtCoX12tm7A==","Organization":"Ideas on Board","Message-ID":"<e21b0d86-c55c-ff9f-a3d6-ed3e9fa3e153@ideasonboard.com>","Date":"Wed, 28 Aug 2019 23:04:28 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.8.0","MIME-Version":"1.0","In-Reply-To":"<20190828162013.rp6rxf3baaqbm3b5@uno.localdomain>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 06/13] libcamera: controls: Allow read\n\tonly 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, 28 Aug 2019 22:04:31 -0000"}}]