bearer-mbim: refactor disconnect_set_ready()
Try to make it more clear which are the different branches in the logic, and jump out as soon as the branch is finished.
This commit is contained in:
@@ -1086,20 +1086,21 @@ disconnect_set_ready (MbimDevice *device,
|
|||||||
guint32 session_id;
|
guint32 session_id;
|
||||||
MbimActivationState activation_state;
|
MbimActivationState activation_state;
|
||||||
guint32 nw_error;
|
guint32 nw_error;
|
||||||
|
GError *inner_error = NULL;
|
||||||
|
gboolean result = FALSE, parsed_result = FALSE;
|
||||||
|
|
||||||
ctx = g_task_get_task_data (task);
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
response = mbim_device_command_finish (device, res, &error);
|
response = mbim_device_command_finish (device, res, &error);
|
||||||
if (response) {
|
if (!response)
|
||||||
GError *inner_error = NULL;
|
goto out;
|
||||||
gboolean result = FALSE, parsed_result = FALSE;
|
|
||||||
|
|
||||||
result = mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error);
|
result = mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error);
|
||||||
|
|
||||||
/* Parse the response only for the cases we need to */
|
/* Parse the response only for the cases we need to */
|
||||||
if (result ||
|
if (result ||
|
||||||
g_error_matches (error, MBIM_STATUS_ERROR, MBIM_STATUS_ERROR_FAILURE) ||
|
g_error_matches (error, MBIM_STATUS_ERROR, MBIM_STATUS_ERROR_FAILURE) ||
|
||||||
g_error_matches (error, MBIM_STATUS_ERROR,
|
g_error_matches (error, MBIM_STATUS_ERROR, MBIM_STATUS_ERROR_CONTEXT_NOT_ACTIVATED)) {
|
||||||
MBIM_STATUS_ERROR_CONTEXT_NOT_ACTIVATED)) {
|
|
||||||
parsed_result = mbim_message_connect_response_parse (
|
parsed_result = mbim_message_connect_response_parse (
|
||||||
response,
|
response,
|
||||||
&session_id,
|
&session_id,
|
||||||
@@ -1112,13 +1113,16 @@ disconnect_set_ready (MbimDevice *device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now handle different response / error cases */
|
/* Now handle different response / error cases */
|
||||||
|
|
||||||
if (result && parsed_result) {
|
if (result && parsed_result) {
|
||||||
mm_dbg ("Session ID '%u': %s",
|
g_assert (!error);
|
||||||
session_id,
|
g_assert (!inner_error);
|
||||||
mbim_activation_state_get_string (activation_state));
|
mm_dbg ("Session ID '%u': %s", session_id, mbim_activation_state_get_string (activation_state));
|
||||||
} else if (g_error_matches (error,
|
/* success */
|
||||||
MBIM_STATUS_ERROR,
|
goto out;
|
||||||
MBIM_STATUS_ERROR_CONTEXT_NOT_ACTIVATED)) {
|
}
|
||||||
|
|
||||||
|
if (g_error_matches (error, MBIM_STATUS_ERROR, MBIM_STATUS_ERROR_CONTEXT_NOT_ACTIVATED)) {
|
||||||
if (parsed_result)
|
if (parsed_result)
|
||||||
mm_dbg ("Context not activated: session ID '%u' already disconnected", session_id);
|
mm_dbg ("Context not activated: session ID '%u' already disconnected", session_id);
|
||||||
else
|
else
|
||||||
@@ -1126,18 +1130,24 @@ disconnect_set_ready (MbimDevice *device,
|
|||||||
|
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
g_clear_error (&inner_error);
|
g_clear_error (&inner_error);
|
||||||
} else if (g_error_matches (error, MBIM_STATUS_ERROR, MBIM_STATUS_ERROR_FAILURE)) {
|
/* success */
|
||||||
if (parsed_result && nw_error != 0) {
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_error_matches (error, MBIM_STATUS_ERROR, MBIM_STATUS_ERROR_FAILURE) && parsed_result && nw_error != 0) {
|
||||||
|
g_assert (!inner_error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
error = mm_mobile_equipment_error_from_mbim_nw_error (nw_error);
|
error = mm_mobile_equipment_error_from_mbim_nw_error (nw_error);
|
||||||
|
/* error out with nw_error error */
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
} /* else: For other errors, give precedence to error over nw_error */
|
|
||||||
|
|
||||||
/* Give precedence to original error over parsing error */
|
/* Give precedence to original error over parsing error */
|
||||||
if (!error && inner_error)
|
if (!error && inner_error)
|
||||||
error = g_error_copy (inner_error);
|
error = g_error_copy (inner_error);
|
||||||
g_clear_error (&inner_error);
|
g_clear_error (&inner_error);
|
||||||
}
|
|
||||||
|
out:
|
||||||
|
|
||||||
if (response)
|
if (response)
|
||||||
mbim_message_unref (response);
|
mbim_message_unref (response);
|
||||||
|
Reference in New Issue
Block a user