aboutsummaryrefslogtreecommitdiff
path: root/src/mm-iface-modem-simple.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-02-25 14:43:22 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-03-10 10:59:22 +0100
commit35e20a48c8b16ae744c4ca3082f70e8aa674c2f4 (patch)
tree2b23fb243ebc151bbac167f9165f5b1cfef6390e /src/mm-iface-modem-simple.c
parent064e92e9b77b35f83cb522c6ea98b9016ce5db8c (diff)
api,modem: deprecate the 'MaxBearers' property
This property was never initialized with a correct value, we would always use the same value as used for MaxActiveBearers, which isn't technically right. Just suggest to ignore this property, and flag it as deprecated. In addition to deprecating the API property, we will internally no longer limit the amount of bearer objects that may be created with different connection settings. The bearer object exposed in DBus is a representation of the connection that may be setup, and so we can hold as many representations as we want as long as the amount of connected bearers doesn't exceed the maximum amount for each modem. Leaving around the disconnected modems also serves another purpose. Each bearer holds information about the amount of times a connection with it has been attempted, and the amount of data transferred through it. If we use the Simple.Connect() method to connect the modem using different bearer settings, we won't lose the information of the past connection attempts with different settings.
Diffstat (limited to 'src/mm-iface-modem-simple.c')
-rw-r--r--src/mm-iface-modem-simple.c89
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, &current,
+ 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...");