[libcamera-devel,RFC,1/4] libcamera: camera: Add acquire() and release()

Message ID 20190121230640.8783-2-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • libcamera: add base for applications to configure cameras
Related show

Commit Message

Niklas Söderlund Jan. 21, 2019, 11:06 p.m. UTC
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

---
 include/libcamera/camera.h |  5 +++++
 src/libcamera/camera.cpp   | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

Patch

diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
index 2ea1a6883311cf9f..03b285c840c246e1 100644
--- a/include/libcamera/camera.h
+++ b/include/libcamera/camera.h
@@ -22,11 +22,16 @@  public:
 
 	const std::string &name() const;
 
+	int acquire();
+	void release();
+
 private:
 	explicit Camera(const std::string &name);
 	~Camera();
 
 	std::string name_;
+
+	bool acquired_;
 };
 
 } /* namespace libcamera */
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index acf912bee95cbec4..b80bc36e410a6e0a 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -92,4 +92,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 */