[libcamera-devel,v3,12/33] cam: stream_options: Use OptionValue::empty() to test if option is set
diff mbox series

Message ID 20210715211459.19373-13-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Multi-camera support in the cam application
Related show

Commit Message

Laurent Pinchart July 15, 2021, 9:14 p.m. UTC
The roles() and updateConfiguration() functions check if the OptStream
OptionValue they receive is empty by first casting it to an array. To
prepare for the toArray() function not allowing such a cast when the
option value is empty, test if the option value is empty instead.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/cam/stream_options.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Jacopo Mondi July 22, 2021, 12:52 p.m. UTC | #1
Hi Laurent,

On Fri, Jul 16, 2021 at 12:14:38AM +0300, Laurent Pinchart wrote:
> The roles() and updateConfiguration() functions check if the OptStream
> OptionValue they receive is empty by first casting it to an array. To
> prepare for the toArray() function not allowing such a cast when the
> option value is empty, test if the option value is empty instead.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
   j

> ---
>  src/cam/stream_options.cpp | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp
> index b90dbb97f087..150bd27caecf 100644
> --- a/src/cam/stream_options.cpp
> +++ b/src/cam/stream_options.cpp
> @@ -40,12 +40,12 @@ KeyValueParser::Options StreamKeyValueParser::parse(const char *arguments)
>
>  StreamRoles StreamKeyValueParser::roles(const OptionValue &values)
>  {
> -	const std::vector<OptionValue> &streamParameters = values.toArray();
> -
>  	/* If no configuration values to examine default to viewfinder. */
> -	if (streamParameters.empty())
> +	if (values.empty())
>  		return { StreamRole::Viewfinder };
>
> +	const std::vector<OptionValue> &streamParameters = values.toArray();
> +
>  	StreamRoles roles;
>  	for (auto const &value : streamParameters) {
>  		StreamRole role;
> @@ -63,17 +63,17 @@ StreamRoles StreamKeyValueParser::roles(const OptionValue &values)
>  int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,
>  					      const OptionValue &values)
>  {
> -	const std::vector<OptionValue> &streamParameters = values.toArray();
> -
>  	if (!config) {
>  		std::cerr << "No configuration provided" << std::endl;
>  		return -EINVAL;
>  	}
>
>  	/* If no configuration values nothing to do. */
> -	if (!streamParameters.size())
> +	if (values.empty())
>  		return 0;
>
> +	const std::vector<OptionValue> &streamParameters = values.toArray();
> +
>  	if (config->size() != streamParameters.size()) {
>  		std::cerr
>  			<< "Number of streams in configuration "
> --
> Regards,
>
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp
index b90dbb97f087..150bd27caecf 100644
--- a/src/cam/stream_options.cpp
+++ b/src/cam/stream_options.cpp
@@ -40,12 +40,12 @@  KeyValueParser::Options StreamKeyValueParser::parse(const char *arguments)
 
 StreamRoles StreamKeyValueParser::roles(const OptionValue &values)
 {
-	const std::vector<OptionValue> &streamParameters = values.toArray();
-
 	/* If no configuration values to examine default to viewfinder. */
-	if (streamParameters.empty())
+	if (values.empty())
 		return { StreamRole::Viewfinder };
 
+	const std::vector<OptionValue> &streamParameters = values.toArray();
+
 	StreamRoles roles;
 	for (auto const &value : streamParameters) {
 		StreamRole role;
@@ -63,17 +63,17 @@  StreamRoles StreamKeyValueParser::roles(const OptionValue &values)
 int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,
 					      const OptionValue &values)
 {
-	const std::vector<OptionValue> &streamParameters = values.toArray();
-
 	if (!config) {
 		std::cerr << "No configuration provided" << std::endl;
 		return -EINVAL;
 	}
 
 	/* If no configuration values nothing to do. */
-	if (!streamParameters.size())
+	if (values.empty())
 		return 0;
 
+	const std::vector<OptionValue> &streamParameters = values.toArray();
+
 	if (config->size() != streamParameters.size()) {
 		std::cerr
 			<< "Number of streams in configuration "