def __init__(self, dictionary, struct_type_name, container_type): # Call the parent constructor Variable.__init__(self, dictionary) # The public format of the struct is built directly from the suggested # struct type name self.public_format = utils.build_camelcase_name(struct_type_name) self.private_format = self.public_format self.container_type = container_type # Load members of this struct self.members = [] for member_dictionary in dictionary["contents"]: member = {} member["name"] = utils.build_underscore_name(member_dictionary["name"]) member["object"] = VariableFactory.create_variable( member_dictionary, struct_type_name + " " + member["name"], self.container_type ) self.members.append(member) # We'll need to dispose if at least one of the members needs it for member in self.members: if member["object"].needs_dispose == True: self.needs_dispose = True
def __init__(self, dictionary, array_element_type, container_type): # Call the parent constructor Variable.__init__(self, dictionary) self.private_format = 'GArray *' self.public_format = self.private_format self.fixed_size = 0 self.name = dictionary['name'] # The array and its contents need to get disposed self.needs_dispose = True # We need to know whether the variable comes in an Input container or in # an Output container, as we should not dump the element clear() helper method # if the variable is from an Input container. self.container_type = container_type # Load variable type of this array if 'name' in dictionary['array-element']: self.array_element = VariableFactory.create_variable(dictionary['array-element'], array_element_type + ' ' + dictionary['array-element']['name'], self.container_type) else: self.array_element = VariableFactory.create_variable(dictionary['array-element'], '', self.container_type) # Load variable type for the array size prefix if 'size-prefix-format' in dictionary: # We do NOT allow 64-bit types as array sizes (GArray won't support them) if dictionary['size-prefix-format'] not in [ 'guint8', 'guint16', 'guint32' ]: raise ValueError('Invalid size prefix format (%s): not guint8 or guint16 or guint32' % dictionary['size-prefix-format']) default_array_size = { 'format' : dictionary['size-prefix-format'] } self.array_size_element = VariableFactory.create_variable(default_array_size, '', self.container_type) elif 'fixed-size' in dictionary: # fixed-size arrays have no size element, obviously self.fixed_size = dictionary['fixed-size'] if int(self.fixed_size) == 0 or int(self.fixed_size) > 512: raise ValueError('Fixed array size %s out of bounds (not between 0 and 512)' % self.fixed_size) else: # Default to 'guint8' if no explicit array size given default_array_size = { 'format' : 'guint8' } self.array_size_element = VariableFactory.create_variable(default_array_size, '', self.container_type) # Load variable type for the sequence prefix if 'sequence-prefix-format' in dictionary: sequence = { 'format' : dictionary['sequence-prefix-format'] } self.array_sequence_element = VariableFactory.create_variable(sequence, '', self.container_type) else: self.array_sequence_element = ''
def __init__(self, prefix, dictionary, common_objects_dictionary, container_type, static): # The field prefix, usually the name of the Container, # e.g. "Qmi Message Ctl Something Output" self.prefix = prefix # The name of the specific field, e.g. "Result" self.name = dictionary['name'] # 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 # The type, which must always be "TLV" self.type = dictionary['type'] # The container type, which must be either "Input" or "Output" self.container_type = container_type # Whether the whole field is internally used only self.static = static # Create the composed full name (prefix + name), # e.g. "Qmi Message Ctl Something Output Result" self.fullname = dictionary['fullname'] if 'fullname' in dictionary else self.prefix + ' ' + self.name # Create our variable object self.variable = VariableFactory.create_variable(dictionary, self.fullname, self.container_type) # Create the variable name within the Container self.variable_name = 'arg_' + utils.build_underscore_name(self.name).lower() # Create the ID enumeration name self.id_enum_name = utils.build_underscore_name(self.prefix + ' TLV ' + self.name).upper() # Output Fields may have prerequisites self.prerequisites = [] if 'prerequisites' in dictionary: self.prerequisites = dictionary['prerequisites'] # First, look for references to common types for prerequisite_dictionary in self.prerequisites: if 'common-ref' in prerequisite_dictionary: for common in common_objects_dictionary: if common['type'] == 'prerequisite' and \ common['common-ref'] == prerequisite_dictionary['common-ref']: # Replace the reference with a copy of the common dictionary copy = dict(common) self.prerequisites.remove(prerequisite_dictionary) self.prerequisites.append(copy) break else: raise RuntimeError('Common type \'%s\' not found' % prerequisite_dictionary['name'])
def __init__(self, dictionary, sequence_type_name, container_type): # Call the parent constructor Variable.__init__(self, dictionary) self.container_type = container_type # Load members of this sequence self.members = [] for member_dictionary in dictionary['contents']: member = {} member['name'] = utils.build_underscore_name(member_dictionary['name']) member['object'] = VariableFactory.create_variable(member_dictionary, sequence_type_name + ' ' + member['name'], self.container_type) self.members.append(member) # TODO: do we need this? # We'll need to dispose if at least one of the members needs it for member in self.members: if member['object'].needs_dispose == True: self.needs_dispose = True
def __init__(self, prefix, dictionary, common_objects_dictionary, container_type, static): # The field prefix, usually the name of the Container, # e.g. "Qmi Message Ctl Something Output" self.prefix = prefix # The name of the specific field, e.g. "Result" self.name = dictionary['name'] # 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 # The type, which must always be "TLV" self.type = dictionary['type'] # The container type, which must be either "Input" or "Output" self.container_type = container_type # Whether the whole field is internally used only self.static = static # Create the composed full name (prefix + name), # e.g. "Qmi Message Ctl Something Output Result" self.fullname = dictionary[ 'fullname'] if 'fullname' in dictionary else self.prefix + ' ' + self.name # libqmi version where the message was introduced self.since = dictionary['since'] if 'since' in dictionary else None if self.since is None: raise ValueError( 'TLV ' + self.fullname + ' requires a "since" tag specifying the major version where it was introduced' ) # Create our variable object self.variable = VariableFactory.create_variable( dictionary, self.fullname, self.container_type) # Create the variable name within the Container self.variable_name = 'arg_' + utils.build_underscore_name( self.name).lower() # Create the ID enumeration name self.id_enum_name = utils.build_underscore_name(self.prefix + ' TLV ' + self.name).upper() # Output Fields may have prerequisites self.prerequisites = [] if 'prerequisites' in dictionary: self.prerequisites = dictionary['prerequisites'] # First, look for references to common types for prerequisite_dictionary in self.prerequisites: if 'common-ref' in prerequisite_dictionary: for common in common_objects_dictionary: if common['type'] == 'prerequisite' and \ common['common-ref'] == prerequisite_dictionary['common-ref']: # Replace the reference with a copy of the common dictionary copy = dict(common) self.prerequisites.remove(prerequisite_dictionary) self.prerequisites.append(copy) break else: raise RuntimeError('Common type \'%s\' not found' % prerequisite_dictionary['name'])