def emit_sections(self, sfile): translations = { 'underscore': utils.build_underscore_name(self.name), 'no_prefix_underscore_upper': utils.build_underscore_name(self.name[4:]).upper(), 'camelcase': utils.build_camelcase_name(self.name), 'hyphened': utils.build_dashed_name(self.name) } template = ('<SECTION>\n' '<FILE>${hyphened}</FILE>\n' '<TITLE>${camelcase}</TITLE>\n' '${camelcase}\n' '<SUBSECTION Standard>\n' '${camelcase}Class\n' 'QMI_TYPE_${no_prefix_underscore_upper}\n' 'QMI_${no_prefix_underscore_upper}\n' 'QMI_${no_prefix_underscore_upper}_CLASS\n' 'QMI_IS_${no_prefix_underscore_upper}\n' 'QMI_IS_${no_prefix_underscore_upper}_CLASS\n' 'QMI_${no_prefix_underscore_upper}_GET_CLASS\n' '${underscore}_get_type\n' '</SECTION>\n' '\n') sfile.write(string.Template(template).substitute(translations))
def emit_section_content(self, sfile): translations = { 'name_dashed' : utils.build_dashed_name(self.name), 'underscore' : utils.build_underscore_name(self.fullname) } template = ( '\n' '<SUBSECTION ${name_dashed}>\n') sfile.write(string.Template(template).substitute(translations)) if self.has_query: template = ( '${underscore}_query_new\n') sfile.write(string.Template(template).substitute(translations)) if self.has_set: template = ( '${underscore}_set_new\n') sfile.write(string.Template(template).substitute(translations)) if self.has_response: template = ( '${underscore}_response_parse\n') sfile.write(string.Template(template).substitute(translations)) if self.has_notification: template = ( '${underscore}_notification_parse\n') sfile.write(string.Template(template).substitute(translations))
def emit_sections(self, sfile, message_list): # Do nothing if no supported messages if len(message_list.indication_list) == 0 and len( message_list.request_list) == 0: return translations = { 'underscore': utils.build_underscore_name(self.name), 'no_prefix_underscore_upper': utils.build_underscore_name(self.name[4:]).upper(), 'camelcase': utils.build_camelcase_name(self.name), 'hyphened': utils.build_dashed_name(self.name) } template = ('<SECTION>\n' '<FILE>${hyphened}</FILE>\n' '<TITLE>${camelcase}</TITLE>\n' '${camelcase}\n' '<SUBSECTION Standard>\n' '${camelcase}Class\n' 'QMI_TYPE_${no_prefix_underscore_upper}\n' 'QMI_${no_prefix_underscore_upper}\n' 'QMI_${no_prefix_underscore_upper}_CLASS\n' 'QMI_IS_${no_prefix_underscore_upper}\n' 'QMI_IS_${no_prefix_underscore_upper}_CLASS\n' 'QMI_${no_prefix_underscore_upper}_GET_CLASS\n' '${underscore}_get_type\n' '</SECTION>\n' '\n') sfile.write(string.Template(template).substitute(translations))
def emit_sections(self, sfile): if self.static: return translations = { 'hyphened': utils.build_dashed_name(self.fullname), 'fullname_underscore': utils.build_underscore_name(self.fullname), 'camelcase': utils.build_camelcase_name(self.fullname), 'service': utils.build_underscore_name(self.service), 'name_underscore': utils.build_underscore_name(self.name), 'build_symbol': self.build_symbol, 'fullname': self.service + ' ' + self.name, 'type': 'response' if self.type == 'Message' else 'indication' } sections = { 'public-types': '', 'public-methods': '', 'standard': '', 'private': '' } if self.input: self.input.add_sections(sections) self.output.add_sections(sections) if self.type == 'Message': template = ('<SUBSECTION ${camelcase}ClientMethods>\n' 'qmi_client_${service}_${name_underscore}\n' 'qmi_client_${service}_${name_underscore}_finish\n') sections['public-methods'] += string.Template(template).substitute( translations) translations['message_type'] = 'request' elif self.type == 'Indication': translations['message_type'] = 'indication' translations['public_types'] = sections['public-types'] translations['public_methods'] = sections['public-methods'] translations['standard'] = sections['standard'] translations['private'] = sections['private'] template = ('<SECTION>\n' '<FILE>${hyphened}</FILE>\n' '<TITLE>${fullname} ${message_type}</TITLE>\n' '${public_types}' '${public_methods}' '<SUBSECTION Private>\n' '${build_symbol}\n' '${private}' '<SUBSECTION Standard>\n' '${standard}' '</SECTION>\n' '\n') sfile.write(string.Template(template).substitute(translations))
def emit_sections(self, sfile): if self.static: return translations = { 'hyphened' : utils.build_dashed_name (self.fullname), 'fullname_underscore' : utils.build_underscore_name(self.fullname), 'camelcase' : utils.build_camelcase_name (self.fullname), 'service' : utils.build_underscore_name (self.service), 'name_underscore' : utils.build_underscore_name (self.name), 'fullname' : self.service + ' ' + self.name, 'type' : 'response' if self.type == 'Message' else 'indication' } sections = { 'public-types' : '', 'public-methods' : '', 'standard' : '', 'private' : '' } if self.input: self.input.add_sections (sections) self.output.add_sections (sections) if self.type == 'Message': template = ( '<SUBSECTION ${camelcase}ClientMethods>\n' 'qmi_client_${service}_${name_underscore}\n' 'qmi_client_${service}_${name_underscore}_finish\n') sections['public-methods'] += string.Template(template).substitute(translations) translations['public_types'] = sections['public-types'] translations['public_methods'] = sections['public-methods'] translations['standard'] = sections['standard'] translations['private'] = sections['private'] template = ( '<SECTION>\n' '<FILE>${hyphened}</FILE>\n' '<TITLE>${fullname}</TITLE>\n' '${public_types}' '${public_methods}' '<SUBSECTION Private>\n' '${private}' '<SUBSECTION Standard>\n' '${standard}' '</SECTION>\n' '\n') sfile.write(string.Template(template).substitute(translations))
def emit_sections(self, sfile): translations = { 'service_dashed': utils.build_dashed_name(self.service), 'service': self.service } # Emit section header template = ('\n' '<SECTION>\n' '<FILE>mbim-${service_dashed}</FILE>\n' '<TITLE>${service}</TITLE>\n') sfile.write(string.Template(template).substitute(translations)) # Emit subsection per type for struct in self.struct_list: struct.emit_section_content(sfile) # Emit subsection per command for command in self.command_list: command.emit_section_content(sfile) sfile.write('</SECTION>\n')
def emit_sections(self, sfile): translations = { 'service_dashed' : utils.build_dashed_name(self.service), 'service' : self.service } # Emit section header template = ( '\n' '<SECTION>\n' '<FILE>mbim-${service_dashed}</FILE>\n' '<TITLE>${service}</TITLE>\n') sfile.write(string.Template(template).substitute(translations)) # Emit subsection per type for struct in self.struct_list: struct.emit_section_content(sfile) # Emit subsection per command for command in self.command_list: command.emit_section_content(sfile) sfile.write( '</SECTION>\n')
def emit_sections(self, sfile): translations = { 'underscore' : utils.build_underscore_name(self.name), 'no_prefix_underscore_upper' : utils.build_underscore_name(self.name[4:]).upper(), 'camelcase' : utils.build_camelcase_name (self.name), 'hyphened' : utils.build_dashed_name (self.name) } template = ( '<SECTION>\n' '<FILE>${hyphened}</FILE>\n' '<TITLE>${camelcase}</TITLE>\n' '${camelcase}\n' '<SUBSECTION Standard>\n' '${camelcase}Class\n' 'QMI_TYPE_${no_prefix_underscore_upper}\n' 'QMI_${no_prefix_underscore_upper}\n' 'QMI_${no_prefix_underscore_upper}_CLASS\n' 'QMI_IS_${no_prefix_underscore_upper}\n' 'QMI_IS_${no_prefix_underscore_upper}_CLASS\n' 'QMI_${no_prefix_underscore_upper}_GET_CLASS\n' '${underscore}_get_type\n' '</SECTION>\n' '\n') sfile.write(string.Template(template).substitute(translations))
def __emit_class(self, hfile, cfile, message_list): # Check if we'll have indications has_indications = False for message in message_list.list: if message.type == 'Indication': has_indications = True break translations = { 'underscore': utils.build_underscore_name(self.name), 'no_prefix_underscore_upper': utils.build_underscore_name(self.name[4:]).upper(), 'camelcase': utils.build_camelcase_name(self.name), 'hyphened': utils.build_dashed_name(self.name), 'service': self.service.upper() } # Emit class header template = ( '#define QMI_TYPE_${no_prefix_underscore_upper} (${underscore}_get_type ())\n' '#define QMI_${no_prefix_underscore_upper}(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QMI_TYPE_${no_prefix_underscore_upper}, ${camelcase}))\n' '#define QMI_${no_prefix_underscore_upper}_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QMI_TYPE_${no_prefix_underscore_upper}, ${camelcase}Class))\n' '#define QMI_IS_${no_prefix_underscore_upper}(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QMI_TYPE_${no_prefix_underscore_upper}))\n' '#define QMI_IS_${no_prefix_underscore_upper}_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QMI_TYPE_${no_prefix_underscore_upper}))\n' '#define QMI_${no_prefix_underscore_upper}_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QMI_TYPE_${no_prefix_underscore_upper}, ${camelcase}Class))\n' '\n' 'typedef struct _${camelcase} ${camelcase};\n' 'typedef struct _${camelcase}Class ${camelcase}Class;\n' '\n' '/**\n' ' * ${camelcase}:\n' ' *\n' ' * The #${camelcase} structure contains private data and should only be accessed\n' ' * using the provided API.\n' ' */\n' 'struct _${camelcase} {\n' ' /*< private >*/\n' ' QmiClient parent;\n' ' gpointer priv_unused;\n' '};\n' '\n' 'struct _${camelcase}Class {\n' ' /*< private >*/\n' ' QmiClientClass parent;\n' '};\n' '\n' 'GType ${underscore}_get_type (void);\n' '\n') hfile.write(string.Template(template).substitute(translations)) # Emit class source. Documentation skipped for the CTL service. template = '' if self.service != 'CTL': template += ( '\n' '/**\n' ' * SECTION: ${hyphened}\n' ' * @title: ${camelcase}\n' ' * @short_description: #QmiClient for the ${service} service.\n' ' *\n' ' * #QmiClient which handles operations in the ${service} service.\n' ' */\n' '\n') template += ( 'G_DEFINE_TYPE (${camelcase}, ${underscore}, QMI_TYPE_CLIENT);\n') if has_indications: template += ('\n' 'enum {\n') for message in message_list.list: if message.type == 'Indication': translations[ 'signal_id'] = utils.build_underscore_uppercase_name( message.name) inner_template = (' SIGNAL_${signal_id},\n') template += string.Template(inner_template).substitute( translations) template += (' SIGNAL_LAST\n' '};\n' '\n' 'static guint signals[SIGNAL_LAST] = { 0 };\n') template += ('\n' 'static void\n' 'process_indication (QmiClient *self,\n' ' QmiMessage *message)\n' '{\n' ' switch (qmi_message_get_message_id (message)) {\n') for message in message_list.list: if message.type == 'Indication': translations['enum_name'] = message.id_enum_name translations[ 'message_fullname_underscore'] = utils.build_underscore_name( message.fullname) translations['message_name'] = message.name translations[ 'signal_id'] = utils.build_underscore_uppercase_name( message.name) inner_template = '' if message.output is not None and message.output.fields is not None: # At least one field in the indication translations[ 'output_camelcase'] = utils.build_camelcase_name( message.output.fullname) translations[ 'output_underscore'] = utils.build_underscore_name( message.output.fullname) translations[ 'output_underscore'] = utils.build_underscore_name( message.output.fullname) inner_template += ( ' case ${enum_name}: {\n' ' ${output_camelcase} *output;\n' ' GError *error = NULL;\n' '\n' ' /* Parse indication */\n' ' output = __${message_fullname_underscore}_indication_parse (message, &error);\n' ' if (!output) {\n' ' g_warning ("Couldn\'t parse \'${message_name}\' indication: %s",\n' ' error ? error->message : "Unknown error");\n' ' if (error)\n' ' g_error_free (error);\n' ' } else {\n' ' g_signal_emit (self, signals[SIGNAL_${signal_id}], 0, output);\n' ' ${output_underscore}_unref (output);\n' ' }\n' ' break;\n' ' }\n') else: # No output field in the indication inner_template += ( ' case ${enum_name}: {\n' ' g_signal_emit (self, signals[SIGNAL_${signal_id}], 0, NULL);\n' ' break;\n' ' }\n') template += string.Template(inner_template).substitute( translations) template += ( ' default:\n' ' break;\n' ' }\n' '}\n' '\n' 'static void\n' '${underscore}_init (${camelcase} *self)\n' '{\n' '}\n' '\n' 'static void\n' '${underscore}_class_init (${camelcase}Class *klass)\n' '{\n' ' QmiClientClass *client_class = QMI_CLIENT_CLASS (klass);\n' '\n' ' client_class->process_indication = process_indication;\n') for message in message_list.list: if message.type == 'Indication': translations['signal_name'] = utils.build_dashed_name( message.name) translations[ 'signal_id'] = utils.build_underscore_uppercase_name( message.name) translations['message_name'] = message.name inner_template = '' if message.output is not None and message.output.fields is not None: # At least one field in the indication translations[ 'output_camelcase'] = utils.build_camelcase_name( message.output.fullname) translations[ 'bundle_type'] = 'QMI_TYPE_' + utils.remove_prefix( utils.build_underscore_uppercase_name( message.output.fullname), 'QMI_') translations['service'] = self.service.upper() translations['message_name_dashed'] = message.name.replace( ' ', '-') inner_template += ( '\n' ' /**\n' ' * ${camelcase}::${signal_name}:\n' ' * @object: A #${camelcase}.\n' ' * @output: A #${output_camelcase}.\n' ' *\n' ' * The ::${signal_name} signal gets emitted when a \'<link linkend=\"libqmi-glib-${service}-${message_name_dashed}.top_of_page\">${message_name}</link>\' indication is received.\n' ' */\n' ' signals[SIGNAL_${signal_id}] =\n' ' g_signal_new ("${signal_name}",\n' ' G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),\n' ' G_SIGNAL_RUN_LAST,\n' ' 0,\n' ' NULL,\n' ' NULL,\n' ' NULL,\n' ' G_TYPE_NONE,\n' ' 1,\n' ' ${bundle_type});\n') else: # No output field in the indication inner_template += ( '\n' ' /**\n' ' * ${camelcase}::${signal_name}:\n' ' * @object: A #${camelcase}.\n' ' *\n' ' * The ::${signal_name} signal gets emitted when a \'${message_name}\' indication is received.\n' ' */\n' ' signals[SIGNAL_${signal_id}] =\n' ' g_signal_new ("${signal_name}",\n' ' G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),\n' ' G_SIGNAL_RUN_LAST,\n' ' 0,\n' ' NULL,\n' ' NULL,\n' ' NULL,\n' ' G_TYPE_NONE,\n' ' 0);\n') template += string.Template(inner_template).substitute( translations) template += ('}\n' '\n') cfile.write(string.Template(template).substitute(translations))
def __emit_class(self, hfile, cfile, message_list): # Check if we'll have indications has_indications = False for message in message_list.list: if message.type == 'Indication': has_indications = True break translations = { 'underscore' : utils.build_underscore_name(self.name), 'no_prefix_underscore_upper' : utils.build_underscore_name(self.name[4:]).upper(), 'camelcase' : utils.build_camelcase_name(self.name), 'hyphened' : utils.build_dashed_name(self.name), 'service' : self.service.upper() } # Emit class header template = ( '#define QMI_TYPE_${no_prefix_underscore_upper} (${underscore}_get_type ())\n' '#define QMI_${no_prefix_underscore_upper}(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QMI_TYPE_${no_prefix_underscore_upper}, ${camelcase}))\n' '#define QMI_${no_prefix_underscore_upper}_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QMI_TYPE_${no_prefix_underscore_upper}, ${camelcase}Class))\n' '#define QMI_IS_${no_prefix_underscore_upper}(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QMI_TYPE_${no_prefix_underscore_upper}))\n' '#define QMI_IS_${no_prefix_underscore_upper}_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QMI_TYPE_${no_prefix_underscore_upper}))\n' '#define QMI_${no_prefix_underscore_upper}_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QMI_TYPE_${no_prefix_underscore_upper}, ${camelcase}Class))\n' '\n' 'typedef struct _${camelcase} ${camelcase};\n' 'typedef struct _${camelcase}Class ${camelcase}Class;\n' '\n' '/**\n' ' * ${camelcase}:\n' ' *\n' ' * The #${camelcase} structure contains private data and should only be accessed\n' ' * using the provided API.\n' ' */\n' 'struct _${camelcase} {\n' ' /*< private >*/\n' ' QmiClient parent;\n' ' gpointer priv_unused;\n' '};\n' '\n' 'struct _${camelcase}Class {\n' ' /*< private >*/\n' ' QmiClientClass parent;\n' '};\n' '\n' 'GType ${underscore}_get_type (void);\n' '\n') hfile.write(string.Template(template).substitute(translations)) # Emit class source. Documentation skipped for the CTL service. template = '' if self.service != 'CTL': template += ( '\n' '/**\n' ' * SECTION: ${hyphened}\n' ' * @title: ${camelcase}\n' ' * @short_description: #QmiClient for the ${service} service.\n' ' *\n' ' * #QmiClient which handles operations in the ${service} service.\n' ' */\n' '\n') template += ( 'G_DEFINE_TYPE (${camelcase}, ${underscore}, QMI_TYPE_CLIENT);\n') if has_indications: template += ( '\n' 'enum {\n') for message in message_list.list: if message.type == 'Indication': translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) inner_template = ( ' SIGNAL_${signal_id},\n') template += string.Template(inner_template).substitute(translations) template += ( ' SIGNAL_LAST\n' '};\n' '\n' 'static guint signals[SIGNAL_LAST] = { 0 };\n') template += ( '\n' 'static void\n' 'process_indication (QmiClient *self,\n' ' QmiMessage *message)\n' '{\n' ' switch (qmi_message_get_message_id (message)) {\n') for message in message_list.list: if message.type == 'Indication': translations['enum_name'] = message.id_enum_name translations['message_fullname_underscore'] = utils.build_underscore_name(message.fullname) translations['message_name'] = message.name translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) inner_template = '' if message.output is not None and message.output.fields is not None: # At least one field in the indication translations['output_camelcase'] = utils.build_camelcase_name(message.output.fullname) translations['output_underscore'] = utils.build_underscore_name(message.output.fullname) translations['output_underscore'] = utils.build_underscore_name(message.output.fullname) inner_template += ( ' case ${enum_name}: {\n' ' ${output_camelcase} *output;\n' ' GError *error = NULL;\n' '\n' ' /* Parse indication */\n' ' output = __${message_fullname_underscore}_indication_parse (message, &error);\n' ' if (!output) {\n' ' g_warning ("Couldn\'t parse \'${message_name}\' indication: %s",\n' ' error ? error->message : "Unknown error");\n' ' if (error)\n' ' g_error_free (error);\n' ' } else {\n' ' g_signal_emit (self, signals[SIGNAL_${signal_id}], 0, output);\n' ' ${output_underscore}_unref (output);\n' ' }\n' ' break;\n' ' }\n') else: # No output field in the indication inner_template += ( ' case ${enum_name}: {\n' ' g_signal_emit (self, signals[SIGNAL_${signal_id}], 0, NULL);\n' ' break;\n' ' }\n') template += string.Template(inner_template).substitute(translations) template += ( ' default:\n' ' break;\n' ' }\n' '}\n' '\n' 'static void\n' '${underscore}_init (${camelcase} *self)\n' '{\n' '}\n' '\n' 'static void\n' '${underscore}_class_init (${camelcase}Class *klass)\n' '{\n' ' QmiClientClass *client_class = QMI_CLIENT_CLASS (klass);\n' '\n' ' client_class->process_indication = process_indication;\n') for message in message_list.list: if message.type == 'Indication': translations['signal_name'] = utils.build_dashed_name(message.name) translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) translations['message_name'] = message.name inner_template = '' if message.output is not None and message.output.fields is not None: # At least one field in the indication translations['output_camelcase'] = utils.build_camelcase_name(message.output.fullname) translations['bundle_type'] = 'QMI_TYPE_' + utils.remove_prefix(utils.build_underscore_uppercase_name(message.output.fullname), 'QMI_') translations['service'] = self.service.upper() translations['message_name_dashed'] = message.name.replace(' ', '-') inner_template += ( '\n' ' /**\n' ' * ${camelcase}::${signal_name}:\n' ' * @object: A #${camelcase}.\n' ' * @output: A #${output_camelcase}.\n' ' *\n' ' * The ::${signal_name} signal gets emitted when a \'<link linkend=\"libqmi-glib-${service}-${message_name_dashed}.top_of_page\">${message_name}</link>\' indication is received.\n' ' */\n' ' signals[SIGNAL_${signal_id}] =\n' ' g_signal_new ("${signal_name}",\n' ' G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),\n' ' G_SIGNAL_RUN_LAST,\n' ' 0,\n' ' NULL,\n' ' NULL,\n' ' NULL,\n' ' G_TYPE_NONE,\n' ' 1,\n' ' ${bundle_type});\n') else: # No output field in the indication inner_template += ( '\n' ' /**\n' ' * ${camelcase}::${signal_name}:\n' ' * @object: A #${camelcase}.\n' ' *\n' ' * The ::${signal_name} signal gets emitted when a \'${message_name}\' indication is received.\n' ' */\n' ' signals[SIGNAL_${signal_id}] =\n' ' g_signal_new ("${signal_name}",\n' ' G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),\n' ' G_SIGNAL_RUN_LAST,\n' ' 0,\n' ' NULL,\n' ' NULL,\n' ' NULL,\n' ' G_TYPE_NONE,\n' ' 0);\n') template += string.Template(inner_template).substitute(translations) template += ( '}\n' '\n') cfile.write(string.Template(template).substitute(translations))