[libcamera-devel] [RFC 1/2] libcamera: camera: Add CameraData
Jacopo Mondi
jacopo at jmondi.org
Tue Jan 22 19:12:24 CET 2019
Add abstract base class CameraData for pipeline handlers to store
pipeline specific data in Camera class instances.
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
include/libcamera/camera.h | 13 ++++++++++
src/libcamera/camera.cpp | 50 ++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
index 2ea1a68..50041f1 100644
--- a/include/libcamera/camera.h
+++ b/include/libcamera/camera.h
@@ -12,6 +12,15 @@
namespace libcamera {
+class CameraData
+{
+public:
+ virtual ~CameraData() { }
+protected:
+ CameraData() { }
+ CameraData(CameraData &) = delete;
+};
+
class Camera final
{
public:
@@ -22,11 +31,15 @@ public:
const std::string &name() const;
+ CameraData *cameraData() const { return data_.get(); }
+ void setCameraData(CameraData *data);
+
private:
explicit Camera(const std::string &name);
~Camera();
std::string name_;
+ std::unique_ptr<CameraData> data_;
};
} /* namespace libcamera */
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index acf912b..1e2c858 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -33,6 +33,26 @@
namespace libcamera {
+/**
+ * \class CameraData
+ * \brief Base class for platform specific data associated with a camera
+ *
+ * The CameraData base abstract class represents platform specific data
+ * a pipeline handler might want to associate with a Camera to access them
+ * at a later time.
+ *
+ * Pipeline handlers are expected to extend this base class with platform
+ * specific implementation, associate instances of the derived classes
+ * using the Camera::setCameraData() method, and access them at a later time
+ * with Camera::cameraData().
+ *
+ * Once associated with a camera, lifetime of derived classes instances will
+ * be tied to the one of the Camera instance itself.
+ *
+ * \sa Camera::setCameraData()
+ * \sa Camera::cameraData()
+ */
+
/**
* \class Camera
* \brief Camera device
@@ -83,6 +103,36 @@ const std::string &Camera::name() const
return name_;
}
+/**
+ * \fn CameraData *Camera::cameraData()
+ * \brief Retrieve the pipeline specific data
+ *
+ * Borrow a reference to the platform specific data, associated to a camera
+ * by pipeline handlers using the setCameraData() method.
+ */
+
+/**
+ * \brief Set pipeline specific data in the camera
+ *
+ * Pipeline handlers might need to associate platform-specific informations to
+ * camera instances, this method allows them to do so while also transferring
+ * ownership of the \a cameraData to the Camera instance.
+ *
+ * Pipeline specific data are stored as unique_ptr<> to guarantee its
+ * destruction at Camera deletion time.
+ *
+ * Pipeline specific data can be accessed again by pipeline handlers by
+ * borrowing a (mutable) reference using the cameraData() method.
+ *
+ * \sa Camera::cameraData()
+ * \sa CameraData
+ */
+void Camera::setCameraData(CameraData *data)
+{
+ data_ = std::unique_ptr<CameraData>(data);
+
+}
+
Camera::Camera(const std::string &name)
: name_(name)
{
--
2.20.1
More information about the libcamera-devel
mailing list