From 1f9a04268f6de7e9aa11073f0bf363aadc2ca29b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 26 Oct 2023 10:54:17 +0000 Subject: core: ensure all errors returned in DBus operations are normalized We want to ensure that all errors reported via DBus operations are normalized to MM-specific errors. We don't want to return QMI or MBIM specific errors, as those are protocol specific and we don't want DBus clients to need to rely on knowing which is the protocol in use by the device. --- src/mm-error-helpers.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/mm-error-helpers.c') diff --git a/src/mm-error-helpers.c b/src/mm-error-helpers.c index a5c96e67..b1efab21 100644 --- a/src/mm-error-helpers.c +++ b/src/mm-error-helpers.c @@ -712,3 +712,49 @@ mm_normalize_error (const GError *error) /* Normalize mapped errors */ return normalize_mapped_error (error); } + +/******************************************************************************/ + +void +mm_dbus_method_invocation_take_error (GDBusMethodInvocation *invocation, + GError *error) +{ + g_autoptr(GError) taken = error; + + mm_dbus_method_invocation_return_gerror (invocation, taken); +} + +void +mm_dbus_method_invocation_return_error_literal (GDBusMethodInvocation *invocation, + GQuark domain, + gint code, + const gchar *message) +{ + g_autoptr(GError) error = NULL; + + error = g_error_new_literal (domain, code, message); + mm_dbus_method_invocation_return_gerror (invocation, error); +} + +void +mm_dbus_method_invocation_return_error (GDBusMethodInvocation *invocation, + GQuark domain, + gint code, + const gchar *format, + ...) +{ + va_list var_args; + g_autoptr(GError) error = NULL; + + va_start (var_args, format); + error = g_error_new_valist (domain, code, format, var_args); + mm_dbus_method_invocation_return_gerror (invocation, error); + va_end (var_args); +} + +void +mm_dbus_method_invocation_return_gerror (GDBusMethodInvocation *invocation, + const GError *error) +{ + g_dbus_method_invocation_take_error (invocation, mm_normalize_error (error)); +} -- cgit v1.2.3-70-g09d2