error-helpers: port to use object logging

This commit is contained in:
Aleksander Morgado
2020-04-04 14:37:42 +02:00
parent bac9ed21cb
commit a2b57474dc
11 changed files with 47 additions and 40 deletions

View File

@@ -483,9 +483,12 @@ ier_query_ready (MMBaseModem *modem,
GAsyncResult *res,
GTask *task)
{
MMBroadbandBearerIcera *self;
const gchar *response;
GError *activation_error = NULL;
self = g_task_get_source_object (task);
response = mm_base_modem_at_command_full_finish (modem, res, NULL);
if (response) {
gint nw_activation_err;
@@ -497,8 +500,7 @@ ier_query_ready (MMBaseModem *modem,
* 33 - Requested service option not subscribed
*/
if (nw_activation_err == 27 || nw_activation_err == 33)
activation_error = mm_mobile_equipment_error_for_code (
MM_MOBILE_EQUIPMENT_ERROR_GPRS_SERVICE_OPTION_NOT_SUBSCRIBED);
activation_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_GPRS_SERVICE_OPTION_NOT_SUBSCRIBED, self);
}
}

View File

@@ -169,7 +169,7 @@ handle_start_ready (MMBaseCall *self,
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_CANCELLED)) {
g_clear_error (&error);
error = mm_connection_error_for_code (MM_CONNECTION_ERROR_NO_DIALTONE);
error = mm_connection_error_for_code (MM_CONNECTION_ERROR_NO_DIALTONE, self);
}
/* Convert errors into call state updates */

View File

@@ -995,12 +995,12 @@ unlock_required_subscriber_ready_state_ready (MbimDevice *device,
* The MC7710 may use this while the SIM is not ready yet. */
break;
case MBIM_SUBSCRIBER_READY_STATE_BAD_SIM:
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG, self);
break;
case MBIM_SUBSCRIBER_READY_STATE_FAILURE:
case MBIM_SUBSCRIBER_READY_STATE_NOT_ACTIVATED:
default:
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_FAILURE);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_FAILURE, self);
break;
}
}
@@ -1020,7 +1020,7 @@ unlock_required_subscriber_ready_state_ready (MbimDevice *device,
/* All retries consumed? issue error */
if (ctx->last_attempt) {
if (ready_state == MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED)
g_task_return_error (task, mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_NOT_INSERTED));
g_task_return_error (task, mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_NOT_INSERTED, self));
else
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Error waiting for SIM to get initialized");

View File

@@ -9682,7 +9682,7 @@ run_cdma_registration_checks_ready (MMBroadbandModem *self,
mm_iface_modem_cdma_update_access_technologies (
MM_IFACE_MODEM_CDMA (self),
MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT, self);
g_task_return_error (task, error);
g_object_unref (task);
return;

View File

@@ -29,7 +29,8 @@ typedef struct {
/* --- Connection errors --- */
GError *
mm_connection_error_for_code (MMConnectionError code)
mm_connection_error_for_code (MMConnectionError code,
gpointer log_object)
{
const gchar *msg;
@@ -51,7 +52,7 @@ mm_connection_error_for_code (MMConnectionError code)
break;
default:
mm_dbg ("Invalid connection error code: %u", code);
mm_obj_dbg (log_object, "invalid connection error code: %u", code);
/* uhm... make something up (yes, ok, lie!). */
code = MM_CONNECTION_ERROR_NO_CARRIER;
msg = "No carrier";
@@ -149,7 +150,8 @@ static ErrorTable me_errors[] = {
};
GError *
mm_mobile_equipment_error_for_code (MMMobileEquipmentError code)
mm_mobile_equipment_error_for_code (MMMobileEquipmentError code,
gpointer log_object)
{
guint i;
@@ -162,14 +164,15 @@ mm_mobile_equipment_error_for_code (MMMobileEquipmentError code)
}
/* Not found? Then, default */
mm_dbg ("Invalid mobile equipment error code: %u", (guint)code);
mm_obj_dbg (log_object, "invalid mobile equipment error code: %u", (guint)code);
return g_error_new (MM_MOBILE_EQUIPMENT_ERROR,
MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN,
"Unknown error");
}
GError *
mm_mobile_equipment_error_for_string (const gchar *str)
mm_mobile_equipment_error_for_string (const gchar *str,
gpointer log_object)
{
MMMobileEquipmentError code = MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN;
const gchar *msg = NULL;
@@ -198,7 +201,7 @@ mm_mobile_equipment_error_for_string (const gchar *str)
/* Not found? Then, default */
if (!msg) {
mm_dbg ("Invalid mobile equipment error string: '%s' (%s)", str, buf);
mm_obj_dbg (log_object, "invalid mobile equipment error string: '%s' (%s)", str, buf);
code = MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN;
msg = "Unknown error";
}
@@ -236,7 +239,8 @@ static ErrorTable msg_errors[] = {
};
GError *
mm_message_error_for_code (MMMessageError code)
mm_message_error_for_code (MMMessageError code,
gpointer log_object)
{
guint i;
@@ -249,14 +253,15 @@ mm_message_error_for_code (MMMessageError code)
}
/* Not found? Then, default */
mm_dbg ("Invalid message error code: %u", (guint)code);
mm_obj_dbg (log_object, "invalid message error code: %u", (guint)code);
return g_error_new (MM_MESSAGE_ERROR,
MM_MESSAGE_ERROR_UNKNOWN,
"Unknown error");
}
GError *
mm_message_error_for_string (const gchar *str)
mm_message_error_for_string (const gchar *str,
gpointer log_object)
{
MMMessageError code = MM_MESSAGE_ERROR_UNKNOWN;
const gchar *msg = NULL;
@@ -285,7 +290,7 @@ mm_message_error_for_string (const gchar *str)
/* Not found? Then, default */
if (!msg) {
mm_dbg ("Invalid message error string: '%s' (%s)", str, buf);
mm_obj_dbg (log_object, "invalid message error string: '%s' (%s)", str, buf);
code = MM_MESSAGE_ERROR_UNKNOWN;
msg = "Unknown error";
}

View File

@@ -23,10 +23,10 @@
#include <ModemManager.h>
#include <libmm-glib.h>
GError *mm_connection_error_for_code (MMConnectionError code);
GError *mm_mobile_equipment_error_for_code (MMMobileEquipmentError code);
GError *mm_mobile_equipment_error_for_string (const gchar *str);
GError *mm_message_error_for_code (MMMessageError code);
GError *mm_message_error_for_string (const gchar *str);
GError *mm_connection_error_for_code (MMConnectionError code, gpointer log_object);
GError *mm_mobile_equipment_error_for_code (MMMobileEquipmentError code, gpointer log_object);
GError *mm_mobile_equipment_error_for_string (const gchar *str, gpointer log_object);
GError *mm_message_error_for_code (MMMessageError code, gpointer log_object);
GError *mm_message_error_for_string (const gchar *str, gpointer log_object);
#endif /* MM_ERROR_HELPERS_H */

View File

@@ -311,7 +311,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self,
mm_obj_dbg (self, "registration denied");
register_in_network_context_complete_failed (
task,
mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_NOT_ALLOWED));
mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_NOT_ALLOWED, self));
return;
}
@@ -333,7 +333,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self,
mm_obj_dbg (self, "3GPP registration check timed out");
register_in_network_context_complete_failed (
task,
mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT));
mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT, self));
return;
}

View File

@@ -164,7 +164,7 @@ check_next_registration (GTask *task)
/* No more tries of anything */
g_task_return_error (
task,
mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT));
mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT, self));
g_object_unref (task);
}

View File

@@ -239,7 +239,7 @@ mm_serial_parser_v1_parse (gpointer data,
if (found) {
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_equipment_error_for_code (atoi (str));
local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object);
goto done;
}
g_match_info_free (match_info);
@@ -252,7 +252,7 @@ mm_serial_parser_v1_parse (gpointer data,
if (found) {
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_equipment_error_for_code (atoi (str));
local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object);
goto done;
}
g_match_info_free (match_info);
@@ -264,7 +264,7 @@ mm_serial_parser_v1_parse (gpointer data,
if (found) {
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_message_error_for_code (atoi (str));
local_error = mm_message_error_for_code (atoi (str), log_object);
goto done;
}
g_match_info_free (match_info);
@@ -276,7 +276,7 @@ mm_serial_parser_v1_parse (gpointer data,
if (found) {
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_equipment_error_for_string (str);
local_error = mm_mobile_equipment_error_for_string (str, log_object);
goto done;
}
g_match_info_free (match_info);
@@ -288,7 +288,7 @@ mm_serial_parser_v1_parse (gpointer data,
if (found) {
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_message_error_for_string (str);
local_error = mm_message_error_for_string (str, log_object);
goto done;
}
g_match_info_free (match_info);
@@ -300,7 +300,7 @@ mm_serial_parser_v1_parse (gpointer data,
if (found) {
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN);
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object);
goto done;
}
g_match_info_free (match_info);
@@ -310,7 +310,7 @@ mm_serial_parser_v1_parse (gpointer data,
response->str, response->len,
0, 0, &match_info, NULL);
if (found) {
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN);
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object);
goto done;
}
g_match_info_free (match_info);
@@ -338,7 +338,7 @@ mm_serial_parser_v1_parse (gpointer data,
code = MM_CONNECTION_ERROR_NO_CARRIER;
}
local_error = mm_connection_error_for_code (code);
local_error = mm_connection_error_for_code (code, log_object);
goto done;
}
g_match_info_free (match_info);

View File

@@ -382,10 +382,10 @@ pin_set_enter_ready (MbimDevice *device,
/* Sending PIN failed, build a better error to report */
if (pin_type == MBIM_PIN_TYPE_PIN1 && pin_state == MBIM_PIN_STATE_LOCKED) {
g_error_free (error);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD, self);
} else if (pin_type == MBIM_PIN_TYPE_PUK1 && pin_state == MBIM_PIN_STATE_LOCKED) {
g_error_free (error);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_PUK);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_PUK, self);
}
}
}
@@ -480,9 +480,9 @@ puk_set_enter_ready (MbimDevice *device,
if (pin_type == MBIM_PIN_TYPE_PUK1 && pin_state == MBIM_PIN_STATE_LOCKED) {
g_error_free (error);
if (remaining_attempts == 0)
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG, self);
else
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD);
error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD, self);
}
}
}

View File

@@ -38,7 +38,7 @@
\
enum_value = g_enum_get_value (enum_class, i); \
if (enum_value) { \
error = mm_## ERROR_SMALL ## _for_code ((MM##ERROR_CAMEL)i); \
error = mm_## ERROR_SMALL ## _for_code ((MM##ERROR_CAMEL)i, NULL); \
g_assert_error (error, MM_ ## ERROR_CAPS, i); \
g_error_free (error); \
} \