aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-09-28 19:46:12 +0200
committerAleksander Morgado <aleksander@aleksander.es>2016-09-29 15:43:05 +0200
commit58c955f5f23e874e4f8c2a4b389e46c0775e7f07 (patch)
tree568f004df95780b881d22284d642f93e5673221c /libmm-glib
parentae9ede926a1747216b54e22398edde203ec9a03c (diff)
core: allow building and running without udev
Instead of relying on the udev daemon and GUDev to manage the devices reported by the kernel, we can now run ModemManager relying solely on the kernel events reported via the new ReportKernelEvent() API. Therefore, the '--no-auto-scan' option is implicit for the ModemManager daemon when udev is disabled in the build. Additionally, a new custom implementation of the kernel device object is provided, which uses sysfs to load the properties and attributes required in each kernel device, instead of using a GUdevDevice. The udev rule files are kept in place, and a simple custom parser is provided which preloads all rules in memory once and then applies them to the different kernel objects reported via ReportKernelEvent(), e.g. to set port type hints. A simple unit test setup is prepared to validate the udev rules during the `check' Makefile target.
Diffstat (limited to 'libmm-glib')
-rw-r--r--libmm-glib/mm-common-helpers.c43
-rw-r--r--libmm-glib/mm-common-helpers.h2
2 files changed, 45 insertions, 0 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c
index 4b784da0..3a5883b2 100644
--- a/libmm-glib/mm-common-helpers.c
+++ b/libmm-glib/mm-common-helpers.c
@@ -1386,6 +1386,49 @@ mm_get_uint_from_str (const gchar *str,
return FALSE;
}
+/**
+ * mm_get_uint_from_hex_str:
+ * @str: the hex string to convert to an unsigned int
+ * @out: on success, the number
+ *
+ * Converts a string to an unsigned number. All characters in the string
+ * MUST be valid hexadecimal digits (0-9, A-F, a-f), otherwise FALSE is
+ * returned.
+ *
+ * An optional "0x" prefix may be given in @str.
+ *
+ * Returns: %TRUE if the string was converted, %FALSE if it was not or if it
+ * did not contain only digits.
+ */
+gboolean
+mm_get_uint_from_hex_str (const gchar *str,
+ guint *out)
+{
+ gulong num;
+
+ if (!str)
+ return FALSE;
+
+ if (g_str_has_prefix (str, "0x"))
+ str = &str[2];
+
+ if (!str[0])
+ return FALSE;
+
+ for (num = 0; str[num]; num++) {
+ if (!g_ascii_isxdigit (str[num]))
+ return FALSE;
+ }
+
+ errno = 0;
+ num = strtoul (str, NULL, 16);
+ if (!errno && num <= G_MAXUINT) {
+ *out = (guint)num;
+ return TRUE;
+ }
+ return FALSE;
+}
+
gboolean
mm_get_uint_from_match_info (GMatchInfo *match_info,
guint32 match_index,
diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h
index c65d3b98..ab5777d1 100644
--- a/libmm-glib/mm-common-helpers.h
+++ b/libmm-glib/mm-common-helpers.h
@@ -143,6 +143,8 @@ gboolean mm_get_int_from_match_info (GMatchInfo *match_info,
gint *out);
gboolean mm_get_uint_from_str (const gchar *str,
guint *out);
+gboolean mm_get_uint_from_hex_str (const gchar *str,
+ guint *out);
gboolean mm_get_uint_from_match_info (GMatchInfo *match_info,
guint32 match_index,
guint *out);