[libcamera-devel,1/6] libcamera: v4l2_device: Add MediaEntity contructor

Message ID 20190121172705.19985-2-jacopo@jmondi.org
State Accepted
Headers show
Series
  • libcamera: Augment V4L2 device
Related show

Commit Message

Jacopo Mondi Jan. 21, 2019, 5:27 p.m. UTC
Construct a V4L2Device from a MediaEntity device node path. While at
there mark constructor as explicit to avoid copy-construction.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/include/v4l2_device.h |  4 +++-
 src/libcamera/v4l2_device.cpp       | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart Jan. 21, 2019, 8:32 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Mon, Jan 21, 2019 at 06:27:00PM +0100, Jacopo Mondi wrote:
> Construct a V4L2Device from a MediaEntity device node path. While at
> there mark constructor as explicit to avoid copy-construction.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

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

> ---
>  src/libcamera/include/v4l2_device.h |  4 +++-
>  src/libcamera/v4l2_device.cpp       | 12 ++++++++++++
>  2 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
> index 474c05b..c6f3d9a 100644
> --- a/src/libcamera/include/v4l2_device.h
> +++ b/src/libcamera/include/v4l2_device.h
> @@ -32,10 +32,12 @@ struct V4L2Capability final : v4l2_capability {
>  	bool hasStreaming() const { return capabilities & V4L2_CAP_STREAMING; }
>  };
>  
> +class MediaEntity;
>  class V4L2Device
>  {
>  public:
> -	V4L2Device(const std::string &devnode);
> +	explicit V4L2Device(const std::string &devnode);
> +	explicit V4L2Device(const MediaEntity &entity);
>  	V4L2Device(const V4L2Device &) = delete;
>  	~V4L2Device();
>  
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 54b53de..59a1ad9 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -12,6 +12,7 @@
>  #include <unistd.h>
>  
>  #include "log.h"
> +#include "media_object.h"
>  #include "v4l2_device.h"
>  
>  /**
> @@ -92,6 +93,17 @@ V4L2Device::V4L2Device(const std::string &devnode)
>  {
>  }
>  
> +/**
> + * \brief Construct a V4L2Device from a MediaEntity
> + * \param entity The MediaEntity to build the device from
> + *
> + * Construct a V4L2Device from a MediaEntity's device node path.
> + */
> +V4L2Device::V4L2Device(const MediaEntity &entity)
> +	: V4L2Device(entity.devnode())
> +{
> +}
> +
>  V4L2Device::~V4L2Device()
>  {
>  	close();
Niklas Söderlund Jan. 22, 2019, 11:28 a.m. UTC | #2
Hi Jacopo,

Thanks for your work.

On 2019-01-21 18:27:00 +0100, Jacopo Mondi wrote:
> Construct a V4L2Device from a MediaEntity device node path. While at
> there mark constructor as explicit to avoid copy-construction.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

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

> ---
>  src/libcamera/include/v4l2_device.h |  4 +++-
>  src/libcamera/v4l2_device.cpp       | 12 ++++++++++++
>  2 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
> index 474c05b..c6f3d9a 100644
> --- a/src/libcamera/include/v4l2_device.h
> +++ b/src/libcamera/include/v4l2_device.h
> @@ -32,10 +32,12 @@ struct V4L2Capability final : v4l2_capability {
>  	bool hasStreaming() const { return capabilities & V4L2_CAP_STREAMING; }
>  };
>  
> +class MediaEntity;
>  class V4L2Device
>  {
>  public:
> -	V4L2Device(const std::string &devnode);
> +	explicit V4L2Device(const std::string &devnode);
> +	explicit V4L2Device(const MediaEntity &entity);
>  	V4L2Device(const V4L2Device &) = delete;
>  	~V4L2Device();
>  
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 54b53de..59a1ad9 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -12,6 +12,7 @@
>  #include <unistd.h>
>  
>  #include "log.h"
> +#include "media_object.h"
>  #include "v4l2_device.h"
>  
>  /**
> @@ -92,6 +93,17 @@ V4L2Device::V4L2Device(const std::string &devnode)
>  {
>  }
>  
> +/**
> + * \brief Construct a V4L2Device from a MediaEntity
> + * \param entity The MediaEntity to build the device from
> + *
> + * Construct a V4L2Device from a MediaEntity's device node path.
> + */
> +V4L2Device::V4L2Device(const MediaEntity &entity)
> +	: V4L2Device(entity.devnode())
> +{
> +}
> +
>  V4L2Device::~V4L2Device()
>  {
>  	close();
> -- 
> 2.20.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index 474c05b..c6f3d9a 100644
--- a/src/libcamera/include/v4l2_device.h
+++ b/src/libcamera/include/v4l2_device.h
@@ -32,10 +32,12 @@  struct V4L2Capability final : v4l2_capability {
 	bool hasStreaming() const { return capabilities & V4L2_CAP_STREAMING; }
 };
 
+class MediaEntity;
 class V4L2Device
 {
 public:
-	V4L2Device(const std::string &devnode);
+	explicit V4L2Device(const std::string &devnode);
+	explicit V4L2Device(const MediaEntity &entity);
 	V4L2Device(const V4L2Device &) = delete;
 	~V4L2Device();
 
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 54b53de..59a1ad9 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -12,6 +12,7 @@ 
 #include <unistd.h>
 
 #include "log.h"
+#include "media_object.h"
 #include "v4l2_device.h"
 
 /**
@@ -92,6 +93,17 @@  V4L2Device::V4L2Device(const std::string &devnode)
 {
 }
 
+/**
+ * \brief Construct a V4L2Device from a MediaEntity
+ * \param entity The MediaEntity to build the device from
+ *
+ * Construct a V4L2Device from a MediaEntity's device node path.
+ */
+V4L2Device::V4L2Device(const MediaEntity &entity)
+	: V4L2Device(entity.devnode())
+{
+}
+
 V4L2Device::~V4L2Device()
 {
 	close();