diff options
Diffstat (limited to 'src/mm-iface-modem-simple.c')
-rw-r--r-- | src/mm-iface-modem-simple.c | 89 |
1 files changed, 12 insertions, 77 deletions
diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c index b0cf5e22..d788f677 100644 --- a/src/mm-iface-modem-simple.c +++ b/src/mm-iface-modem-simple.c @@ -226,6 +226,7 @@ typedef struct { GDBusMethodInvocation *invocation; MMIfaceModemSimple *self; ConnectionStep step; + MMBearerList *bearer_list; /* Expected input properties */ GVariant *dictionary; @@ -263,6 +264,7 @@ connection_context_free (ConnectionContext *ctx) cleanup_cancellation (ctx); g_clear_object (&ctx->properties); g_clear_object (&ctx->bearer); + g_clear_object (&ctx->bearer_list); g_variant_unref (ctx->dictionary); g_object_unref (ctx->skeleton); g_object_unref (ctx->invocation); @@ -477,22 +479,6 @@ update_lock_info_ready (MMIfaceModem *self, g_object_unref (sim); } -typedef struct { - MMBaseBearer *found; -} BearerListFindContext; - -static void -bearer_list_find_disconnected (MMBaseBearer *bearer, - BearerListFindContext *ctx) -{ - /* If already marked one to remove, do nothing */ - if (ctx->found) - return; - - if (mm_base_bearer_get_status (bearer) == MM_BEARER_STATUS_DISCONNECTED) - ctx->found = g_object_ref (bearer); -} - static gboolean completed_if_cancelled (ConnectionContext *ctx) { @@ -595,85 +581,26 @@ connection_step (ConnectionContext *ctx) /* fall through */ case CONNECTION_STEP_BEARER: { - MMBearerList *list = NULL; - MMBearerProperties *bearer_properties; + g_autoptr(MMBearerProperties) bearer_properties = NULL; mm_obj_info (ctx->self, "simple connect state (%d/%d): bearer", ctx->step, CONNECTION_STEP_LAST); - g_object_get (ctx->self, - MM_IFACE_MODEM_BEARER_LIST, &list, - NULL); - if (!list) { - g_dbus_method_invocation_return_error ( - ctx->invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't get the bearer list"); - connection_context_free (ctx); - return; - } bearer_properties = mm_simple_connect_properties_get_bearer_properties (ctx->properties); /* Check if the bearer we want to create is already in the list */ - ctx->bearer = mm_bearer_list_find_by_properties (list, bearer_properties); + ctx->bearer = mm_bearer_list_find_by_properties (ctx->bearer_list, bearer_properties); if (!ctx->bearer) { mm_obj_dbg (ctx->self, "creating new bearer..."); - /* If we don't have enough space to create the bearer, try to remove - * a disconnected bearer first. */ - if (mm_bearer_list_get_max (list) == mm_bearer_list_get_count (list)) { - BearerListFindContext foreach_ctx; - - foreach_ctx.found = NULL; - mm_bearer_list_foreach (list, - (MMBearerListForeachFunc)bearer_list_find_disconnected, - &foreach_ctx); - - /* Found a disconnected bearer, remove it */ - if (foreach_ctx.found) { - GError *error = NULL; - - if (!mm_bearer_list_delete_bearer (list, - mm_base_bearer_get_path (foreach_ctx.found), - &error)) { - mm_obj_dbg (ctx->self, "couldn't delete disconnected bearer at '%s': %s", - mm_base_bearer_get_path (foreach_ctx.found), - error->message); - g_error_free (error); - } else - mm_obj_dbg (ctx->self, "deleted disconnected bearer at '%s'", - mm_base_bearer_get_path (foreach_ctx.found)); - g_object_unref (foreach_ctx.found); - } - - /* Re-check space, and if we still are in max, return an error */ - if (mm_bearer_list_get_max (list) == mm_bearer_list_get_count (list)) { - g_dbus_method_invocation_return_error ( - ctx->invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_TOO_MANY, - "Cannot create new bearer: all existing bearers are connected"); - connection_context_free (ctx); - g_object_unref (list); - g_object_unref (bearer_properties); - return; - } - } - mm_iface_modem_create_bearer (MM_IFACE_MODEM (ctx->self), bearer_properties, (GAsyncReadyCallback)create_bearer_ready, ctx); - - g_object_unref (list); - g_object_unref (bearer_properties); return; } mm_obj_dbg (ctx->self, "Using already existing bearer at '%s'...", mm_base_bearer_get_path (ctx->bearer)); - g_object_unref (list); - g_object_unref (bearer_properties); ctx->step++; } /* fall through */ @@ -748,7 +675,15 @@ connect_auth_ready (MMBaseModem *self, /* We may be able to skip some steps, so check that before doing anything */ g_object_get (self, MM_IFACE_MODEM_STATE, ¤t, + MM_IFACE_MODEM_BEARER_LIST, &ctx->bearer_list, NULL); + if (!ctx->bearer_list) { + g_dbus_method_invocation_return_error ( + ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't get the bearer list"); + connection_context_free (ctx); + return; + } mm_obj_info (self, "simple connect started..."); |