diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-12-21 11:18:46 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:36 +0100 |
commit | 215b9c1a31e182cd34c792995e08b1ea56de5507 (patch) | |
tree | 2919d5d5fbd20b1fbc8d7aaa7b884ad9307c8bb4 /libmm-glib/mm-bearer.c | |
parent | a422f5619fbcc99dd1e14905ecad52583b168847 (diff) |
libmm-glib: allow getting properties used when the bearer was created
Diffstat (limited to 'libmm-glib/mm-bearer.c')
-rw-r--r-- | libmm-glib/mm-bearer.c | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/libmm-glib/mm-bearer.c b/libmm-glib/mm-bearer.c index 702fe7c1..28808584 100644 --- a/libmm-glib/mm-bearer.c +++ b/libmm-glib/mm-bearer.c @@ -22,6 +22,7 @@ #include "mm-helpers.h" #include "mm-bearer.h" +#include "mm-modem.h" /** * mm_bearer_get_path: @@ -372,6 +373,180 @@ mm_bearer_dup_ipv6_config (MMBearer *self) return config; } +struct _MMBearerProperties { + gchar *apn; + gchar *ip_type; + gboolean allow_roaming; + gchar *user; + gchar *password; + gchar *number; +}; + +void +mm_bearer_properties_free (MMBearerProperties *properties) +{ + if (!properties) + return; + + g_free (properties->apn); + g_free (properties->ip_type); + g_free (properties->user); + g_free (properties->password); + g_free (properties->number); + g_slice_free (MMBearerProperties, properties); +} + +static MMBearerProperties * +create_properties_struct (GVariant *variant) +{ + GVariantIter iter; + const gchar *key; + GVariant *value; + MMBearerProperties *c; + + c = g_slice_new0 (MMBearerProperties); + + g_variant_iter_init (&iter, variant); + while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) { + if (g_str_equal (key, MM_BEARER_PROPERTY_APN)) { + g_warn_if_fail (c->apn == NULL); + c->apn = g_variant_dup_string (value, NULL); + } else if (g_str_equal (key, MM_BEARER_PROPERTY_IP_TYPE)) { + g_warn_if_fail (c->ip_type == NULL); + c->ip_type = g_variant_dup_string (value, NULL); + } else if (g_str_equal (key, MM_BEARER_PROPERTY_ALLOW_ROAMING)) { + c->allow_roaming = g_variant_get_boolean (value); + } else if (g_str_equal (key, MM_BEARER_PROPERTY_USER)) { + g_warn_if_fail (c->user == NULL); + c->user = g_variant_dup_string (value, NULL); + } else if (g_str_equal (key, MM_BEARER_PROPERTY_PASSWORD)) { + g_warn_if_fail (c->password == NULL); + c->password = g_variant_dup_string (value, NULL); + } else if (g_str_equal (key, MM_BEARER_PROPERTY_NUMBER)) { + g_warn_if_fail (c->number == NULL); + c->number = g_variant_dup_string (value, NULL); + } else + g_warning ("Unexpected property '%s' found in Bearer properties", key); + } + + return c; +} + +const gchar * +mm_bearer_properties_get_apn (const MMBearerProperties *properties) +{ + return properties->apn; +} + +gchar * +mm_bearer_properties_dup_apn (const MMBearerProperties *properties) +{ + return g_strdup (properties->apn); +} + +const gchar * +mm_bearer_properties_get_ip_type (const MMBearerProperties *properties) +{ + return properties->ip_type; +} + +gchar * +mm_bearer_properties_dup_ip_type (const MMBearerProperties *properties) +{ + return g_strdup (properties->ip_type); +} + +const gchar * +mm_bearer_properties_get_user (const MMBearerProperties *properties) +{ + return properties->user; +} + +gchar * +mm_bearer_properties_dup_user (const MMBearerProperties *properties) +{ + return g_strdup (properties->user); +} + +const gchar * +mm_bearer_properties_get_password (const MMBearerProperties *properties) +{ + return properties->password; +} + +gchar * +mm_bearer_properties_dup_password (const MMBearerProperties *properties) +{ + return g_strdup (properties->password); +} + +const gchar * +mm_bearer_properties_get_number (const MMBearerProperties *properties) +{ + return properties->number; +} + +gchar * +mm_bearer_properties_dup_number (const MMBearerProperties *properties) +{ + return g_strdup (properties->number); +} + +gboolean +mm_bearer_properties_get_allow_roaming (const MMBearerProperties *properties) +{ + return properties->allow_roaming; +} + +#define MM_BEARER_PROPERTIES_DATA "bearer-properties" + +static void +properties_changed (MMBearer *self) +{ + g_object_set_data (G_OBJECT (self), MM_BEARER_PROPERTIES_DATA, NULL); +} + +const MMBearerProperties * +mm_bearer_get_properties (MMBearer *self) +{ + MMBearerProperties *properties; + + g_return_val_if_fail (MM_IS_BEARER (self), NULL); + + properties = g_object_get_data (G_OBJECT (self), + MM_BEARER_PROPERTIES_DATA); + if (!properties) { + properties = create_properties_struct ( + mm_gdbus_bearer_get_properties (MM_GDBUS_BEARER (self))); + + g_object_set_data_full (G_OBJECT (self), + MM_BEARER_PROPERTIES_DATA, + properties, + (GDestroyNotify)mm_bearer_properties_free); + g_signal_connect (self, + "notify::properties", + G_CALLBACK (properties_changed), + NULL); + } + + return properties; +} + +MMBearerProperties * +mm_bearer_dup_properties (MMBearer *self) +{ + MMBearerProperties *properties; + GVariant *variant; + + g_return_val_if_fail (MM_IS_BEARER (self), NULL); + + variant = mm_gdbus_bearer_dup_properties (MM_GDBUS_BEARER (self)); + properties = create_properties_struct (variant); + g_variant_unref (variant); + + return properties; +} + /** * mm_bearer_connect: * @self: A #MMBearer. |