huawei: port huawei_custom_init to use GTask
This commit is contained in:

committed by
Aleksander Morgado

parent
e76015ac49
commit
7880a35b19
@@ -75,8 +75,6 @@ first_interface_context_free (FirstInterfaceContext *ctx)
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
MMPortSerialAt *port;
|
MMPortSerialAt *port;
|
||||||
GCancellable *cancellable;
|
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
gboolean curc_done;
|
gboolean curc_done;
|
||||||
guint curc_retries;
|
guint curc_retries;
|
||||||
gboolean getportmode_done;
|
gboolean getportmode_done;
|
||||||
@@ -84,15 +82,10 @@ typedef struct {
|
|||||||
} HuaweiCustomInitContext;
|
} HuaweiCustomInitContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
huawei_custom_init_context_complete_and_free (HuaweiCustomInitContext *ctx)
|
huawei_custom_init_context_free (HuaweiCustomInitContext *ctx)
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
|
||||||
|
|
||||||
if (ctx->cancellable)
|
|
||||||
g_object_unref (ctx->cancellable);
|
|
||||||
g_object_unref (ctx->port);
|
g_object_unref (ctx->port);
|
||||||
g_object_unref (ctx->probe);
|
g_object_unref (ctx->probe);
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_slice_free (HuaweiCustomInitContext, ctx);
|
g_slice_free (HuaweiCustomInitContext, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,10 +94,10 @@ huawei_custom_init_finish (MMPortProbe *probe,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void huawei_custom_init_step (HuaweiCustomInitContext *ctx);
|
static void huawei_custom_init_step (GTask *task);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cache_port_mode (MMDevice *device,
|
cache_port_mode (MMDevice *device,
|
||||||
@@ -129,11 +122,14 @@ cache_port_mode (MMDevice *device,
|
|||||||
static void
|
static void
|
||||||
getportmode_ready (MMPortSerialAt *port,
|
getportmode_ready (MMPortSerialAt *port,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
HuaweiCustomInitContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
|
HuaweiCustomInitContext *ctx;
|
||||||
const gchar *response;
|
const gchar *response;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
response = mm_port_serial_at_command_finish (port, res, &error);
|
response = mm_port_serial_at_command_finish (port, res, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
mm_dbg ("(Huawei) couldn't get port mode: '%s'",
|
mm_dbg ("(Huawei) couldn't get port mode: '%s'",
|
||||||
@@ -175,17 +171,20 @@ out:
|
|||||||
if (error)
|
if (error)
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
|
||||||
huawei_custom_init_step (ctx);
|
huawei_custom_init_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
curc_ready (MMPortSerialAt *port,
|
curc_ready (MMPortSerialAt *port,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
HuaweiCustomInitContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
|
HuaweiCustomInitContext *ctx;
|
||||||
const gchar *response;
|
const gchar *response;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
response = mm_port_serial_at_command_finish (port, res, &error);
|
response = mm_port_serial_at_command_finish (port, res, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
/* Retry if we get a timeout error */
|
/* Retry if we get a timeout error */
|
||||||
@@ -206,7 +205,7 @@ out:
|
|||||||
if (error)
|
if (error)
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
|
||||||
huawei_custom_init_step (ctx);
|
huawei_custom_init_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -251,17 +250,20 @@ try_next_usbif (MMDevice *device)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
huawei_custom_init_step (HuaweiCustomInitContext *ctx)
|
huawei_custom_init_step (GTask *task)
|
||||||
{
|
{
|
||||||
|
HuaweiCustomInitContext *ctx;
|
||||||
FirstInterfaceContext *fi_ctx;
|
FirstInterfaceContext *fi_ctx;
|
||||||
MMKernelDevice *port;
|
MMKernelDevice *port;
|
||||||
|
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
/* If cancelled, end */
|
/* If cancelled, end */
|
||||||
if (g_cancellable_is_cancelled (ctx->cancellable)) {
|
if (g_task_return_error_if_cancelled (task)) {
|
||||||
mm_dbg ("(Huawei) no need to keep on running custom init in (%s)",
|
mm_dbg ("(Huawei) no need to keep on running custom init in (%s)",
|
||||||
mm_port_get_device (MM_PORT (ctx->port)));
|
mm_port_get_device (MM_PORT (ctx->port)));
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
huawei_custom_init_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,10 +271,10 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
|
|||||||
if (ctx->curc_retries == 0) {
|
if (ctx->curc_retries == 0) {
|
||||||
/* All retries consumed, probably not an AT port */
|
/* All retries consumed, probably not an AT port */
|
||||||
mm_port_probe_set_result_at (ctx->probe, FALSE);
|
mm_port_probe_set_result_at (ctx->probe, FALSE);
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
|
||||||
/* Try with next */
|
/* Try with next */
|
||||||
try_next_usbif (mm_port_probe_peek_device (ctx->probe));
|
try_next_usbif (mm_port_probe_peek_device (ctx->probe));
|
||||||
huawei_custom_init_context_complete_and_free (ctx);
|
g_task_return_boolean (task, TRUE);
|
||||||
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,9 +286,9 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
|
|||||||
3,
|
3,
|
||||||
FALSE, /* raw */
|
FALSE, /* raw */
|
||||||
FALSE, /* allow_cached */
|
FALSE, /* allow_cached */
|
||||||
ctx->cancellable,
|
g_task_get_cancellable (task),
|
||||||
(GAsyncReadyCallback)curc_ready,
|
(GAsyncReadyCallback)curc_ready,
|
||||||
ctx);
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,8 +296,8 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
|
|||||||
port = mm_port_probe_peek_port (ctx->probe);
|
port = mm_port_probe_peek_port (ctx->probe);
|
||||||
if (!ctx->getportmode_done && !mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_HUAWEI_DISABLE_GETPORTMODE")) {
|
if (!ctx->getportmode_done && !mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_HUAWEI_DISABLE_GETPORTMODE")) {
|
||||||
if (ctx->getportmode_retries == 0) {
|
if (ctx->getportmode_retries == 0) {
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
huawei_custom_init_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,9 +308,9 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
|
|||||||
3,
|
3,
|
||||||
FALSE, /* raw */
|
FALSE, /* raw */
|
||||||
FALSE, /* allow_cached */
|
FALSE, /* allow_cached */
|
||||||
ctx->cancellable,
|
g_task_get_cancellable (task),
|
||||||
(GAsyncReadyCallback)getportmode_ready,
|
(GAsyncReadyCallback)getportmode_ready,
|
||||||
ctx);
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,8 +319,8 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
|
|||||||
g_assert (fi_ctx != NULL);
|
g_assert (fi_ctx != NULL);
|
||||||
fi_ctx->custom_init_run = TRUE;
|
fi_ctx->custom_init_run = TRUE;
|
||||||
|
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
huawei_custom_init_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -341,6 +343,7 @@ huawei_custom_init (MMPortProbe *probe,
|
|||||||
MMDevice *device;
|
MMDevice *device;
|
||||||
FirstInterfaceContext *fi_ctx;
|
FirstInterfaceContext *fi_ctx;
|
||||||
HuaweiCustomInitContext *ctx;
|
HuaweiCustomInitContext *ctx;
|
||||||
|
GTask *task;
|
||||||
|
|
||||||
device = mm_port_probe_peek_device (probe);
|
device = mm_port_probe_peek_device (probe);
|
||||||
|
|
||||||
@@ -377,33 +380,31 @@ huawei_custom_init (MMPortProbe *probe,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx = g_slice_new (HuaweiCustomInitContext);
|
ctx = g_slice_new (HuaweiCustomInitContext);
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (probe),
|
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
huawei_custom_init);
|
|
||||||
ctx->probe = g_object_ref (probe);
|
ctx->probe = g_object_ref (probe);
|
||||||
ctx->port = g_object_ref (port);
|
ctx->port = g_object_ref (port);
|
||||||
ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
||||||
ctx->curc_done = FALSE;
|
ctx->curc_done = FALSE;
|
||||||
ctx->curc_retries = 3;
|
ctx->curc_retries = 3;
|
||||||
ctx->getportmode_done = FALSE;
|
ctx->getportmode_done = FALSE;
|
||||||
ctx->getportmode_retries = 3;
|
ctx->getportmode_retries = 3;
|
||||||
|
|
||||||
|
task = g_task_new (probe, cancellable, callback, user_data);
|
||||||
|
g_task_set_task_data (task, ctx, (GDestroyNotify)huawei_custom_init_context_free);
|
||||||
|
|
||||||
/* Custom init only to be run in the first interface */
|
/* Custom init only to be run in the first interface */
|
||||||
if (mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (probe),
|
if (mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (probe),
|
||||||
"ID_USB_INTERFACE_NUM") != fi_ctx->first_usbif) {
|
"ID_USB_INTERFACE_NUM") != fi_ctx->first_usbif) {
|
||||||
|
|
||||||
if (fi_ctx->custom_init_run)
|
if (fi_ctx->custom_init_run)
|
||||||
/* If custom init was run already, we can consider this as successfully run */
|
/* If custom init was run already, we can consider this as successfully run */
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
else
|
else
|
||||||
/* Otherwise, we'll need to defer the probing a bit more */
|
/* Otherwise, we'll need to defer the probing a bit more */
|
||||||
g_simple_async_result_set_error (ctx->result,
|
g_task_return_new_error (task,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_RETRY,
|
MM_CORE_ERROR_RETRY,
|
||||||
"Defer needed");
|
"Defer needed");
|
||||||
|
|
||||||
huawei_custom_init_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,7 +414,7 @@ huawei_custom_init (MMPortProbe *probe,
|
|||||||
fi_ctx->timeout_id = 0;
|
fi_ctx->timeout_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
huawei_custom_init_step (ctx);
|
huawei_custom_init_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
Reference in New Issue
Block a user