aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2017-09-20 17:11:59 -0700
committerAleksander Morgado <aleksander@aleksander.es>2017-10-07 13:40:30 +0200
commit7e478e408d8bf49947217dc882102ecf3bac0adc (patch)
treea4751f35f7ff72fccd83e909a5952fcf9cabf850 /plugins
parent6e68f4052b17cd145bcc7883469aac57fccf76e2 (diff)
cinterion: port plugin custom_init to GTask
Diffstat (limited to 'plugins')
-rw-r--r--plugins/cinterion/mm-plugin-cinterion.c74
1 files changed, 25 insertions, 49 deletions
diff --git a/plugins/cinterion/mm-plugin-cinterion.c b/plugins/cinterion/mm-plugin-cinterion.c
index 3bf19d1d..f6ebfc46 100644
--- a/plugins/cinterion/mm-plugin-cinterion.c
+++ b/plugins/cinterion/mm-plugin-cinterion.c
@@ -46,84 +46,60 @@ MM_PLUGIN_DEFINE_MINOR_VERSION
#define TAG_CINTERION_APP_PORT "cinterion-app-port"
#define TAG_CINTERION_MODEM_PORT "cinterion-modem-port"
-typedef struct {
- MMPortProbe *probe;
- MMPortSerialAt *port;
- GCancellable *cancellable;
- GSimpleAsyncResult *result;
-} CinterionCustomInitContext;
-
-static void
-cinterion_custom_init_context_complete_and_free (CinterionCustomInitContext *ctx)
-{
- g_simple_async_result_complete (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 (CinterionCustomInitContext, ctx);
-}
-
static gboolean
-cinterion_custom_init_finish (MMPortProbe *probe,
- GAsyncResult *result,
- GError **error)
+cinterion_custom_init_finish (MMPortProbe *probe,
+ GAsyncResult *result,
+ 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
sqport_ready (MMPortSerialAt *port,
- GAsyncResult *res,
- CinterionCustomInitContext *ctx)
+ GAsyncResult *res,
+ GTask *task)
{
+ MMPortProbe *probe;
const gchar *response;
+ probe = g_task_get_source_object (task);
+
/* Ignore errors, just avoid tagging */
response = mm_port_serial_at_command_finish (port, res, NULL);
if (response) {
/* A valid reply to AT^SQPORT tells us this is an AT port already */
- mm_port_probe_set_result_at (ctx->probe, TRUE);
+ mm_port_probe_set_result_at (probe, TRUE);
if (strstr (response, "Application"))
- g_object_set_data (G_OBJECT (ctx->probe), TAG_CINTERION_APP_PORT, GUINT_TO_POINTER (TRUE));
+ g_object_set_data (G_OBJECT (probe), TAG_CINTERION_APP_PORT, GUINT_TO_POINTER (TRUE));
else if (strstr (response, "Modem"))
- g_object_set_data (G_OBJECT (ctx->probe), TAG_CINTERION_MODEM_PORT, GUINT_TO_POINTER (TRUE));
+ g_object_set_data (G_OBJECT (probe), TAG_CINTERION_MODEM_PORT, GUINT_TO_POINTER (TRUE));
}
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- cinterion_custom_init_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
-cinterion_custom_init (MMPortProbe *probe,
- MMPortSerialAt *port,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+cinterion_custom_init (MMPortProbe *probe,
+ MMPortSerialAt *port,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- CinterionCustomInitContext *ctx;
+ GTask *task;
- ctx = g_slice_new (CinterionCustomInitContext);
- ctx->result = g_simple_async_result_new (G_OBJECT (probe),
- callback,
- user_data,
- cinterion_custom_init);
- ctx->probe = g_object_ref (probe);
- ctx->port = g_object_ref (port);
- ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
+ task = g_task_new (probe, cancellable, callback, user_data);
mm_port_serial_at_command (
- ctx->port,
+ port,
"AT^SQPORT?",
3,
FALSE, /* raw */
FALSE, /* allow cached */
- ctx->cancellable,
- (GAsyncReadyCallback)sqport_ready,
- ctx);
+ cancellable,
+ (GAsyncReadyCallback) sqport_ready,
+ task);
}
/*****************************************************************************/