altair-lte: port disconnect_3gpp to use GTask

This commit is contained in:
Ben Chan
2017-07-18 22:33:15 -07:00
committed by Aleksander Morgado
parent 710d5c036b
commit 15109a8513

View File

@@ -226,52 +226,27 @@ typedef struct {
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
} DetailedDisconnectContext; } DetailedDisconnectContext;
static DetailedDisconnectContext *
detailed_disconnect_context_new (MMBroadbandBearer *self,
MMBroadbandModem *modem,
MMPortSerialAt *primary,
MMPort *data,
GAsyncReadyCallback callback,
gpointer user_data)
{
DetailedDisconnectContext *ctx;
ctx = g_new0 (DetailedDisconnectContext, 1);
ctx->self = g_object_ref (self);
ctx->modem = MM_BASE_MODEM (g_object_ref (modem));
ctx->primary = g_object_ref (primary);
ctx->data = g_object_ref (data);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
detailed_disconnect_context_new);
return ctx;
}
static gboolean static gboolean
disconnect_3gpp_finish (MMBroadbandBearer *self, disconnect_3gpp_finish (MMBroadbandBearer *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GError **error)
{ {
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); return g_task_propagate_boolean (G_TASK (res), error);
} }
static void static void
detailed_disconnect_context_complete_and_free (DetailedDisconnectContext *ctx) detailed_disconnect_context_free (DetailedDisconnectContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->result);
g_object_unref (ctx->data); g_object_unref (ctx->data);
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);
} }
static void static void
disconnect_3gpp_check_status (MMBaseModem *modem, disconnect_3gpp_check_status (MMBaseModem *modem,
GAsyncResult *res, GAsyncResult *res,
DetailedDisconnectContext *ctx) GTask *task)
{ {
const gchar *result; const gchar *result;
@@ -280,12 +255,12 @@ disconnect_3gpp_check_status (MMBaseModem *modem,
result = mm_base_modem_at_command_full_finish (modem, res, &error); result = mm_base_modem_at_command_full_finish (modem, res, &error);
if (!result) { if (!result) {
mm_warn ("Disconnect failed: %s", error->message); mm_warn ("Disconnect failed: %s", error->message);
g_simple_async_result_take_error (ctx->result, error); g_task_return_error (task, error);
} }
else else
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); g_task_return_boolean (task, TRUE);
detailed_disconnect_context_complete_and_free (ctx); g_object_unref (task);
} }
static void static void
@@ -300,6 +275,7 @@ disconnect_3gpp (MMBroadbandBearer *self,
{ {
DetailedDisconnectContext *ctx; DetailedDisconnectContext *ctx;
MMModem3gppRegistrationState registration_state; MMModem3gppRegistrationState registration_state;
GTask *task;
/* There is a known firmware bug that can leave the modem unusable if a /* There is a known firmware bug that can leave the modem unusable if a
* disconnect attempt is made when out of coverage. So, fail without trying. * disconnect attempt is made when out of coverage. So, fail without trying.
@@ -308,16 +284,23 @@ disconnect_3gpp (MMBroadbandBearer *self,
MM_IFACE_MODEM_3GPP_REGISTRATION_STATE, &registration_state, MM_IFACE_MODEM_3GPP_REGISTRATION_STATE, &registration_state,
NULL); NULL);
if (registration_state == MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN) { if (registration_state == MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN) {
g_simple_async_report_error_in_idle (G_OBJECT (self), g_task_report_new_error (self,
callback, callback,
user_data, user_data,
MM_MOBILE_EQUIPMENT_ERROR, disconnect_3gpp,
MM_MOBILE_EQUIPMENT_ERROR_NO_NETWORK, MM_MOBILE_EQUIPMENT_ERROR,
"Out of coverage, can't disconnect."); MM_MOBILE_EQUIPMENT_ERROR_NO_NETWORK,
"Out of coverage, can't disconnect.");
return; return;
} }
ctx = detailed_disconnect_context_new (self, modem, primary, data, callback, user_data); ctx = g_new0 (DetailedDisconnectContext, 1);
ctx->modem = MM_BASE_MODEM (g_object_ref (modem));
ctx->primary = g_object_ref (primary);
ctx->data = g_object_ref (data);
task = g_task_new (self, NULL, callback, user_data);
g_task_set_task_data (task, ctx, (GDestroyNotify)detailed_disconnect_context_free);
mm_base_modem_at_command_full (ctx->modem, mm_base_modem_at_command_full (ctx->modem,
ctx->primary, ctx->primary,
@@ -327,7 +310,7 @@ disconnect_3gpp (MMBroadbandBearer *self,
FALSE, /* is_raw */ FALSE, /* is_raw */
NULL, /* cancellable */ NULL, /* cancellable */
(GAsyncReadyCallback)disconnect_3gpp_check_status, (GAsyncReadyCallback)disconnect_3gpp_check_status,
ctx); /* user_data */ task); /* user_data */
} }
/*****************************************************************************/ /*****************************************************************************/