aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2017-09-13 22:11:45 +0200
committerAleksander Morgado <aleksander@aleksander.es>2017-10-06 09:57:23 +0200
commit23124fc6e95dd344d6920516faa4db58ffda2524 (patch)
tree1931c40825fab5aa71f8f040c97c99b36d7080d8
parenta1d355784bfbe802322c781632a1f393a93cedef (diff)
dell: port custom_init to GTask
-rw-r--r--plugins/dell/mm-plugin-dell.c201
1 files changed, 101 insertions, 100 deletions
diff --git a/plugins/dell/mm-plugin-dell.c b/plugins/dell/mm-plugin-dell.c
index fbb0a9ce..5c97a4c2 100644
--- a/plugins/dell/mm-plugin-dell.c
+++ b/plugins/dell/mm-plugin-dell.c
@@ -65,104 +65,103 @@ typedef enum {
/* Custom init */
typedef struct {
- MMPortProbe *probe;
MMPortSerialAt *port;
- GCancellable *cancellable;
- GSimpleAsyncResult *result;
- guint gmi_retries;
- guint cgmi_retries;
- guint ati_retries;
- guint timeouts;
+ guint gmi_retries;
+ guint cgmi_retries;
+ guint ati_retries;
+ guint timeouts;
} CustomInitContext;
static void
-custom_init_context_complete_and_free (CustomInitContext *ctx)
+custom_init_context_free (CustomInitContext *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->probe);
- g_object_unref (ctx->result);
g_slice_free (CustomInitContext, ctx);
}
static gboolean
-dell_custom_init_finish (MMPortProbe *probe,
- GAsyncResult *result,
- GError **error)
+dell_custom_init_finish (MMPortProbe *probe,
+ GAsyncResult *res,
+ GError **error)
{
- return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
+ return g_task_propagate_boolean (G_TASK (res), error);
}
static void
-novatel_custom_init_ready (MMPortProbe *probe,
- GAsyncResult *res,
- CustomInitContext *ctx)
+novatel_custom_init_ready (MMPortProbe *probe,
+ GAsyncResult *res,
+ GTask *task)
{
GError *error = NULL;
if (!mm_common_novatel_custom_init_finish (probe, res, &error))
- g_simple_async_result_take_error (ctx->result, error);
+ g_task_return_error (task, error);
else
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- custom_init_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
-sierra_custom_init_ready (MMPortProbe *probe,
- GAsyncResult *res,
- CustomInitContext *ctx)
+sierra_custom_init_ready (MMPortProbe *probe,
+ GAsyncResult *res,
+ GTask *task)
{
GError *error = NULL;
if (!mm_common_sierra_custom_init_finish (probe, res, &error))
- g_simple_async_result_take_error (ctx->result, error);
+ g_task_return_error (task, error);
else
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- custom_init_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
-telit_custom_init_ready (MMPortProbe *probe,
- GAsyncResult *res,
- CustomInitContext *ctx)
+telit_custom_init_ready (MMPortProbe *probe,
+ GAsyncResult *res,
+ GTask *task)
{
GError *error = NULL;
if (!telit_custom_init_finish (probe, res, &error))
- g_simple_async_result_take_error (ctx->result, error);
+ g_task_return_error (task, error);
else
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- custom_init_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
-static void custom_init_step (CustomInitContext *ctx);
+static void custom_init_step (GTask *task);
static void
-custom_init_step_next_command (CustomInitContext *ctx)
+custom_init_step_next_command (GTask *task)
{
- ctx->timeouts = 0;
+ CustomInitContext *ctx;
+
+ ctx = g_task_get_task_data (task);
+ ctx->timeouts = 0;
if (ctx->gmi_retries > 0)
ctx->gmi_retries = 0;
else if (ctx->cgmi_retries > 0)
ctx->cgmi_retries = 0;
else if (ctx->ati_retries > 0)
ctx->ati_retries = 0;
- custom_init_step (ctx);
+ custom_init_step (task);
}
static void
response_ready (MMPortSerialAt *port,
- GAsyncResult *res,
- CustomInitContext *ctx)
+ GAsyncResult *res,
+ GTask *task)
{
- const gchar *response;
- GError *error = NULL;
- gchar *lower;
- DellManufacturer manufacturer;
+ CustomInitContext *ctx;
+ MMPortProbe *probe;
+ const gchar *response;
+ GError *error = NULL;
+ gchar *lower;
+ DellManufacturer manufacturer;
+
+ probe = g_task_get_source_object (task);
+ ctx = g_task_get_task_data (task);
response = mm_port_serial_at_command_finish (port, res, &error);
if (error) {
@@ -170,12 +169,12 @@ response_ready (MMPortSerialAt *port,
if (!g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
mm_dbg ("(Dell) Error probing AT port: %s", error->message);
g_error_free (error);
- custom_init_step_next_command (ctx);
+ custom_init_step_next_command (task);
return;
}
/* Directly retry same command on timeout */
ctx->timeouts++;
- custom_init_step (ctx);
+ custom_init_step (task);
g_error_free (error);
return;
}
@@ -196,81 +195,87 @@ response_ready (MMPortSerialAt *port,
/* Tag based on manufacturer */
if (manufacturer != DELL_MANUFACTURER_UNKNOWN) {
- g_object_set_data (G_OBJECT (ctx->probe), TAG_DELL_MANUFACTURER, GUINT_TO_POINTER (manufacturer));
+ g_object_set_data (G_OBJECT (probe), TAG_DELL_MANUFACTURER, GUINT_TO_POINTER (manufacturer));
/* Run additional custom init, if needed */
if (manufacturer == DELL_MANUFACTURER_NOVATEL) {
- mm_common_novatel_custom_init (ctx->probe,
+ mm_common_novatel_custom_init (probe,
ctx->port,
- ctx->cancellable,
+ g_task_get_cancellable (task),
(GAsyncReadyCallback) novatel_custom_init_ready,
- ctx);
+ task);
return;
}
if (manufacturer == DELL_MANUFACTURER_SIERRA) {
- mm_common_sierra_custom_init (ctx->probe,
+ mm_common_sierra_custom_init (probe,
ctx->port,
- ctx->cancellable,
+ g_task_get_cancellable (task),
(GAsyncReadyCallback) sierra_custom_init_ready,
- ctx);
+ task);
return;
}
if (manufacturer == DELL_MANUFACTURER_TELIT) {
- telit_custom_init (ctx->probe,
+ telit_custom_init (probe,
ctx->port,
- ctx->cancellable,
+ g_task_get_cancellable (task),
(GAsyncReadyCallback) telit_custom_init_ready,
- ctx);
+ task);
return;
}
/* Finish custom_init */
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- custom_init_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
return;
}
/* If we got a response, but we didn't get an expected string, try with next command */
- custom_init_step_next_command (ctx);
+ custom_init_step_next_command (task);
}
static void
-custom_init_step (CustomInitContext *ctx)
+custom_init_step (GTask *task)
{
- /* If cancelled, end */
- if (g_cancellable_is_cancelled (ctx->cancellable)) {
+ CustomInitContext *ctx;
+ MMPortProbe *probe;
+
+ probe = g_task_get_source_object (task);
+ ctx = g_task_get_task_data (task);
+
+ /* If cancelled, end without error right away */
+ if (g_cancellable_is_cancelled (g_task_get_cancellable (task))) {
mm_dbg ("(Dell) no need to keep on running custom init in (%s)",
mm_port_get_device (MM_PORT (ctx->port)));
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- custom_init_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
return;
}
#if defined WITH_QMI
/* If device has a QMI port, don't run anything else, as we don't care */
- if (mm_port_probe_list_has_qmi_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (ctx->probe)))) {
+ if (mm_port_probe_list_has_qmi_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (probe)))) {
mm_dbg ("(Dell) no need to run custom init in (%s): device has QMI port",
mm_port_get_device (MM_PORT (ctx->port)));
- mm_port_probe_set_result_at (ctx->probe, FALSE);
- mm_port_probe_set_result_qcdm (ctx->probe, FALSE);
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- custom_init_context_complete_and_free (ctx);
+ mm_port_probe_set_result_at (probe, FALSE);
+ mm_port_probe_set_result_qcdm (probe, FALSE);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
return;
}
#endif
#if defined WITH_MBIM
/* If device has a MBIM port, don't run anything else, as we don't care */
- if (mm_port_probe_list_has_mbim_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (ctx->probe)))) {
+ if (mm_port_probe_list_has_mbim_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (probe)))) {
mm_dbg ("(Dell) no need to run custom init in (%s): device has MBIM port",
mm_port_get_device (MM_PORT (ctx->port)));
- mm_port_probe_set_result_at (ctx->probe, FALSE);
- mm_port_probe_set_result_qcdm (ctx->probe, FALSE);
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- custom_init_context_complete_and_free (ctx);
+ mm_port_probe_set_result_at (probe, FALSE);
+ mm_port_probe_set_result_qcdm (probe, FALSE);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
return;
}
#endif
@@ -278,7 +283,7 @@ custom_init_step (CustomInitContext *ctx)
if (ctx->timeouts >= MAX_PORT_PROBE_TIMEOUTS) {
mm_dbg ("(Dell) couldn't detect real manufacturer in (%s): too many timeouts",
mm_port_get_device (MM_PORT (ctx->port)));
- mm_port_probe_set_result_at (ctx->probe, FALSE);
+ mm_port_probe_set_result_at (probe, FALSE);
goto out;
}
@@ -289,9 +294,9 @@ custom_init_step (CustomInitContext *ctx)
3,
FALSE, /* raw */
FALSE, /* allow_cached */
- ctx->cancellable,
+ g_task_get_cancellable (task),
(GAsyncReadyCallback)response_ready,
- ctx);
+ task);
return;
}
@@ -302,9 +307,9 @@ custom_init_step (CustomInitContext *ctx)
3,
FALSE, /* raw */
FALSE, /* allow_cached */
- ctx->cancellable,
+ g_task_get_cancellable (task),
(GAsyncReadyCallback)response_ready,
- ctx);
+ task);
return;
}
@@ -316,9 +321,9 @@ custom_init_step (CustomInitContext *ctx)
3,
FALSE, /* raw */
FALSE, /* allow_cached */
- ctx->cancellable,
+ g_task_get_cancellable (task),
(GAsyncReadyCallback)response_ready,
- ctx);
+ task);
return;
}
@@ -326,35 +331,31 @@ custom_init_step (CustomInitContext *ctx)
mm_port_get_device (MM_PORT (ctx->port)));
out:
/* Finish custom_init */
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- custom_init_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
-dell_custom_init (MMPortProbe *probe,
- MMPortSerialAt *port,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+dell_custom_init (MMPortProbe *probe,
+ MMPortSerialAt *port,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
+ GTask *task;
CustomInitContext *ctx;
- MMKernelDevice *port_device;
-
- port_device = mm_port_probe_peek_port (probe);
ctx = g_slice_new0 (CustomInitContext);
- ctx->result = g_simple_async_result_new (G_OBJECT (probe),
- callback,
- user_data,
- dell_custom_init);
- ctx->probe = g_object_ref (probe);
ctx->port = g_object_ref (port);
- ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
ctx->gmi_retries = 3;
ctx->cgmi_retries = 1;
ctx->ati_retries = 1;
- custom_init_step (ctx);
+ task = g_task_new (probe, cancellable, callback, user_data);
+ g_task_set_check_cancellable (task, FALSE);
+ g_task_set_task_data (task, ctx, (GDestroyNotify) custom_init_context_free);
+
+ custom_init_step (task);
}
/*****************************************************************************/