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.
This commit is contained in:
Lubomir Rintel
2023-01-08 19:57:31 +01:00
committed by Aleksander Morgado
parent e1e7bc8de6
commit c40876de95
14 changed files with 26 additions and 33 deletions

View File

@@ -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 ();

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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)) {

View File

@@ -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);

View File

@@ -110,8 +110,8 @@ static void
at_command_ready (MMPortSerialAt *serial_at,
GAsyncResult *res)
{
const gchar *response;
GError *error = NULL;
g_autofree gchar *response = NULL;
GError *error = NULL;
response = mm_port_serial_at_command_finish (serial_at, res, &error);
if (response)