From patchwork Wed Feb 6 06:08:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 531 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AA7B56101F for ; Wed, 6 Feb 2019 07:08:27 +0100 (CET) Received: from pendragon.ideasonboard.com (d51A4137F.access.telenet.be [81.164.19.127]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4DA5B2D7 for ; Wed, 6 Feb 2019 07:08:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549433307; bh=Ae3SwmEM8GyAopNtp+dAlcyU3evcdUf6DpcGsF2unv8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HuEZMh1ORf4aeUc3F3/Wk9tFOvS2tcIhTcMEQ5h0nCcLtaB68z1hNmGEMGmNKpMyY 9ava9FWx/7LxRDEO2fcY3uIDVUsILPsVHu6/BBH7uj2v8ZsroCbua5Gc8IFYcF1vNH sbC14R8+6JWyS5eRqakBZsqK32p/qDu2le0fu1UQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Feb 2019 08:08:08 +0200 Message-Id: <20190206060818.13907-18-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> References: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 17/27] libcamera: camera: Add helper to check for exclusive access X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Feb 2019 06:08:29 -0000 From: Niklas Söderlund Some operations on the camera requires the application to have exclusive access to the camera. To help check for this in these operations add a helper. Signed-off-by: Niklas Söderlund Signed-off-by: Jacopo Mondi Signed-off-by: Kieran Bingham Signed-off-by: Laurent Pinchart --- include/libcamera/camera.h | 1 + src/libcamera/camera.cpp | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index bbe2696e837b..36bf1cbb215b 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -50,6 +50,7 @@ private: friend class PipelineHandler; void disconnect(); + int exclusiveAccess(); std::shared_ptr pipe_; std::string name_; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index e8dab6f0bab2..62291d2c9e6c 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -240,6 +240,23 @@ Camera::streamConfiguration(std::vector &streams) * \retval -EINVAL The configuration is not valid */ int Camera::configureStreams(std::map &config) +{ + int ret; + + ret = exclusiveAccess(); + if (ret) + return ret; + + if (!config.size()) { + LOG(Camera, Error) + << "Can't configure streams without a configuration"; + return -EINVAL; + } + + return pipe_->configureStreams(this, config); +} + +int Camera::exclusiveAccess() { if (disconnected_) return -ENODEV; @@ -247,10 +264,7 @@ int Camera::configureStreams(std::map &config) if (!acquired_) return -EACCES; - if (!config.size()) - return -EINVAL; - - return pipe_->configureStreams(this, config); + return 0; } } /* namespace libcamera */