diff options
Diffstat (limited to 'src/mm-broadband-bearer.c')
-rw-r--r-- | src/mm-broadband-bearer.c | 201 |
1 files changed, 45 insertions, 156 deletions
diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c index f9a0dad0..b0a46713 100644 --- a/src/mm-broadband-bearer.c +++ b/src/mm-broadband-bearer.c @@ -13,6 +13,7 @@ * Copyright (C) 2008 - 2009 Novell, Inc. * Copyright (C) 2009 - 2012 Red Hat, Inc. * Copyright (C) 2011 - 2012 Google, Inc. + * Copyright (C) 2011 - 2013 Aleksander Morgado <aleksander@gnu.org> */ #include <config.h> @@ -68,44 +69,8 @@ mm_broadband_bearer_get_3gpp_cid (MMBroadbandBearer *self) } /*****************************************************************************/ -/* Detailed connect result, used in both CDMA and 3GPP sequences */ -typedef struct { - MMPort *data; - MMBearerIpConfig *ipv4_config; - MMBearerIpConfig *ipv6_config; -} DetailedConnectResult; - -static void -detailed_connect_result_free (DetailedConnectResult *result) -{ - if (result->ipv4_config) - g_object_unref (result->ipv4_config); - if (result->ipv6_config) - g_object_unref (result->ipv6_config); - if (result->data) - g_object_unref (result->data); - g_slice_free (DetailedConnectResult, result); -} - -static DetailedConnectResult * -detailed_connect_result_new (MMPort *data, - MMBearerIpConfig *ipv4_config, - MMBearerIpConfig *ipv6_config) -{ - DetailedConnectResult *result; - - result = g_slice_new0 (DetailedConnectResult); - if (data) - result->data = g_object_ref (data); - if (ipv4_config) - result->ipv4_config = g_object_ref (ipv4_config); - if (ipv6_config) - result->ipv6_config = g_object_ref (ipv6_config); - return result; -} - -/*****************************************************************************/ /* Detailed connect context, used in both CDMA and 3GPP sequences */ + typedef struct { MMBroadbandBearer *self; MMBaseModem *modem; @@ -120,25 +85,15 @@ typedef struct { guint max_cid; } DetailedConnectContext; -static gboolean +static MMBearerConnectResult * detailed_connect_finish (MMBroadbandBearer *self, GAsyncResult *res, - MMPort **data, - MMBearerIpConfig **ipv4_config, - MMBearerIpConfig **ipv6_config, GError **error) { - DetailedConnectResult *result; - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) - return FALSE; - - result = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)); + return NULL; - *data = (result->data ? g_object_ref (result->data) : NULL); - *ipv4_config = (result->ipv4_config ? g_object_ref (result->ipv4_config) : NULL); - *ipv6_config = (result->ipv6_config ? g_object_ref (result->ipv6_config) : NULL); - return TRUE; + return mm_bearer_connect_result_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); } static void @@ -153,7 +108,7 @@ detailed_connect_context_complete_and_free (DetailedConnectContext *ctx) g_object_unref (ctx->secondary); g_object_unref (ctx->self); g_object_unref (ctx->modem); - g_free (ctx); + g_slice_free (DetailedConnectContext, ctx); } static gboolean @@ -195,7 +150,7 @@ detailed_connect_context_new (MMBroadbandBearer *self, { DetailedConnectContext *ctx; - ctx = g_new0 (DetailedConnectContext, 1); + ctx = g_slice_new0 (DetailedConnectContext); ctx->self = g_object_ref (self); ctx->modem = MM_BASE_MODEM (g_object_ref (modem)); ctx->primary = g_object_ref (primary); @@ -252,8 +207,8 @@ dial_cdma_ready (MMBaseModem *modem, /* Assume only IPv4 is given */ g_simple_async_result_set_op_res_gpointer ( ctx->result, - detailed_connect_result_new (ctx->data, config, NULL), - (GDestroyNotify)detailed_connect_result_free); + mm_bearer_connect_result_new (ctx->data, config, NULL), + (GDestroyNotify)mm_bearer_connect_result_unref); detailed_connect_context_complete_and_free (ctx); g_object_unref (config); @@ -631,8 +586,8 @@ get_ip_config_3gpp_ready (MMBroadbandModem *modem, g_simple_async_result_set_op_res_gpointer ( ctx->result, - detailed_connect_result_new (ctx->data, ipv4_config, ipv6_config), - (GDestroyNotify)detailed_connect_result_free); + mm_bearer_connect_result_new (ctx->data, ipv4_config, ipv6_config), + (GDestroyNotify)mm_bearer_connect_result_unref); detailed_connect_context_complete_and_free (ctx); if (ipv4_config) @@ -686,8 +641,8 @@ dial_3gpp_ready (MMBroadbandModem *modem, g_simple_async_result_set_op_res_gpointer ( ctx->result, - detailed_connect_result_new (ctx->data, config, NULL), - (GDestroyNotify)detailed_connect_result_free); + mm_bearer_connect_result_new (ctx->data, config, NULL), + (GDestroyNotify)mm_bearer_connect_result_unref); detailed_connect_context_complete_and_free (ctx); g_object_unref (config); @@ -998,23 +953,6 @@ connect_3gpp (MMBroadbandBearer *self, /* CONNECT */ typedef struct { - MMPort *data; - MMBearerIpConfig *ipv4_config; - MMBearerIpConfig *ipv6_config; -} ConnectResult; - -static void -connect_result_free (ConnectResult *result) -{ - if (result->ipv4_config) - g_object_unref (result->ipv4_config); - if (result->ipv6_config) - g_object_unref (result->ipv6_config); - g_object_unref (result->data); - g_free (result); -} - -typedef struct { MMBroadbandBearer *self; GSimpleAsyncResult *result; MMPort *suggested_data; @@ -1027,81 +965,36 @@ connect_context_complete_and_free (ConnectContext *ctx) g_object_unref (ctx->result); g_object_unref (ctx->suggested_data); g_object_unref (ctx->self); - g_free (ctx); + g_slice_free (ConnectContext, ctx); } -static gboolean +static MMBearerConnectResult * connect_finish (MMBearer *self, GAsyncResult *res, - MMPort **data, - MMBearerIpConfig **ipv4_config, - MMBearerIpConfig **ipv6_config, GError **error) { - ConnectResult *result; - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) - return FALSE; - - result = (ConnectResult *) g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)); - *data = MM_PORT (g_object_ref (result->data)); - *ipv4_config = (result->ipv4_config ? g_object_ref (result->ipv4_config) : NULL); - *ipv6_config = (result->ipv6_config ? g_object_ref (result->ipv6_config) : NULL); + return NULL; - return TRUE; + return mm_bearer_connect_result_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); } static void connect_succeeded (ConnectContext *ctx, ConnectionType connection_type, - MMPort *data, - MMBearerIpConfig *ipv4_config, - MMBearerIpConfig *ipv6_config) + MMBearerConnectResult *result) { - ConnectResult *result; - MMPort *real_data; - - if (data) { - if (data != ctx->suggested_data) - mm_dbg ("Suggested to use port '%s/%s' for connection, but using '%s/%s' instead", - mm_port_subsys_get_string (mm_port_get_subsys (ctx->suggested_data)), - mm_port_get_device (ctx->suggested_data), - mm_port_subsys_get_string (mm_port_get_subsys (data)), - mm_port_get_device (data)); - real_data = data; - } else - real_data = g_object_ref (ctx->suggested_data); - - /* Port is connected; update the state */ - mm_port_set_connected (real_data, TRUE); - /* Keep connected port and type of connection */ - ctx->self->priv->port = g_object_ref (real_data); + ctx->self->priv->port = g_object_ref (mm_bearer_connect_result_peek_data (result)); ctx->self->priv->connection_type = connection_type; - /* Build result */ - result = g_new0 (ConnectResult, 1); - result->data = real_data; - result->ipv4_config = ipv4_config; - result->ipv6_config = ipv6_config; + /* Port is connected; update the state */ + mm_port_set_connected (ctx->self->priv->port, TRUE); /* Set operation result */ g_simple_async_result_set_op_res_gpointer (ctx->result, result, - (GDestroyNotify)connect_result_free); - - connect_context_complete_and_free (ctx); -} - -static void -connect_failed (ConnectContext *ctx, - GError *error) -{ - /* On errors, close the data port */ - if (MM_IS_AT_SERIAL_PORT (ctx->suggested_data)) - mm_serial_port_close (MM_SERIAL_PORT (ctx->suggested_data)); - - g_simple_async_result_take_error (ctx->result, error); + (GDestroyNotify)mm_bearer_connect_result_unref); connect_context_complete_and_free (ctx); } @@ -1110,20 +1003,18 @@ connect_cdma_ready (MMBroadbandBearer *self, GAsyncResult *res, ConnectContext *ctx) { + MMBearerConnectResult *result; GError *error = NULL; - MMBearerIpConfig *ipv4_config = NULL; - MMBearerIpConfig *ipv6_config = NULL; - MMPort *data = NULL; - - if (!MM_BROADBAND_BEARER_GET_CLASS (self)->connect_cdma_finish (self, - res, - &data, - &ipv4_config, - &ipv6_config, - &error)) - connect_failed (ctx, error); - else - connect_succeeded (ctx, CONNECTION_TYPE_CDMA, data, ipv4_config, ipv6_config); + + result = MM_BROADBAND_BEARER_GET_CLASS (self)->connect_cdma_finish (self, res, &error); + if (!result) { + g_simple_async_result_take_error (ctx->result, error); + connect_context_complete_and_free (ctx); + return; + } + + /* take result */ + connect_succeeded (ctx, CONNECTION_TYPE_CDMA, result); } static void @@ -1131,20 +1022,18 @@ connect_3gpp_ready (MMBroadbandBearer *self, GAsyncResult *res, ConnectContext *ctx) { + MMBearerConnectResult *result; GError *error = NULL; - MMBearerIpConfig *ipv4_config = NULL; - MMBearerIpConfig *ipv6_config = NULL; - MMPort *data = NULL; - - if (!MM_BROADBAND_BEARER_GET_CLASS (self)->connect_3gpp_finish (self, - res, - &data, - &ipv4_config, - &ipv6_config, - &error)) - connect_failed (ctx, error); - else - connect_succeeded (ctx, CONNECTION_TYPE_3GPP, data, ipv4_config, ipv6_config); + + result = MM_BROADBAND_BEARER_GET_CLASS (self)->connect_3gpp_finish (self, res, &error); + if (!result) { + g_simple_async_result_take_error (ctx->result, error); + connect_context_complete_and_free (ctx); + return; + } + + /* take result */ + connect_succeeded (ctx, CONNECTION_TYPE_3GPP, result); } static void @@ -1238,7 +1127,7 @@ connect (MMBearer *self, } /* In this context, we only keep the stuff we'll need later */ - ctx = g_new0 (ConnectContext, 1); + ctx = g_slice_new0 (ConnectContext); ctx->self = g_object_ref (self); ctx->suggested_data = g_object_ref (suggested_data); ctx->result = g_simple_async_result_new (G_OBJECT (self), |