summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksandermj@chromium.org>2023-04-27 12:19:18 +0000
committerAleksander Morgado <aleksander@aleksander.es>2023-04-27 12:23:04 +0000
commitbf2843ad77732f5fbe1ee04e7ad5415a60bf5eeb (patch)
treed9be783f8a8e239652ea7837700d98dc6359765f
parentfdf03f9b2ccbc4a6a0a8102d44a991f78673e5a1 (diff)
downloadModemManager-bf2843ad77732f5fbe1ee04e7ad5415a60bf5eeb.tar.gz
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.
-rw-r--r--build-aux/templates/mm-enums-types.c.template64
-rw-r--r--build-aux/templates/mm-enums-types.h.template19
-rw-r--r--build-aux/templates/mm-flags-types.c.template75
-rw-r--r--build-aux/templates/mm-flags-types.h.template33
-rw-r--r--docs/reference/libmm-glib/libmm-glib-sections.txt55
-rw-r--r--libmm-glib/generated/meson.build36
-rw-r--r--libmm-glib/libmm-glib.h1
-rw-r--r--libmm-glib/mm-3gpp-profile.c1
-rw-r--r--libmm-glib/mm-bearer-properties.c1
-rw-r--r--libmm-glib/mm-call-properties.c1
-rw-r--r--libmm-glib/mm-cell-info.c1
-rw-r--r--libmm-glib/mm-common-helpers.c1
-rw-r--r--libmm-glib/mm-kernel-event-properties.c1
-rw-r--r--libmm-glib/mm-pco.c1
-rw-r--r--libmm-glib/mm-simple-status.c1
-rw-r--r--libmm-glib/mm-sms-properties.c1
-rw-r--r--libmm-glib/mm-unlock-retries.c1
-rw-r--r--src/mm-modem-helpers-mbim.c1
-rw-r--r--src/mm-modem-helpers-qmi.c1
-rw-r--r--src/tests/test-modem-helpers-qmi.c1
20 files changed, 166 insertions, 130 deletions
diff --git a/build-aux/templates/mm-enums-types.c.template b/build-aux/templates/mm-enums-types.c.template
index 2a7f264b1..e09d0c912 100644
--- a/build-aux/templates/mm-enums-types.c.template
+++ b/build-aux/templates/mm-enums-types.c.template
@@ -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 ***/
diff --git a/build-aux/templates/mm-enums-types.h.template b/build-aux/templates/mm-enums-types.h.template
index 24d18a9dc..4c99eb9f9 100644
--- a/build-aux/templates/mm-enums-types.h.template
+++ b/build-aux/templates/mm-enums-types.h.template
@@ -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 ***/
diff --git a/build-aux/templates/mm-flags-types.c.template b/build-aux/templates/mm-flags-types.c.template
new file mode 100644
index 000000000..dce00905f
--- /dev/null
+++ b/build-aux/templates/mm-flags-types.c.template
@@ -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 ***/
diff --git a/build-aux/templates/mm-flags-types.h.template b/build-aux/templates/mm-flags-types.h.template
new file mode 100644
index 000000000..b7ac597e1
--- /dev/null
+++ b/build-aux/templates/mm-flags-types.h.template
@@ -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 ***/
diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt
index 685dc082c..1054d8b43 100644
--- a/docs/reference/libmm-glib/libmm-glib-sections.txt
+++ b/docs/reference/libmm-glib/libmm-glib-sections.txt
@@ -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
diff --git a/libmm-glib/generated/meson.build b/libmm-glib/generated/meson.build
index 268c4fb17..2f77e1bd1 100644
--- a/libmm-glib/generated/meson.build
+++ b/libmm-glib/generated/meson.build
@@ -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'
diff --git a/libmm-glib/libmm-glib.h b/libmm-glib/libmm-glib.h
index a6490fd86..8c2825624 100644
--- a/libmm-glib/libmm-glib.h
+++ b/libmm-glib/libmm-glib.h
@@ -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>
diff --git a/libmm-glib/mm-3gpp-profile.c b/libmm-glib/mm-3gpp-profile.c
index 88c417561..65fe94cac 100644
--- a/libmm-glib/mm-3gpp-profile.c
+++ b/libmm-glib/mm-3gpp-profile.c
@@ -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"
diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c
index 6d0750bc8..6005405c1 100644
--- a/libmm-glib/mm-bearer-properties.c
+++ b/libmm-glib/mm-bearer-properties.c
@@ -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"
diff --git a/libmm-glib/mm-call-properties.c b/libmm-glib/mm-call-properties.c
index eef665072..c5da49207 100644
--- a/libmm-glib/mm-call-properties.c
+++ b/libmm-glib/mm-call-properties.c
@@ -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"
diff --git a/libmm-glib/mm-cell-info.c b/libmm-glib/mm-cell-info.c
index 9ba775558..846e470f2 100644
--- a/libmm-glib/mm-cell-info.c
+++ b/libmm-glib/mm-cell-info.c
@@ -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"
/**
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c
index d233a801b..217daf989 100644
--- a/libmm-glib/mm-common-helpers.c
+++ b/libmm-glib/mm-common-helpers.c
@@ -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"
diff --git a/libmm-glib/mm-kernel-event-properties.c b/libmm-glib/mm-kernel-event-properties.c
index 250c8350e..23d088047 100644
--- a/libmm-glib/mm-kernel-event-properties.c
+++ b/libmm-glib/mm-kernel-event-properties.c
@@ -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"
diff --git a/libmm-glib/mm-pco.c b/libmm-glib/mm-pco.c
index ab3d08869..137e4c2db 100644
--- a/libmm-glib/mm-pco.c
+++ b/libmm-glib/mm-pco.c
@@ -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"
diff --git a/libmm-glib/mm-simple-status.c b/libmm-glib/mm-simple-status.c
index 7ac79eccd..75e1a054b 100644
--- a/libmm-glib/mm-simple-status.c
+++ b/libmm-glib/mm-simple-status.c
@@ -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"
diff --git a/libmm-glib/mm-sms-properties.c b/libmm-glib/mm-sms-properties.c
index 1783c423b..72817ac25 100644
--- a/libmm-glib/mm-sms-properties.c
+++ b/libmm-glib/mm-sms-properties.c
@@ -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"
diff --git a/libmm-glib/mm-unlock-retries.c b/libmm-glib/mm-unlock-retries.c
index d66d82e5e..b093bab83 100644
--- a/libmm-glib/mm-unlock-retries.c
+++ b/libmm-glib/mm-unlock-retries.c
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include "mm-enums-types.h"
+#include "mm-flags-types.h"
#include "mm-unlock-retries.h"
/**
diff --git a/src/mm-modem-helpers-mbim.c b/src/mm-modem-helpers-mbim.c
index 7701c918e..7714387d7 100644
--- a/src/mm-modem-helpers-mbim.c
+++ b/src/mm-modem-helpers-mbim.c
@@ -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"
diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c
index 850ef01ce..12639c16c 100644
--- a/src/mm-modem-helpers-qmi.c
+++ b/src/mm-modem-helpers-qmi.c
@@ -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"
/*****************************************************************************/
diff --git a/src/tests/test-modem-helpers-qmi.c b/src/tests/test-modem-helpers-qmi.c
index 07e2e1b88..7ff1c9f25 100644
--- a/src/tests/test-modem-helpers-qmi.c
+++ b/src/tests/test-modem-helpers-qmi.c
@@ -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"