From patchwork Sun Sep 26 21:21:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13942 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BECA8BDC71 for ; Sun, 26 Sep 2021 21:21:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 192AB69196; Sun, 26 Sep 2021 23:21:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bgRMjNTY"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B49BE6918C for ; Sun, 26 Sep 2021 23:21:17 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 565C0EF for ; Sun, 26 Sep 2021 23:21:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1632691277; bh=TR+ZJaJoSYN3LVeVnSyz1vepTTzQqgphN7g9/FMDlEs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bgRMjNTYmDWt44Yyxblp5LGxjSYwkTfAcnBwBfIdpYztUu7fL4GkYBVnMAUxSc+EF 3MqoPNQiPI1V3BxwRECjuJnsz91/EbFnHnr9YiFLrU8fGhoiuEwoXcj8q+PCtt0Vkc OjO/XAoUvSoLl7qVZdirLNNyjunbtXpz1G5OmS/A= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Sep 2021 00:21:08 +0300 Message-Id: <20210926212108.22510-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210926212108.22510-1-laurent.pinchart@ideasonboard.com> References: <20210926212108.22510-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] Documentation: application-developer: Add camera detection check X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- 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);