wavecom: port set_current_modes to use GTask
This commit is contained in:
@@ -407,18 +407,13 @@ load_current_modes (MMIfaceModem *self,
|
|||||||
/* Set allowed modes (Modem interface) */
|
/* Set allowed modes (Modem interface) */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MMBroadbandModemWavecom *self;
|
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
gchar *cgclass_command;
|
gchar *cgclass_command;
|
||||||
gchar *wwsm_command;
|
gchar *wwsm_command;
|
||||||
} SetCurrentModesContext;
|
} SetCurrentModesContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_current_modes_context_complete_and_free (SetCurrentModesContext *ctx)
|
set_current_modes_context_free (SetCurrentModesContext *ctx)
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_object_unref (ctx->self);
|
|
||||||
g_free (ctx->cgclass_command);
|
g_free (ctx->cgclass_command);
|
||||||
g_free (ctx->wwsm_command);
|
g_free (ctx->wwsm_command);
|
||||||
g_free (ctx);
|
g_free (ctx);
|
||||||
@@ -429,44 +424,44 @@ set_current_modes_finish (MMIfaceModem *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
|
||||||
wwsm_update_ready (MMBaseModem *self,
|
wwsm_update_ready (MMBaseModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
SetCurrentModesContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
mm_base_modem_at_command_finish (self, res, &error);
|
||||||
if (error)
|
if (error)
|
||||||
/* Let the error be critical. */
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
|
||||||
else
|
else
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
|
g_object_unref (task);
|
||||||
set_current_modes_context_complete_and_free (ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cgclass_update_ready (MMBaseModem *self,
|
cgclass_update_ready (MMBaseModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
SetCurrentModesContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
|
SetCurrentModesContext *ctx;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
/* Let the error be critical. */
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
g_object_unref (task);
|
||||||
set_current_modes_context_complete_and_free (ctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->wwsm_command) {
|
if (!ctx->wwsm_command) {
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
set_current_modes_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +470,7 @@ cgclass_update_ready (MMBaseModem *self,
|
|||||||
3,
|
3,
|
||||||
FALSE,
|
FALSE,
|
||||||
(GAsyncReadyCallback)wwsm_update_ready,
|
(GAsyncReadyCallback)wwsm_update_ready,
|
||||||
ctx);
|
task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -485,14 +480,13 @@ set_current_modes (MMIfaceModem *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
|
GTask *task;
|
||||||
SetCurrentModesContext *ctx;
|
SetCurrentModesContext *ctx;
|
||||||
|
|
||||||
|
task = g_task_new (self, NULL, callback, user_data);
|
||||||
|
|
||||||
ctx = g_new0 (SetCurrentModesContext, 1);
|
ctx = g_new0 (SetCurrentModesContext, 1);
|
||||||
ctx->self = g_object_ref (self);
|
g_task_set_task_data (task, ctx, (GDestroyNotify) set_current_modes_context_free);
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
set_current_modes);
|
|
||||||
|
|
||||||
/* Handle ANY/NONE */
|
/* Handle ANY/NONE */
|
||||||
if (allowed == MM_MODEM_MODE_ANY && preferred == MM_MODEM_MODE_NONE) {
|
if (allowed == MM_MODEM_MODE_ANY && preferred == MM_MODEM_MODE_NONE) {
|
||||||
@@ -533,17 +527,15 @@ set_current_modes (MMIfaceModem *self,
|
|||||||
|
|
||||||
allowed_str = mm_modem_mode_build_string_from_mask (allowed);
|
allowed_str = mm_modem_mode_build_string_from_mask (allowed);
|
||||||
preferred_str = mm_modem_mode_build_string_from_mask (preferred);
|
preferred_str = mm_modem_mode_build_string_from_mask (preferred);
|
||||||
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,
|
||||||
"Requested mode (allowed: '%s', preferred: '%s') not "
|
"Requested mode (allowed: '%s', preferred: '%s') not "
|
||||||
"supported by the modem.",
|
"supported by the modem.",
|
||||||
allowed_str,
|
allowed_str, preferred_str);
|
||||||
preferred_str);
|
g_object_unref (task);
|
||||||
g_free (allowed_str);
|
g_free (allowed_str);
|
||||||
g_free (preferred_str);
|
g_free (preferred_str);
|
||||||
|
|
||||||
set_current_modes_context_complete_and_free (ctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,7 +544,7 @@ set_current_modes (MMIfaceModem *self,
|
|||||||
3,
|
3,
|
||||||
FALSE,
|
FALSE,
|
||||||
(GAsyncReadyCallback)cgclass_update_ready,
|
(GAsyncReadyCallback)cgclass_update_ready,
|
||||||
ctx);
|
task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
Reference in New Issue
Block a user