libmm-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.
This commit is contained in:
Aleksander Morgado
2023-04-27 12:19:18 +00:00
committed by Aleksander Morgado
parent fdf03f9b2c
commit bf2843ad77
20 changed files with 166 additions and 130 deletions

View File

@@ -16,11 +16,6 @@ static const G@Type@Value @enum_name@_values[] = {
{ 0, NULL, NULL } { 0, NULL, NULL }
}; };
/* Define type-specific symbols */
#undef __MM_IS_ENUM__
#undef __MM_IS_FLAGS__
#define __MM_IS_@TYPE@__
GType GType
@enum_name@_get_type (void) @enum_name@_get_type (void)
{ {
@@ -36,15 +31,6 @@ GType
return g_define_type_id_initialized; return g_define_type_id_initialized;
} }
/**
* @enum_name@_get_string:
* @val: a @EnumName@.
*
* Gets the nickname string for the #@EnumName@ specified at @val.
*
* Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value.
*/
#if defined __MM_IS_ENUM__
const gchar * const gchar *
@enum_name@_get_string (@EnumName@ val) @enum_name@_get_string (@EnumName@ val)
{ {
@@ -57,56 +43,6 @@ const gchar *
return NULL; return NULL;
} }
#endif /* __MM_IS_ENUM_ */
/**
* @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().
*/
#if defined __MM_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 (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 /* __MM_IS_FLAGS__ */
/*** END value-tail ***/ /*** END value-tail ***/

View File

@@ -14,18 +14,15 @@ G_BEGIN_DECLS
GType @enum_name@_get_type (void) G_GNUC_CONST; GType @enum_name@_get_type (void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
/* Define type-specific symbols */ /**
#undef __MM_IS_ENUM__ * @enum_name@_get_string:
#undef __MM_IS_FLAGS__ * @val: a @EnumName@.
#define __MM_IS_@TYPE@__ *
* Gets the nickname string for the #@EnumName@ specified at @val.
#if defined __MM_IS_ENUM__ *
* Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value.
*/
const gchar *@enum_name@_get_string (@EnumName@ val); const gchar *@enum_name@_get_string (@EnumName@ val);
#endif
#if defined __MM_IS_FLAGS__
gchar *@enum_name@_build_string_from_mask (@EnumName@ mask);
#endif
/*** END value-header ***/ /*** END value-header ***/

View File

@@ -0,0 +1,75 @@
/*** 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 }
};
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;
}
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 (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 ***/

View File

@@ -0,0 +1,33 @@
/*** BEGIN file-header ***/
#include <glib-object.h>
G_BEGIN_DECLS
/*** END file-header ***/
/*** BEGIN file-production ***/
/* enumerations from "@basename@" */
/*** END file-production ***/
/*** BEGIN value-header ***/
GType @enum_name@_get_type (void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_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().
*/
gchar *@enum_name@_build_string_from_mask (@EnumName@ mask);
/*** END value-header ***/
/*** BEGIN file-tail ***/
G_END_DECLS
/*** END file-tail ***/

View File

@@ -2039,61 +2039,6 @@ mm_call_direction_get_string
mm_call_state_get_string mm_call_state_get_string
mm_call_state_reason_get_string mm_call_state_reason_get_string
mm_cell_type_get_string mm_cell_type_get_string
<SUBSECTION Private>
mm_modem_capability_get_string
mm_modem_lock_build_string_from_mask
mm_modem_state_build_string_from_mask
mm_modem_state_failed_reason_build_string_from_mask
mm_modem_state_change_reason_build_string_from_mask
mm_modem_power_state_build_string_from_mask
mm_modem_access_technology_get_string
mm_modem_mode_get_string
mm_modem_band_build_string_from_mask
mm_sms_pdu_type_build_string_from_mask
mm_sms_state_build_string_from_mask
mm_sms_delivery_state_build_string_from_mask
mm_sms_storage_build_string_from_mask
mm_sms_validity_type_build_string_from_mask
mm_sms_cdma_teleservice_id_build_string_from_mask
mm_sms_cdma_service_category_build_string_from_mask
mm_modem_location_source_get_string
mm_modem_location_assistance_data_type_get_string
mm_modem_contacts_storage_build_string_from_mask
mm_bearer_type_build_string_from_mask
mm_bearer_ip_family_build_string_from_mask
mm_bearer_ip_method_build_string_from_mask
mm_bearer_allowed_auth_get_string
mm_bearer_multiplex_support_build_string_from_mask
mm_bearer_apn_type_get_string
mm_sim_type_build_string_from_mask
mm_sim_esim_status_build_string_from_mask
mm_sim_removability_build_string_from_mask
mm_bearer_access_type_preference_build_string_from_mask
mm_bearer_roaming_allowance_get_string
mm_bearer_profile_source_build_string_from_mask
mm_modem_cdma_registration_state_build_string_from_mask
mm_modem_cdma_activation_state_build_string_from_mask
mm_modem_cdma_rm_protocol_build_string_from_mask
mm_modem_3gpp_registration_state_build_string_from_mask
mm_modem_3gpp_packet_service_state_build_string_from_mask
mm_modem_3gpp_mico_mode_build_string_from_mask
mm_modem_3gpp_drx_cycle_build_string_from_mask
mm_modem_3gpp_subscription_state_build_string_from_mask
mm_modem_3gpp_facility_get_string
mm_modem_3gpp_network_availability_build_string_from_mask
mm_modem_3gpp_ussd_session_state_build_string_from_mask
mm_modem_3gpp_eps_ue_mode_operation_build_string_from_mask
mm_firmware_image_type_build_string_from_mask
mm_modem_port_type_build_string_from_mask
mm_oma_feature_get_string
mm_oma_session_type_build_string_from_mask
mm_oma_session_state_build_string_from_mask
mm_oma_session_state_failed_reason_build_string_from_mask
mm_call_direction_build_string_from_mask
mm_call_state_build_string_from_mask
mm_call_state_reason_build_string_from_mask
mm_modem_firmware_update_method_get_string
mm_cell_type_build_string_from_mask
<SUBSECTION Standard> <SUBSECTION Standard>
MM_TYPE_BEARER_TYPE MM_TYPE_BEARER_TYPE
MM_TYPE_BEARER_IP_FAMILY MM_TYPE_BEARER_IP_FAMILY

View File

@@ -24,6 +24,7 @@ gen_sources += custom_target(
command: [ command: [
python, python,
mm_mkenums, mm_mkenums,
'--enums-only',
'--fhead', '#include "mm-enums-types.h"\n', '--fhead', '#include "mm-enums-types.h"\n',
'--template', files(templates_dir / enums_types + '.c.template'), '--template', files(templates_dir / enums_types + '.c.template'),
'@INPUT@'], '@INPUT@'],
@@ -37,6 +38,7 @@ gen_headers += custom_target(
command: [ command: [
python, python,
mm_mkenums, mm_mkenums,
'--enums-only',
'--fhead', '#include <ModemManager.h>\n#ifndef __MM_ENUMS_TYPES_H__\n#define __MM_ENUMS_TYPES_H__\n', '--fhead', '#include <ModemManager.h>\n#ifndef __MM_ENUMS_TYPES_H__\n#define __MM_ENUMS_TYPES_H__\n',
'--template', files(templates_dir / enums_types + '.h.template'), '--template', files(templates_dir / enums_types + '.h.template'),
'--ftail', '#endif /* __MM_ENUMS_TYPES_H__ */\n', '--ftail', '#endif /* __MM_ENUMS_TYPES_H__ */\n',
@@ -46,6 +48,40 @@ gen_headers += custom_target(
install_dir: mm_glib_pkgincludedir, install_dir: mm_glib_pkgincludedir,
) )
# Flag types
enums_types = 'mm-flags-types'
gen_sources += custom_target(
enums_types + '.c',
input: mm_enums_header,
output: enums_types + '.c',
command: [
python,
mm_mkenums,
'--flags-only',
'--fhead', '#include "mm-flags-types.h"\n',
'--template', files(templates_dir / enums_types + '.c.template'),
'@INPUT@'],
capture: true,
)
gen_headers += custom_target(
enums_types + '.h',
input: mm_enums_header,
output: enums_types + '.h',
command: [
python,
mm_mkenums,
'--flags-only',
'--fhead', '#include <ModemManager.h>\n#ifndef __MM_FLAGS_TYPES_H__\n#define __MM_FLAGS_TYPES_H__\n',
'--template', files(templates_dir / enums_types + '.h.template'),
'--ftail', '#endif /* __MM_FLAGS_TYPES_H__ */\n',
'@INPUT@'],
capture: true,
install: true,
install_dir: mm_glib_pkgincludedir,
)
# Error types & quarks # Error types & quarks
errors_types = 'mm-errors-types' errors_types = 'mm-errors-types'

View File

@@ -98,6 +98,7 @@
/* generated */ /* generated */
#include <mm-errors-types.h> #include <mm-errors-types.h>
#include <mm-enums-types.h> #include <mm-enums-types.h>
#include <mm-flags-types.h>
#include <mm-gdbus-manager.h> #include <mm-gdbus-manager.h>
#include <mm-gdbus-modem.h> #include <mm-gdbus-modem.h>
#include <mm-gdbus-bearer.h> #include <mm-gdbus-bearer.h>

View File

@@ -24,6 +24,7 @@
#include <string.h> #include <string.h>
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-common-helpers.h" #include "mm-common-helpers.h"
#include "mm-3gpp-profile.h" #include "mm-3gpp-profile.h"

View File

@@ -25,6 +25,7 @@
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-common-helpers.h" #include "mm-common-helpers.h"
#include "mm-bearer-properties.h" #include "mm-bearer-properties.h"

View File

@@ -26,6 +26,7 @@
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-common-helpers.h" #include "mm-common-helpers.h"
#include "mm-call-properties.h" #include "mm-call-properties.h"

View File

@@ -29,6 +29,7 @@
#include "mm-cell-info-nr5g.h" #include "mm-cell-info-nr5g.h"
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-errors-types.h" #include "mm-errors-types.h"
/** /**

View File

@@ -29,6 +29,7 @@
#include <ModemManager.h> #include <ModemManager.h>
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-common-helpers.h" #include "mm-common-helpers.h"

View File

@@ -26,6 +26,7 @@
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-common-helpers.h" #include "mm-common-helpers.h"
#include "mm-kernel-event-properties.h" #include "mm-kernel-event-properties.h"

View File

@@ -24,6 +24,7 @@
#include <glib.h> #include <glib.h>
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-common-helpers.h" #include "mm-common-helpers.h"
#include "mm-pco.h" #include "mm-pco.h"

View File

@@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-common-helpers.h" #include "mm-common-helpers.h"
#include "mm-simple-status.h" #include "mm-simple-status.h"

View File

@@ -26,6 +26,7 @@
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-common-helpers.h" #include "mm-common-helpers.h"
#include "mm-sms-properties.h" #include "mm-sms-properties.h"

View File

@@ -25,6 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-unlock-retries.h" #include "mm-unlock-retries.h"
/** /**

View File

@@ -16,6 +16,7 @@
#include "mm-modem-helpers-mbim.h" #include "mm-modem-helpers-mbim.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-error-helpers.h" #include "mm-error-helpers.h"
#include "mm-log-object.h" #include "mm-log-object.h"

View File

@@ -24,6 +24,7 @@
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-error-helpers.h" #include "mm-error-helpers.h"
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-log-object.h" #include "mm-log-object.h"
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -25,6 +25,7 @@
#include <libmm-glib.h> #include <libmm-glib.h>
#include "mm-enums-types.h" #include "mm-enums-types.h"
#include "mm-flags-types.h"
#include "mm-modem-helpers-qmi.h" #include "mm-modem-helpers-qmi.h"
#include "mm-log-test.h" #include "mm-log-test.h"