diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2015-12-03 12:01:00 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2015-12-03 12:08:48 +0100 |
commit | 236a15efefaf09a0cea1a6f79e1b105f5701c1a6 (patch) | |
tree | 46a267597b9713d63b623a56909f9ebd3be6a3e8 | |
parent | a2e1b771eecf2420bc8819aef9f4a4d0b70ad674 (diff) | |
download | ModemManager-236a15efefaf09a0cea1a6f79e1b105f5701c1a6.tar.gz |
iface-modem: explicitly disconnect bearer before removing it
https://bugs.freedesktop.org/show_bug.cgi?id=90408
-rw-r--r-- | src/mm-bearer-list.c | 23 | ||||
-rw-r--r-- | src/mm-bearer-list.h | 2 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 53 |
3 files changed, 62 insertions, 16 deletions
diff --git a/src/mm-bearer-list.c b/src/mm-bearer-list.c index b90448f61..205193ae0 100644 --- a/src/mm-bearer-list.c +++ b/src/mm-bearer-list.c @@ -105,15 +105,6 @@ mm_bearer_list_delete_bearer (MMBearerList *self, { GList *l; - if (!g_str_has_prefix (path, MM_DBUS_BEARER_PREFIX)) { - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_INVALID_ARGS, - "Cannot delete bearer: invalid path '%s'", - path); - return FALSE; - } - for (l = self->priv->bearers; l; l = g_list_next (l)) { if (g_str_equal (path, mm_base_bearer_get_path (MM_BASE_BEARER (l->data)))) { g_object_unref (l->data); @@ -169,6 +160,20 @@ mm_bearer_list_find_by_properties (MMBearerList *self, return NULL; } +MMBaseBearer * +mm_bearer_list_find_by_path (MMBearerList *self, + const gchar *path) +{ + GList *l; + + for (l = self->priv->bearers; l; l = g_list_next (l)) { + if (g_str_equal (path, mm_base_bearer_get_path (MM_BASE_BEARER (l->data)))) + return g_object_ref (l->data); + } + + return NULL; +} + /*****************************************************************************/ typedef struct { diff --git a/src/mm-bearer-list.h b/src/mm-bearer-list.h index 748547457..73c1454f3 100644 --- a/src/mm-bearer-list.h +++ b/src/mm-bearer-list.h @@ -74,6 +74,8 @@ void mm_bearer_list_foreach (MMBearerList *self, MMBaseBearer *mm_bearer_list_find_by_properties (MMBearerList *self, MMBearerProperties *properties); +MMBaseBearer *mm_bearer_list_find_by_path (MMBearerList *self, + const gchar *path); void mm_bearer_list_disconnect_all_bearers (MMBearerList *self, GAsyncReadyCallback callback, diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 0de50e225..615c0b987 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -760,11 +760,14 @@ typedef struct { MMIfaceModem *self; MMBearerList *list; gchar *bearer_path; + MMBaseBearer *bearer; } HandleDeleteBearerContext; static void handle_delete_bearer_context_free (HandleDeleteBearerContext *ctx) { + if (ctx->bearer) + g_object_unref (ctx->bearer); g_object_unref (ctx->skeleton); g_object_unref (ctx->invocation); g_object_unref (ctx->self); @@ -775,6 +778,26 @@ handle_delete_bearer_context_free (HandleDeleteBearerContext *ctx) } static void +delete_bearer_disconnect_ready (MMBaseBearer *bearer, + GAsyncResult *res, + HandleDeleteBearerContext *ctx) +{ + GError *error = NULL; + + if (!mm_base_bearer_disconnect_finish (bearer, res, &error)) { + g_dbus_method_invocation_take_error (ctx->invocation, error); + handle_delete_bearer_context_free (ctx); + return; + } + + if (!mm_bearer_list_delete_bearer (ctx->list, ctx->bearer_path, &error)) + g_dbus_method_invocation_take_error (ctx->invocation, error); + else + mm_gdbus_modem_complete_delete_bearer (ctx->skeleton, ctx->invocation); + handle_delete_bearer_context_free (ctx); +} + +static void handle_delete_bearer_auth_ready (MMBaseModem *self, GAsyncResult *res, HandleDeleteBearerContext *ctx) @@ -787,14 +810,30 @@ handle_delete_bearer_auth_ready (MMBaseModem *self, return; } - if (!ctx->list) - mm_gdbus_modem_complete_delete_bearer (ctx->skeleton, ctx->invocation); - else if (!mm_bearer_list_delete_bearer (ctx->list, ctx->bearer_path, &error)) - g_dbus_method_invocation_take_error (ctx->invocation, error); - else - mm_gdbus_modem_complete_delete_bearer (ctx->skeleton, ctx->invocation); + if (!g_str_has_prefix (ctx->bearer_path, MM_DBUS_BEARER_PREFIX)) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Cannot delete bearer: invalid path '%s'", + ctx->bearer_path); + handle_delete_bearer_context_free (ctx); + return; + } - handle_delete_bearer_context_free (ctx); + ctx->bearer = mm_bearer_list_find_by_path (ctx->list, ctx->bearer_path); + if (!ctx->bearer) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Cannot delete bearer: no bearer found with path '%s'", + ctx->bearer_path); + handle_delete_bearer_context_free (ctx); + return; + } + + mm_base_bearer_disconnect (ctx->bearer, + (GAsyncReadyCallback)delete_bearer_disconnect_ready, + ctx); } static gboolean |