From 7e8885d569d20259d1ae9f3c8c890ae9d4a2cd4d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 18 May 2021 16:00:35 +0200 Subject: base-bearer: report connection error on failed connection attempts When a user-requested connection attempt fails, we not only return the connection error to the user that requested it, we also publish the specific connection error in DBus for others to check why the failure happened. --- src/mm-base-bearer.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/mm-base-bearer.c') diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index a8f8a262..e65799c3 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -242,6 +242,19 @@ connection_monitor_start (MMBaseBearer *self) /*****************************************************************************/ +static void +bearer_update_connection_error (MMBaseBearer *self, + const GError *connection_error) +{ + g_autoptr(GVariant) tuple = NULL; + + if (connection_error) + tuple = mm_common_error_to_tuple (connection_error); + mm_gdbus_bearer_set_connection_error (MM_GDBUS_BEARER (self), tuple); +} + +/*****************************************************************************/ + static void bearer_update_interface_stats (MMBaseBearer *self) { @@ -815,8 +828,11 @@ connect_ready (MMBaseBearer *self, if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { /* Will launch disconnection */ launch_disconnect = TRUE; - } else + } else { + /* Update reported connection error before the status update */ + bearer_update_connection_error (self, error); bearer_update_status (self, MM_BEARER_STATUS_DISCONNECTED); + } } /* Handle cancellations detected after successful connection */ else if (g_cancellable_is_cancelled (self->priv->connect_cancellable)) { @@ -841,6 +857,8 @@ connect_ready (MMBaseBearer *self, } if (launch_disconnect) { + /* Update reported connection error before the status update */ + bearer_update_connection_error (self, error); bearer_update_status (self, MM_BEARER_STATUS_DISCONNECTING); MM_BASE_BEARER_GET_CLASS (self)->disconnect ( self, -- cgit v1.2.3-70-g09d2