[libcamera-devel,v2,6/8] libcamera: device_enumerator: Don't mark the search() function as const

Message ID 20190115151849.1547-7-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Pipeline handler refactoring and assorted improvements
Related show

Commit Message

Laurent Pinchart Jan. 15, 2019, 3:18 p.m. UTC
While the DeviceEnumerator::search() function doesn't modify the
instance directly, it returns a non-const pointer to a MediaEntity that
is owned by the DeviceEnumerator instance. This breaks the const
semantics. Don't mark the function as const.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/device_enumerator.cpp       | 2 +-
 src/libcamera/include/device_enumerator.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Niklas Söderlund Jan. 15, 2019, 10:29 p.m. UTC | #1
Hi Laurent,

Thanks for your patch.

On 2019-01-15 17:18:47 +0200, Laurent Pinchart wrote:
> While the DeviceEnumerator::search() function doesn't modify the
> instance directly, it returns a non-const pointer to a MediaEntity that
> is owned by the DeviceEnumerator instance. This breaks the const
> semantics. Don't mark the function as const.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/libcamera/device_enumerator.cpp       | 2 +-
>  src/libcamera/include/device_enumerator.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
> index 1653e4f4651a..18d7e86843e8 100644
> --- a/src/libcamera/device_enumerator.cpp
> +++ b/src/libcamera/device_enumerator.cpp
> @@ -245,7 +245,7 @@ int DeviceEnumerator::addDevice(const std::string &devnode)
>   *
>   * \return pointer to the matching MediaDevice, or nullptr if no match is found
>   */
> -MediaDevice *DeviceEnumerator::search(const DeviceMatch &dm) const
> +MediaDevice *DeviceEnumerator::search(const DeviceMatch &dm)
>  {
>  	for (MediaDevice *dev : devices_) {
>  		if (dev->busy())
> diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h
> index 29737da7a225..b68c815827dd 100644
> --- a/src/libcamera/include/device_enumerator.h
> +++ b/src/libcamera/include/device_enumerator.h
> @@ -41,7 +41,7 @@ public:
>  	virtual int init() = 0;
>  	virtual int enumerate() = 0;
>  
> -	MediaDevice *search(const DeviceMatch &dm) const;
> +	MediaDevice *search(const DeviceMatch &dm);
>  
>  protected:
>  	int addDevice(const std::string &devnode);
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
index 1653e4f4651a..18d7e86843e8 100644
--- a/src/libcamera/device_enumerator.cpp
+++ b/src/libcamera/device_enumerator.cpp
@@ -245,7 +245,7 @@  int DeviceEnumerator::addDevice(const std::string &devnode)
  *
  * \return pointer to the matching MediaDevice, or nullptr if no match is found
  */
-MediaDevice *DeviceEnumerator::search(const DeviceMatch &dm) const
+MediaDevice *DeviceEnumerator::search(const DeviceMatch &dm)
 {
 	for (MediaDevice *dev : devices_) {
 		if (dev->busy())
diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h
index 29737da7a225..b68c815827dd 100644
--- a/src/libcamera/include/device_enumerator.h
+++ b/src/libcamera/include/device_enumerator.h
@@ -41,7 +41,7 @@  public:
 	virtual int init() = 0;
 	virtual int enumerate() = 0;
 
-	MediaDevice *search(const DeviceMatch &dm) const;
+	MediaDevice *search(const DeviceMatch &dm);
 
 protected:
 	int addDevice(const std::string &devnode);