diff options
-rw-r--r-- | build-aux/mbim-codegen/ObjectList.py | 150 | ||||
-rwxr-xr-x | build-aux/mbim-codegen/mbim-codegen | 14 | ||||
-rw-r--r-- | docs/reference/libmbim-glib/libmbim-glib-docs.xml | 3 | ||||
-rw-r--r-- | src/libmbim-glib/generated/meson.build | 48 | ||||
-rw-r--r-- | src/libmbim-glib/libmbim-glib.h | 3 | ||||
-rw-r--r-- | src/libmbim-glib/mbim-message.c | 3 |
6 files changed, 118 insertions, 103 deletions
diff --git a/build-aux/mbim-codegen/ObjectList.py b/build-aux/mbim-codegen/ObjectList.py index 3afdf21..bb3d45a 100644 --- a/build-aux/mbim-codegen/ObjectList.py +++ b/build-aux/mbim-codegen/ObjectList.py @@ -46,27 +46,33 @@ class ObjectList: def __init__(self, objects_dictionary): self.command_list = [] self.struct_list = [] - self.service = '' - self.mbimex_service = '' - self.mbimex_version = '' + self.service_list = [] # Loop items in the list, creating Message objects for the messages + service_iter = '' + mbimex_service_iter = '' + mbimex_version_iter = '' + for object_dictionary in objects_dictionary: if object_dictionary['type'] == 'Command': - if self.service == '': + if service_iter == '': raise ValueError('Service name not specified before the first command') - self.command_list.append(Message(self.service, self.mbimex_service, self.mbimex_version, object_dictionary)) + self.command_list.append(Message(service_iter, mbimex_service_iter, mbimex_version_iter, object_dictionary)) elif object_dictionary['type'] == 'Struct': self.struct_list.append(Struct(object_dictionary)) elif object_dictionary['type'] == 'Service': - self.service = object_dictionary['name'] + service_iter = object_dictionary['name'] + self.service_list.append(service_iter) if 'mbimex-service' in object_dictionary: - self.mbimex_service = object_dictionary['mbimex-service'] - self.mbimex_version = object_dictionary['mbimex-version'] + mbimex_service_iter = object_dictionary['mbimex-service'] + mbimex_version_iter = object_dictionary['mbimex-version'] + else: + mbimex_service_iter = '' + mbimex_version_iter = '' else: raise ValueError('Cannot handle object type \'%s\'' % object_dictionary['type']) - if self.service == '': + if not self.service_list: raise ValueError('Service name not specified') # Populate struct usages @@ -90,61 +96,47 @@ class ObjectList: """ - Emit support for printing messages in this service + Emit support for printing messages in a single service """ - def emit_printable(self, hfile, cfile): - translations = { 'service_underscore' : utils.build_underscore_name(self.service), - 'service' : self.service } - + def emit_printable_service(self, hfile, cfile, service): + translations = { 'service_underscore' : utils.build_underscore_name(service), + 'service' : service } template = ( '\n' - '/*****************************************************************************/\n' - '/* Service helper for printable fields */\n' - '\n' - '#if defined (LIBMBIM_GLIB_COMPILATION)\n' - '\n' 'G_GNUC_INTERNAL\n' 'gchar *\n' '__mbim_message_${service_underscore}_get_printable_fields (\n' ' const MbimMessage *message,\n' ' const gchar *line_prefix,\n' - ' GError **error);\n' - '\n' - '#endif\n') + ' GError **error);\n') hfile.write(string.Template(template).substitute(translations)) template = ( '\n' - 'typedef struct {\n' - ' gchar * (* query_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);\n' - ' gchar * (* set_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);\n' - ' gchar * (* response_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);\n' - ' gchar * (* notification_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);\n' - '} GetPrintableCallbacks;\n' - '\n' - 'static const GetPrintableCallbacks get_printable_callbacks[] = {\n') + 'static const GetPrintableCallbacks ${service_underscore}_get_printable_callbacks[] = {\n') for item in self.command_list: - translations['message'] = utils.build_underscore_name (item.fullname) - translations['cid'] = item.cid_enum_name - inner_template = ( - ' [${cid}] = {\n') - if item.has_query: - inner_template += ( - ' .query_cb = ${message}_query_get_printable,\n') - if item.has_set: + if item.service == service: + translations['message'] = utils.build_underscore_name (item.fullname) + translations['cid'] = item.cid_enum_name + inner_template = ( + ' [${cid}] = {\n') + if item.has_query: + inner_template += ( + ' .query_cb = ${message}_query_get_printable,\n') + if item.has_set: + inner_template += ( + ' .set_cb = ${message}_set_get_printable,\n') + if item.has_response: + inner_template += ( + ' .response_cb = ${message}_response_get_printable,\n') + if item.has_notification: + inner_template += ( + ' .notification_cb = ${message}_notification_get_printable,\n') inner_template += ( - ' .set_cb = ${message}_set_get_printable,\n') - if item.has_response: - inner_template += ( - ' .response_cb = ${message}_response_get_printable,\n') - if item.has_notification: - inner_template += ( - ' .notification_cb = ${message}_notification_get_printable,\n') - inner_template += ( - ' },\n') - template += (string.Template(inner_template).substitute(translations)) + ' },\n') + template += (string.Template(inner_template).substitute(translations)) template += ( '};\n' @@ -160,15 +152,15 @@ class ObjectList: ' switch (mbim_message_get_message_type (message)) {\n' ' case MBIM_MESSAGE_TYPE_COMMAND: {\n' ' cid = mbim_message_command_get_cid (message);\n' - ' if (cid < G_N_ELEMENTS (get_printable_callbacks)) {\n' + ' if (cid < G_N_ELEMENTS (${service_underscore}_get_printable_callbacks)) {\n' ' switch (mbim_message_command_get_command_type (message)) {\n' ' case MBIM_MESSAGE_COMMAND_TYPE_QUERY:\n' - ' if (get_printable_callbacks[cid].query_cb)\n' - ' return get_printable_callbacks[cid].query_cb (message, line_prefix, error);\n' + ' if (${service_underscore}_get_printable_callbacks[cid].query_cb)\n' + ' return ${service_underscore}_get_printable_callbacks[cid].query_cb (message, line_prefix, error);\n' ' break;\n' ' case MBIM_MESSAGE_COMMAND_TYPE_SET:\n' - ' if (get_printable_callbacks[cid].set_cb)\n' - ' return get_printable_callbacks[cid].set_cb (message, line_prefix, error);\n' + ' if (${service_underscore}_get_printable_callbacks[cid].set_cb)\n' + ' return ${service_underscore}_get_printable_callbacks[cid].set_cb (message, line_prefix, error);\n' ' break;\n' ' case MBIM_MESSAGE_COMMAND_TYPE_UNKNOWN:\n' ' default:\n' @@ -184,17 +176,17 @@ class ObjectList: '\n' ' case MBIM_MESSAGE_TYPE_COMMAND_DONE:\n' ' cid = mbim_message_command_done_get_cid (message);\n' - ' if (cid < G_N_ELEMENTS (get_printable_callbacks)) {\n' - ' if (get_printable_callbacks[cid].response_cb)\n' - ' return get_printable_callbacks[cid].response_cb (message, line_prefix, error);\n' + ' if (cid < G_N_ELEMENTS (${service_underscore}_get_printable_callbacks)) {\n' + ' if (${service_underscore}_get_printable_callbacks[cid].response_cb)\n' + ' return ${service_underscore}_get_printable_callbacks[cid].response_cb (message, line_prefix, error);\n' ' }\n' ' break;\n' '\n' ' case MBIM_MESSAGE_TYPE_INDICATE_STATUS:\n' ' cid = mbim_message_indicate_status_get_cid (message);\n' - ' if (cid < G_N_ELEMENTS (get_printable_callbacks)) {\n' - ' if (get_printable_callbacks[cid].notification_cb)\n' - ' return get_printable_callbacks[cid].notification_cb (message, line_prefix, error);\n' + ' if (cid < G_N_ELEMENTS (${service_underscore}_get_printable_callbacks)) {\n' + ' if (${service_underscore}_get_printable_callbacks[cid].notification_cb)\n' + ' return ${service_underscore}_get_printable_callbacks[cid].notification_cb (message, line_prefix, error);\n' ' }\n' ' break;\n' '\n' @@ -222,13 +214,41 @@ class ObjectList: cfile.write(string.Template(template).substitute(translations)) + def emit_printable(self, hfile, cfile): + + template = ( + '\n' + '/*****************************************************************************/\n' + '/* Service helpers for printable fields */\n' + '\n' + '#if defined (LIBMBIM_GLIB_COMPILATION)\n') + hfile.write(template) + + template = ( + '\n' + 'typedef struct {\n' + ' gchar * (* query_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);\n' + ' gchar * (* set_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);\n' + ' gchar * (* response_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);\n' + ' gchar * (* notification_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);\n' + '} GetPrintableCallbacks;\n') + cfile.write(template) + + for service in self.service_list: + self.emit_printable_service(hfile, cfile, service) + + template = ( + '\n' + '#endif\n') + hfile.write(template) + """ - Emit the sections + Emit the section for a single service """ - def emit_sections(self, sfile): - translations = { 'service_dashed' : utils.build_dashed_name(self.service), - 'service' : self.service } + def emit_sections_service(self, sfile, service): + translations = { 'service_dashed' : utils.build_dashed_name(service), + 'service' : service } # Emit section header template = ( @@ -248,3 +268,7 @@ class ObjectList: sfile.write( '</SECTION>\n') + + def emit_sections(self, sfile): + for service in self.service_list: + self.emit_sections_service(sfile, service) diff --git a/build-aux/mbim-codegen/mbim-codegen b/build-aux/mbim-codegen/mbim-codegen index 5b60440..4d7c4ad 100755 --- a/build-aux/mbim-codegen/mbim-codegen +++ b/build-aux/mbim-codegen/mbim-codegen @@ -17,13 +17,11 @@ import utils def codegen_main(): # Input arguments arg_parser = optparse.OptionParser('%prog [options]') - arg_parser.add_option('', '--input', metavar='JSONFILE', - help='Input JSON-formatted database') arg_parser.add_option('', '--output', metavar='OUTFILES', help='Generate C code in OUTFILES.[ch]') (opts, args) = arg_parser.parse_args(); - if opts.input == None: + if args == None: raise RuntimeError('Input JSON file is mandatory') if opts.output == None: raise RuntimeError('Output file pattern is mandatory') @@ -33,11 +31,11 @@ def codegen_main(): output_file_h = open(opts.output + ".h", 'w') output_file_sections = open(opts.output + ".sections", 'w') - # Load database file contents - database_file_contents = utils.read_json_file(opts.input) - - # Build message list - object_list_json = json.loads(database_file_contents) + # Build message list from all input files + object_list_json = [] + for input_file in args: + database_file_contents = utils.read_json_file(input_file) + object_list_json += json.loads(database_file_contents) object_list = ObjectList(object_list_json) # Add common stuff to the output files diff --git a/docs/reference/libmbim-glib/libmbim-glib-docs.xml b/docs/reference/libmbim-glib/libmbim-glib-docs.xml index 6ff3371..9974e5c 100644 --- a/docs/reference/libmbim-glib/libmbim-glib-docs.xml +++ b/docs/reference/libmbim-glib/libmbim-glib-docs.xml @@ -75,9 +75,6 @@ <chapter> <title>Microsoft-defined services</title> <xi:include href="xml/mbim-ms-basic-connect-extensions.xml"/> - <xi:include href="xml/mbim-ms-basic-connect-extensions-v3.xml"/> - <xi:include href="xml/mbim-ms-basic-connect-v2.xml"/> - <xi:include href="xml/mbim-ms-basic-connect-v3.xml"/> <xi:include href="xml/mbim-ms-uicc-low-level-access.xml"/> <xi:include href="xml/mbim-ms-firmware-id.xml"/> <xi:include href="xml/mbim-ms-host-shutdown.xml"/> diff --git a/src/libmbim-glib/generated/meson.build b/src/libmbim-glib/generated/meson.build index 3089983..8673609 100644 --- a/src/libmbim-glib/generated/meson.build +++ b/src/libmbim-glib/generated/meson.build @@ -88,37 +88,39 @@ gen_sources += custom_target( ) services_data = [ - ['atds', true], - ['auth', true], - ['basic-connect', true], - ['dss', true], - ['intel-firmware-update', true], - ['ms-basic-connect-extensions', true], - ['ms-basic-connect-extensions-v3', true], - ['ms-uicc-low-level-access', true], - ['ms-basic-connect-v2', true], - ['ms-basic-connect-v3', true], - ['ms-firmware-id', true], - ['ms-host-shutdown', true], - ['ms-sar', true], - ['phonebook', true], - ['proxy-control', false], - ['qdu', true], - ['qmi', true], - ['sms', true], - ['stk', true], - ['ussd', true], + [['atds'], true], + [['auth'], true], + [['basic-connect', 'ms-basic-connect-v2', 'ms-basic-connect-v3'], true], + [['dss'], true], + [['intel-firmware-update'], true], + [['ms-basic-connect-extensions', 'ms-basic-connect-extensions-v3'], true], + [['ms-uicc-low-level-access'], true], + [['ms-firmware-id'], true], + [['ms-host-shutdown'], true], + [['ms-sar'], true], + [['phonebook'], true], + [['proxy-control'], false], + [['qdu'], true], + [['qmi'], true], + [['sms'], true], + [['stk'], true], + [['ussd'], true], ] foreach service_data: services_data - service = service_data[0] + service = service_data[0][0] name = 'mbim-' + service + input = [] + foreach service_file: service_data[0] + input += data_dir / 'mbim-service-@0@.json'.format(service_file) + endforeach + generated = custom_target( name, - input: data_dir / 'mbim-service-@0@.json'.format(service), + input: input, output: [name + '.c', name + '.h', name + '.sections'], - command: [mbim_codegen, '--input', '@INPUT@', '--output', '@OUTDIR@' / name], + command: [mbim_codegen, '--output', '@OUTDIR@' / name, '@INPUT@'], install: true, install_dir: [false, mbim_glib_pkgincludedir, false], ) diff --git a/src/libmbim-glib/libmbim-glib.h b/src/libmbim-glib/libmbim-glib.h index 2cab3d2..7fdf8e0 100644 --- a/src/libmbim-glib/libmbim-glib.h +++ b/src/libmbim-glib/libmbim-glib.h @@ -41,9 +41,6 @@ #include "mbim-intel-firmware-update.h" #include "mbim-ms-basic-connect-extensions.h" #include "mbim-ms-uicc-low-level-access.h" -#include "mbim-ms-basic-connect-v2.h" -#include "mbim-ms-basic-connect-v3.h" -#include "mbim-ms-basic-connect-extensions-v3.h" /* backwards compatibility */ #include "mbim-compat.h" diff --git a/src/libmbim-glib/mbim-message.c b/src/libmbim-glib/mbim-message.c index 9c28620..3439dae 100644 --- a/src/libmbim-glib/mbim-message.c +++ b/src/libmbim-glib/mbim-message.c @@ -34,9 +34,6 @@ #include "mbim-qdu.h" #include "mbim-ms-basic-connect-extensions.h" #include "mbim-ms-uicc-low-level-access.h" -#include "mbim-ms-basic-connect-v2.h" -#include "mbim-ms-basic-connect-v3.h" -#include "mbim-ms-basic-connect-extensions-v3.h" /*****************************************************************************/ |