bearer: new helper 'MMBearerConnectResult' type

Instead of returning 3 variables in connect_finish(), return a single reference
counted struct. This simplifies how the result is built and passed within a
GSimpleAsyncResult to each _finish() method.

This also simplifies the dialling step in the 3GPP connection sequence, as we
can use the same new type.
This commit is contained in:
Aleksander Morgado
2013-02-17 20:27:24 +01:00
parent 1746949277
commit 15d34d56fd
8 changed files with 194 additions and 312 deletions

View File

@@ -71,22 +71,15 @@ connect_3gpp_context_complete_and_free (Connect3gppContext *ctx)
g_slice_free (Connect3gppContext, ctx);
}
static gboolean
static MMBearerConnectResult *
connect_3gpp_finish (MMBroadbandBearer *self,
GAsyncResult *res,
MMPort **data,
MMBearerIpConfig **ipv4_config,
MMBearerIpConfig **ipv6_config,
GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return FALSE;
return NULL;
*data = g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
*ipv4_config = mm_bearer_ip_config_new ();
mm_bearer_ip_config_set_method (*ipv4_config, MM_BEARER_IP_METHOD_DHCP);
*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 connect_3gpp_context_step (Connect3gppContext *ctx);
@@ -312,10 +305,20 @@ connect_3gpp_context_step (Connect3gppContext *ctx)
case CONNECT_3GPP_CONTEXT_STEP_LAST:
/* Clear context */
ctx->self->priv->connect_pending = NULL;
/* Set data port as result */
g_simple_async_result_set_op_res_gpointer (ctx->result,
g_object_ref (ctx->data),
g_object_unref);
/* Setup result */
{
MMBearerIpConfig *ipv4_config;
ipv4_config = mm_bearer_ip_config_new ();
mm_bearer_ip_config_set_method (ipv4_config, MM_BEARER_IP_METHOD_DHCP);
g_simple_async_result_set_op_res_gpointer (
ctx->result,
mm_bearer_connect_result_new (ctx->data, ipv4_config, NULL),
(GDestroyNotify)mm_bearer_connect_result_unref);
g_object_unref (ipv4_config);
}
connect_3gpp_context_complete_and_free (ctx);
return;
}

View File

@@ -36,23 +36,6 @@ G_DEFINE_TYPE (MMBearerIridium, mm_bearer_iridium, MM_TYPE_BEARER);
/*****************************************************************************/
/* 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 {
MMBearerIridium *self;
GSimpleAsyncResult *result;
@@ -75,25 +58,15 @@ connect_context_complete_and_free (ConnectContext *ctx)
g_free (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;
return NULL;
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 TRUE;
return mm_bearer_connect_result_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
}
static void
@@ -141,7 +114,6 @@ dial_ready (MMBaseModem *modem,
ConnectContext *ctx)
{
MMBearerIpConfig *config;
ConnectResult *result;
/* DO NOT check for cancellable here. If we got here without errors, the
* bearer is really connected and therefore we need to reflect that in
@@ -169,16 +141,13 @@ dial_ready (MMBaseModem *modem,
config = mm_bearer_ip_config_new ();
mm_bearer_ip_config_set_method (config, MM_BEARER_IP_METHOD_PPP);
/* Build result */
result = g_new0 (ConnectResult, 1);
result->data = g_object_ref (ctx->primary);
result->ipv4_config = config;
result->ipv6_config = g_object_ref (config);
/* Set operation result */
g_simple_async_result_set_op_res_gpointer (ctx->result,
result,
(GDestroyNotify)connect_result_free);
g_simple_async_result_set_op_res_gpointer (
ctx->result,
mm_bearer_connect_result_new (MM_PORT (ctx->primary), config, NULL),
(GDestroyNotify)mm_bearer_connect_result_unref);
g_object_unref (config);
connect_context_complete_and_free (ctx);
}

View File

@@ -96,28 +96,15 @@ detailed_connect_context_complete_and_free (DetailedConnectContext *ctx)
g_free (ctx);
}
static gboolean
static MMBearerConnectResult *
connect_3gpp_finish (MMBroadbandBearer *self,
GAsyncResult *res,
MMPort **data,
MMBearerIpConfig **ipv4_config,
MMBearerIpConfig **ipv6_config,
GError **error)
{
MMBearerIpConfig *config;
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return FALSE;
return NULL;
config = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
/* In the default implementation, we assume only IPv4 is supported */
*ipv4_config = g_object_ref (config);
*ipv6_config = NULL;
/* We used the input suggested data port */
*data = NULL;
return TRUE;
return mm_bearer_connect_result_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
}
static gboolean connect_3gpp_qmistatus (DetailedConnectContext *ctx);
@@ -209,9 +196,11 @@ connect_3gpp_qmistatus_ready (MMBaseModem *modem,
ctx->self);
config = mm_bearer_ip_config_new ();
mm_bearer_ip_config_set_method (config, MM_BEARER_IP_METHOD_DHCP);
g_simple_async_result_set_op_res_gpointer (ctx->result,
config,
(GDestroyNotify)g_object_unref);
g_simple_async_result_set_op_res_gpointer (
ctx->result,
mm_bearer_connect_result_new (ctx->data, config, NULL),
(GDestroyNotify)mm_bearer_connect_result_unref);
g_object_unref (config);
detailed_connect_context_complete_and_free (ctx);
return;
}

View File

@@ -47,23 +47,6 @@ struct _MMBearerQmiPrivate {
/*****************************************************************************/
/* 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_slice_free (ConnectResult, result);
}
typedef enum {
CONNECT_STEP_FIRST,
CONNECT_STEP_OPEN_QMI_PORT,
@@ -129,25 +112,15 @@ connect_context_complete_and_free (ConnectContext *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;
return NULL;
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 TRUE;
return mm_bearer_connect_result_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
}
static void connect_context_step (ConnectContext *ctx);
@@ -744,7 +717,6 @@ connect_context_step (ConnectContext *ctx)
/* If one of IPv4 or IPv6 succeeds, we're connected */
if (ctx->packet_data_handle_ipv4 || ctx->packet_data_handle_ipv6) {
MMBearerIpConfig *config;
ConnectResult *result;
/* Port is connected; update the state */
mm_port_set_connected (MM_PORT (ctx->data), TRUE);
@@ -771,20 +743,15 @@ connect_context_step (ConnectContext *ctx)
config = mm_bearer_ip_config_new ();
mm_bearer_ip_config_set_method (config, MM_BEARER_IP_METHOD_DHCP);
/* Build result */
result = g_slice_new0 (ConnectResult);
result->data = g_object_ref (ctx->data);
if (ctx->packet_data_handle_ipv4)
result->ipv4_config = g_object_ref (config);
if (ctx->packet_data_handle_ipv6)
result->ipv6_config = g_object_ref (config);
g_object_unref (config);
/* Set operation result */
g_simple_async_result_set_op_res_gpointer (ctx->result,
result,
(GDestroyNotify)connect_result_free);
g_simple_async_result_set_op_res_gpointer (
ctx->result,
mm_bearer_connect_result_new (
ctx->data,
ctx->packet_data_handle_ipv4 ? config : NULL,
ctx->packet_data_handle_ipv6 ? config : NULL),
(GDestroyNotify)mm_bearer_connect_result_unref);
g_object_unref (config);
} else {
GError *error;

View File

@@ -13,6 +13,7 @@
* Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 - 2011 Red Hat, Inc.
* Copyright (C) 2011 Google, Inc.
* Copyright (C) 2011 - 2013 Aleksander Morgado <aleksander@gnu.org>
*/
#include <config.h>
@@ -373,17 +374,11 @@ connect_ready (MMBearer *self,
{
GError *error = NULL;
gboolean launch_disconnect = FALSE;
MMPort *data = NULL;
MMBearerIpConfig *ipv4_config = NULL;
MMBearerIpConfig *ipv6_config = NULL;
MMBearerConnectResult *result;
/* NOTE: connect() implementations *MUST* handle cancellations themselves */
if (!MM_BEARER_GET_CLASS (self)->connect_finish (self,
res,
&data,
&ipv4_config,
&ipv6_config,
&error)) {
result = MM_BEARER_GET_CLASS (self)->connect_finish (self, res, &error);
if (!result) {
mm_dbg ("Couldn't connect bearer '%s': '%s'",
self->priv->path,
error->message);
@@ -400,11 +395,7 @@ connect_ready (MMBearer *self,
/* Handle cancellations detected after successful connection */
else if (g_cancellable_is_cancelled (self->priv->connect_cancellable)) {
mm_dbg ("Connected bearer '%s', but need to disconnect", self->priv->path);
g_clear_object (&data);
g_clear_object (&ipv4_config);
g_clear_object (&ipv6_config);
mm_bearer_connect_result_unref (result);
g_simple_async_result_set_error (
simple,
MM_CORE_ERROR,
@@ -416,15 +407,12 @@ connect_ready (MMBearer *self,
mm_dbg ("Connected bearer '%s'", self->priv->path);
/* Update bearer and interface status */
bearer_update_status_connected (self,
mm_port_get_device (data),
ipv4_config,
ipv6_config);
g_clear_object (&data);
g_clear_object (&ipv4_config);
g_clear_object (&ipv6_config);
bearer_update_status_connected (
self,
mm_port_get_device (mm_bearer_connect_result_peek_data (result)),
mm_bearer_connect_result_peek_ipv4_config (result),
mm_bearer_connect_result_peek_ipv6_config (result));
mm_bearer_connect_result_unref (result);
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
}
@@ -1123,3 +1111,72 @@ mm_bearer_class_init (MMBearerClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CONFIG, properties[PROP_CONFIG]);
}
/*****************************************************************************/
/* Helpers to implement connect() */
struct _MMBearerConnectResult {
volatile gint ref_count;
MMPort *data;
MMBearerIpConfig *ipv4_config;
MMBearerIpConfig *ipv6_config;
};
MMBearerConnectResult *
mm_bearer_connect_result_ref (MMBearerConnectResult *result)
{
g_atomic_int_inc (&result->ref_count);
return result;
}
void
mm_bearer_connect_result_unref (MMBearerConnectResult *result)
{
if (g_atomic_int_dec_and_test (&result->ref_count)) {
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 (MMBearerConnectResult, result);
}
}
MMPort *
mm_bearer_connect_result_peek_data (MMBearerConnectResult *result)
{
return result->data;
}
MMBearerIpConfig *
mm_bearer_connect_result_peek_ipv4_config (MMBearerConnectResult *result)
{
return result->ipv4_config;
}
MMBearerIpConfig *
mm_bearer_connect_result_peek_ipv6_config (MMBearerConnectResult *result)
{
return result->ipv6_config;
}
MMBearerConnectResult *
mm_bearer_connect_result_new (MMPort *data,
MMBearerIpConfig *ipv4_config,
MMBearerIpConfig *ipv6_config)
{
MMBearerConnectResult *result;
/* 'data' must always be given */
g_assert (MM_IS_PORT (data));
result = g_slice_new0 (MMBearerConnectResult);
result->ref_count = 1;
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;
}

View File

@@ -13,6 +13,7 @@
* Author: Aleksander Morgado <aleksander@lanedo.com>
*
* Copyright (C) 2011 Google, Inc.
* Copyright (C) 2011 - 2013 Aleksander Morgado <aleksander@gnu.org>
*/
#ifndef MM_BEARER_H
@@ -26,6 +27,21 @@
#include "mm-base-modem.h"
/*****************************************************************************/
/* Helpers to implement connect() */
typedef struct _MMBearerConnectResult MMBearerConnectResult;
MMBearerConnectResult *mm_bearer_connect_result_new (MMPort *data,
MMBearerIpConfig *ipv4_config,
MMBearerIpConfig *ipv6_config);
void mm_bearer_connect_result_unref (MMBearerConnectResult *result);
MMBearerConnectResult *mm_bearer_connect_result_ref (MMBearerConnectResult *result);
MMPort *mm_bearer_connect_result_peek_data (MMBearerConnectResult *result);
MMBearerIpConfig *mm_bearer_connect_result_peek_ipv4_config (MMBearerConnectResult *result);
MMBearerIpConfig *mm_bearer_connect_result_peek_ipv6_config (MMBearerConnectResult *result);
/*****************************************************************************/
#define MM_TYPE_BEARER (mm_bearer_get_type ())
#define MM_BEARER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BEARER, MMBearer))
#define MM_BEARER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BEARER, MMBearerClass))
@@ -63,12 +79,9 @@ struct _MMBearerClass {
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* connect_finish) (MMBearer *bearer,
GAsyncResult *res,
MMPort **data,
MMBearerIpConfig **ipv4_config,
MMBearerIpConfig **ipv6_config,
GError **error);
MMBearerConnectResult * (* connect_finish) (MMBearer *bearer,
GAsyncResult *res,
GError **error);
/* Disconnect this bearer */
void (* disconnect) (MMBearer *bearer,

View File

@@ -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>
@@ -67,45 +68,9 @@ mm_broadband_bearer_get_3gpp_cid (MMBroadbandBearer *self)
return self->priv->cid;
}
/*****************************************************************************/
/* 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;
return NULL;
result = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
*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);
@@ -997,23 +952,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;
@@ -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;
return NULL;
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 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),

View File

@@ -13,6 +13,7 @@
* Author: Aleksander Morgado <aleksander@lanedo.com>
*
* Copyright (C) 2011 - 2012 Google, Inc.
* Copyright (C) 2011 - 2013 Aleksander Morgado <aleksander@gnu.org>
*/
#ifndef MM_BROADBAND_BEARER_H
@@ -55,12 +56,9 @@ struct _MMBroadbandBearerClass {
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* connect_3gpp_finish) (MMBroadbandBearer *self,
GAsyncResult *res,
MMPort **data,
MMBearerIpConfig **ipv4_config,
MMBearerIpConfig **ipv6_config,
GError **error);
MMBearerConnectResult * (* connect_3gpp_finish) (MMBroadbandBearer *self,
GAsyncResult *res,
GError **error);
/* Dialing sub-part of 3GPP connection */
void (* dial_3gpp) (MMBroadbandBearer *self,
@@ -113,12 +111,9 @@ struct _MMBroadbandBearerClass {
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* connect_cdma_finish) (MMBroadbandBearer *self,
GAsyncResult *res,
MMPort **data,
MMBearerIpConfig **ipv4_config,
MMBearerIpConfig **ipv6_config,
GError **error);
MMBearerConnectResult * (* connect_cdma_finish) (MMBroadbandBearer *self,
GAsyncResult *res,
GError **error);
/* Full CDMA disconnection sequence */
void (* disconnect_cdma) (MMBroadbandBearer *self,