summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
authorAleksander Morgado <aleksandermj@chromium.org>2023-04-27 10:43:15 +0000
committerAleksander Morgado <aleksandermj@chromium.org>2023-04-27 10:43:15 +0000
commit1eba37dcd93c84fff9d63d975706a8b7f283eca4 (patch)
tree6a39d3bbb6977e548318066f2089db1f52287961 /build-aux
parent4e5e10a1b78cc2a18529738f6a70ea95b447a253 (diff)
downloadlibqmi-1eba37dcd93c84fff9d63d975706a8b7f283eca4.tar.gz
libqmi-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.
Diffstat (limited to 'build-aux')
-rw-r--r--build-aux/qmi-codegen/utils.py2
-rw-r--r--build-aux/templates/qmi-enum-types-nodoc.h.template6
-rw-r--r--build-aux/templates/qmi-enum-types.c.template46
-rw-r--r--build-aux/templates/qmi-enum-types.h.template16
-rw-r--r--build-aux/templates/qmi-flag-types-nodoc.h.template27
l---------build-aux/templates/qmi-flag-types-private.c.template1
l---------build-aux/templates/qmi-flag-types-private.h.template1
-rw-r--r--build-aux/templates/qmi-flag-types.c.template81
-rw-r--r--build-aux/templates/qmi-flag-types.h.template37
9 files changed, 149 insertions, 68 deletions
diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py
index 7dcfaaa7..0de344c6 100644
--- a/build-aux/qmi-codegen/utils.py
+++ b/build-aux/qmi-codegen/utils.py
@@ -115,7 +115,9 @@ def add_source_start(f, output_name):
"\n"
"#include \"${name}.h\"\n"
"#include \"qmi-enum-types.h\"\n"
+ "#include \"qmi-flag-types.h\"\n"
"#include \"qmi-enum-types-private.h\"\n"
+ "#include \"qmi-flag-types-private.h\"\n"
"#include \"qmi-flags64-types.h\"\n"
"#include \"qmi-error-types.h\"\n"
"#include \"qmi-device.h\"\n"
diff --git a/build-aux/templates/qmi-enum-types-nodoc.h.template b/build-aux/templates/qmi-enum-types-nodoc.h.template
index 31e0732b..69fa558e 100644
--- a/build-aux/templates/qmi-enum-types-nodoc.h.template
+++ b/build-aux/templates/qmi-enum-types-nodoc.h.template
@@ -17,13 +17,7 @@ GType @enum_name@_get_type (void) G_GNUC_CONST;
/* 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 ***/
diff --git a/build-aux/templates/qmi-enum-types.c.template b/build-aux/templates/qmi-enum-types.c.template
index d2670110..011793ec 100644
--- a/build-aux/templates/qmi-enum-types.c.template
+++ b/build-aux/templates/qmi-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/qmi-enum-types.h.template b/build-aux/templates/qmi-enum-types.h.template
index 5500038e..58af6867 100644
--- a/build-aux/templates/qmi-enum-types.h.template
+++ b/build-aux/templates/qmi-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@.
@@ -28,21 +27,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/qmi-flag-types-nodoc.h.template b/build-aux/templates/qmi-flag-types-nodoc.h.template
new file mode 100644
index 00000000..46319f3a
--- /dev/null
+++ b/build-aux/templates/qmi-flag-types-nodoc.h.template
@@ -0,0 +1,27 @@
+/*** 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@__
+
+gchar *@enum_name@_build_string_from_mask (@EnumName@ mask);
+
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+/*** END file-tail ***/
diff --git a/build-aux/templates/qmi-flag-types-private.c.template b/build-aux/templates/qmi-flag-types-private.c.template
new file mode 120000
index 00000000..aae32e40
--- /dev/null
+++ b/build-aux/templates/qmi-flag-types-private.c.template
@@ -0,0 +1 @@
+qmi-flag-types.c.template \ No newline at end of file
diff --git a/build-aux/templates/qmi-flag-types-private.h.template b/build-aux/templates/qmi-flag-types-private.h.template
new file mode 120000
index 00000000..0ee7e8bf
--- /dev/null
+++ b/build-aux/templates/qmi-flag-types-private.h.template
@@ -0,0 +1 @@
+qmi-flag-types-nodoc.h.template \ No newline at end of file
diff --git a/build-aux/templates/qmi-flag-types.c.template b/build-aux/templates/qmi-flag-types.c.template
new file mode 100644
index 00000000..9ae0a7c8
--- /dev/null
+++ b/build-aux/templates/qmi-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/qmi-flag-types.h.template b/build-aux/templates/qmi-flag-types.h.template
new file mode 100644
index 00000000..74d3b14a
--- /dev/null
+++ b/build-aux/templates/qmi-flag-types.h.template
@@ -0,0 +1,37 @@
+/*** 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 ***/