[libcamera-devel] [PATCH v3 8/8] libcamera: v4l2_subdevice: Inherit from Loggable

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Feb 27 19:07:06 CET 2019


Hi Jacopo,

Thank you for the patch.

On Tue, Feb 26, 2019 at 05:26:41PM +0100, Jacopo Mondi wrote:
> Prefix the V4L2Subdevice error messages with the name of the entity.
> Remove the manually printed name from log messages where it was used.
> 
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
> ---
>  src/libcamera/include/v4l2_subdevice.h |  7 ++++++-
>  src/libcamera/v4l2_subdevice.cpp       | 10 ++++------
>  2 files changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
> index 6b21308d2087..dcf38d719fcb 100644
> --- a/src/libcamera/include/v4l2_subdevice.h
> +++ b/src/libcamera/include/v4l2_subdevice.h
> @@ -13,6 +13,8 @@
>  
>  #include "media_object.h"
>  
> +#include "log.h"
> +

This should go above the media_object.h include without any blank line
in between.

>  namespace libcamera {
>  
>  struct Rectangle;
> @@ -23,7 +25,7 @@ struct V4L2SubdeviceFormat {
>  	uint32_t height;
>  };
>  
> -class V4L2Subdevice
> +class V4L2Subdevice : protected Loggable
>  {
>  public:
>  	explicit V4L2Subdevice(const MediaEntity *entity);
> @@ -44,6 +46,9 @@ public:
>  	int getFormat(unsigned int pad, V4L2SubdeviceFormat *format);
>  	int setFormat(unsigned int pad, V4L2SubdeviceFormat *format);
>  
> +protected:
> +	std::string logPrefix() const { return "'" + deviceName() + "'"; }

This will end up inlining two + operations between strings for every
call. Let's not make it an inline function.

Apart from that,

Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

> +
>  private:
>  	int listPadSizes(unsigned int pad, unsigned int mbus_code,
>  			 std::vector<V4L2SubdeviceFormat> *formats);
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index a043a07ff156..20439b895b99 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -222,7 +222,7 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format)
>  		ret = -errno;
>  		LOG(V4L2Subdev, Error)
>  			<< "Unable to get format on pad " << pad
> -			<< " of " << deviceName() << ": " << strerror(-ret);
> +			<< ": " << strerror(-ret);
>  		return ret;
>  	}
>  
> @@ -311,8 +311,7 @@ int V4L2Subdevice::listPadSizes(unsigned int pad, unsigned int mbus_code,
>  	if (ret && (errno != EINVAL && errno != ENOTTY)) {
>  		LOG(V4L2Subdev, Error)
>  			<< "Unable to enumerate format on pad " << pad
> -			<< " of " << deviceName() << ": "
> -			<< strerror(errno);
> +			<< ": " << strerror(errno);
>  		return ret;
>  	}
>  
> @@ -340,7 +339,7 @@ std::vector<V4L2SubdeviceFormat> V4L2Subdevice::listPadFormats(unsigned int pad)
>  	if (ret && (errno != EINVAL && errno != ENOTTY)) {
>  		LOG(V4L2Subdev, Error)
>  			<< "Unable to enumerate format on pad " << pad
> -			<< " of " << deviceName() << ": " << strerror(-ret);
> +			<< ": " << strerror(-ret);
>  		return formats;
>  	}
>  
> @@ -380,8 +379,7 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
>  		ret = -errno;
>  		LOG(V4L2Subdev, Error)
>  			<< "Unable to set rectangle " << target << " on pad "
> -			<< pad << " of " << deviceName() << ": "
> -			<< strerror(-ret);
> +			<< ": " << strerror(-ret);
>  		return ret;
>  	}
>  

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list