mbm: port get_ip_config_3gpp to use GTask

This commit is contained in:
Ben Chan
2017-09-26 06:08:19 -07:00
committed by Aleksander Morgado
parent a910c45c08
commit e0a3eeee5d

View File

@@ -434,43 +434,16 @@ dial_3gpp (MMBroadbandBearer *self,
/* 3GPP IP config retrieval (sub-step of the 3GPP Connection sequence) */
typedef struct {
MMBroadbandBearerMbm *self;
MMBaseModem *modem;
MMPortSerialAt *primary;
MMBearerIpFamily family;
GSimpleAsyncResult *result;
} GetIpConfig3gppContext;
static GetIpConfig3gppContext *
get_ip_config_3gpp_context_new (MMBroadbandBearerMbm *self,
MMBaseModem *modem,
MMPortSerialAt *primary,
MMBearerIpFamily family,
GAsyncReadyCallback callback,
gpointer user_data)
{
GetIpConfig3gppContext *ctx;
ctx = g_new0 (GetIpConfig3gppContext, 1);
ctx->self = g_object_ref (self);
ctx->modem = g_object_ref (modem);
ctx->primary = g_object_ref (primary);
ctx->family = family;
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
get_ip_config_3gpp_context_new);
return ctx;
}
static void
get_ip_config_context_complete_and_free (GetIpConfig3gppContext *ctx)
get_ip_config_context_free (GetIpConfig3gppContext *ctx)
{
g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->result);
g_object_unref (ctx->primary);
g_object_unref (ctx->modem);
g_object_unref (ctx->self);
g_free (ctx);
}
@@ -484,12 +457,10 @@ get_ip_config_3gpp_finish (MMBroadbandBearer *self,
MMBearerConnectResult *configs;
MMBearerIpConfig *ipv4, *ipv6;
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
configs = g_task_propagate_pointer (G_TASK (res), error);
if (!configs)
return FALSE;
configs = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
g_assert (configs);
ipv4 = mm_bearer_connect_result_peek_ipv4_config (configs);
ipv6 = mm_bearer_connect_result_peek_ipv6_config (configs);
g_assert (ipv4 || ipv6);
@@ -498,20 +469,24 @@ get_ip_config_3gpp_finish (MMBroadbandBearer *self,
if (ipv6_config && ipv6)
*ipv6_config = g_object_ref (ipv6);
mm_bearer_connect_result_unref (configs);
return TRUE;
}
static void
ip_config_ready (MMBaseModem *modem,
GAsyncResult *res,
GetIpConfig3gppContext *ctx)
GTask *task)
{
GetIpConfig3gppContext *ctx;
MMBearerIpConfig *ipv4_config = NULL;
MMBearerIpConfig *ipv6_config = NULL;
const gchar *response;
GError *error = NULL;
MMBearerConnectResult *connect_result;
ctx = g_task_get_task_data (task);
response = mm_base_modem_at_command_full_finish (modem, res, &error);
if (error) {
g_error_free (error);
@@ -530,16 +505,16 @@ ip_config_ready (MMBaseModem *modem,
&ipv4_config,
&ipv6_config,
&error)) {
g_simple_async_result_take_error (ctx->result, error);
g_task_return_error (task, error);
goto out;
}
if (!ipv4_config && !ipv6_config) {
g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't get IP config: couldn't parse response '%s'",
response);
g_task_return_new_error (task,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't get IP config: couldn't parse response '%s'",
response);
goto out;
}
}
@@ -547,14 +522,14 @@ ip_config_ready (MMBaseModem *modem,
connect_result = mm_bearer_connect_result_new (MM_PORT (ctx->primary),
ipv4_config,
ipv6_config);
g_simple_async_result_set_op_res_gpointer (ctx->result,
connect_result,
(GDestroyNotify)mm_bearer_connect_result_unref);
g_task_return_pointer (task,
connect_result,
(GDestroyNotify)mm_bearer_connect_result_unref);
out:
g_object_unref (task);
g_clear_object (&ipv4_config);
g_clear_object (&ipv6_config);
get_ip_config_context_complete_and_free (ctx);
}
static void
@@ -569,13 +544,15 @@ get_ip_config_3gpp (MMBroadbandBearer *self,
gpointer user_data)
{
GetIpConfig3gppContext *ctx;
GTask *task;
ctx = get_ip_config_3gpp_context_new (MM_BROADBAND_BEARER_MBM (self),
MM_BASE_MODEM (modem),
primary,
ip_family,
callback,
user_data);
ctx = g_new0 (GetIpConfig3gppContext, 1);
ctx->modem = g_object_ref (modem);
ctx->primary = g_object_ref (primary);
ctx->family = ip_family;
task = g_task_new (self, NULL, callback, user_data);
g_task_set_task_data (task, ctx, (GDestroyNotify)get_ip_config_context_free);
mm_base_modem_at_command_full (MM_BASE_MODEM (modem),
primary,
@@ -585,7 +562,7 @@ get_ip_config_3gpp (MMBroadbandBearer *self,
FALSE, /* raw */
NULL, /* cancellable */
(GAsyncReadyCallback)ip_config_ready,
ctx);
task);
}
/*****************************************************************************/