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 | |
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')
-rw-r--r-- | src/mm-base-modem-at.c | 6 | ||||
-rw-r--r-- | src/mm-port-probe.c | 2 | ||||
-rw-r--r-- | src/mm-port-serial-at.c | 19 | ||||
-rw-r--r-- | src/mm-port-serial-at.h | 2 | ||||
-rw-r--r-- | src/plugins/cinterion/mm-plugin-cinterion.c | 2 | ||||
-rw-r--r-- | src/plugins/dell/mm-plugin-dell.c | 2 | ||||
-rw-r--r-- | src/plugins/huawei/mm-plugin-huawei.c | 2 | ||||
-rw-r--r-- | src/plugins/longcheer/mm-plugin-longcheer.c | 2 | ||||
-rw-r--r-- | src/plugins/novatel/mm-common-novatel.c | 3 | ||||
-rw-r--r-- | src/plugins/sierra/mm-common-sierra.c | 2 | ||||
-rw-r--r-- | src/plugins/telit/mm-common-telit.c | 2 | ||||
-rw-r--r-- | src/plugins/ublox/mm-plugin-ublox.c | 3 | ||||
-rw-r--r-- | src/plugins/x22x/mm-plugin-x22x.c | 8 |
13 files changed, 24 insertions, 31 deletions
diff --git a/src/mm-base-modem-at.c b/src/mm-base-modem-at.c index d1352e08..893a3280 100644 --- a/src/mm-base-modem-at.c +++ b/src/mm-base-modem-at.c @@ -160,7 +160,7 @@ at_sequence_parse_response (MMPortSerialAt *port, GVariant *result = NULL; GError *result_error = NULL; GSimpleAsyncResult *simple; - const gchar *response; + g_autofree gchar *response = NULL; GError *error = NULL; response = mm_port_serial_at_command_finish (port, res, &error); @@ -513,7 +513,7 @@ at_command_ready (MMPortSerialAt *port, GAsyncResult *res, AtCommandContext *ctx) { - const gchar *response; + gchar *response; GError *error = NULL; response = mm_port_serial_at_command_finish (port, res, &error); @@ -530,7 +530,7 @@ at_command_ready (MMPortSerialAt *port, g_simple_async_result_take_error (ctx->result, error); /* Valid string response */ else if (response) - g_simple_async_result_set_op_res_gpointer (ctx->result, (gchar *)response, NULL); + g_simple_async_result_set_op_res_gpointer (ctx->result, response, g_free); else g_assert_not_reached (); diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c index e3298ed8..61b8cef3 100644 --- a/src/mm-port-probe.c +++ b/src/mm-port-probe.c @@ -994,7 +994,7 @@ serial_probe_at_parse_response (MMPortSerialAt *port, { GVariant *result = NULL; GError *result_error = NULL; - const gchar *response = NULL; + g_autofree gchar *response = NULL; GError *error = NULL; PortProbeRunContext *ctx; 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); } diff --git a/src/mm-port-serial-at.h b/src/mm-port-serial-at.h index 901afcba..82368875 100644 --- a/src/mm-port-serial-at.h +++ b/src/mm-port-serial-at.h @@ -108,7 +108,7 @@ void mm_port_serial_at_command (MMPortSerialAt *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); -const gchar *mm_port_serial_at_command_finish (MMPortSerialAt *self, +gchar *mm_port_serial_at_command_finish (MMPortSerialAt *self, GAsyncResult *res, GError **error); diff --git a/src/plugins/cinterion/mm-plugin-cinterion.c b/src/plugins/cinterion/mm-plugin-cinterion.c index 7ec7838b..f1b581f1 100644 --- a/src/plugins/cinterion/mm-plugin-cinterion.c +++ b/src/plugins/cinterion/mm-plugin-cinterion.c @@ -80,7 +80,7 @@ sqport_ready (MMPortSerialAt *port, GTask *task) { MMPortProbe *probe; - const gchar *response; + g_autofree gchar *response = NULL; probe = g_task_get_source_object (task); diff --git a/src/plugins/dell/mm-plugin-dell.c b/src/plugins/dell/mm-plugin-dell.c index 47b2a69b..e7f813b1 100644 --- a/src/plugins/dell/mm-plugin-dell.c +++ b/src/plugins/dell/mm-plugin-dell.c @@ -158,7 +158,7 @@ response_ready (MMPortSerialAt *port, { CustomInitContext *ctx; MMPortProbe *probe; - const gchar *response; + g_autofree gchar *response = NULL; GError *error = NULL; gchar *lower; DellManufacturer manufacturer; diff --git a/src/plugins/huawei/mm-plugin-huawei.c b/src/plugins/huawei/mm-plugin-huawei.c index 89897e9e..b0b7a616 100644 --- a/src/plugins/huawei/mm-plugin-huawei.c +++ b/src/plugins/huawei/mm-plugin-huawei.c @@ -104,7 +104,7 @@ getportmode_ready (MMPortSerialAt *port, MMDevice *device; MMPortProbe *probe; HuaweiCustomInitContext *ctx; - const gchar *response; + g_autofree gchar *response = NULL; GArray *modes; g_autoptr(GError) error = NULL; diff --git a/src/plugins/longcheer/mm-plugin-longcheer.c b/src/plugins/longcheer/mm-plugin-longcheer.c index f3c6bc6c..a53e6d03 100644 --- a/src/plugins/longcheer/mm-plugin-longcheer.c +++ b/src/plugins/longcheer/mm-plugin-longcheer.c @@ -61,7 +61,7 @@ gmr_ready (MMPortSerialAt *port, { MMPortProbe *probe; const gchar *p; - const gchar *response; + g_autofree gchar *response = NULL; probe = g_task_get_source_object (task); diff --git a/src/plugins/novatel/mm-common-novatel.c b/src/plugins/novatel/mm-common-novatel.c index b6b0e272..2e0d3da3 100644 --- a/src/plugins/novatel/mm-common-novatel.c +++ b/src/plugins/novatel/mm-common-novatel.c @@ -49,10 +49,11 @@ nwdmat_ready (MMPortSerialAt *port, { g_autoptr(GError) error = NULL; MMPortProbe *probe; + g_autofree gchar *response = NULL; probe = g_task_get_source_object (task); - mm_port_serial_at_command_finish (port, res, &error); + response = mm_port_serial_at_command_finish (port, res, &error); if (error) { if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) { custom_init_step (task); diff --git a/src/plugins/sierra/mm-common-sierra.c b/src/plugins/sierra/mm-common-sierra.c index 72cbc34f..06b889ee 100644 --- a/src/plugins/sierra/mm-common-sierra.c +++ b/src/plugins/sierra/mm-common-sierra.c @@ -105,7 +105,7 @@ gcap_ready (MMPortSerialAt *port, { MMPortProbe *probe; SierraCustomInitContext *ctx; - const gchar *response; + g_autofree gchar *response = NULL; GError *error = NULL; probe = g_task_get_source_object (task); diff --git a/src/plugins/telit/mm-common-telit.c b/src/plugins/telit/mm-common-telit.c index 66c82b9d..a401b1ae 100644 --- a/src/plugins/telit/mm-common-telit.c +++ b/src/plugins/telit/mm-common-telit.c @@ -185,7 +185,7 @@ getportcfg_ready (MMPortSerialAt *port, GAsyncResult *res, GTask *task) { - const gchar *response; + g_autofree gchar *response = NULL; GError *error = NULL; MMPortProbe *probe; TelitCustomInitContext *ctx; diff --git a/src/plugins/ublox/mm-plugin-ublox.c b/src/plugins/ublox/mm-plugin-ublox.c index e606eba1..c88369de 100644 --- a/src/plugins/ublox/mm-plugin-ublox.c +++ b/src/plugins/ublox/mm-plugin-ublox.c @@ -151,10 +151,11 @@ quick_at_ready (MMPortSerialAt *port, { MMPortProbe *probe; g_autoptr(GError) error = NULL; + g_autofree gchar *response = NULL; probe = g_task_get_source_object (task); - mm_port_serial_at_command_finish (port, res, &error); + response = mm_port_serial_at_command_finish (port, res, &error); if (error) { /* On a timeout error, wait for READY URC */ if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) { diff --git a/src/plugins/x22x/mm-plugin-x22x.c b/src/plugins/x22x/mm-plugin-x22x.c index ccfcd465..e68e6b24 100644 --- a/src/plugins/x22x/mm-plugin-x22x.c +++ b/src/plugins/x22x/mm-plugin-x22x.c @@ -63,10 +63,10 @@ gmr_ready (MMPortSerialAt *port, GAsyncResult *res, GTask *task) { - MMPortProbe *probe; - const gchar *p; - const gchar *response; - GError *error = NULL; + MMPortProbe *probe; + const gchar *p; + g_autofree gchar *response = NULL; + GError *error = NULL; probe = g_task_get_source_object (task); |