mbm: port get_ip_config_3gpp to use GTask
This commit is contained in:

committed by
Aleksander Morgado

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