aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--build-aux/Makefile.am4
-rw-r--r--build-aux/qmi-enum-types-template.c104
-rw-r--r--build-aux/qmi-enum-types-template.h35
-rw-r--r--src/Makefile.am16
-rw-r--r--src/libqmi-glib.h1
-rw-r--r--src/qmi-enums.h69
7 files changed, 230 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 09a2d4d..f424e58 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,3 +36,5 @@ src/Makefile.in
src/libqmi-glib.la
src/qmi-error-types.c
src/qmi-error-types.h
+src/qmi-enum-types.h
+src/qmi-enum-types.c
diff --git a/build-aux/Makefile.am b/build-aux/Makefile.am
index 452a91b..110e8e3 100644
--- a/build-aux/Makefile.am
+++ b/build-aux/Makefile.am
@@ -1,4 +1,6 @@
EXTRA_DIST = \
qmi-error-types-template.h \
- qmi-error-types-template.c
+ qmi-error-types-template.c \
+ qmi-enum-types-template.h \
+ qmi-enum-types-template.c
diff --git a/build-aux/qmi-enum-types-template.c b/build-aux/qmi-enum-types-template.c
new file mode 100644
index 0000000..7f12c2c
--- /dev/null
+++ b/build-aux/qmi-enum-types-template.c
@@ -0,0 +1,104 @@
+/*** 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 */
+#undef IS_ENUM
+#undef IS_FLAGS
+#define IS_@TYPE@
+
+GType
+@enum_name@_get_type (void)
+{
+ static volatile gsize g_define_type_id__volatile = 0;
+
+ if (g_once_init_enter (&g_define_type_id__volatile)) {
+ 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__volatile, g_define_type_id);
+ }
+
+ return g_define_type_id__volatile;
+}
+
+/* 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 IS_ENUM
+const gchar *
+@enum_name@_get_string (@EnumName@ val)
+{
+ guint i;
+
+ for (i = 0; @enum_name@_values[i].value_nick; i++) {
+ if (val == @enum_name@_values[i].value)
+ return @enum_name@_values[i].value_nick;
+ }
+
+ return NULL;
+}
+#endif /* 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 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 /* IS_FLAGS */
+
+/*** END value-tail ***/
+
+/*** BEGIN file-tail ***/
+/*** END file-tail ***/
diff --git a/build-aux/qmi-enum-types-template.h b/build-aux/qmi-enum-types-template.h
new file mode 100644
index 0000000..13db2a6
--- /dev/null
+++ b/build-aux/qmi-enum-types-template.h
@@ -0,0 +1,35 @@
+/*** 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 */
+#undef IS_ENUM
+#undef IS_FLAGS
+#define IS_@TYPE@
+
+#if defined IS_ENUM
+const gchar *@enum_name@_get_string (@EnumName@ val);
+#endif
+
+#if defined 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/src/Makefile.am b/src/Makefile.am
index c96b47f..b5b0899 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,12 +22,27 @@ qmi-error-types.c: qmi-errors.h qmi-error-types.h $(top_srcdir)/build-aux/qmi-er
--template $(top_srcdir)/build-aux/qmi-error-types-template.c \
qmi-errors.h > $@
+# Enum types
+qmi-enum-types.h: qmi-enums.h $(top_srcdir)/build-aux/qmi-enum-types-template.h
+ $(AM_V_GEN) $(GLIB_MKENUMS) \
+ --fhead "#ifndef __LIBQMI_GLIB_ENUM_TYPES_H__\n#define __LIBQMI_GLIB_ENUM_TYPES_H__\n#include \"qmi-enums.h\"\n" \
+ --template $(top_srcdir)/build-aux/qmi-enum-types-template.h \
+ --ftail "#endif /* __LIBQMI_GLIB_ENUM_TYPES_H__ */\n" \
+ qmi-enums.h > $@
+
+qmi-enum-types.c: qmi-enums.h qmi-enum-types.h $(top_srcdir)/build-aux/qmi-enum-types-template.c
+ $(AM_V_GEN) $(GLIB_MKENUMS) \
+ --fhead "#include \"qmi-enums.h\"\n#include \"qmi-enum-types.h\"\n" \
+ --template $(top_srcdir)/build-aux/qmi-enum-types-template.c \
+ qmi-enums.h > $@
+
# Additional dependencies
qmi-device.c: qmi-error-types.h
libqmi_glib_la_SOURCES = \
libqmi-glib.h \
qmi-errors.h qmi-error-types.h qmi-error-types.c \
+ qmi-enums.h qmi-enum-types.h qmi-enum-types.c \
qmi-device.h qmi-device.c
libqmi_glib_la_LIBADD = \
@@ -37,4 +52,5 @@ includedir = @includedir@/libqmi-glib
include_HEADERS = \
libqmi-glib.h \
qmi-errors.h qmi-error-types.h \
+ qmi-enums.h qmi-enum-types.h \
qmi-device.h
diff --git a/src/libqmi-glib.h b/src/libqmi-glib.h
index 29072f6..9644b0d 100644
--- a/src/libqmi-glib.h
+++ b/src/libqmi-glib.h
@@ -25,6 +25,7 @@
#include "qmi-errors.h"
#include "qmi-error-types.h"
+#include "qmi-enum-types.h"
#include "qmi-device.h"
#endif /* _LIBQMI_GLIB_H_ */
diff --git a/src/qmi-enums.h b/src/qmi-enums.h
new file mode 100644
index 0000000..ba15dfc
--- /dev/null
+++ b/src/qmi-enums.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * libqmi-glib -- GLib/GIO based library to control QMI devices
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2012 Aleksander Morgado <aleksander@lanedo.com>
+ */
+
+#ifndef _LIBQMI_GLIB_QMI_ENUMS_H_
+#define _LIBQMI_GLIB_QMI_ENUMS_H_
+
+typedef enum {
+ /* Unknown service */
+ QMI_SERVICE_UNKNOWN = -1,
+ /* Control service */
+ QMI_SERVICE_CTL = 0x00,
+ /* Wireless Data Service */
+ QMI_SERVICE_WDS = 0x01,
+ /* Device Management Service */
+ QMI_SERVICE_DMS = 0x02,
+ /* Network Access Service */
+ QMI_SERVICE_NAS = 0x03,
+ /* Quality Of Service service */
+ QMI_SERVICE_QOS = 0x04,
+ /* Wireless Messaging Service */
+ QMI_SERVICE_WMS = 0x05,
+ /* Position Determination Service */
+ QMI_SERVICE_PDS = 0x06,
+ /* Authentication service */
+ QMI_SERVICE_AUTH = 0x07,
+ /* AT service */
+ QMI_SERVICE_AT = 0x08,
+ /* Voice service */
+ QMI_SERVICE_VOICE = 0x09,
+
+ QMI_SERVICE_CAT2 = 0x0A,
+ QMI_SERVICE_UIM = 0x0B,
+ QMI_SERVICE_PBM = 0x0C,
+ QMI_SERVICE_LOC = 0x10,
+ QMI_SERVICE_SAR = 0x11,
+ QMI_SERVICE_RMTFS = 0x14,
+
+ /* Card Application Toolkit service */
+ QMI_SERVICE_CAT = 0xE0,
+ /* Remote Management Service */
+ QMI_SERVICE_RMS = 0xE1,
+ /* Open Mobile Alliance device management service */
+ QMI_SERVICE_OMA = 0xE2
+} QmiService;
+
+typedef enum {
+ QMI_CTL_MESSAGE_GET_VERSION_INFO = 0x0021,
+} QmiCtlMessage;
+
+#endif /* _LIBQMI_GLIB_QMI_ENUMS_H_ */