port-serial-qcdm: port mm_port_serial_qcdm_command to use GTask

This commit is contained in:
Ben Chan
2017-07-04 11:40:22 -07:00
committed by Aleksander Morgado
parent 75aebc71c7
commit ba3a7f0c69

View File

@@ -153,27 +153,24 @@ mm_port_serial_qcdm_command_finish (MMPortSerialQcdm *self,
GAsyncResult *res,
GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
return g_byte_array_ref ((GByteArray *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
return g_task_propagate_pointer (G_TASK (res), error);
}
static void
serial_command_ready (MMPortSerial *port,
GAsyncResult *res,
GSimpleAsyncResult *simple)
GTask *task)
{
GByteArray *response;
GError *error = NULL;
response = mm_port_serial_command_finish (port, res, &error);
if (!response)
g_simple_async_result_take_error (simple, error);
g_task_return_error (task, error);
else
g_simple_async_result_set_op_res_gpointer (simple, response, (GDestroyNotify)g_byte_array_unref);
g_simple_async_result_complete (simple);
g_object_unref (simple);
g_task_return_pointer (task, response, (GDestroyNotify)g_byte_array_unref);
g_object_unref (task);
}
void
@@ -184,15 +181,12 @@ mm_port_serial_qcdm_command (MMPortSerialQcdm *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
GTask *task;
g_return_if_fail (MM_IS_PORT_SERIAL_QCDM (self));
g_return_if_fail (command != NULL);
simple = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_port_serial_qcdm_command);
task = g_task_new (self, cancellable, callback, user_data);
/* 'command' is expected to be already CRC-ed and escaped */
mm_port_serial_command (MM_PORT_SERIAL (self),
@@ -201,7 +195,7 @@ mm_port_serial_qcdm_command (MMPortSerialQcdm *self,
FALSE, /* never cached */
cancellable,
(GAsyncReadyCallback)serial_command_ready,
simple);
task);
}
static void