diff options
author | Aleksander Morgado <aleksandermj@chromium.org> | 2023-04-27 09:37:39 +0000 |
---|---|---|
committer | Aleksander Morgado <aleksandermj@chromium.org> | 2023-04-27 10:01:49 +0000 |
commit | 8d2415d2a529d2ab17fbd501ce5e7f94d496292e (patch) | |
tree | 48295d711745e375d4efe097912b4f9059cab109 | |
parent | a1ce19926cc60438ea2b9fd815c178b75f9436bf (diff) | |
download | libmbim-8d2415d2a529d2ab17fbd501ce5e7f94d496292e.tar.gz |
libmbim-glib: separate files for flags and enums types
This allows us to skip needing to include the non-existent
build_string_from_mask() or get_string() counterparts in the
documentation index.
-rw-r--r-- | build-aux/mbim-codegen/utils.py | 1 | ||||
-rw-r--r-- | build-aux/templates/mbim-enum-types.c.template | 46 | ||||
-rw-r--r-- | build-aux/templates/mbim-enum-types.h.template | 17 | ||||
-rw-r--r-- | build-aux/templates/mbim-flag-types.c.template | 81 | ||||
-rw-r--r-- | build-aux/templates/mbim-flag-types.h.template | 38 | ||||
-rw-r--r-- | docs/reference/libmbim-glib/libmbim-glib-common.sections | 100 | ||||
-rw-r--r-- | src/libmbim-glib/generated/meson.build | 38 | ||||
-rw-r--r-- | src/libmbim-glib/libmbim-glib.h | 1 |
8 files changed, 158 insertions, 164 deletions
diff --git a/build-aux/mbim-codegen/utils.py b/build-aux/mbim-codegen/utils.py index 8f39b8b..8ae85bb 100644 --- a/build-aux/mbim-codegen/utils.py +++ b/build-aux/mbim-codegen/utils.py @@ -98,6 +98,7 @@ def add_source_start(f, output_name): "#include \"mbim-message-private.h\"\n" "#include \"mbim-tlv-private.h\"\n" "#include \"mbim-enum-types.h\"\n" + "#include \"mbim-flag-types.h\"\n" "#include \"mbim-error-types.h\"\n" "#include \"mbim-device.h\"\n" "#include \"mbim-utils.h\"\n") diff --git a/build-aux/templates/mbim-enum-types.c.template b/build-aux/templates/mbim-enum-types.c.template index fd3d47e..0fa59a6 100644 --- a/build-aux/templates/mbim-enum-types.c.template +++ b/build-aux/templates/mbim-enum-types.c.template @@ -36,7 +36,6 @@ GType /* Enum-specific method to get the value as a string. * We get the nick of the GEnumValue. Note that this will be * valid even if the GEnumClass is not referenced anywhere. */ -#if defined __@ENUMNAME@_IS_ENUM__ const gchar * @enum_name@_get_string (@EnumName@ val) { @@ -49,51 +48,6 @@ const gchar * return NULL; } -#endif /* __@ENUMNAME@_IS_ENUM__ */ - -/* Flags-specific method to build a string with the given mask. - * We get a comma separated list of the nicks of the GFlagsValues. - * Note that this will be valid even if the GFlagsClass is not referenced - * anywhere. */ -#if defined __@ENUMNAME@_IS_FLAGS__ -gchar * -@enum_name@_build_string_from_mask (@EnumName@ mask) -{ - guint i; - gboolean first = TRUE; - GString *str = NULL; - - for (i = 0; @enum_name@_values[i].value_nick; i++) { - /* We also look for exact matches */ - if ((guint)mask == @enum_name@_values[i].value) { - if (str) - g_string_free (str, TRUE); - return g_strdup (@enum_name@_values[i].value_nick); - } - - /* Build list with single-bit masks */ - if (mask & @enum_name@_values[i].value) { - guint c; - gulong number = @enum_name@_values[i].value; - - for (c = 0; number; c++) - number &= number - 1; - - if (c == 1) { - if (!str) - str = g_string_new (""); - g_string_append_printf (str, "%s%s", - first ? "" : ", ", - @enum_name@_values[i].value_nick); - if (first) - first = FALSE; - } - } - } - - return (str ? g_string_free (str, FALSE) : NULL); -} -#endif /* __@ENUMNAME@_IS_FLAGS__ */ /*** END value-tail ***/ diff --git a/build-aux/templates/mbim-enum-types.h.template b/build-aux/templates/mbim-enum-types.h.template index c72f7d9..c4eeed9 100644 --- a/build-aux/templates/mbim-enum-types.h.template +++ b/build-aux/templates/mbim-enum-types.h.template @@ -17,7 +17,6 @@ GType @enum_name@_get_type (void) G_GNUC_CONST; /* Define type-specific symbols */ #define __@ENUMNAME@_IS_@TYPE@__ -#if defined __@ENUMNAME@_IS_ENUM__ /** * @enum_name@_get_string: * @val: a @EnumName@. @@ -29,22 +28,6 @@ GType @enum_name@_get_type (void) G_GNUC_CONST; * Since: @enumsince@ */ const gchar *@enum_name@_get_string (@EnumName@ val); -#endif - -#if defined __@ENUMNAME@_IS_FLAGS__ -/** - * @enum_name@_build_string_from_mask: - * @mask: bitmask of @EnumName@ values. - * - * Builds a string containing a comma-separated list of nicknames for - * each #@EnumName@ in @mask. - * - * Returns: (transfer full): a string with the list of nicknames, or %NULL if none given. The returned value should be freed with g_free(). - * - * Since: @enumsince@ - */ -gchar *@enum_name@_build_string_from_mask (@EnumName@ mask); -#endif /*** END value-header ***/ diff --git a/build-aux/templates/mbim-flag-types.c.template b/build-aux/templates/mbim-flag-types.c.template new file mode 100644 index 0000000..d2877b7 --- /dev/null +++ b/build-aux/templates/mbim-flag-types.c.template @@ -0,0 +1,81 @@ +/*** BEGIN file-header ***/ + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +static const G@Type@Value @enum_name@_values[] = { +/*** END value-header ***/ +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } +}; + +/* Define type-specific symbols */ + +GType +@enum_name@_get_type (void) +{ + static gsize g_define_type_id_initialized = 0; + + if (g_once_init_enter (&g_define_type_id_initialized)) { + GType g_define_type_id = + g_@type@_register_static (g_intern_static_string ("@EnumName@"), + @enum_name@_values); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); + } + + return g_define_type_id_initialized; +} + +/* Flags-specific method to build a string with the given mask. + * We get a comma separated list of the nicks of the GFlagsValues. + * Note that this will be valid even if the GFlagsClass is not referenced + * anywhere. */ +gchar * +@enum_name@_build_string_from_mask (@EnumName@ mask) +{ + guint i; + gboolean first = TRUE; + GString *str = NULL; + + for (i = 0; @enum_name@_values[i].value_nick; i++) { + /* We also look for exact matches */ + if ((guint)mask == @enum_name@_values[i].value) { + if (str) + g_string_free (str, TRUE); + return g_strdup (@enum_name@_values[i].value_nick); + } + + /* Build list with single-bit masks */ + if (mask & @enum_name@_values[i].value) { + guint c; + gulong number = @enum_name@_values[i].value; + + for (c = 0; number; c++) + number &= number - 1; + + if (c == 1) { + if (!str) + str = g_string_new (""); + g_string_append_printf (str, "%s%s", + first ? "" : ", ", + @enum_name@_values[i].value_nick); + if (first) + first = FALSE; + } + } + } + + return (str ? g_string_free (str, FALSE) : NULL); +} + +/*** END value-tail ***/ + +/*** BEGIN file-tail ***/ +/*** END file-tail ***/ diff --git a/build-aux/templates/mbim-flag-types.h.template b/build-aux/templates/mbim-flag-types.h.template new file mode 100644 index 0000000..4742b6d --- /dev/null +++ b/build-aux/templates/mbim-flag-types.h.template @@ -0,0 +1,38 @@ +/*** BEGIN file-header ***/ + +#include <glib-object.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) + +/* Define type-specific symbols */ +#define __@ENUMNAME@_IS_@TYPE@__ + +/** + * @enum_name@_build_string_from_mask: + * @mask: bitmask of @EnumName@ values. + * + * Builds a string containing a comma-separated list of nicknames for + * each #@EnumName@ in @mask. + * + * Returns: (transfer full): a string with the list of nicknames, or %NULL if none given. The returned value should be freed with g_free(). + * + * Since: @enumsince@ + */ +gchar *@enum_name@_build_string_from_mask (@EnumName@ mask); + +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +/*** END file-tail ***/ diff --git a/docs/reference/libmbim-glib/libmbim-glib-common.sections b/docs/reference/libmbim-glib/libmbim-glib-common.sections index 0cc6d04..e22acc3 100644 --- a/docs/reference/libmbim-glib/libmbim-glib-common.sections +++ b/docs/reference/libmbim-glib/libmbim-glib-common.sections @@ -537,106 +537,6 @@ mbim_trace_command_get_string mbim_carrier_lock_status_get_string mbim_carrier_lock_modem_state_get_string mbim_carrier_lock_cause_get_string -<SUBSECTION Private> -mbim_device_type_build_string_from_mask -mbim_cellular_class_get_string -mbim_voice_class_build_string_from_mask -mbim_sim_class_get_string -mbim_data_class_get_string -mbim_sms_caps_get_string -mbim_ctrl_caps_get_string -mbim_subscriber_ready_state_build_string_from_mask -mbim_ready_info_flag_get_string -mbim_radio_switch_state_build_string_from_mask -mbim_pin_type_build_string_from_mask -mbim_pin_state_build_string_from_mask -mbim_pin_operation_build_string_from_mask -mbim_pin_mode_build_string_from_mask -mbim_pin_format_build_string_from_mask -mbim_provider_state_get_string -mbim_visible_providers_action_build_string_from_mask -mbim_nw_error_build_string_from_mask -mbim_register_action_build_string_from_mask -mbim_register_state_build_string_from_mask -mbim_register_mode_build_string_from_mask -mbim_registration_flag_get_string -mbim_registration_flag_build_string_from_mask -mbim_packet_service_action_build_string_from_mask -mbim_packet_service_state_build_string_from_mask -mbim_activation_command_build_string_from_mask -mbim_compression_build_string_from_mask -mbim_auth_protocol_build_string_from_mask -mbim_context_ip_type_build_string_from_mask -mbim_activation_state_build_string_from_mask -mbim_voice_call_state_build_string_from_mask -mbim_ip_configuration_available_flag_get_string -mbim_sms_cdma_encoding_build_string_from_mask -mbim_sms_cdma_lang_build_string_from_mask -mbim_sms_flag_build_string_from_mask -mbim_sms_format_build_string_from_mask -mbim_sms_status_build_string_from_mask -mbim_sms_storage_state_build_string_from_mask -mbim_ussd_action_build_string_from_mask -mbim_ussd_response_build_string_from_mask -mbim_ussd_session_state_build_string_from_mask -mbim_phonebook_flag_build_string_from_mask -mbim_phonebook_state_build_string_from_mask -mbim_phonebook_write_flag_build_string_from_mask -mbim_stk_pac_profile_build_string_from_mask -mbim_stk_pac_type_build_string_from_mask -mbim_network_idle_hint_state_build_string_from_mask -mbim_emergency_mode_state_build_string_from_mask -mbim_dss_link_state_build_string_from_mask -mbim_atds_provider_plmn_mode_build_string_from_mask -mbim_atds_rat_mode_build_string_from_mask -mbim_pco_type_build_string_from_mask -mbim_context_source_build_string_from_mask -mbim_lte_attach_context_operation_build_string_from_mask -mbim_lte_attach_context_roaming_control_build_string_from_mask -mbim_lte_attach_state_build_string_from_mask -mbim_sar_backoff_state_build_string_from_mask -mbim_sar_control_mode_build_string_from_mask -mbim_sar_wifi_hardware_state_build_string_from_mask -mbim_transmission_notification_status_build_string_from_mask -mbim_transmission_state_build_string_from_mask -mbim_qdu_file_type_build_string_from_mask -mbim_qdu_session_action_build_string_from_mask -mbim_qdu_session_result_build_string_from_mask -mbim_qdu_session_status_build_string_from_mask -mbim_qdu_session_type_build_string_from_mask -mbim_qdu_quectel_reboot_type_build_string_from_mask -mbim_qdu_quectel_version_type_build_string_from_mask -mbim_uicc_slot_state_build_string_from_mask -mbim_uicc_secure_messaging_build_string_from_mask -mbim_uicc_class_byte_type_build_string_from_mask -mbim_uicc_pass_through_action_build_string_from_mask -mbim_uicc_pass_through_status_build_string_from_mask -mbim_frequency_range_get_string -mbim_context_roaming_control_build_string_from_mask -mbim_context_media_type_build_string_from_mask -mbim_context_state_build_string_from_mask -mbim_context_operation_build_string_from_mask -mbim_mico_mode_build_string_from_mask -mbim_default_pdu_activation_hint_build_string_from_mask -mbim_ladn_info_build_string_from_mask -mbim_drx_cycle_build_string_from_mask -mbim_subscriber_ready_status_flag_get_string -mbim_data_class_v3_get_string -mbim_data_subclass_get_string -mbim_modem_configuration_status_build_string_from_mask -mbim_wake_type_build_string_from_mask -mbim_quectel_radio_switch_state_build_string_from_mask -mbim_access_media_type_build_string_from_mask -mbim_intel_serving_cell_info_build_string_from_mask -mbim_intel_boot_mode_build_string_from_mask -mbim_uicc_application_type_build_string_from_mask -mbim_uicc_file_accessibility_build_string_from_mask -mbim_uicc_file_type_build_string_from_mask -mbim_uicc_file_structure_build_string_from_mask -mbim_trace_command_build_string_from_mask -mbim_carrier_lock_status_build_string_from_mask -mbim_carrier_lock_modem_state_build_string_from_mask -mbim_carrier_lock_cause_build_string_from_mask <SUBSECTION Standard> MBIM_TYPE_ACTIVATION_COMMAND MBIM_TYPE_ACTIVATION_STATE diff --git a/src/libmbim-glib/generated/meson.build b/src/libmbim-glib/generated/meson.build index 79c8561..0153c22 100644 --- a/src/libmbim-glib/generated/meson.build +++ b/src/libmbim-glib/generated/meson.build @@ -55,7 +55,7 @@ gen_sources += custom_target( capture: true, ) -# Enum/Flag types +# Enum types enum_types = 'mbim-enum-types' gen_headers += custom_target( @@ -65,6 +65,7 @@ gen_headers += custom_target( command: [ python, mbim_mkenums, + '--enums-only', '--fhead', '#ifndef __LIBMBIM_GLIB_ENUM_TYPES_H__\n#define __LIBMBIM_GLIB_ENUM_TYPES_H__\n#include "mbim-uuid.h"\n#include "mbim-cid.h"\n#include "mbim-message.h"\n#include "mbim-enums.h"\n#include "mbim-tlv.h"\n', '--template', files(templates_dir / enum_types + '.h.template'), '--ftail', '#endif /* __LIBMBIM_GLIB_ENUM_TYPES_H__ */\n', @@ -81,12 +82,47 @@ gen_sources += custom_target( command: [ python, mbim_mkenums, + '--enums-only', '--fhead', '#include "mbim-enum-types.h"\n', '--template', files(templates_dir / enum_types + '.c.template'), '@INPUT@'], capture: true, ) +# Flag types +enum_types = 'mbim-flag-types' + +gen_headers += custom_target( + enum_types + '.h', + input: mbim_enums_headers, + output: enum_types + '.h', + command: [ + python, + mbim_mkenums, + '--flags-only', + '--fhead', '#ifndef __LIBMBIM_GLIB_FLAG_TYPES_H__\n#define __LIBMBIM_GLIB_FLAG_TYPES_H__\n#include "mbim-uuid.h"\n#include "mbim-cid.h"\n#include "mbim-message.h"\n#include "mbim-enums.h"\n#include "mbim-tlv.h"\n', + '--template', files(templates_dir / enum_types + '.h.template'), + '--ftail', '#endif /* __LIBMBIM_GLIB_FLAG_TYPES_H__ */\n', + '@INPUT@'], + capture: true, + install: true, + install_dir: mbim_glib_pkgincludedir, +) + +gen_sources += custom_target( + enum_types + '.c', + input: mbim_enums_headers, + output: enum_types + '.c', + command: [ + python, + mbim_mkenums, + '--flags-only', + '--fhead', '#include "mbim-flag-types.h"\n', + '--template', files(templates_dir / enum_types + '.c.template'), + '@INPUT@'], + capture: true, +) + services_data = [ ['atds'], ['auth'], diff --git a/src/libmbim-glib/libmbim-glib.h b/src/libmbim-glib/libmbim-glib.h index bf2c07b..d096051 100644 --- a/src/libmbim-glib/libmbim-glib.h +++ b/src/libmbim-glib/libmbim-glib.h @@ -26,6 +26,7 @@ /* generated */ #include "mbim-enum-types.h" +#include "mbim-flag-types.h" #include "mbim-error-types.h" #include "mbim-basic-connect.h" #include "mbim-sms.h" |