[RFC,v1] libcamera: controls: Generate macro for each control
diff mbox series

Message ID 20250317181146.214160-1-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [RFC,v1] libcamera: controls: Generate macro for each control
Related show

Commit Message

Barnabás Pőcze March 17, 2025, 6:11 p.m. UTC
Generate a macro in the form of LIBCAMERA_HAS_$VENDOR_$MODE_$NAME
for each control so that its existence can be checked easily
and without extra version checks.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/control_ids.h.in | 1 +
 1 file changed, 1 insertion(+)

Comments

Jacopo Mondi March 17, 2025, 6:54 p.m. UTC | #1
Hi Barnabás

On Mon, Mar 17, 2025 at 07:11:46PM +0100, Barnabás Pőcze wrote:
> Generate a macro in the form of LIBCAMERA_HAS_$VENDOR_$MODE_$NAME
> for each control so that its existence can be checked easily
> and without extra version checks.
>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

Do we really want this ? Applications should discover controls
programmatically.

Or is this useful for ABI compliance validation ?

> ---
>  include/libcamera/control_ids.h.in | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in
> index 5d0594c68..8f037589d 100644
> --- a/include/libcamera/control_ids.h.in
> +++ b/include/libcamera/control_ids.h.in
> @@ -49,6 +49,7 @@ extern const std::array<const ControlValue, {{ctrl.enum_values_count}}> {{ctrl.n
>  extern const std::map<std::string, {{ctrl.type}}> {{ctrl.name}}NameValueMap;
>  {% endif -%}
>  extern const Control<{{ctrl.type}}> {{ctrl.name}};
> +#define LIBCAMERA_HAS_{{vendor|upper}}_{{mode|upper}}_{{ctrl.name|snake_case|upper}}
>  {% endfor -%}
>
>  {% if vendor != 'libcamera' %}
> --
> 2.49.0
>
Barnabás Pőcze March 17, 2025, 9 p.m. UTC | #2
Hi


2025. 03. 17. 19:54 keltezéssel, Jacopo Mondi írta:
> Hi Barnabás
> 
> On Mon, Mar 17, 2025 at 07:11:46PM +0100, Barnabás Pőcze wrote:
>> Generate a macro in the form of LIBCAMERA_HAS_$VENDOR_$MODE_$NAME
>> for each control so that its existence can be checked easily
>> and without extra version checks.
>>
>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> 
> Do we really want this ?

Good question, hence the RFC; I don't think there is a very nice
way to discover (and use) controls at comptime/runtime. Also note
that the control namespaces already have their own existence macros
(e.g. `LIBCAMERA_HAS_RPI_VENDOR_CONTROLS`).

> Applications should discover controls
> programmatically.

What do you have in mind? Looking up the numeric id in the appropriate
`ControlIdMap` by the (namespace, name) pair?


Regards,
Barnabás Pőcze


> 
> Or is this useful for ABI compliance validation ?
> 
>> ---
>>   include/libcamera/control_ids.h.in | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in
>> index 5d0594c68..8f037589d 100644
>> --- a/include/libcamera/control_ids.h.in
>> +++ b/include/libcamera/control_ids.h.in
>> @@ -49,6 +49,7 @@ extern const std::array<const ControlValue, {{ctrl.enum_values_count}}> {{ctrl.n
>>   extern const std::map<std::string, {{ctrl.type}}> {{ctrl.name}}NameValueMap;
>>   {% endif -%}
>>   extern const Control<{{ctrl.type}}> {{ctrl.name}};
>> +#define LIBCAMERA_HAS_{{vendor|upper}}_{{mode|upper}}_{{ctrl.name|snake_case|upper}}
>>   {% endfor -%}
>>
>>   {% if vendor != 'libcamera' %}
>> --
>> 2.49.0
>>

Patch
diff mbox series

diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in
index 5d0594c68..8f037589d 100644
--- a/include/libcamera/control_ids.h.in
+++ b/include/libcamera/control_ids.h.in
@@ -49,6 +49,7 @@  extern const std::array<const ControlValue, {{ctrl.enum_values_count}}> {{ctrl.n
 extern const std::map<std::string, {{ctrl.type}}> {{ctrl.name}}NameValueMap;
 {% endif -%}
 extern const Control<{{ctrl.type}}> {{ctrl.name}};
+#define LIBCAMERA_HAS_{{vendor|upper}}_{{mode|upper}}_{{ctrl.name|snake_case|upper}}
 {% endfor -%}
 
 {% if vendor != 'libcamera' %}