[libcamera-devel] [PATCH 2/2] libcamera: v4l2_device: Inherit from Loggable to print device node name

Niklas Söderlund niklas.soderlund at ragnatech.se
Sun Feb 10 14:15:04 CET 2019


Hi Laurent,

Thanks for your patch.

On 2019-02-08 16:45:40 +0200, Laurent Pinchart wrote:
> Automate printing of device node name in log messages by inheriting from
> the Loggable class.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

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

> ---
>  src/libcamera/include/v4l2_device.h |  7 ++++++-
>  src/libcamera/v4l2_device.cpp       | 16 +++++++++-------
>  2 files changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
> index 988e646c5de1..983b9d900aea 100644
> --- a/src/libcamera/include/v4l2_device.h
> +++ b/src/libcamera/include/v4l2_device.h
> @@ -15,6 +15,8 @@
>  
>  #include <libcamera/signal.h>
>  
> +#include "log.h"
> +
>  namespace libcamera {
>  
>  class Buffer;
> @@ -76,7 +78,7 @@ public:
>  	unsigned int planesCount;
>  };
>  
> -class V4L2Device
> +class V4L2Device : protected Loggable
>  {
>  public:
>  	explicit V4L2Device(const std::string &deviceNode);
> @@ -106,6 +108,9 @@ public:
>  	int streamOn();
>  	int streamOff();
>  
> +protected:
> +	std::string logPrefix() const;
> +
>  private:
>  	int getFormatSingleplane(V4L2DeviceFormat *format);
>  	int setFormatSingleplane(V4L2DeviceFormat *format);
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 64325ff9f5d9..23c0da295905 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -262,8 +262,7 @@ int V4L2Device::open()
>  	if (ret < 0) {
>  		ret = -errno;
>  		LOG(V4L2, Error)
> -			<< "Failed to open V4L2 device '" << deviceNode_
> -			<< "': " << strerror(-ret);
> +			<< "Failed to open V4L2 device: " << strerror(-ret);
>  		return ret;
>  	}
>  	fd_ = ret;
> @@ -278,9 +277,8 @@ int V4L2Device::open()
>  	}
>  
>  	LOG(V4L2, Debug)
> -		<< "Opened '" << deviceNode_ << "' "
> -		<< caps_.bus_info() << ": " << caps_.driver()
> -		<< ": " << caps_.card();
> +		<< "Opened device " << caps_.bus_info() << ": "
> +		<< caps_.driver() << ": " << caps_.card();
>  
>  	if (!caps_.isCapture() && !caps_.isOutput()) {
>  		LOG(V4L2, Debug) << "Device is not a supported type";
> @@ -350,6 +348,11 @@ void V4L2Device::close()
>   * \return The string containing the device location
>   */
>  
> +std::string V4L2Device::logPrefix() const
> +{
> +	return deviceNode_;
> +}
> +
>  /**
>   * \brief Retrieve the image format set on the V4L2 device
>   * \param[out] format The image format applied on the device
> @@ -519,8 +522,7 @@ int V4L2Device::requestBuffers(unsigned int count)
>  		return ret;
>  	}
>  
> -	LOG(V4L2, Debug)
> -		<< deviceNode_ << ":" << rb.count << " buffers requested.";
> +	LOG(V4L2, Debug) << rb.count << " buffers requested.";
>  
>  	return rb.count;
>  }
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list