[libcamera-devel,3/3] Documentation: application-developer: Add camera detection check
diff mbox series

Message ID 20210926212108.22510-3-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel,1/3] Documentation: application-developer: Make global variable static
Related show

Commit Message

Laurent Pinchart Sept. 26, 2021, 9:21 p.m. UTC
The simple-cam application has a check to ensure that at least one
camera is present before attempting to access the first camera, to avoid
a crash. Update the application developer's guide accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 Documentation/guides/application-developer.rst | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart Sept. 26, 2021, 9:24 p.m. UTC | #1
On Mon, Sep 27, 2021 at 12:21:08AM +0300, Laurent Pinchart wrote:
> The simple-cam application has a check to ensure that at least one
> camera is present before attempting to access the first camera, to avoid
> a crash. Update the application developer's guide accordingly.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  Documentation/guides/application-developer.rst | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst
> index 41a7d88369be..11d3df15825b 100644
> --- a/Documentation/guides/application-developer.rst
> +++ b/Documentation/guides/application-developer.rst
> @@ -109,9 +109,16 @@ the Camera Manager reports as available to applications.
>  Camera devices are stored by the CameraManager in a list accessible by index, or
>  can be retrieved by name through the ``CameraManager::get()`` function. The
>  code below retrieves the name of the first available camera and gets the camera
> -by name from the Camera Manager.
> +by name from the Camera Manager, after making sure that at least one camera is
> +available.
>  
>  .. code:: cpp

This is obviously missing a blank line here :-S I'll fix it in v2 (or
when pushing if no v2 is otherwise needed).

> +   if (cm->cameras().empty()) {
> +       std::cout << "No cameras were identified on the system."
> +                 << std::endl;
> +       cm->stop();
> +       return EXIT_FAILURE;
> +   }
>  
>     std::string cameraId = cm->cameras()[0]->id();
>     camera = cm->get(cameraId);
Paul Elder Sept. 27, 2021, 6:57 a.m. UTC | #2
Hi Laurent,

On Mon, Sep 27, 2021 at 12:21:08AM +0300, Laurent Pinchart wrote:
> The simple-cam application has a check to ensure that at least one
> camera is present before attempting to access the first camera, to avoid
> a crash. Update the application developer's guide accordingly.

s/accordingly/to match this behavior/ ?

> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  Documentation/guides/application-developer.rst | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst
> index 41a7d88369be..11d3df15825b 100644
> --- a/Documentation/guides/application-developer.rst
> +++ b/Documentation/guides/application-developer.rst
> @@ -109,9 +109,16 @@ the Camera Manager reports as available to applications.
>  Camera devices are stored by the CameraManager in a list accessible by index, or
>  can be retrieved by name through the ``CameraManager::get()`` function. The
>  code below retrieves the name of the first available camera and gets the camera
> -by name from the Camera Manager.
> +by name from the Camera Manager, after making sure that at least one camera is
> +available.
>  
>  .. code:: cpp
> +   if (cm->cameras().empty()) {
> +       std::cout << "No cameras were identified on the system."
> +                 << std::endl;
> +       cm->stop();
> +       return EXIT_FAILURE;
> +   }
>  
>     std::string cameraId = cm->cameras()[0]->id();
>     camera = cm->get(cameraId);
> -- 
> Regards,
> 
> Laurent Pinchart
>
Kieran Bingham Sept. 27, 2021, 12:22 p.m. UTC | #3
On Mon, Sep 27, 2021 at 12:24:14AM +0300, Laurent Pinchart wrote:
> On Mon, Sep 27, 2021 at 12:21:08AM +0300, Laurent Pinchart wrote:
> > The simple-cam application has a check to ensure that at least one
> > camera is present before attempting to access the first camera, to avoid
> > a crash. Update the application developer's guide accordingly.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  Documentation/guides/application-developer.rst | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst
> > index 41a7d88369be..11d3df15825b 100644
> > --- a/Documentation/guides/application-developer.rst
> > +++ b/Documentation/guides/application-developer.rst
> > @@ -109,9 +109,16 @@ the Camera Manager reports as available to applications.
> >  Camera devices are stored by the CameraManager in a list accessible by index, or
> >  can be retrieved by name through the ``CameraManager::get()`` function. The
> >  code below retrieves the name of the first available camera and gets the camera
> > -by name from the Camera Manager.
> > +by name from the Camera Manager, after making sure that at least one camera is
> > +available.
> >  
> >  .. code:: cpp
> 
> This is obviously missing a blank line here :-S I'll fix it in v2 (or
> when pushing if no v2 is otherwise needed).
> 

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

> > +   if (cm->cameras().empty()) {
> > +       std::cout << "No cameras were identified on the system."
> > +                 << std::endl;
> > +       cm->stop();
> > +       return EXIT_FAILURE;
> > +   }
> >  
> >     std::string cameraId = cm->cameras()[0]->id();
> >     camera = cm->get(cameraId);
> 
> -- 
> Regards,
> 
> Laurent Pinchart

Patch
diff mbox series

diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst
index 41a7d88369be..11d3df15825b 100644
--- a/Documentation/guides/application-developer.rst
+++ b/Documentation/guides/application-developer.rst
@@ -109,9 +109,16 @@  the Camera Manager reports as available to applications.
 Camera devices are stored by the CameraManager in a list accessible by index, or
 can be retrieved by name through the ``CameraManager::get()`` function. The
 code below retrieves the name of the first available camera and gets the camera
-by name from the Camera Manager.
+by name from the Camera Manager, after making sure that at least one camera is
+available.
 
 .. code:: cpp
+   if (cm->cameras().empty()) {
+       std::cout << "No cameras were identified on the system."
+                 << std::endl;
+       cm->stop();
+       return EXIT_FAILURE;
+   }
 
    std::string cameraId = cm->cameras()[0]->id();
    camera = cm->get(cameraId);