port-serial-at: port mm_port_serial_at_command() to GTask
Use GTask API in place of the deprecated GSimpleAsyncResult.
This commit is contained in:

committed by
Aleksander Morgado

parent
c40876de95
commit
189606a8f3
@@ -345,16 +345,13 @@ mm_port_serial_at_command_finish (MMPortSerialAt *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 (gchar *)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_buffer;
|
GByteArray *response_buffer;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@@ -363,9 +360,8 @@ serial_command_ready (MMPortSerial *port,
|
|||||||
|
|
||||||
response_buffer = mm_port_serial_command_finish (port, res, &error);
|
response_buffer = mm_port_serial_command_finish (port, res, &error);
|
||||||
if (!response_buffer) {
|
if (!response_buffer) {
|
||||||
g_simple_async_result_take_error (simple, error);
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_complete (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,9 +373,8 @@ serial_command_ready (MMPortSerial *port,
|
|||||||
g_byte_array_unref (response_buffer);
|
g_byte_array_unref (response_buffer);
|
||||||
|
|
||||||
str = g_string_free (response, FALSE);
|
str = g_string_free (response, FALSE);
|
||||||
g_simple_async_result_set_op_res_gpointer (simple, str, g_free);
|
g_task_return_pointer (task, str, g_free);
|
||||||
g_simple_async_result_complete (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -392,8 +387,8 @@ mm_port_serial_at_command (MMPortSerialAt *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
|
||||||
GByteArray *buf;
|
GByteArray *buf;
|
||||||
|
GTask *task;
|
||||||
|
|
||||||
g_return_if_fail (self != NULL);
|
g_return_if_fail (self != NULL);
|
||||||
g_return_if_fail (MM_IS_PORT_SERIAL_AT (self));
|
g_return_if_fail (MM_IS_PORT_SERIAL_AT (self));
|
||||||
@@ -406,10 +401,7 @@ mm_port_serial_at_command (MMPortSerialAt *self,
|
|||||||
TRUE));
|
TRUE));
|
||||||
g_return_if_fail (buf != NULL);
|
g_return_if_fail (buf != NULL);
|
||||||
|
|
||||||
simple = g_simple_async_result_new (G_OBJECT (self),
|
task = g_task_new (self, NULL, callback, user_data);
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
mm_port_serial_at_command);
|
|
||||||
|
|
||||||
mm_port_serial_command (MM_PORT_SERIAL (self),
|
mm_port_serial_command (MM_PORT_SERIAL (self),
|
||||||
buf,
|
buf,
|
||||||
@@ -418,7 +410,7 @@ mm_port_serial_at_command (MMPortSerialAt *self,
|
|||||||
is_raw, /* raw commands always run next, never queued last */
|
is_raw, /* raw commands always run next, never queued last */
|
||||||
cancellable,
|
cancellable,
|
||||||
(GAsyncReadyCallback)serial_command_ready,
|
(GAsyncReadyCallback)serial_command_ready,
|
||||||
simple);
|
task);
|
||||||
g_byte_array_unref (buf);
|
g_byte_array_unref (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user