port-serial-qcdm: port mm_port_serial_qcdm_command to use GTask
This commit is contained in:

committed by
Aleksander Morgado

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