aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-02-17 20:27:24 +0100
committerAleksander Morgado <aleksander@lanedo.com>2013-02-18 15:41:26 +0100
commit15d34d56fd3277b23c5f477d9aab257cb0bc10a7 (patch)
treed236228bfdd57acf160333925a507493664d80b3 /plugins
parent1746949277cbcf9209fc67b36a091177a8476b29 (diff)
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.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/huawei/mm-broadband-bearer-huawei.c31
-rw-r--r--plugins/iridium/mm-bearer-iridium.c49
-rw-r--r--plugins/novatel/mm-broadband-bearer-novatel-lte.c27
3 files changed, 34 insertions, 73 deletions
diff --git a/plugins/huawei/mm-broadband-bearer-huawei.c b/plugins/huawei/mm-broadband-bearer-huawei.c
index 67a98243..804d1659 100644
--- a/plugins/huawei/mm-broadband-bearer-huawei.c
+++ b/plugins/huawei/mm-broadband-bearer-huawei.c
@@ -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;
}
diff --git a/plugins/iridium/mm-bearer-iridium.c b/plugins/iridium/mm-bearer-iridium.c
index fe2013bd..e19d427b 100644
--- a/plugins/iridium/mm-bearer-iridium.c
+++ b/plugins/iridium/mm-bearer-iridium.c
@@ -37,23 +37,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;
GCancellable *cancellable;
@@ -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);
}
diff --git a/plugins/novatel/mm-broadband-bearer-novatel-lte.c b/plugins/novatel/mm-broadband-bearer-novatel-lte.c
index 4b67cd64..88d46cc7 100644
--- a/plugins/novatel/mm-broadband-bearer-novatel-lte.c
+++ b/plugins/novatel/mm-broadband-bearer-novatel-lte.c
@@ -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;
-
- 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 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;
}