[libcamera-devel,v2,3/9] libcamera: bound_method: Store connection type in BoundMethodBase

Message ID 20191028104913.14985-4-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Add support for blocking method invocation
Related show

Commit Message

Laurent Pinchart Oct. 28, 2019, 10:49 a.m. UTC
Store the connection type in the base BoundMethodBase class to make it
accessible to all bound methods. The default type is ConnectionTypeAuto.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/bound_method.h | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Comments

Niklas Söderlund Oct. 29, 2019, 2:39 p.m. UTC | #1
Hi Laurent,

Thanks for your patch.

On 2019-10-28 12:49:07 +0200, Laurent Pinchart wrote:
> Store the connection type in the base BoundMethodBase class to make it
> accessible to all bound methods. The default type is ConnectionTypeAuto.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

> ---
>  include/libcamera/bound_method.h | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h
> index e1524c917e4b..06c5a3b12305 100644
> --- a/include/libcamera/bound_method.h
> +++ b/include/libcamera/bound_method.h
> @@ -24,8 +24,10 @@ enum ConnectionType {
>  class BoundMethodBase
>  {
>  public:
> -	BoundMethodBase(void *obj, Object *object)
> -		: obj_(obj), object_(object) {}
> +	BoundMethodBase(void *obj, Object *object, ConnectionType type)
> +		: obj_(obj), object_(object), connectionType_(type)
> +	{
> +	}
>  	virtual ~BoundMethodBase() {}
>  
>  	template<typename T, typename std::enable_if<!std::is_same<Object, T>::value>::type * = nullptr>
> @@ -33,6 +35,7 @@ public:
>  	bool match(Object *object) { return object == object_; }
>  
>  	Object *object() const { return object_; }
> +	ConnectionType connectionType() const { return connectionType_; }
>  
>  	void activatePack(void *pack);
>  	virtual void invokePack(void *pack) = 0;
> @@ -40,6 +43,7 @@ public:
>  protected:
>  	void *obj_;
>  	Object *object_;
> +	ConnectionType connectionType_;
>  };
>  
>  template<typename... Args>
> @@ -76,8 +80,8 @@ private:
>  	}
>  
>  public:
> -	BoundMethodArgs(void *obj, Object *object)
> -		: BoundMethodBase(obj, object) {}
> +	BoundMethodArgs(void *obj, Object *object, ConnectionType type)
> +		: BoundMethodBase(obj, object, type) {}
>  
>  	void invokePack(void *pack) override
>  	{
> @@ -94,8 +98,11 @@ class BoundMemberMethod : public BoundMethodArgs<Args...>
>  public:
>  	using PackType = std::tuple<typename std::remove_reference<Args>::type...>;
>  
> -	BoundMemberMethod(T *obj, Object *object, void (T::*func)(Args...))
> -		: BoundMethodArgs<Args...>(obj, object), func_(func) {}
> +	BoundMemberMethod(T *obj, Object *object, void (T::*func)(Args...),
> +			  ConnectionType type = ConnectionTypeAuto)
> +		: BoundMethodArgs<Args...>(obj, object, type), func_(func)
> +	{
> +	}
>  
>  	bool match(void (T::*func)(Args...)) const { return func == func_; }
>  
> @@ -121,7 +128,10 @@ class BoundStaticMethod : public BoundMethodArgs<Args...>
>  {
>  public:
>  	BoundStaticMethod(void (*func)(Args...))
> -		: BoundMethodArgs<Args...>(nullptr, nullptr), func_(func) {}
> +		: BoundMethodArgs<Args...>(nullptr, nullptr, ConnectionTypeAuto),
> +		  func_(func)
> +	{
> +	}
>  
>  	bool match(void (*func)(Args...)) const { return func == func_; }
>  
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h
index e1524c917e4b..06c5a3b12305 100644
--- a/include/libcamera/bound_method.h
+++ b/include/libcamera/bound_method.h
@@ -24,8 +24,10 @@  enum ConnectionType {
 class BoundMethodBase
 {
 public:
-	BoundMethodBase(void *obj, Object *object)
-		: obj_(obj), object_(object) {}
+	BoundMethodBase(void *obj, Object *object, ConnectionType type)
+		: obj_(obj), object_(object), connectionType_(type)
+	{
+	}
 	virtual ~BoundMethodBase() {}
 
 	template<typename T, typename std::enable_if<!std::is_same<Object, T>::value>::type * = nullptr>
@@ -33,6 +35,7 @@  public:
 	bool match(Object *object) { return object == object_; }
 
 	Object *object() const { return object_; }
+	ConnectionType connectionType() const { return connectionType_; }
 
 	void activatePack(void *pack);
 	virtual void invokePack(void *pack) = 0;
@@ -40,6 +43,7 @@  public:
 protected:
 	void *obj_;
 	Object *object_;
+	ConnectionType connectionType_;
 };
 
 template<typename... Args>
@@ -76,8 +80,8 @@  private:
 	}
 
 public:
-	BoundMethodArgs(void *obj, Object *object)
-		: BoundMethodBase(obj, object) {}
+	BoundMethodArgs(void *obj, Object *object, ConnectionType type)
+		: BoundMethodBase(obj, object, type) {}
 
 	void invokePack(void *pack) override
 	{
@@ -94,8 +98,11 @@  class BoundMemberMethod : public BoundMethodArgs<Args...>
 public:
 	using PackType = std::tuple<typename std::remove_reference<Args>::type...>;
 
-	BoundMemberMethod(T *obj, Object *object, void (T::*func)(Args...))
-		: BoundMethodArgs<Args...>(obj, object), func_(func) {}
+	BoundMemberMethod(T *obj, Object *object, void (T::*func)(Args...),
+			  ConnectionType type = ConnectionTypeAuto)
+		: BoundMethodArgs<Args...>(obj, object, type), func_(func)
+	{
+	}
 
 	bool match(void (T::*func)(Args...)) const { return func == func_; }
 
@@ -121,7 +128,10 @@  class BoundStaticMethod : public BoundMethodArgs<Args...>
 {
 public:
 	BoundStaticMethod(void (*func)(Args...))
-		: BoundMethodArgs<Args...>(nullptr, nullptr), func_(func) {}
+		: BoundMethodArgs<Args...>(nullptr, nullptr, ConnectionTypeAuto),
+		  func_(func)
+	{
+	}
 
 	bool match(void (*func)(Args...)) const { return func == func_; }