diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2023-01-08 19:57:31 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2023-04-11 13:49:03 +0000 |
commit | c40876de956311ef9a17b920486263d46f4fef3b (patch) | |
tree | 381c755c74cc53fc99e0f8c53ea260f4da3a5da0 /src/mm-port-serial-at.c | |
parent | e1e7bc8de6c6d90e79444fc2f0b0cf912c9d791c (diff) |
port-serial-at: make mm_port_serial_at_command_finish() transfer ownership
This will make it slightly easier to port mm_port_serial_at_command() to
use GTask, since we won't have to keep a pointer to the result in GTask
after _finish() has been called.
In most cases the caller needs the value anyway, so this doesn't add too
much hasle.
Diffstat (limited to 'src/mm-port-serial-at.c')
-rw-r--r-- | src/mm-port-serial-at.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c index 88d01cf4..bd8c3b32 100644 --- a/src/mm-port-serial-at.c +++ b/src/mm-port-serial-at.c @@ -340,24 +340,15 @@ at_command_to_byte_array (const char *command, gboolean is_raw, gboolean send_lf return buf; } -const gchar * +gchar * mm_port_serial_at_command_finish (MMPortSerialAt *self, GAsyncResult *res, GError **error) { - GString *str; - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) return NULL; - str = (GString *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)); - return str->str; -} - -static void -string_free (GString *str) -{ - g_string_free (str, TRUE); + return (gchar *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)); } static void @@ -368,6 +359,7 @@ serial_command_ready (MMPortSerial *port, GByteArray *response_buffer; GError *error = NULL; GString *response; + gchar *str; response_buffer = mm_port_serial_command_finish (port, res, &error); if (!response_buffer) { @@ -384,9 +376,8 @@ serial_command_ready (MMPortSerial *port, g_byte_array_remove_range (response_buffer, 0, response_buffer->len); g_byte_array_unref (response_buffer); - g_simple_async_result_set_op_res_gpointer (simple, - response, - (GDestroyNotify)string_free); + str = g_string_free (response, FALSE); + g_simple_async_result_set_op_res_gpointer (simple, str, g_free); g_simple_async_result_complete (simple); g_object_unref (simple); } |