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:

committed by
Aleksander Morgado

parent
fdf03f9b2c
commit
bf2843ad77
@@ -16,11 +16,6 @@ static const G@Type@Value @enum_name@_values[] = {
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
/* Define type-specific symbols */
|
||||
#undef __MM_IS_ENUM__
|
||||
#undef __MM_IS_FLAGS__
|
||||
#define __MM_IS_@TYPE@__
|
||||
|
||||
GType
|
||||
@enum_name@_get_type (void)
|
||||
{
|
||||
@@ -36,15 +31,6 @@ GType
|
||||
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 *
|
||||
@enum_name@_get_string (@EnumName@ val)
|
||||
{
|
||||
@@ -57,56 +43,6 @@ const gchar *
|
||||
|
||||
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 ***/
|
||||
|
||||
|
@@ -14,18 +14,15 @@ G_BEGIN_DECLS
|
||||
GType @enum_name@_get_type (void) G_GNUC_CONST;
|
||||
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
|
||||
|
||||
/* Define type-specific symbols */
|
||||
#undef __MM_IS_ENUM__
|
||||
#undef __MM_IS_FLAGS__
|
||||
#define __MM_IS_@TYPE@__
|
||||
|
||||
#if defined __MM_IS_ENUM__
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
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 ***/
|
||||
|
||||
|
75
build-aux/templates/mm-flags-types.c.template
Normal file
75
build-aux/templates/mm-flags-types.c.template
Normal 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 ***/
|
33
build-aux/templates/mm-flags-types.h.template
Normal file
33
build-aux/templates/mm-flags-types.h.template
Normal 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 ***/
|
@@ -2039,61 +2039,6 @@ mm_call_direction_get_string
|
||||
mm_call_state_get_string
|
||||
mm_call_state_reason_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>
|
||||
MM_TYPE_BEARER_TYPE
|
||||
MM_TYPE_BEARER_IP_FAMILY
|
||||
|
@@ -24,6 +24,7 @@ gen_sources += custom_target(
|
||||
command: [
|
||||
python,
|
||||
mm_mkenums,
|
||||
'--enums-only',
|
||||
'--fhead', '#include "mm-enums-types.h"\n',
|
||||
'--template', files(templates_dir / enums_types + '.c.template'),
|
||||
'@INPUT@'],
|
||||
@@ -37,6 +38,7 @@ gen_headers += custom_target(
|
||||
command: [
|
||||
python,
|
||||
mm_mkenums,
|
||||
'--enums-only',
|
||||
'--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'),
|
||||
'--ftail', '#endif /* __MM_ENUMS_TYPES_H__ */\n',
|
||||
@@ -46,6 +48,40 @@ gen_headers += custom_target(
|
||||
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
|
||||
errors_types = 'mm-errors-types'
|
||||
|
||||
|
@@ -98,6 +98,7 @@
|
||||
/* generated */
|
||||
#include <mm-errors-types.h>
|
||||
#include <mm-enums-types.h>
|
||||
#include <mm-flags-types.h>
|
||||
#include <mm-gdbus-manager.h>
|
||||
#include <mm-gdbus-modem.h>
|
||||
#include <mm-gdbus-bearer.h>
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
#include "mm-3gpp-profile.h"
|
||||
|
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
#include "mm-bearer-properties.h"
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
#include "mm-call-properties.h"
|
||||
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "mm-cell-info-nr5g.h"
|
||||
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-errors-types.h"
|
||||
|
||||
/**
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include <ModemManager.h>
|
||||
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
#include "mm-kernel-event-properties.h"
|
||||
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
#include "mm-pco.h"
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
#include "mm-simple-status.h"
|
||||
|
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
#include "mm-sms-properties.h"
|
||||
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-unlock-retries.h"
|
||||
|
||||
/**
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include "mm-modem-helpers-mbim.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-error-helpers.h"
|
||||
#include "mm-log-object.h"
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-error-helpers.h"
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-log-object.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include <libmm-glib.h>
|
||||
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-flags-types.h"
|
||||
#include "mm-modem-helpers-qmi.h"
|
||||
#include "mm-log-test.h"
|
||||
|
||||
|
Reference in New Issue
Block a user