diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2021-05-17 21:33:32 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2021-05-23 01:22:07 +0200 |
commit | de6b1324cb80413e552806f75c70be72cc41e933 (patch) | |
tree | 8f20a6bfc9a1ae4f4288e11a77aa54d1d178d8ce /libmm-glib/mm-common-helpers.c | |
parent | ff45d292ee75b0e49c3de3677211218445659884 (diff) |
api,bearer: new 'ConnectionError' property
This new property will provide detailed information about the failed
connection attempt, or about the network initiated disconnection. The
property will be cleared only if a new connection attempt is
triggered, and so it can be used to investigate why a given attempt
failed without needing to be the one who triggered the attempt (e.g.
so that failures in NetworkManager-triggered connection attempts can
be investigated looking at the DBus API).
The property is built as a (ss) tuple, but the libmm-glib interface
provides methods to read this property as a GError.
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r-- | libmm-glib/mm-common-helpers.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 50c4c830..fdd72a3b 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1911,3 +1911,53 @@ mm_common_register_errors (void) return TRUE; } + +GError * +mm_common_error_from_tuple (GVariant *tuple, + GError **error) +{ + g_autoptr(GError) dbus_error = NULL; + g_autofree gchar *error_name = NULL; + g_autofree gchar *error_message = NULL; + + mm_common_register_errors (); + + if (!g_variant_is_of_type (tuple, G_VARIANT_TYPE ("(ss)"))) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Cannot create error from tuple: " + "invalid variant type received"); + return NULL; + } + + g_variant_get (tuple, "(ss)", &error_name, &error_message); + if (!error_name || !error_name[0]) + return NULL; + + /* We convert the error name into a proper GError (domain+code), but we + * don't attempt to give the error message to new_for_dbus_error() as that + * would generate a string we don't want (e.g. instead of just "Unknown + * Error" we would get "GDBus.Error:org.freedesktop.ModemManager1.Error.MobileEquipment.Unknown: Unknown error" + */ + dbus_error = g_dbus_error_new_for_dbus_error (error_name, ""); + + /* And now we build a new GError with same domain+code but with the received + * error message */ + return g_error_new (dbus_error->domain, dbus_error->code, "%s", error_message); +} + +GVariant * +mm_common_error_to_tuple (const GError *error) +{ + g_autofree gchar *error_name = NULL; + GVariant *tuple[2]; + + mm_common_register_errors (); + + error_name = g_dbus_error_encode_gerror (error); + tuple[0] = g_variant_new_string (error_name); + tuple[1] = g_variant_new_string (error->message); + + return g_variant_ref_sink (g_variant_new_tuple (tuple, 2)); +} |