api,dbus: 'ip-type' property now given as a MMBearerIpFamily (u)
Instead of using a predefined set of string values for 'ip-type' in Modem.CreateBearer() and Simple.Connect(), we'll use an enumeration. The implementation will then need to convert the requested IP family type to e.g. the correct PDP type in 3GPP modems. This change also consolidates the use of enums in dictionary properties when possible to do so, as with the Rm Protocol.
This commit is contained in:
@@ -33,7 +33,7 @@ struct _MMBearerPropertiesPrivate {
|
||||
/* APN */
|
||||
gchar *apn;
|
||||
/* IP type */
|
||||
gchar *ip_type;
|
||||
MMBearerIpFamily ip_type;
|
||||
/* Number */
|
||||
gchar *number;
|
||||
/* User */
|
||||
@@ -81,12 +81,11 @@ mm_bearer_properties_set_password (MMBearerProperties *self,
|
||||
|
||||
void
|
||||
mm_bearer_properties_set_ip_type (MMBearerProperties *self,
|
||||
const gchar *ip_type)
|
||||
MMBearerIpFamily ip_type)
|
||||
{
|
||||
g_return_if_fail (MM_IS_BEARER_PROPERTIES (self));
|
||||
|
||||
g_free (self->priv->ip_type);
|
||||
self->priv->ip_type = g_strdup (ip_type);
|
||||
self->priv->ip_type = ip_type;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -144,10 +143,10 @@ mm_bearer_properties_get_password (MMBearerProperties *self)
|
||||
return self->priv->password;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
MMBearerIpFamily
|
||||
mm_bearer_properties_get_ip_type (MMBearerProperties *self)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL);
|
||||
g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), MM_BEARER_IP_FAMILY_UNKNOWN);
|
||||
|
||||
return self->priv->ip_type;
|
||||
}
|
||||
@@ -209,11 +208,11 @@ mm_bearer_properties_get_dictionary (MMBearerProperties *self)
|
||||
PROPERTY_PASSWORD,
|
||||
g_variant_new_string (self->priv->password));
|
||||
|
||||
if (self->priv->ip_type)
|
||||
if (self->priv->ip_type != MM_BEARER_IP_FAMILY_UNKNOWN)
|
||||
g_variant_builder_add (&builder,
|
||||
"{sv}",
|
||||
PROPERTY_IP_TYPE,
|
||||
g_variant_new_string (self->priv->ip_type));
|
||||
g_variant_new_uint32 (self->priv->ip_type));
|
||||
|
||||
if (self->priv->number)
|
||||
g_variant_builder_add (&builder,
|
||||
@@ -252,9 +251,17 @@ mm_bearer_properties_consume_string (MMBearerProperties *self,
|
||||
mm_bearer_properties_set_user (self, value);
|
||||
else if (g_str_equal (key, PROPERTY_PASSWORD))
|
||||
mm_bearer_properties_set_password (self, value);
|
||||
else if (g_str_equal (key, PROPERTY_IP_TYPE))
|
||||
mm_bearer_properties_set_ip_type (self, value);
|
||||
else if (g_str_equal (key, PROPERTY_ALLOW_ROAMING)) {
|
||||
else if (g_str_equal (key, PROPERTY_IP_TYPE)) {
|
||||
GError *inner_error = NULL;
|
||||
MMBearerIpFamily ip_type;
|
||||
|
||||
ip_type = mm_common_get_ip_type_from_string (value, &inner_error);
|
||||
if (inner_error) {
|
||||
g_propagate_error (error, inner_error);
|
||||
return FALSE;
|
||||
}
|
||||
mm_bearer_properties_set_ip_type (self, ip_type);
|
||||
} else if (g_str_equal (key, PROPERTY_ALLOW_ROAMING)) {
|
||||
GError *inner_error = NULL;
|
||||
gboolean allow_roaming;
|
||||
|
||||
@@ -352,7 +359,7 @@ mm_bearer_properties_consume_variant (MMBearerProperties *properties,
|
||||
else if (g_str_equal (key, PROPERTY_IP_TYPE))
|
||||
mm_bearer_properties_set_ip_type (
|
||||
properties,
|
||||
g_variant_get_string (value, NULL));
|
||||
g_variant_get_uint32 (value));
|
||||
else if (g_str_equal (key, PROPERTY_NUMBER))
|
||||
mm_bearer_properties_set_number (
|
||||
properties,
|
||||
@@ -445,7 +452,7 @@ mm_bearer_properties_cmp (MMBearerProperties *a,
|
||||
MMBearerProperties *b)
|
||||
{
|
||||
return ((!g_strcmp0 (a->priv->apn, b->priv->apn)) &&
|
||||
(!g_strcmp0 (a->priv->ip_type, b->priv->ip_type)) &&
|
||||
(a->priv->ip_type == b->priv->ip_type) &&
|
||||
(!g_strcmp0 (a->priv->number, b->priv->number)) &&
|
||||
(!g_strcmp0 (a->priv->user, b->priv->user)) &&
|
||||
(!g_strcmp0 (a->priv->password, b->priv->password)) &&
|
||||
@@ -479,7 +486,7 @@ mm_bearer_properties_init (MMBearerProperties *self)
|
||||
* even better approach would likely be to query which PDP types the
|
||||
* modem supports (using AT+CGDCONT=?), and set the default accordingly
|
||||
*/
|
||||
self->priv->ip_type = g_strdup ("IPV4");
|
||||
self->priv->ip_type = MM_BEARER_IP_FAMILY_IPV4;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -490,7 +497,6 @@ finalize (GObject *object)
|
||||
g_free (self->priv->apn);
|
||||
g_free (self->priv->user);
|
||||
g_free (self->priv->password);
|
||||
g_free (self->priv->ip_type);
|
||||
g_free (self->priv->number);
|
||||
|
||||
G_OBJECT_CLASS (mm_bearer_properties_parent_class)->finalize (object);
|
||||
|
||||
@@ -58,7 +58,7 @@ void mm_bearer_properties_set_user (MMBearerProperties *properties,
|
||||
void mm_bearer_properties_set_password (MMBearerProperties *properties,
|
||||
const gchar *password);
|
||||
void mm_bearer_properties_set_ip_type (MMBearerProperties *properties,
|
||||
const gchar *ip_type);
|
||||
MMBearerIpFamily ip_type);
|
||||
void mm_bearer_properties_set_allow_roaming (MMBearerProperties *properties,
|
||||
gboolean allow_roaming);
|
||||
void mm_bearer_properties_set_number (MMBearerProperties *properties,
|
||||
@@ -69,7 +69,7 @@ void mm_bearer_properties_set_rm_protocol (MMBearerProperties *properties,
|
||||
const gchar *mm_bearer_properties_get_apn (MMBearerProperties *properties);
|
||||
const gchar *mm_bearer_properties_get_user (MMBearerProperties *properties);
|
||||
const gchar *mm_bearer_properties_get_password (MMBearerProperties *properties);
|
||||
const gchar *mm_bearer_properties_get_ip_type (MMBearerProperties *properties);
|
||||
MMBearerIpFamily mm_bearer_properties_get_ip_type (MMBearerProperties *properties);
|
||||
gboolean mm_bearer_properties_get_allow_roaming (MMBearerProperties *properties);
|
||||
const gchar *mm_bearer_properties_get_number (MMBearerProperties *properties);
|
||||
MMModemCdmaRmProtocol mm_bearer_properties_get_rm_protocol (MMBearerProperties *properties);
|
||||
|
||||
@@ -334,6 +334,28 @@ mm_common_get_rm_protocol_from_string (const gchar *str,
|
||||
return MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN;
|
||||
}
|
||||
|
||||
MMBearerIpFamily
|
||||
mm_common_get_ip_type_from_string (const gchar *str,
|
||||
GError **error)
|
||||
{
|
||||
GEnumClass *enum_class;
|
||||
guint i;
|
||||
|
||||
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_BEARER_IP_FAMILY));
|
||||
|
||||
for (i = 0; enum_class->values[i].value_nick; i++) {
|
||||
if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick))
|
||||
return enum_class->values[i].value;
|
||||
}
|
||||
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_INVALID_ARGS,
|
||||
"Couldn't match '%s' with a valid MMBearerIpFamily value",
|
||||
str);
|
||||
return MM_BEARER_IP_FAMILY_UNKNOWN;
|
||||
}
|
||||
|
||||
GVariant *
|
||||
mm_common_build_bands_unknown (void)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,8 @@ gboolean mm_common_get_boolean_from_string (const gchar *value,
|
||||
GError **error);
|
||||
MMModemCdmaRmProtocol mm_common_get_rm_protocol_from_string (const gchar *str,
|
||||
GError **error);
|
||||
MMBearerIpFamily mm_common_get_ip_type_from_string (const gchar *str,
|
||||
GError **error);
|
||||
|
||||
GArray *mm_common_bands_variant_to_garray (GVariant *variant);
|
||||
MMModemBand *mm_common_bands_variant_to_array (GVariant *variant,
|
||||
|
||||
@@ -124,7 +124,7 @@ mm_simple_connect_properties_set_password (MMSimpleConnectProperties *self,
|
||||
|
||||
void
|
||||
mm_simple_connect_properties_set_ip_type (MMSimpleConnectProperties *self,
|
||||
const gchar *ip_type)
|
||||
MMBearerIpFamily ip_type)
|
||||
{
|
||||
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
|
||||
|
||||
@@ -228,10 +228,10 @@ mm_simple_connect_properties_get_password (MMSimpleConnectProperties *self)
|
||||
return mm_bearer_properties_get_password (self->priv->bearer_properties);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
MMBearerIpFamily
|
||||
mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), NULL);
|
||||
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), MM_BEARER_IP_FAMILY_UNKNOWN);
|
||||
|
||||
return mm_bearer_properties_get_ip_type (self->priv->bearer_properties);
|
||||
}
|
||||
|
||||
@@ -68,26 +68,26 @@ void mm_simple_connect_properties_set_user (MMSimpleConnectProperties *
|
||||
void mm_simple_connect_properties_set_password (MMSimpleConnectProperties *properties,
|
||||
const gchar *password);
|
||||
void mm_simple_connect_properties_set_ip_type (MMSimpleConnectProperties *properties,
|
||||
const gchar *ip_type);
|
||||
MMBearerIpFamily ip_type);
|
||||
void mm_simple_connect_properties_set_allow_roaming (MMSimpleConnectProperties *properties,
|
||||
gboolean allow_roaming);
|
||||
void mm_simple_connect_properties_set_number (MMSimpleConnectProperties *properties,
|
||||
const gchar *number);
|
||||
|
||||
const gchar *mm_simple_connect_properties_get_pin (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_operator_id (MMSimpleConnectProperties *properties);
|
||||
void mm_simple_connect_properties_get_bands (MMSimpleConnectProperties *properties,
|
||||
const MMModemBand **bands,
|
||||
guint *n_bands);
|
||||
void mm_simple_connect_properties_get_allowed_modes (MMSimpleConnectProperties *properties,
|
||||
MMModemMode *allowed,
|
||||
MMModemMode *preferred);
|
||||
const gchar *mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_user (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_password (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *properties);
|
||||
gboolean mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_number (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_pin (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_operator_id (MMSimpleConnectProperties *properties);
|
||||
void mm_simple_connect_properties_get_bands (MMSimpleConnectProperties *properties,
|
||||
const MMModemBand **bands,
|
||||
guint *n_bands);
|
||||
void mm_simple_connect_properties_get_allowed_modes (MMSimpleConnectProperties *properties,
|
||||
MMModemMode *allowed,
|
||||
MMModemMode *preferred);
|
||||
const gchar *mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_user (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_password (MMSimpleConnectProperties *properties);
|
||||
MMBearerIpFamily mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *properties);
|
||||
gboolean mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *properties);
|
||||
const gchar *mm_simple_connect_properties_get_number (MMSimpleConnectProperties *properties);
|
||||
|
||||
MMBearerProperties *mm_simple_connect_properties_get_bearer_properties (MMSimpleConnectProperties *properties);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user