[libcamera-devel,3/9] libcamera: flags: Add friend class IPADataSerializer
diff mbox series

Message ID 20220803112150.3040287-4-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • utils: ipc: Add support for enums and Flags
Related show

Commit Message

Paul Elder Aug. 3, 2022, 11:21 a.m. UTC
To prepare for the ability to send Flags over IPC, add IPADataSerializer
as a friend class to Flags.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 include/libcamera/base/flags.h | 3 +++
 1 file changed, 3 insertions(+)

Comments

Laurent Pinchart Aug. 9, 2022, 1:12 a.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Wed, Aug 03, 2022 at 08:21:44PM +0900, Paul Elder via libcamera-devel wrote:
> To prepare for the ability to send Flags over IPC, add IPADataSerializer
> as a friend class to Flags.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
>  include/libcamera/base/flags.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/include/libcamera/base/flags.h b/include/libcamera/base/flags.h
> index a1b404bd..43afdf26 100644
> --- a/include/libcamera/base/flags.h
> +++ b/include/libcamera/base/flags.h
> @@ -137,6 +137,9 @@ public:
>  	}
>  
>  private:
> +	template<typename>
> +	friend class IPADataSerializer;

I'd rather not do this, to avoid exposing internals in the public API.
You can convert a Flags to the raw value with operator Type(), which is
called by

	static_cast<Flags<...>::Type>(flags)

I however suspect you need the friend statement for the other way
around. I think you can use the Flags(E flag) constructor then, casting
the deserialized uint32_t to a E first.

> +
>  	Type value_;
>  };
>

Patch
diff mbox series

diff --git a/include/libcamera/base/flags.h b/include/libcamera/base/flags.h
index a1b404bd..43afdf26 100644
--- a/include/libcamera/base/flags.h
+++ b/include/libcamera/base/flags.h
@@ -137,6 +137,9 @@  public:
 	}
 
 private:
+	template<typename>
+	friend class IPADataSerializer;
+
 	Type value_;
 };