diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2023-04-17 16:09:43 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksandermj@chromium.org> | 2023-05-03 12:38:43 +0000 |
commit | 200f827d386a15ce096d8dd476b21d09d919d8f0 (patch) | |
tree | 72dd5df754135b7b7130936bdef3d9e4ebc1e3fc /src/mm-iface-modem-simple.c | |
parent | acc98e43ba3aeea8d8be1a92d009f775a8cd83f4 (diff) |
bearer-list: new common method to disconnect one or all bearers
Diffstat (limited to 'src/mm-iface-modem-simple.c')
-rw-r--r-- | src/mm-iface-modem-simple.c | 75 |
1 files changed, 11 insertions, 64 deletions
diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c index 635d915d..a3609eaf 100644 --- a/src/mm-iface-modem-simple.c +++ b/src/mm-iface-modem-simple.c @@ -974,8 +974,6 @@ typedef struct { MmGdbusModemSimple *skeleton; GDBusMethodInvocation *invocation; gchar *bearer_path; - GList *bearers; - MMBaseBearer *current; } DisconnectionContext; static void @@ -985,61 +983,24 @@ disconnection_context_free (DisconnectionContext *ctx) g_object_unref (ctx->invocation); g_object_unref (ctx->self); g_free (ctx->bearer_path); - g_clear_object (&ctx->current); - g_list_free_full (ctx->bearers, g_object_unref); g_slice_free (DisconnectionContext, ctx); } -static void disconnect_next_bearer (DisconnectionContext *ctx); - static void -disconnect_ready (MMBaseBearer *bearer, - GAsyncResult *res, - DisconnectionContext *ctx) +bearer_list_disconnect_bearers_ready (MMBearerList *bearer_list, + GAsyncResult *res, + DisconnectionContext *ctx) { GError *error = NULL; - if (!mm_base_bearer_disconnect_finish (bearer, res, &error)) { - mm_obj_warn (ctx->self, "failed to disconnect bearer '%s': %s", - mm_base_bearer_get_path (bearer), error->message); + if (!mm_bearer_list_disconnect_bearers_finish (bearer_list, res, &error)) { + mm_obj_warn (ctx->self, "failed to disconnect bearers: %s", error->message); g_dbus_method_invocation_take_error (ctx->invocation, error); - disconnection_context_free (ctx); - return; - } - - disconnect_next_bearer (ctx); -} - -static void -disconnect_next_bearer (DisconnectionContext *ctx) -{ - if (ctx->current) - g_clear_object (&ctx->current); - - /* No more bearers? all done! */ - if (!ctx->bearers) { + } else { mm_obj_info (ctx->self, "all requested bearers disconnected"); mm_gdbus_modem_simple_complete_disconnect (ctx->skeleton, ctx->invocation); - disconnection_context_free (ctx); - return; } - - ctx->current = MM_BASE_BEARER (ctx->bearers->data); - ctx->bearers = g_list_delete_link (ctx->bearers, ctx->bearers); - - mm_obj_info (ctx->self, "disconnecting bearer '%s'...", mm_base_bearer_get_path (ctx->current)); - mm_base_bearer_disconnect (ctx->current, - (GAsyncReadyCallback)disconnect_ready, - ctx); -} - -static void -build_connected_bearer_list (MMBaseBearer *bearer, - DisconnectionContext *ctx) -{ - if (!ctx->bearer_path || - g_str_equal (ctx->bearer_path, mm_base_bearer_get_path (bearer))) - ctx->bearers = g_list_prepend (ctx->bearers, g_object_ref (bearer)); + disconnection_context_free (ctx); } static void @@ -1083,24 +1044,10 @@ disconnect_auth_ready (MMBaseModem *self, else mm_obj_info (self, "processing user request to disconnect modem: all bearers"); - mm_bearer_list_foreach (list, - (MMBearerListForeachFunc)build_connected_bearer_list, - ctx); - - if (ctx->bearer_path && !ctx->bearers) { - mm_obj_warn (self, "failed to disconnect bearer '%s': not found", ctx->bearer_path); - g_dbus_method_invocation_return_error ( - ctx->invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_INVALID_ARGS, - "Couldn't disconnect bearer '%s': not found", - ctx->bearer_path); - disconnection_context_free (ctx); - return; - } - - /* Go on disconnecting bearers */ - disconnect_next_bearer (ctx); + mm_bearer_list_disconnect_bearers (list, + ctx->bearer_path, + (GAsyncReadyCallback)bearer_list_disconnect_bearers_ready, + ctx); } static gboolean |