[libcamera-devel] [PATCH v5 2/9] libcamera: v4l2_subdevice: Inherit from Loggable

Jacopo Mondi jacopo at jmondi.org
Thu Feb 28 21:01:44 CET 2019


Prefix the V4L2Subdevice error messages with the name of the entity.
Remove the manually printed name from log messages where it was used and
standardize error messages while at there.

Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/libcamera/include/v4l2_subdevice.h |  6 +++++-
 src/libcamera/v4l2_subdevice.cpp       | 13 +++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
index eac699a06109..669e79f9a9fd 100644
--- a/src/libcamera/include/v4l2_subdevice.h
+++ b/src/libcamera/include/v4l2_subdevice.h
@@ -9,6 +9,7 @@
 
 #include <string>
 
+#include "log.h"
 #include "media_object.h"
 
 namespace libcamera {
@@ -21,7 +22,7 @@ struct V4L2SubdeviceFormat {
 	uint32_t height;
 };
 
-class V4L2Subdevice
+class V4L2Subdevice : protected Loggable
 {
 public:
 	explicit V4L2Subdevice(const MediaEntity *entity);
@@ -41,6 +42,9 @@ public:
 	int getFormat(unsigned int pad, V4L2SubdeviceFormat *format);
 	int setFormat(unsigned int pad, V4L2SubdeviceFormat *format);
 
+protected:
+	std::string logPrefix() const;
+
 private:
 	int setSelection(unsigned int pad, unsigned int target,
 			 Rectangle *rect);
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index c44cafd4b4c5..4fe59c45f000 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -154,6 +154,11 @@ void V4L2Subdevice::close()
  * \return The name of the media entity the subdevice is associated to
  */
 
+std::string V4L2Subdevice::logPrefix() const
+{
+	return "'" + deviceName() + "'";
+}
+
 /**
  * \brief Set a crop rectangle on one of the V4L2 subdevice pads
  * \param[in] pad The 0-indexed pad number the rectangle is to be applied to
@@ -196,7 +201,7 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format)
 		ret = -errno;
 		LOG(V4L2Subdev, Error)
 			<< "Unable to get format on pad " << pad
-			<< " of " << deviceNode() << ": " << strerror(-ret);
+			<< ": " << strerror(-ret);
 		return ret;
 	}
 
@@ -231,7 +236,8 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)
 	if (ret) {
 		ret = -errno;
 		LOG(V4L2Subdev, Error)
-			<< "Unable to set format: " << strerror(-ret);
+			<< "Unable to set format on pad " << pad
+			<< ": " << strerror(-ret);
 		return ret;
 	}
 
@@ -262,8 +268,7 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
 		ret = -errno;
 		LOG(V4L2Subdev, Error)
 			<< "Unable to set rectangle " << target << " on pad "
-			<< pad << " of " << deviceNode() << ": "
-			<< strerror(-ret);
+			<< pad << ": " << strerror(-ret);
 		return ret;
 	}
 
-- 
2.20.1



More information about the libcamera-devel mailing list