diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-bearer-list.c | 51 | ||||
-rw-r--r-- | src/mm-bearer-list.h | 10 | ||||
-rw-r--r-- | src/mm-iface-modem-simple.c | 89 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 26 |
4 files changed, 24 insertions, 152 deletions
diff --git a/src/mm-bearer-list.c b/src/mm-bearer-list.c index 65717132..8bf6ae05 100644 --- a/src/mm-bearer-list.c +++ b/src/mm-bearer-list.c @@ -34,7 +34,6 @@ G_DEFINE_TYPE (MMBearerList, mm_bearer_list, G_TYPE_OBJECT); enum { PROP_0, PROP_NUM_BEARERS, - PROP_MAX_BEARERS, PROP_MAX_ACTIVE_BEARERS, PROP_LAST }; @@ -44,8 +43,6 @@ static GParamSpec *properties[PROP_LAST]; struct _MMBearerListPrivate { /* List of bearers */ GList *bearers; - /* Max number of bearers */ - guint max_bearers; /* Max number of active bearers */ guint max_active_bearers; }; @@ -53,44 +50,16 @@ struct _MMBearerListPrivate { /*****************************************************************************/ guint -mm_bearer_list_get_max (MMBearerList *self) -{ - return self->priv->max_bearers; -} - -guint mm_bearer_list_get_max_active (MMBearerList *self) { return self->priv->max_active_bearers; } -guint -mm_bearer_list_get_count (MMBearerList *self) -{ - return g_list_length (self->priv->bearers); -} - -guint -mm_bearer_list_get_count_active (MMBearerList *self) -{ - return 0; /* TODO */ -} - gboolean mm_bearer_list_add_bearer (MMBearerList *self, MMBaseBearer *bearer, GError **error) { - /* Just in case, ensure we don't go off limits */ - if (g_list_length (self->priv->bearers) == self->priv->max_bearers) { - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_TOO_MANY, - "Cannot add new bearer: already reached maximum (%u)", - self->priv->max_bearers); - return FALSE; - } - /* Keep our own reference */ self->priv->bearers = g_list_prepend (self->priv->bearers, g_object_ref (bearer)); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NUM_BEARERS]); @@ -269,12 +238,10 @@ mm_bearer_list_disconnect_all_bearers (MMBearerList *self, /*****************************************************************************/ MMBearerList * -mm_bearer_list_new (guint max_bearers, - guint max_active_bearers) +mm_bearer_list_new (guint max_active_bearers) { /* Create the object */ return g_object_new (MM_TYPE_BEARER_LIST, - MM_BEARER_LIST_MAX_BEARERS, max_bearers, MM_BEARER_LIST_MAX_ACTIVE_BEARERS, max_active_bearers, NULL); } @@ -291,9 +258,6 @@ set_property (GObject *object, case PROP_NUM_BEARERS: g_assert_not_reached (); break; - case PROP_MAX_BEARERS: - self->priv->max_bearers = g_value_get_uint (value); - break; case PROP_MAX_ACTIVE_BEARERS: self->priv->max_active_bearers = g_value_get_uint (value); break; @@ -315,9 +279,6 @@ get_property (GObject *object, case PROP_NUM_BEARERS: g_value_set_uint (value, g_list_length (self->priv->bearers)); break; - case PROP_MAX_BEARERS: - g_value_set_uint (value, self->priv->max_bearers); - break; case PROP_MAX_ACTIVE_BEARERS: g_value_set_uint (value, self->priv->max_active_bearers); break; @@ -371,16 +332,6 @@ mm_bearer_list_class_init (MMBearerListClass *klass) G_PARAM_READABLE); g_object_class_install_property (object_class, PROP_NUM_BEARERS, properties[PROP_NUM_BEARERS]); - properties[PROP_MAX_BEARERS] = - g_param_spec_uint (MM_BEARER_LIST_MAX_BEARERS, - "Max bearers", - "Maximum number of bearers the list can handle", - 1, - G_MAXUINT, - 1, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (object_class, PROP_MAX_BEARERS, properties[PROP_MAX_BEARERS]); - properties[PROP_MAX_ACTIVE_BEARERS] = g_param_spec_uint (MM_BEARER_LIST_MAX_ACTIVE_BEARERS, "Max active bearers", diff --git a/src/mm-bearer-list.h b/src/mm-bearer-list.h index 0d220eee..1d8db726 100644 --- a/src/mm-bearer-list.h +++ b/src/mm-bearer-list.h @@ -31,7 +31,6 @@ #define MM_BEARER_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BEARER_LIST, MMBearerListClass)) #define MM_BEARER_LIST_NUM_BEARERS "num-bearers" -#define MM_BEARER_LIST_MAX_BEARERS "max-bearers" #define MM_BEARER_LIST_MAX_ACTIVE_BEARERS "max-active-bearers" typedef struct _MMBearerList MMBearerList; @@ -50,14 +49,9 @@ struct _MMBearerListClass { GType mm_bearer_list_get_type (void); G_DEFINE_AUTOPTR_CLEANUP_FUNC (MMBearerList, g_object_unref) -MMBearerList *mm_bearer_list_new (guint max_bearers, - guint max_active_bearers); +MMBearerList *mm_bearer_list_new (guint max_active_bearers); -GStrv mm_bearer_list_get_paths (MMBearerList *self); - -guint mm_bearer_list_get_count (MMBearerList *self); -guint mm_bearer_list_get_count_active (MMBearerList *self); -guint mm_bearer_list_get_max (MMBearerList *self); +GStrv mm_bearer_list_get_paths (MMBearerList *self); guint mm_bearer_list_get_max_active (MMBearerList *self); gboolean mm_bearer_list_add_bearer (MMBearerList *self, 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..."); diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 2e9a3004..5ac3da9c 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -670,17 +670,6 @@ mm_iface_modem_create_bearer (MMIfaceModem *self, return; } - if (mm_bearer_list_get_count (ctx->list) == mm_bearer_list_get_max (ctx->list)) { - g_task_return_new_error ( - task, - MM_CORE_ERROR, - MM_CORE_ERROR_TOO_MANY, - "Cannot add new bearer: already reached maximum (%u)", - mm_bearer_list_get_count (ctx->list)); - g_object_unref (task); - return; - } - MM_IFACE_MODEM_GET_INTERFACE (self)->create_bearer ( self, properties, @@ -5109,10 +5098,10 @@ interface_initialization_step (GTask *task) /* The maximum number of available/connected modems is guessed from * the size of the data ports list. */ n = g_list_length (mm_base_modem_peek_data_ports (MM_BASE_MODEM (self))); - mm_obj_dbg (self, "allowed up to %u bearers", n); + mm_obj_dbg (self, "allowed up to %u active bearers", n); /* Create new default list */ - list = mm_bearer_list_new (n, n); + list = mm_bearer_list_new (n); g_signal_connect (list, "notify::" MM_BEARER_LIST_NUM_BEARERS, G_CALLBACK (bearer_list_updated), @@ -5122,14 +5111,17 @@ interface_initialization_step (GTask *task) NULL); } - if (mm_gdbus_modem_get_max_bearers (ctx->skeleton) == 0) - mm_gdbus_modem_set_max_bearers ( - ctx->skeleton, - mm_bearer_list_get_max (list)); if (mm_gdbus_modem_get_max_active_bearers (ctx->skeleton) == 0) mm_gdbus_modem_set_max_active_bearers ( ctx->skeleton, mm_bearer_list_get_max_active (list)); + + /* MaxBearers set equal to MaxActiveBearers */ + if (mm_gdbus_modem_get_max_bearers (ctx->skeleton) == 0) + mm_gdbus_modem_set_max_bearers ( + ctx->skeleton, + mm_gdbus_modem_get_max_active_bearers (ctx->skeleton)); + g_object_unref (list); ctx->step++; |