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

Thomas Weißschuh thomas at t-8ch.de
Sun Feb 11 21:36:15 UTC 2018


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
         # 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'
-- 
2.16.1



More information about the libqmi-devel mailing list