diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-01-18 13:43:49 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:52 +0100 |
commit | 7e36f04b37c14a518370dd5be2e99b7c629b5214 (patch) | |
tree | c81193004d48ea09af12b0c3703860dc9ad6bddf | |
parent | 04fc34fab89483e9cfdaf7b273a867b72e622fbc (diff) |
core: use new enums/flags string getters/builders
-rw-r--r-- | src/mm-bearer-cdma.c | 9 | ||||
-rw-r--r-- | src/mm-bearer.c | 20 | ||||
-rw-r--r-- | src/mm-broadband-modem.c | 2 | ||||
-rw-r--r-- | src/mm-iface-modem-3gpp.c | 16 | ||||
-rw-r--r-- | src/mm-iface-modem-simple.c | 8 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 54 | ||||
-rw-r--r-- | src/mm-modem-helpers.c | 30 | ||||
-rw-r--r-- | src/mm-sim.c | 18 |
8 files changed, 36 insertions, 121 deletions
diff --git a/src/mm-bearer-cdma.c b/src/mm-bearer-cdma.c index 622d9bf4..20297144 100644 --- a/src/mm-bearer-cdma.c +++ b/src/mm-bearer-cdma.c @@ -619,9 +619,6 @@ crm_range_ready (MMBaseModem *modem, if (mm_cdma_parse_crm_range_response (response, &min, &max, &error)) { - GEnumClass *enum_class; - GEnumValue *value; - /* Check if value within the range */ if (ctx->self->priv->rm_protocol >= min && ctx->self->priv->rm_protocol <= max) { @@ -630,14 +627,12 @@ crm_range_ready (MMBaseModem *modem, 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); error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Requested RM protocol '%s' is not supported", - value->value_nick); - g_type_class_unref (enum_class); + mm_modem_cdma_rm_protocol_get_string ( + ctx->self->priv->rm_protocol)); } /* Failed, set as fatal as well */ diff --git a/src/mm-bearer.c b/src/mm-bearer.c index 0833f044..b13eb1a7 100644 --- a/src/mm-bearer.c +++ b/src/mm-bearer.c @@ -166,12 +166,6 @@ mm_bearer_connect (MMBearer *self, /* Bearer may not be allowed to connect yet */ 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_OBJECT (self), callback, @@ -179,9 +173,8 @@ mm_bearer_connect (MMBearer *self, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED, "Not allowed to connect bearer: %s", - value->value_nick); - - g_type_class_unref (enum_class); + mm_bearer_connection_forbidden_reason_get_string ( + self->priv->connection_forbidden_reason)); return; } @@ -503,18 +496,13 @@ void mm_bearer_set_connection_forbidden (MMBearer *self, MMBearerConnectionForbiddenReason reason) { - GEnumClass *enum_class; - GEnumValue *value; - g_assert (reason != MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE); 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'", self->priv->path, - value->value_nick); - g_type_class_unref (enum_class); + mm_bearer_connection_forbidden_reason_get_string ( + self->priv->connection_forbidden_reason)); if (self->priv->status == MM_BEARER_STATUS_DISCONNECTING || self->priv->status == MM_BEARER_STATUS_DISCONNECTED) { diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index e858cd5c..e76f673d 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -470,7 +470,7 @@ modem_load_current_capabilities_finish (MMIfaceModem *self, return MM_MODEM_CAPABILITY_NONE; 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); g_free (caps_str); return caps; diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index b4885af1..00651092 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -717,20 +717,10 @@ update_registration_state (MMIfaceModem3gpp *self, NULL); 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)", - dbus_path, - old_value->value_nick, - new_value->value_nick); - g_type_class_unref (enum_class); + g_dbus_object_get_object_path (G_DBUS_OBJECT (self)), + mm_modem_3gpp_registration_state_get_string (old_state), + mm_modem_3gpp_registration_state_get_string (new_state)); /* The property in the interface is bound to the property * in the skeleton, so just updating here is enough */ diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c index 3e3a9153..ef66c88b 100644 --- a/src/mm-iface-modem-simple.c +++ b/src/mm-iface-modem-simple.c @@ -683,18 +683,12 @@ unlock_check_ready (MMIfaceModem *self, /* During simple connect we are only allowed to use SIM PIN */ if (lock != MM_MODEM_LOCK_SIM_PIN || !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 ( ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED, "Modem is locked with '%s' code; cannot unlock it", - value->value_nick); - g_type_class_unref (enum_class); + mm_modem_lock_get_string (lock)); connection_context_free (ctx); return; } diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 0c9912e9..00b84094 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -370,16 +370,14 @@ mm_iface_modem_update_access_tech (MMIfaceModem *self, if (built_access_tech != old_access_tech) { gchar *old_access_tech_string; gchar *new_access_tech_string; - const gchar *dbus_path; mm_gdbus_modem_set_access_technologies (skeleton, built_access_tech); /* Log */ - old_access_tech_string = mm_common_get_access_technologies_string (old_access_tech); - new_access_tech_string = mm_common_get_access_technologies_string (built_access_tech); - dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self)); + old_access_tech_string = mm_modem_access_technology_build_string_from_mask (old_access_tech); + new_access_tech_string = mm_modem_access_technology_build_string_from_mask (built_access_tech); 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, new_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 */ 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_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)); - if (dbus_path) - mm_info ("Modem %s: state changed (%s -> %s)", - dbus_path, - old_value->value_nick, - new_value->value_nick); - else - mm_info ("Modem: state changed (%s -> %s)", - old_value->value_nick, - new_value->value_nick); - g_type_class_unref (enum_class); + mm_info ("Modem%s%s: state changed (%s -> %s)", + dbus_path ? " " : "", + dbus_path ? dbus_path : "", + mm_modem_state_get_string (old_state), + mm_modem_state_get_string (new_state)); /* The property in the interface is bound to the property * 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); if (band == MM_MODEM_BAND_UNKNOWN || 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, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, "Wrong list of bands: " "'%s' should have been the only element in the list", - value->value_nick); - g_type_class_unref (enum_class); + mm_modem_band_get_string (band)); return FALSE; } @@ -1132,22 +1113,17 @@ validate_allowed_bands (const GArray *supported_bands_array, } if (!found) { - GEnumClass *enum_class; - GEnumValue *value; 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, 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, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, "Given allowed band (%s) is not supported (%s)", - value->value_nick, + mm_modem_band_get_string (band), supported_bands_str); - g_type_class_unref (enum_class); g_free (supported_bands_str); return FALSE; } @@ -1371,8 +1347,8 @@ mm_iface_modem_set_allowed_modes (MMIfaceModem *self, gchar *not_supported_str; gchar *supported_str; - not_supported_str = mm_common_get_modes_string (not_supported); - supported_str = mm_common_get_modes_string (supported); + not_supported_str = mm_modem_mode_build_string_from_mask (not_supported); + supported_str = mm_modem_mode_build_string_from_mask (supported); g_simple_async_result_set_error (ctx->result, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, @@ -1392,8 +1368,8 @@ mm_iface_modem_set_allowed_modes (MMIfaceModem *self, gchar *preferred_str; gchar *allowed_str; - preferred_str = mm_common_get_modes_string (preferred); - allowed_str = mm_common_get_modes_string (allowed); + preferred_str = mm_modem_mode_build_string_from_mask (preferred); + allowed_str = mm_modem_mode_build_string_from_mask (allowed); g_simple_async_result_set_error (ctx->result, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 00cfa3ed..b83a0eb2 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -151,8 +151,6 @@ mm_3gpp_parse_scan_response (const gchar *reply, GList *info_list = NULL; GMatchInfo *match_info; gboolean umts_format = TRUE; - GEnumClass *network_availability_class; - GFlagsClass *access_tech_class; GError *inner_error = NULL; g_return_val_if_fail (reply != NULL, NULL); @@ -225,9 +223,6 @@ mm_3gpp_parse_scan_response (const gchar *reply, 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 */ while (g_match_info_matches (match_info)) { MM3gppNetworkInfo *info; @@ -272,20 +267,16 @@ mm_3gpp_parse_scan_response (const gchar *reply, } if (valid) { - GEnumValue *network_availability; - 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); + gchar *access_tech_str; + 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", info->operator_code, info->operator_short ? info->operator_short : "no short name", info->operator_long ? info->operator_long : "no long name", - network_availability->value_nick, - access_tech->value_nick); + mm_modem_3gpp_network_availability_get_string (info->status), + access_tech_str); + g_free (access_tech_str); 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_regex_unref (r); - g_type_class_unref (network_availability_class); - g_type_class_unref (access_tech_class); - return info_list; } @@ -1600,17 +1588,11 @@ mm_cdma_get_index_from_rm_protocol (MMModemCdmaRmProtocol protocol, GError **error) { 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, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Unexpected RM protocol (%s)", - value->value_nick); - g_type_class_unref (enum_class); + mm_modem_cdma_rm_protocol_get_string (protocol)); return 0; } diff --git a/src/mm-sim.c b/src/mm-sim.c index df82adaf..c90a6e21 100644 --- a/src/mm-sim.c +++ b/src/mm-sim.c @@ -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_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_PH_NETSUB_PUK); - enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_LOCK)); - enum_value = g_enum_get_value (enum_class, lock); - error = g_error_new (MM_MOBILE_EQUIPMENT_ERROR, - errors_for_locks[lock], - "Device is locked: '%s'", - enum_value->value_nick); - - mm_warn ("ERROR: %s", error->message); - - g_type_class_unref (enum_class); - return error; + return g_error_new (MM_MOBILE_EQUIPMENT_ERROR, + errors_for_locks[lock], + "Device is locked: '%s'", + mm_modem_lock_get_string (lock)); } gboolean |