[PATCH] qmi-codegen: TLVs < 0x10 are mandatory by default
Aleksander Morgado
aleksander at aleksander.es
Fri Feb 23 12:01:40 UTC 2018
On 11/02/18 22:36, Thomas Weißschuh wrote:
> The old code did not regards any TLVs as mandatory, as Field.mandatory
> was a boolean but compared to the string "yes", breaking the logic.
> ---
> build-aux/qmi-codegen/Field.py | 5 ++++-
> build-aux/qmi-codegen/Message.py | 4 ++--
> 2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/build-aux/qmi-codegen/Field.py b/build-aux/qmi-codegen/Field.py
> index 631890f..c74fab4 100644
> --- a/build-aux/qmi-codegen/Field.py
> +++ b/build-aux/qmi-codegen/Field.py
> @@ -42,7 +42,10 @@ class Field:
> # The specific TLV ID
> self.id = dictionary['id']
> # Whether the field is to be considered mandatory in the message
> - self.mandatory = True if dictionary['mandatory'] == 'yes' else False
> + if 'mandatory' in dictionary:
> + self.mandatory = dictionary['mandatory'] == 'yes'
> + else:
> + self.mandatory = self.id < 0x10
If we were to do this, I would suggest to just get rid of the mandatory keyword in the JSON files alltogether, and automatically detect whether it's mandatory or not based on the id number.
Dan, Bjørn, what do you think?
> # The type, which must always be "TLV"
> self.type = dictionary['type']
> # The container type, which must be either "Input" or "Output"
> diff --git a/build-aux/qmi-codegen/Message.py b/build-aux/qmi-codegen/Message.py
> index 0bf62f1..518f085 100644
> --- a/build-aux/qmi-codegen/Message.py
> +++ b/build-aux/qmi-codegen/Message.py
> @@ -125,7 +125,7 @@ class Message:
> # Count how many mandatory fields we have
> n_mandatory = 0
> for field in self.input.fields:
> - if field.mandatory == 'yes':
> + if field.mandatory:
> n_mandatory += 1
>
> if n_mandatory == 0:
> @@ -164,7 +164,7 @@ class Message:
> # Emit the TLV getter
> field.emit_input_tlv_add(cfile, ' ')
>
> - if field.mandatory == 'yes':
> + if field.mandatory:
> template = (
> ' } else {\n'
> ' g_set_error (error,\n'
>
--
Aleksander
https://aleksander.es
More information about the libqmi-devel
mailing list