[libcamera-devel,v2,1/3] libcamera: pipeline_handler: Add const version of cameraData()

Message ID 20200814104509.189023-2-niklas.soderlund@ragnatech.se
State Accepted
Commit ef5f5c4db05e5d88d58b0d565f7716c59751b991
Headers show
Series
  • libcamera: Mark controls and property accessors as const operations
Related show

Commit Message

Niklas Söderlund Aug. 14, 2020, 10:45 a.m. UTC
Add a version of camerData() that returns a const pointer and mark it as
a const operation. The assert in the non-const version of the function
already enforces that a std::map::at() operation would always succeed so
there is no change in operation from the non-const version.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
* Changes since v1
- Do not change current implementation add a new version that returns a
  const pointer.
---
 include/libcamera/internal/pipeline_handler.h |  1 +
 src/libcamera/pipeline_handler.cpp            | 13 +++++++++++++
 2 files changed, 14 insertions(+)

Comments

Kieran Bingham Aug. 14, 2020, 10:56 a.m. UTC | #1
Hi Niklas,

On 14/08/2020 11:45, Niklas Söderlund wrote:
> Add a version of camerData() that returns a const pointer and mark it as

cameraData()

> a const operation. The assert in the non-const version of the function
> already enforces that a std::map::at() operation would always succeed so
> there is no change in operation from the non-const version.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
> * Changes since v1
> - Do not change current implementation add a new version that returns a
>   const pointer.
> ---
>  include/libcamera/internal/pipeline_handler.h |  1 +
>  src/libcamera/pipeline_handler.cpp            | 13 +++++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
> index 22e629a8401d1e4e..c1873df00b6a2a28 100644
> --- a/include/libcamera/internal/pipeline_handler.h
> +++ b/include/libcamera/internal/pipeline_handler.h
> @@ -97,6 +97,7 @@ protected:
>  	virtual int queueRequestDevice(Camera *camera, Request *request) = 0;
>  
>  	CameraData *cameraData(const Camera *camera);
> +	const CameraData *cameraData(const Camera *camera) const;
>  
>  	CameraManager *manager_;
>  
> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
> index ccd45edc847b9e3f..73c51972a225a247 100644
> --- a/src/libcamera/pipeline_handler.cpp
> +++ b/src/libcamera/pipeline_handler.cpp
> @@ -601,6 +601,19 @@ CameraData *PipelineHandler::cameraData(const Camera *camera)
>  	return cameraData_[camera].get();
>  }
>  
> +/**
> + * \brief Retrieve the pipeline-specific data associated with a Camera
> + * \param[in] camera The camera whose data to retrieve
> + * \sa cameraData()
> + * \return A const pointer to the pipeline-specific data passed to
> + * registerCamera().
> + */
> +const CameraData *PipelineHandler::cameraData(const Camera *camera) const
> +{
> +	ASSERT(cameraData_.count(camera));
> +	return cameraData_.at(camera).get();

I wonder if we should unify the code across both of these functions now,
so they both use the same mechanism.


But that's not essential, they both work.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +}
> +
>  /**
>   * \var PipelineHandler::manager_
>   * \brief The Camera manager associated with the pipeline handler
>

Patch

diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
index 22e629a8401d1e4e..c1873df00b6a2a28 100644
--- a/include/libcamera/internal/pipeline_handler.h
+++ b/include/libcamera/internal/pipeline_handler.h
@@ -97,6 +97,7 @@  protected:
 	virtual int queueRequestDevice(Camera *camera, Request *request) = 0;
 
 	CameraData *cameraData(const Camera *camera);
+	const CameraData *cameraData(const Camera *camera) const;
 
 	CameraManager *manager_;
 
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index ccd45edc847b9e3f..73c51972a225a247 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -601,6 +601,19 @@  CameraData *PipelineHandler::cameraData(const Camera *camera)
 	return cameraData_[camera].get();
 }
 
+/**
+ * \brief Retrieve the pipeline-specific data associated with a Camera
+ * \param[in] camera The camera whose data to retrieve
+ * \sa cameraData()
+ * \return A const pointer to the pipeline-specific data passed to
+ * registerCamera().
+ */
+const CameraData *PipelineHandler::cameraData(const Camera *camera) const
+{
+	ASSERT(cameraData_.count(camera));
+	return cameraData_.at(camera).get();
+}
+
 /**
  * \var PipelineHandler::manager_
  * \brief The Camera manager associated with the pipeline handler