[PATCH] qmi-codegen: TLVs < 0x10 are mandatory by default

Bjørn Mork bjorn at mork.no
Fri Feb 23 14:19:18 UTC 2018


I don't have strong enough feelings either way. Simplifying the json files is good. But I don't think maintaining the redundant keyword is a real problem.


Bjørn 

On February 23, 2018 1:01:40 PM GMT+01:00, Aleksander Morgado <aleksander at aleksander.es> wrote:
>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'
>> 


More information about the libqmi-devel mailing list