libqmi-glib,device: make sure transaction is removed from table on early errors

This commit is contained in:
Aleksander Morgado 2016-10-27 22:35:17 +02:00
parent b760b98a5d
commit c1442b3a7f
1 changed files with 28 additions and 16 deletions

View File

@ -2754,6 +2754,23 @@ qmi_device_command_finish (QmiDevice *self,
G_SIMPLE_ASYNC_RESULT (res))); G_SIMPLE_ASYNC_RESULT (res)));
} }
static void
transaction_early_error (QmiDevice *self,
Transaction *tr,
gboolean stored,
GError *error)
{
g_assert (error);
if (stored) {
/* Match transaction so that we remove it from our tracking table */
tr = device_match_transaction (self, tr->message);
g_assert (tr);
}
transaction_complete_and_free (tr, NULL, error);
g_error_free (error);
}
/** /**
* qmi_device_command: * qmi_device_command:
* @self: a #QmiDevice. * @self: a #QmiDevice.
@ -2807,8 +2824,7 @@ qmi_device_command (QmiDevice *self,
error = g_error_new (QMI_CORE_ERROR, error = g_error_new (QMI_CORE_ERROR,
QMI_CORE_ERROR_WRONG_STATE, QMI_CORE_ERROR_WRONG_STATE,
"Device must be open to send commands"); "Device must be open to send commands");
transaction_complete_and_free (tr, NULL, error); transaction_early_error (self, tr, FALSE, error);
g_error_free (error);
return; return;
} }
} }
@ -2820,8 +2836,7 @@ qmi_device_command (QmiDevice *self,
QMI_CORE_ERROR_FAILED, QMI_CORE_ERROR_FAILED,
"Cannot send message in service '%s' without a CID", "Cannot send message in service '%s' without a CID",
qmi_service_get_string (qmi_message_get_service (message))); qmi_service_get_string (qmi_message_get_service (message)));
transaction_complete_and_free (tr, NULL, error); transaction_early_error (self, tr, FALSE, error);
g_error_free (error);
return; return;
} }
@ -2829,8 +2844,7 @@ qmi_device_command (QmiDevice *self,
* (only applicable if we did version info check when opening) */ * (only applicable if we did version info check when opening) */
if (!check_message_supported (self, message, &error)) { if (!check_message_supported (self, message, &error)) {
g_prefix_error (&error, "Cannot send message: "); g_prefix_error (&error, "Cannot send message: ");
transaction_complete_and_free (tr, NULL, error); transaction_early_error (self, tr, FALSE, error);
g_error_free (error);
return; return;
} }
@ -2838,8 +2852,7 @@ qmi_device_command (QmiDevice *self,
raw_message = qmi_message_get_raw (message, &raw_message_len, &error); raw_message = qmi_message_get_raw (message, &raw_message_len, &error);
if (!raw_message) { if (!raw_message) {
g_prefix_error (&error, "Cannot get raw message: "); g_prefix_error (&error, "Cannot get raw message: ");
transaction_complete_and_free (tr, NULL, error); transaction_early_error (self, tr, FALSE, error);
g_error_free (error);
return; return;
} }
@ -2854,11 +2867,13 @@ qmi_device_command (QmiDevice *self,
/* Setup context to match response */ /* Setup context to match response */
if (!device_store_transaction (self, tr, transaction_timeout, &error)) { if (!device_store_transaction (self, tr, transaction_timeout, &error)) {
g_prefix_error (&error, "Cannot store transaction: "); g_prefix_error (&error, "Cannot store transaction: ");
transaction_complete_and_free (tr, NULL, error); transaction_early_error (self, tr, FALSE, error);
g_error_free (error);
return; return;
} }
/* From now on, if we want to complete the transaction with an early error,
* it needs to be removed from the tracking table as well. */
if (qmi_utils_get_traces_enabled ()) { if (qmi_utils_get_traces_enabled ()) {
gchar *printable; gchar *printable;
@ -2891,8 +2906,7 @@ qmi_device_command (QmiDevice *self,
cancellable, cancellable,
&error)) { &error)) {
g_prefix_error (&error, "Cannot create MBIM command: "); g_prefix_error (&error, "Cannot create MBIM command: ");
transaction_complete_and_free (tr, NULL, error); transaction_early_error (self, tr, TRUE, error);
g_error_free (error);
} }
return; return;
} }
@ -2905,10 +2919,8 @@ qmi_device_command (QmiDevice *self,
NULL, /* cancellable */ NULL, /* cancellable */
&error)) { &error)) {
g_prefix_error (&error, "Cannot write message: "); g_prefix_error (&error, "Cannot write message: ");
/* Match transaction so that we remove it from our tracking table */ transaction_early_error (self, tr, TRUE, error);
tr = device_match_transaction (self, message); return;
transaction_complete_and_free (tr, NULL, error);
g_error_free (error);
} }
/* Flush explicitly if correctly written */ /* Flush explicitly if correctly written */