summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksandermj@chromium.org>2023-04-27 12:06:57 +0000
committerAleksander Morgado <aleksander@aleksander.es>2023-04-27 12:23:04 +0000
commitfdf03f9b2ccbc4a6a0a8102d44a991f78673e5a1 (patch)
tree0538173882334fcb8b171166952680f2f813abab
parentefcfce02a95fe43adb40c1e01e82e0719a217983 (diff)
downloadModemManager-fdf03f9b2ccbc4a6a0a8102d44a991f78673e5a1.tar.gz
build-aux,mkenums: use mixed enums+flags template without docs in daemon
l---------build-aux/templates/mm-daemon-enums-types.c.template2
l---------build-aux/templates/mm-daemon-enums-types.h.template2
-rw-r--r--build-aux/templates/mm-enumflags-types.c.template92
-rw-r--r--build-aux/templates/mm-enumflags-types.h.template33
l---------build-aux/templates/mm-helper-enums-types.c.template2
l---------build-aux/templates/mm-helper-enums-types.h.template2
l---------build-aux/templates/mm-huawei-enums-types.c.template2
l---------build-aux/templates/mm-huawei-enums-types.h.template2
l---------build-aux/templates/mm-port-enums-types.c.template2
l---------build-aux/templates/mm-port-enums-types.h.template2
l---------build-aux/templates/mm-telit-enums-types.c.template2
l---------build-aux/templates/mm-telit-enums-types.h.template2
l---------build-aux/templates/mm-ublox-enums-types.c.template2
l---------build-aux/templates/mm-ublox-enums-types.h.template2
14 files changed, 137 insertions, 12 deletions
diff --git a/build-aux/templates/mm-daemon-enums-types.c.template b/build-aux/templates/mm-daemon-enums-types.c.template
index 471d2931f..6a247265e 120000
--- a/build-aux/templates/mm-daemon-enums-types.c.template
+++ b/build-aux/templates/mm-daemon-enums-types.c.template
@@ -1 +1 @@
-mm-enums-types.c.template \ No newline at end of file
+mm-enumflags-types.c.template \ No newline at end of file
diff --git a/build-aux/templates/mm-daemon-enums-types.h.template b/build-aux/templates/mm-daemon-enums-types.h.template
index 12f144f53..7fada6bc5 120000
--- a/build-aux/templates/mm-daemon-enums-types.h.template
+++ b/build-aux/templates/mm-daemon-enums-types.h.template
@@ -1 +1 @@
-mm-enums-types.h.template \ No newline at end of file
+mm-enumflags-types.h.template \ No newline at end of file
diff --git a/build-aux/templates/mm-enumflags-types.c.template b/build-aux/templates/mm-enumflags-types.c.template
new file mode 100644
index 000000000..203cceaf4
--- /dev/null
+++ b/build-aux/templates/mm-enumflags-types.c.template
@@ -0,0 +1,92 @@
+/*** 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;
+}
+
+#if defined __@ENUMNAME@_IS_ENUM__
+const gchar *
+@enum_name@_get_string (@EnumName@ val)
+{
+ guint i;
+
+ for (i = 0; @enum_name@_values[i].value_nick; i++) {
+ if ((gint)val == @enum_name@_values[i].value)
+ return @enum_name@_values[i].value_nick;
+ }
+
+ return NULL;
+}
+#endif
+
+#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 (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
+
+/*** END value-tail ***/
+
+/*** BEGIN file-tail ***/
+/*** END file-tail ***/
diff --git a/build-aux/templates/mm-enumflags-types.h.template b/build-aux/templates/mm-enumflags-types.h.template
new file mode 100644
index 000000000..db1634b47
--- /dev/null
+++ b/build-aux/templates/mm-enumflags-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 ())
+
+/* Define type-specific symbols */
+#define __@ENUMNAME@_IS_@TYPE@__
+
+#if defined __@ENUMNAME@_IS_ENUM__
+const gchar *@enum_name@_get_string (@EnumName@ val);
+#endif
+
+#if defined __@ENUMNAME@_IS_FLAGS__
+gchar *@enum_name@_build_string_from_mask (@EnumName@ mask);
+#endif
+
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+/*** END file-tail ***/
diff --git a/build-aux/templates/mm-helper-enums-types.c.template b/build-aux/templates/mm-helper-enums-types.c.template
index 471d2931f..6a247265e 120000
--- a/build-aux/templates/mm-helper-enums-types.c.template
+++ b/build-aux/templates/mm-helper-enums-types.c.template
@@ -1 +1 @@
-mm-enums-types.c.template \ No newline at end of file
+mm-enumflags-types.c.template \ No newline at end of file
diff --git a/build-aux/templates/mm-helper-enums-types.h.template b/build-aux/templates/mm-helper-enums-types.h.template
index 12f144f53..7fada6bc5 120000
--- a/build-aux/templates/mm-helper-enums-types.h.template
+++ b/build-aux/templates/mm-helper-enums-types.h.template
@@ -1 +1 @@
-mm-enums-types.h.template \ No newline at end of file
+mm-enumflags-types.h.template \ No newline at end of file
diff --git a/build-aux/templates/mm-huawei-enums-types.c.template b/build-aux/templates/mm-huawei-enums-types.c.template
index 471d2931f..6a247265e 120000
--- a/build-aux/templates/mm-huawei-enums-types.c.template
+++ b/build-aux/templates/mm-huawei-enums-types.c.template
@@ -1 +1 @@
-mm-enums-types.c.template \ No newline at end of file
+mm-enumflags-types.c.template \ No newline at end of file
diff --git a/build-aux/templates/mm-huawei-enums-types.h.template b/build-aux/templates/mm-huawei-enums-types.h.template
index 12f144f53..7fada6bc5 120000
--- a/build-aux/templates/mm-huawei-enums-types.h.template
+++ b/build-aux/templates/mm-huawei-enums-types.h.template
@@ -1 +1 @@
-mm-enums-types.h.template \ No newline at end of file
+mm-enumflags-types.h.template \ No newline at end of file
diff --git a/build-aux/templates/mm-port-enums-types.c.template b/build-aux/templates/mm-port-enums-types.c.template
index 471d2931f..6a247265e 120000
--- a/build-aux/templates/mm-port-enums-types.c.template
+++ b/build-aux/templates/mm-port-enums-types.c.template
@@ -1 +1 @@
-mm-enums-types.c.template \ No newline at end of file
+mm-enumflags-types.c.template \ No newline at end of file
diff --git a/build-aux/templates/mm-port-enums-types.h.template b/build-aux/templates/mm-port-enums-types.h.template
index 12f144f53..7fada6bc5 120000
--- a/build-aux/templates/mm-port-enums-types.h.template
+++ b/build-aux/templates/mm-port-enums-types.h.template
@@ -1 +1 @@
-mm-enums-types.h.template \ No newline at end of file
+mm-enumflags-types.h.template \ No newline at end of file
diff --git a/build-aux/templates/mm-telit-enums-types.c.template b/build-aux/templates/mm-telit-enums-types.c.template
index 471d2931f..6a247265e 120000
--- a/build-aux/templates/mm-telit-enums-types.c.template
+++ b/build-aux/templates/mm-telit-enums-types.c.template
@@ -1 +1 @@
-mm-enums-types.c.template \ No newline at end of file
+mm-enumflags-types.c.template \ No newline at end of file
diff --git a/build-aux/templates/mm-telit-enums-types.h.template b/build-aux/templates/mm-telit-enums-types.h.template
index 12f144f53..7fada6bc5 120000
--- a/build-aux/templates/mm-telit-enums-types.h.template
+++ b/build-aux/templates/mm-telit-enums-types.h.template
@@ -1 +1 @@
-mm-enums-types.h.template \ No newline at end of file
+mm-enumflags-types.h.template \ No newline at end of file
diff --git a/build-aux/templates/mm-ublox-enums-types.c.template b/build-aux/templates/mm-ublox-enums-types.c.template
index 471d2931f..6a247265e 120000
--- a/build-aux/templates/mm-ublox-enums-types.c.template
+++ b/build-aux/templates/mm-ublox-enums-types.c.template
@@ -1 +1 @@
-mm-enums-types.c.template \ No newline at end of file
+mm-enumflags-types.c.template \ No newline at end of file
diff --git a/build-aux/templates/mm-ublox-enums-types.h.template b/build-aux/templates/mm-ublox-enums-types.h.template
index 12f144f53..7fada6bc5 120000
--- a/build-aux/templates/mm-ublox-enums-types.h.template
+++ b/build-aux/templates/mm-ublox-enums-types.h.template
@@ -1 +1 @@
-mm-enums-types.h.template \ No newline at end of file
+mm-enumflags-types.h.template \ No newline at end of file