[libcamera-devel] simple-cam: Update to the new ControList::get() API
diff mbox series

Message ID 20220719122604.20709-1-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel] simple-cam: Update to the new ControList::get() API
Related show

Commit Message

Laurent Pinchart July 19, 2022, 12:26 p.m. UTC
The ControlList::get() function has changed and now returns a
std::optional<T>. Adapt simple-cam accordingly.

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


base-commit: bb97f3bbd96a9d347e1b7f6cb68d94efaf8db574

Comments

Kieran Bingham July 19, 2022, 12:38 p.m. UTC | #1
Quoting Laurent Pinchart (2022-07-19 13:26:04)
> The ControlList::get() function has changed and now returns a
> std::optional<T>. Adapt simple-cam accordingly.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  simple-cam.cpp | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/simple-cam.cpp b/simple-cam.cpp
> index 4de1b7de9ced..3e17839d17e6 100644
> --- a/simple-cam.cpp
> +++ b/simple-cam.cpp
> @@ -133,18 +133,22 @@ std::string cameraName(Camera *camera)
>         const ControlList &props = camera->properties();
>         std::string name;
>  
> -       switch (props.get(properties::Location)) {
> -       case properties::CameraLocationFront:
> -               name = "Internal front camera";
> -               break;
> -       case properties::CameraLocationBack:
> -               name = "Internal back camera";
> -               break;
> -       case properties::CameraLocationExternal:
> -               name = "External camera";
> -               if (props.contains(properties::Model))
> -                       name += " '" + props.get(properties::Model) + "'";
> -               break;
> +       const auto &location = props.get(properties::Location);
> +       if (location) {
> +               switch (*location) {
> +               case properties::CameraLocationFront:
> +                       name = "Internal front camera";
> +                       break;
> +               case properties::CameraLocationBack:
> +                       name = "Internal back camera";
> +                       break;
> +               case properties::CameraLocationExternal:
> +                       name = "External camera";
> +                       const auto &model = props.get(properties::Model);
> +                       if (model)
> +                               name = " '" + *model + "'";

I like that this saves double-lookups!
It's a shame we end up an extra level indented though.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +                       break;
> +               }
>         }
>  
>         name += " (" + camera->id() + ")";
> 
> base-commit: bb97f3bbd96a9d347e1b7f6cb68d94efaf8db574
> -- 
> Regards,
> 
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/simple-cam.cpp b/simple-cam.cpp
index 4de1b7de9ced..3e17839d17e6 100644
--- a/simple-cam.cpp
+++ b/simple-cam.cpp
@@ -133,18 +133,22 @@  std::string cameraName(Camera *camera)
 	const ControlList &props = camera->properties();
 	std::string name;
 
-	switch (props.get(properties::Location)) {
-	case properties::CameraLocationFront:
-		name = "Internal front camera";
-		break;
-	case properties::CameraLocationBack:
-		name = "Internal back camera";
-		break;
-	case properties::CameraLocationExternal:
-		name = "External camera";
-		if (props.contains(properties::Model))
-			name += " '" + props.get(properties::Model) + "'";
-		break;
+	const auto &location = props.get(properties::Location);
+	if (location) {
+		switch (*location) {
+		case properties::CameraLocationFront:
+			name = "Internal front camera";
+			break;
+		case properties::CameraLocationBack:
+			name = "Internal back camera";
+			break;
+		case properties::CameraLocationExternal:
+			name = "External camera";
+			const auto &model = props.get(properties::Model);
+			if (model)
+				name = " '" + *model + "'";
+			break;
+		}
 	}
 
 	name += " (" + camera->id() + ")";