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:

committed by
Aleksander Morgado

parent
e1e7bc8de6
commit
c40876de95
@@ -160,7 +160,7 @@ at_sequence_parse_response (MMPortSerialAt *port,
|
|||||||
GVariant *result = NULL;
|
GVariant *result = NULL;
|
||||||
GError *result_error = NULL;
|
GError *result_error = NULL;
|
||||||
GSimpleAsyncResult *simple;
|
GSimpleAsyncResult *simple;
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
response = mm_port_serial_at_command_finish (port, res, &error);
|
response = mm_port_serial_at_command_finish (port, res, &error);
|
||||||
@@ -513,7 +513,7 @@ at_command_ready (MMPortSerialAt *port,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
AtCommandContext *ctx)
|
AtCommandContext *ctx)
|
||||||
{
|
{
|
||||||
const gchar *response;
|
gchar *response;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
response = mm_port_serial_at_command_finish (port, res, &error);
|
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);
|
g_simple_async_result_take_error (ctx->result, error);
|
||||||
/* Valid string response */
|
/* Valid string response */
|
||||||
else if (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
|
else
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
|
|
||||||
|
@@ -994,7 +994,7 @@ serial_probe_at_parse_response (MMPortSerialAt *port,
|
|||||||
{
|
{
|
||||||
GVariant *result = NULL;
|
GVariant *result = NULL;
|
||||||
GError *result_error = NULL;
|
GError *result_error = NULL;
|
||||||
const gchar *response = NULL;
|
g_autofree gchar *response = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
PortProbeRunContext *ctx;
|
PortProbeRunContext *ctx;
|
||||||
|
|
||||||
|
@@ -340,24 +340,15 @@ at_command_to_byte_array (const char *command, gboolean is_raw, gboolean send_lf
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
gchar *
|
||||||
mm_port_serial_at_command_finish (MMPortSerialAt *self,
|
mm_port_serial_at_command_finish (MMPortSerialAt *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GString *str;
|
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
str = (GString *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
|
return (gchar *)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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -368,6 +359,7 @@ serial_command_ready (MMPortSerial *port,
|
|||||||
GByteArray *response_buffer;
|
GByteArray *response_buffer;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GString *response;
|
GString *response;
|
||||||
|
gchar *str;
|
||||||
|
|
||||||
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) {
|
||||||
@@ -384,9 +376,8 @@ serial_command_ready (MMPortSerial *port,
|
|||||||
g_byte_array_remove_range (response_buffer, 0, response_buffer->len);
|
g_byte_array_remove_range (response_buffer, 0, response_buffer->len);
|
||||||
g_byte_array_unref (response_buffer);
|
g_byte_array_unref (response_buffer);
|
||||||
|
|
||||||
g_simple_async_result_set_op_res_gpointer (simple,
|
str = g_string_free (response, FALSE);
|
||||||
response,
|
g_simple_async_result_set_op_res_gpointer (simple, str, g_free);
|
||||||
(GDestroyNotify)string_free);
|
|
||||||
g_simple_async_result_complete (simple);
|
g_simple_async_result_complete (simple);
|
||||||
g_object_unref (simple);
|
g_object_unref (simple);
|
||||||
}
|
}
|
||||||
|
@@ -108,7 +108,7 @@ void mm_port_serial_at_command (MMPortSerialAt *self,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
const gchar *mm_port_serial_at_command_finish (MMPortSerialAt *self,
|
gchar *mm_port_serial_at_command_finish (MMPortSerialAt *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ sqport_ready (MMPortSerialAt *port,
|
|||||||
GTask *task)
|
GTask *task)
|
||||||
{
|
{
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
|
|
||||||
probe = g_task_get_source_object (task);
|
probe = g_task_get_source_object (task);
|
||||||
|
|
||||||
|
@@ -158,7 +158,7 @@ response_ready (MMPortSerialAt *port,
|
|||||||
{
|
{
|
||||||
CustomInitContext *ctx;
|
CustomInitContext *ctx;
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gchar *lower;
|
gchar *lower;
|
||||||
DellManufacturer manufacturer;
|
DellManufacturer manufacturer;
|
||||||
|
@@ -104,7 +104,7 @@ getportmode_ready (MMPortSerialAt *port,
|
|||||||
MMDevice *device;
|
MMDevice *device;
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
HuaweiCustomInitContext *ctx;
|
HuaweiCustomInitContext *ctx;
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
GArray *modes;
|
GArray *modes;
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
|
@@ -61,7 +61,7 @@ gmr_ready (MMPortSerialAt *port,
|
|||||||
{
|
{
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
const gchar *p;
|
const gchar *p;
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
|
|
||||||
probe = g_task_get_source_object (task);
|
probe = g_task_get_source_object (task);
|
||||||
|
|
||||||
|
@@ -49,10 +49,11 @@ nwdmat_ready (MMPortSerialAt *port,
|
|||||||
{
|
{
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
|
g_autofree gchar *response = NULL;
|
||||||
|
|
||||||
probe = g_task_get_source_object (task);
|
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 (error) {
|
||||||
if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
|
if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
|
||||||
custom_init_step (task);
|
custom_init_step (task);
|
||||||
|
@@ -105,7 +105,7 @@ gcap_ready (MMPortSerialAt *port,
|
|||||||
{
|
{
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
SierraCustomInitContext *ctx;
|
SierraCustomInitContext *ctx;
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
probe = g_task_get_source_object (task);
|
probe = g_task_get_source_object (task);
|
||||||
|
@@ -185,7 +185,7 @@ getportcfg_ready (MMPortSerialAt *port,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GTask *task)
|
GTask *task)
|
||||||
{
|
{
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
TelitCustomInitContext *ctx;
|
TelitCustomInitContext *ctx;
|
||||||
|
@@ -151,10 +151,11 @@ quick_at_ready (MMPortSerialAt *port,
|
|||||||
{
|
{
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
g_autofree gchar *response = NULL;
|
||||||
|
|
||||||
probe = g_task_get_source_object (task);
|
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 (error) {
|
||||||
/* On a timeout error, wait for READY URC */
|
/* On a timeout error, wait for READY URC */
|
||||||
if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
|
if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
|
||||||
|
@@ -65,7 +65,7 @@ gmr_ready (MMPortSerialAt *port,
|
|||||||
{
|
{
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
const gchar *p;
|
const gchar *p;
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
probe = g_task_get_source_object (task);
|
probe = g_task_get_source_object (task);
|
||||||
|
@@ -110,7 +110,7 @@ static void
|
|||||||
at_command_ready (MMPortSerialAt *serial_at,
|
at_command_ready (MMPortSerialAt *serial_at,
|
||||||
GAsyncResult *res)
|
GAsyncResult *res)
|
||||||
{
|
{
|
||||||
const gchar *response;
|
g_autofree gchar *response = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
response = mm_port_serial_at_command_finish (serial_at, res, &error);
|
response = mm_port_serial_at_command_finish (serial_at, res, &error);
|
||||||
|
Reference in New Issue
Block a user