From patchwork Tue Jan 22 23:45:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 340 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 193A060C7F for ; Wed, 23 Jan 2019 00:46:44 +0100 (CET) X-Halon-ID: ebbfdc7c-1e9f-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id ebbfdc7c-1e9f-11e9-911a-0050569116f7; Wed, 23 Jan 2019 00:46:21 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Jan 2019 00:45:03 +0100 Message-Id: <20190122234505.32634-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190122234505.32634-1-niklas.soderlund@ragnatech.se> References: <20190122234505.32634-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/8] libcamera: camera: Add acquire() and release() 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: Tue, 22 Jan 2019 23:46:44 -0000 From: Laurent Pinchart Signed-off-by: Niklas Söderlund --- include/libcamera/camera.h | 5 +++++ src/libcamera/camera.cpp | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index b5d4dfe4b1f6a586..3cb1ab62b791ab87 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -27,12 +27,17 @@ public: void disconnect(); + int acquire(); + void release(); + private: explicit Camera(const std::string &name, class PipelineHandler *pipe); ~Camera(); std::string name_; class PipelineHandler *pipe_; + + bool acquired_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 496fb1021c4fccf0..ee5e6dedb242a1fd 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -103,7 +103,7 @@ void Camera::disconnect() } Camera::Camera(const std::string &name, class PipelineHandler *pipe) - : name_(name), pipe_(pipe) + : name_(name), pipe_(pipe), acquired_(false) { } @@ -111,4 +111,37 @@ Camera::~Camera() { } +/** + * \brief Acquire the camera device for exclusive access + * + * After opening the device with open(), exclusive access must be obtained + * before performing operations that change the device state. This function is + * not blocking, if the device has already been acquired (by the same or another + * process) the -EBUSY error code is returned. + * + * Once exclusive access isn't needed anymore, the device should be released + * with a call to the release() function. + * + * \return 0 on success or a negative error code on error. + */ +int Camera::acquire() +{ + if (acquired_) + return -EBUSY; + + acquired_ = true; + return 0; +} + +/** + * \brief Release exclusive access to the camera device + * + * Releasing the camera device allows other users to acquire exclusive access + * with the acquire() function. + */ +void Camera::release() +{ + acquired_ = false; +} + } /* namespace libcamera */