core: use new enums/flags string getters/builders

This commit is contained in:
Aleksander Morgado
2012-01-18 13:43:49 +01:00
parent 04fc34fab8
commit 7e36f04b37
8 changed files with 36 additions and 121 deletions

View File

@@ -619,9 +619,6 @@ crm_range_ready (MMBaseModem *modem,
if (mm_cdma_parse_crm_range_response (response, if (mm_cdma_parse_crm_range_response (response,
&min, &max, &min, &max,
&error)) { &error)) {
GEnumClass *enum_class;
GEnumValue *value;
/* Check if value within the range */ /* Check if value within the range */
if (ctx->self->priv->rm_protocol >= min && if (ctx->self->priv->rm_protocol >= min &&
ctx->self->priv->rm_protocol <= max) { ctx->self->priv->rm_protocol <= max) {
@@ -630,14 +627,12 @@ crm_range_ready (MMBaseModem *modem,
interface_initialization_step (ctx); interface_initialization_step (ctx);
} }
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_CDMA_RM_PROTOCOL));
value = g_enum_get_value (enum_class, ctx->self->priv->rm_protocol);
g_assert (error == NULL); g_assert (error == NULL);
error = g_error_new (MM_CORE_ERROR, error = g_error_new (MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Requested RM protocol '%s' is not supported", "Requested RM protocol '%s' is not supported",
value->value_nick); mm_modem_cdma_rm_protocol_get_string (
g_type_class_unref (enum_class); ctx->self->priv->rm_protocol));
} }
/* Failed, set as fatal as well */ /* Failed, set as fatal as well */

View File

@@ -166,12 +166,6 @@ mm_bearer_connect (MMBearer *self,
/* Bearer may not be allowed to connect yet */ /* Bearer may not be allowed to connect yet */
if (self->priv->connection_forbidden_reason != MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE) { if (self->priv->connection_forbidden_reason != MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE) {
GEnumClass *enum_class;
GEnumValue *value;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_BEARER_CONNECTION_FORBIDDEN_REASON));
value = g_enum_get_value (enum_class, self->priv->connection_forbidden_reason);
g_simple_async_report_error_in_idle ( g_simple_async_report_error_in_idle (
G_OBJECT (self), G_OBJECT (self),
callback, callback,
@@ -179,9 +173,8 @@ mm_bearer_connect (MMBearer *self,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_UNAUTHORIZED, MM_CORE_ERROR_UNAUTHORIZED,
"Not allowed to connect bearer: %s", "Not allowed to connect bearer: %s",
value->value_nick); mm_bearer_connection_forbidden_reason_get_string (
self->priv->connection_forbidden_reason));
g_type_class_unref (enum_class);
return; return;
} }
@@ -503,18 +496,13 @@ void
mm_bearer_set_connection_forbidden (MMBearer *self, mm_bearer_set_connection_forbidden (MMBearer *self,
MMBearerConnectionForbiddenReason reason) MMBearerConnectionForbiddenReason reason)
{ {
GEnumClass *enum_class;
GEnumValue *value;
g_assert (reason != MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE); g_assert (reason != MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE);
self->priv->connection_forbidden_reason = reason; self->priv->connection_forbidden_reason = reason;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_BEARER_CONNECTION_FORBIDDEN_REASON));
value = g_enum_get_value (enum_class, self->priv->connection_forbidden_reason);
mm_dbg ("Connection in bearer '%s' is forbidden: '%s'", mm_dbg ("Connection in bearer '%s' is forbidden: '%s'",
self->priv->path, self->priv->path,
value->value_nick); mm_bearer_connection_forbidden_reason_get_string (
g_type_class_unref (enum_class); self->priv->connection_forbidden_reason));
if (self->priv->status == MM_BEARER_STATUS_DISCONNECTING || if (self->priv->status == MM_BEARER_STATUS_DISCONNECTING ||
self->priv->status == MM_BEARER_STATUS_DISCONNECTED) { self->priv->status == MM_BEARER_STATUS_DISCONNECTED) {

View File

@@ -470,7 +470,7 @@ modem_load_current_capabilities_finish (MMIfaceModem *self,
return MM_MODEM_CAPABILITY_NONE; return MM_MODEM_CAPABILITY_NONE;
caps = (MMModemCapability)g_variant_get_uint32 (result); caps = (MMModemCapability)g_variant_get_uint32 (result);
caps_str = mm_common_get_capabilities_string (caps); caps_str = mm_modem_capability_build_string_from_mask (caps);
mm_dbg ("loaded current capabilities: %s", caps_str); mm_dbg ("loaded current capabilities: %s", caps_str);
g_free (caps_str); g_free (caps_str);
return caps; return caps;

View File

@@ -717,20 +717,10 @@ update_registration_state (MMIfaceModem3gpp *self,
NULL); NULL);
if (new_state != old_state) { if (new_state != old_state) {
GEnumClass *enum_class;
GEnumValue *new_value;
GEnumValue *old_value;
const gchar *dbus_path;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_3GPP_REGISTRATION_STATE));
new_value = g_enum_get_value (enum_class, new_state);
old_value = g_enum_get_value (enum_class, old_state);
dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self));
mm_info ("Modem %s: 3GPP Registration state changed (%s -> %s)", mm_info ("Modem %s: 3GPP Registration state changed (%s -> %s)",
dbus_path, g_dbus_object_get_object_path (G_DBUS_OBJECT (self)),
old_value->value_nick, mm_modem_3gpp_registration_state_get_string (old_state),
new_value->value_nick); mm_modem_3gpp_registration_state_get_string (new_state));
g_type_class_unref (enum_class);
/* The property in the interface is bound to the property /* The property in the interface is bound to the property
* in the skeleton, so just updating here is enough */ * in the skeleton, so just updating here is enough */

View File

@@ -683,18 +683,12 @@ unlock_check_ready (MMIfaceModem *self,
/* During simple connect we are only allowed to use SIM PIN */ /* During simple connect we are only allowed to use SIM PIN */
if (lock != MM_MODEM_LOCK_SIM_PIN || if (lock != MM_MODEM_LOCK_SIM_PIN ||
!mm_common_connect_properties_get_pin (ctx->properties)) { !mm_common_connect_properties_get_pin (ctx->properties)) {
GEnumClass *enum_class;
GEnumValue *value;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_LOCK));
value = g_enum_get_value (enum_class, lock);
g_dbus_method_invocation_return_error ( g_dbus_method_invocation_return_error (
ctx->invocation, ctx->invocation,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_UNAUTHORIZED, MM_CORE_ERROR_UNAUTHORIZED,
"Modem is locked with '%s' code; cannot unlock it", "Modem is locked with '%s' code; cannot unlock it",
value->value_nick); mm_modem_lock_get_string (lock));
g_type_class_unref (enum_class);
connection_context_free (ctx); connection_context_free (ctx);
return; return;
} }

View File

@@ -370,16 +370,14 @@ mm_iface_modem_update_access_tech (MMIfaceModem *self,
if (built_access_tech != old_access_tech) { if (built_access_tech != old_access_tech) {
gchar *old_access_tech_string; gchar *old_access_tech_string;
gchar *new_access_tech_string; gchar *new_access_tech_string;
const gchar *dbus_path;
mm_gdbus_modem_set_access_technologies (skeleton, built_access_tech); mm_gdbus_modem_set_access_technologies (skeleton, built_access_tech);
/* Log */ /* Log */
old_access_tech_string = mm_common_get_access_technologies_string (old_access_tech); old_access_tech_string = mm_modem_access_technology_build_string_from_mask (old_access_tech);
new_access_tech_string = mm_common_get_access_technologies_string (built_access_tech); new_access_tech_string = mm_modem_access_technology_build_string_from_mask (built_access_tech);
dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self));
mm_info ("Modem %s: access technology changed (%s -> %s)", mm_info ("Modem %s: access technology changed (%s -> %s)",
dbus_path, g_dbus_object_get_object_path (G_DBUS_OBJECT (self)),
old_access_tech_string, old_access_tech_string,
new_access_tech_string); new_access_tech_string);
g_free (old_access_tech_string); g_free (old_access_tech_string);
@@ -683,25 +681,14 @@ mm_iface_modem_update_state (MMIfaceModem *self,
/* Update state only if different */ /* Update state only if different */
if (new_state != old_state) { if (new_state != old_state) {
GEnumClass *enum_class;
GEnumValue *new_value;
GEnumValue *old_value;
const gchar *dbus_path; const gchar *dbus_path;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_STATE));
new_value = g_enum_get_value (enum_class, new_state);
old_value = g_enum_get_value (enum_class, old_state);
dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self)); dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self));
if (dbus_path) mm_info ("Modem%s%s: state changed (%s -> %s)",
mm_info ("Modem %s: state changed (%s -> %s)", dbus_path ? " " : "",
dbus_path, dbus_path ? dbus_path : "",
old_value->value_nick, mm_modem_state_get_string (old_state),
new_value->value_nick); mm_modem_state_get_string (new_state));
else
mm_info ("Modem: state changed (%s -> %s)",
old_value->value_nick,
new_value->value_nick);
g_type_class_unref (enum_class);
/* The property in the interface is bound to the property /* The property in the interface is bound to the property
* in the skeleton, so just updating here is enough */ * in the skeleton, so just updating here is enough */
@@ -1105,18 +1092,12 @@ validate_allowed_bands (const GArray *supported_bands_array,
band = g_array_index (allowed_bands_array, MMModemBand, i); band = g_array_index (allowed_bands_array, MMModemBand, i);
if (band == MM_MODEM_BAND_UNKNOWN || if (band == MM_MODEM_BAND_UNKNOWN ||
band == MM_MODEM_BAND_ANY) { band == MM_MODEM_BAND_ANY) {
GEnumClass *enum_class;
GEnumValue *value;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_BAND));
value = g_enum_get_value (enum_class, band);
g_set_error (error, g_set_error (error,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS, MM_CORE_ERROR_INVALID_ARGS,
"Wrong list of bands: " "Wrong list of bands: "
"'%s' should have been the only element in the list", "'%s' should have been the only element in the list",
value->value_nick); mm_modem_band_get_string (band));
g_type_class_unref (enum_class);
return FALSE; return FALSE;
} }
@@ -1132,22 +1113,17 @@ validate_allowed_bands (const GArray *supported_bands_array,
} }
if (!found) { if (!found) {
GEnumClass *enum_class;
GEnumValue *value;
gchar *supported_bands_str; gchar *supported_bands_str;
supported_bands_str = (mm_common_get_bands_string ( supported_bands_str = (mm_common_build_bands_string (
(const MMModemBand *)supported_bands_array->data, (const MMModemBand *)supported_bands_array->data,
supported_bands_array->len)); supported_bands_array->len));
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_BAND));
value = g_enum_get_value (enum_class, band);
g_set_error (error, g_set_error (error,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS, MM_CORE_ERROR_INVALID_ARGS,
"Given allowed band (%s) is not supported (%s)", "Given allowed band (%s) is not supported (%s)",
value->value_nick, mm_modem_band_get_string (band),
supported_bands_str); supported_bands_str);
g_type_class_unref (enum_class);
g_free (supported_bands_str); g_free (supported_bands_str);
return FALSE; return FALSE;
} }
@@ -1371,8 +1347,8 @@ mm_iface_modem_set_allowed_modes (MMIfaceModem *self,
gchar *not_supported_str; gchar *not_supported_str;
gchar *supported_str; gchar *supported_str;
not_supported_str = mm_common_get_modes_string (not_supported); not_supported_str = mm_modem_mode_build_string_from_mask (not_supported);
supported_str = mm_common_get_modes_string (supported); supported_str = mm_modem_mode_build_string_from_mask (supported);
g_simple_async_result_set_error (ctx->result, g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED, MM_CORE_ERROR_UNSUPPORTED,
@@ -1392,8 +1368,8 @@ mm_iface_modem_set_allowed_modes (MMIfaceModem *self,
gchar *preferred_str; gchar *preferred_str;
gchar *allowed_str; gchar *allowed_str;
preferred_str = mm_common_get_modes_string (preferred); preferred_str = mm_modem_mode_build_string_from_mask (preferred);
allowed_str = mm_common_get_modes_string (allowed); allowed_str = mm_modem_mode_build_string_from_mask (allowed);
g_simple_async_result_set_error (ctx->result, g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED, MM_CORE_ERROR_UNSUPPORTED,

View File

@@ -151,8 +151,6 @@ mm_3gpp_parse_scan_response (const gchar *reply,
GList *info_list = NULL; GList *info_list = NULL;
GMatchInfo *match_info; GMatchInfo *match_info;
gboolean umts_format = TRUE; gboolean umts_format = TRUE;
GEnumClass *network_availability_class;
GFlagsClass *access_tech_class;
GError *inner_error = NULL; GError *inner_error = NULL;
g_return_val_if_fail (reply != NULL, NULL); g_return_val_if_fail (reply != NULL, NULL);
@@ -225,9 +223,6 @@ mm_3gpp_parse_scan_response (const gchar *reply,
umts_format = FALSE; umts_format = FALSE;
} }
network_availability_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_3GPP_NETWORK_AVAILABILITY));
access_tech_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_MODEM_ACCESS_TECHNOLOGY));
/* Parse the results */ /* Parse the results */
while (g_match_info_matches (match_info)) { while (g_match_info_matches (match_info)) {
MM3gppNetworkInfo *info; MM3gppNetworkInfo *info;
@@ -272,20 +267,16 @@ mm_3gpp_parse_scan_response (const gchar *reply,
} }
if (valid) { if (valid) {
GEnumValue *network_availability; gchar *access_tech_str;
GFlagsValue *access_tech;
network_availability = g_enum_get_value (network_availability_class,
info->status);
access_tech = g_flags_get_first_value (access_tech_class,
info->access_tech);
access_tech_str = mm_modem_access_technology_build_string_from_mask (info->access_tech);
mm_dbg ("Found network '%s' ('%s','%s'); availability: %s, access tech: %s", mm_dbg ("Found network '%s' ('%s','%s'); availability: %s, access tech: %s",
info->operator_code, info->operator_code,
info->operator_short ? info->operator_short : "no short name", info->operator_short ? info->operator_short : "no short name",
info->operator_long ? info->operator_long : "no long name", info->operator_long ? info->operator_long : "no long name",
network_availability->value_nick, mm_modem_3gpp_network_availability_get_string (info->status),
access_tech->value_nick); access_tech_str);
g_free (access_tech_str);
info_list = g_list_prepend (info_list, info); info_list = g_list_prepend (info_list, info);
} }
@@ -298,9 +289,6 @@ mm_3gpp_parse_scan_response (const gchar *reply,
g_match_info_free (match_info); g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);
g_type_class_unref (network_availability_class);
g_type_class_unref (access_tech_class);
return info_list; return info_list;
} }
@@ -1600,17 +1588,11 @@ mm_cdma_get_index_from_rm_protocol (MMModemCdmaRmProtocol protocol,
GError **error) GError **error)
{ {
if (protocol == MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) { if (protocol == MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) {
GEnumClass *enum_class;
GEnumValue *value;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_CDMA_RM_PROTOCOL));
value = g_enum_get_value (enum_class, protocol);
g_set_error (error, g_set_error (error,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Unexpected RM protocol (%s)", "Unexpected RM protocol (%s)",
value->value_nick); mm_modem_cdma_rm_protocol_get_string (protocol));
g_type_class_unref (enum_class);
return 0; return 0;
} }

View File

@@ -199,24 +199,14 @@ error_for_unlock_check (MMModemLock lock)
MM_MOBILE_EQUIPMENT_ERROR_NETWORK_SUBSET_PIN, /* MM_MODEM_LOCK_PH_NETSUB_PIN */ MM_MOBILE_EQUIPMENT_ERROR_NETWORK_SUBSET_PIN, /* MM_MODEM_LOCK_PH_NETSUB_PIN */
MM_MOBILE_EQUIPMENT_ERROR_NETWORK_SUBSET_PUK, /* MM_MODEM_LOCK_PH_NETSUB_PUK */ MM_MOBILE_EQUIPMENT_ERROR_NETWORK_SUBSET_PUK, /* MM_MODEM_LOCK_PH_NETSUB_PUK */
}; };
GEnumClass *enum_class;
GEnumValue *enum_value;
GError *error;
g_assert (lock >= MM_MODEM_LOCK_UNKNOWN); g_assert (lock >= MM_MODEM_LOCK_UNKNOWN);
g_assert (lock <= MM_MODEM_LOCK_PH_NETSUB_PUK); g_assert (lock <= MM_MODEM_LOCK_PH_NETSUB_PUK);
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_LOCK)); return g_error_new (MM_MOBILE_EQUIPMENT_ERROR,
enum_value = g_enum_get_value (enum_class, lock);
error = g_error_new (MM_MOBILE_EQUIPMENT_ERROR,
errors_for_locks[lock], errors_for_locks[lock],
"Device is locked: '%s'", "Device is locked: '%s'",
enum_value->value_nick); mm_modem_lock_get_string (lock));
mm_warn ("ERROR: %s", error->message);
g_type_class_unref (enum_class);
return error;
} }
gboolean gboolean