diff options
-rw-r--r-- | libmm-common/Makefile.am | 3 | ||||
-rw-r--r-- | libmm-common/libmm-common.h | 1 | ||||
-rw-r--r-- | libmm-common/mm-common-bearer-properties.c | 368 | ||||
-rw-r--r-- | libmm-common/mm-common-bearer-properties.h | 90 | ||||
-rw-r--r-- | libmm-glib/Makefile.am | 2 | ||||
-rw-r--r-- | libmm-glib/mm-bearer-properties.c | 173 | ||||
-rw-r--r-- | libmm-glib/mm-bearer-properties.h | 80 | ||||
-rw-r--r-- | libmm-glib/mm-bearer.c | 169 | ||||
-rw-r--r-- | libmm-glib/mm-bearer.h | 28 | ||||
-rw-r--r-- | libmm-glib/mm-modem.c | 71 | ||||
-rw-r--r-- | libmm-glib/mm-modem.h | 20 |
11 files changed, 750 insertions, 255 deletions
diff --git a/libmm-common/Makefile.am b/libmm-common/Makefile.am index 14766be1..f224b78b 100644 --- a/libmm-common/Makefile.am +++ b/libmm-common/Makefile.am @@ -152,6 +152,7 @@ include_HEADERS = \ mm-enums-types.h \ mm-common-helpers.h \ mm-common-connect-properties.h \ + mm-common-bearer-properties.h \ mm-gdbus-manager.h \ mm-gdbus-modem.h \ mm-gdbus-bearer.h \ @@ -166,6 +167,8 @@ libmm_common_la_SOURCES = \ mm-common-helpers.c \ mm-common-connect-properties.h \ mm-common-connect-properties.c \ + mm-common-bearer-properties.h \ + mm-common-bearer-properties.c \ libmm-common.h libmm_common_la_CPPFLAGS = \ diff --git a/libmm-common/libmm-common.h b/libmm-common/libmm-common.h index 75bbc364..1a50dc6a 100644 --- a/libmm-common/libmm-common.h +++ b/libmm-common/libmm-common.h @@ -27,6 +27,7 @@ #include "mm-enums-types.h" #include "mm-common-helpers.h" #include "mm-common-connect-properties.h" +#include "mm-common-bearer-properties.h" #include "mm-gdbus-manager.h" #include "mm-gdbus-modem.h" #include "mm-gdbus-bearer.h" diff --git a/libmm-common/mm-common-bearer-properties.c b/libmm-common/mm-common-bearer-properties.c new file mode 100644 index 00000000..5f397e21 --- /dev/null +++ b/libmm-common/mm-common-bearer-properties.c @@ -0,0 +1,368 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org> + */ + +#include <string.h> + +#include <libmm-common.h> + +#include "mm-common-bearer-properties.h" + +G_DEFINE_TYPE (MMCommonBearerProperties, mm_common_bearer_properties, G_TYPE_OBJECT); + +#define PROPERTY_APN "apn" +#define PROPERTY_USER "user" +#define PROPERTY_PASSWORD "password" +#define PROPERTY_IP_TYPE "ip-type" +#define PROPERTY_NUMBER "number" +#define PROPERTY_ALLOW_ROAMING "allow-roaming" + +struct _MMCommonBearerPropertiesPrivate { + /* APN */ + gchar *apn; + /* IP type */ + gchar *ip_type; + /* Number */ + gchar *number; + /* User */ + gchar *user; + /* Password */ + gchar *password; + /* Roaming allowance */ + gboolean allow_roaming_set; + gboolean allow_roaming; +}; + +/*****************************************************************************/ + +void +mm_common_bearer_properties_set_apn (MMCommonBearerProperties *self, + const gchar *apn) +{ + g_free (self->priv->apn); + self->priv->apn = g_strdup (apn); +} + +void +mm_common_bearer_properties_set_user (MMCommonBearerProperties *self, + const gchar *user) +{ + g_free (self->priv->user); + self->priv->user = g_strdup (user); +} + +void +mm_common_bearer_properties_set_password (MMCommonBearerProperties *self, + const gchar *password) +{ + g_free (self->priv->password); + self->priv->password = g_strdup (password); +} + +void +mm_common_bearer_properties_set_ip_type (MMCommonBearerProperties *self, + const gchar *ip_type) +{ + g_free (self->priv->ip_type); + self->priv->ip_type = g_strdup (ip_type); +} + +void +mm_common_bearer_properties_set_allow_roaming (MMCommonBearerProperties *self, + gboolean allow_roaming) +{ + self->priv->allow_roaming = allow_roaming; + self->priv->allow_roaming_set = TRUE; +} + +void +mm_common_bearer_properties_set_number (MMCommonBearerProperties *self, + const gchar *number) +{ + g_free (self->priv->number); + self->priv->number = g_strdup (number); +} + +/*****************************************************************************/ + +const gchar * +mm_common_bearer_properties_get_apn (MMCommonBearerProperties *self) +{ + return self->priv->apn; +} + +const gchar * +mm_common_bearer_properties_get_user (MMCommonBearerProperties *self) +{ + return self->priv->user; +} + +const gchar * +mm_common_bearer_properties_get_password (MMCommonBearerProperties *self) +{ + return self->priv->password; +} + +const gchar * +mm_common_bearer_properties_get_ip_type (MMCommonBearerProperties *self) +{ + return self->priv->ip_type; +} + +gboolean +mm_common_bearer_properties_get_allow_roaming (MMCommonBearerProperties *self) +{ + return self->priv->allow_roaming; +} + +const gchar * +mm_common_bearer_properties_get_number (MMCommonBearerProperties *self) +{ + return self->priv->number; +} + +/*****************************************************************************/ + +GVariant * +mm_common_bearer_properties_get_dictionary (MMCommonBearerProperties *self) +{ + GVariantBuilder builder; + + /* We do allow NULL */ + if (!self) + return NULL; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); + + if (self->priv->apn) + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_APN, + g_variant_new_string (self->priv->apn)); + + if (self->priv->user) + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_USER, + g_variant_new_string (self->priv->user)); + + if (self->priv->password) + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_PASSWORD, + g_variant_new_string (self->priv->password)); + + if (self->priv->ip_type) + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_IP_TYPE, + g_variant_new_string (self->priv->ip_type)); + + if (self->priv->number) + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_NUMBER, + g_variant_new_string (self->priv->number)); + + if (self->priv->allow_roaming_set) + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_ALLOW_ROAMING, + g_variant_new_boolean (self->priv->allow_roaming)); + + return g_variant_ref_sink (g_variant_builder_end (&builder)); +} + +/*****************************************************************************/ + +MMCommonBearerProperties * +mm_common_bearer_properties_new_from_string (const gchar *str, + GError **error) +{ + GError *inner_error = NULL; + MMCommonBearerProperties *properties; + gchar **words; + gchar *key; + gchar *value; + guint i; + + properties = mm_common_bearer_properties_new (); + + /* Expecting input as: + * key1=string,key2=true,key3=false... + * */ + + words = g_strsplit_set (str, ",= ", -1); + if (!words) + return properties; + + i = 0; + key = words[i]; + while (key) { + value = words[++i]; + + if (!value) { + inner_error = g_error_new (MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Invalid properties string, no value for key '%s'", + key); + break; + } + + if (g_str_equal (key, PROPERTY_APN)) + mm_common_bearer_properties_set_apn (properties, value); + else if (g_str_equal (key, PROPERTY_USER)) + mm_common_bearer_properties_set_user (properties, value); + else if (g_str_equal (key, PROPERTY_PASSWORD)) + mm_common_bearer_properties_set_password (properties, value); + else if (g_str_equal (key, PROPERTY_IP_TYPE)) + mm_common_bearer_properties_set_ip_type (properties, value); + else if (g_str_equal (key, PROPERTY_ALLOW_ROAMING)) { + gboolean allow_roaming; + + allow_roaming = mm_common_get_boolean_from_string (value, &inner_error); + if (!inner_error) + mm_common_bearer_properties_set_allow_roaming (properties, allow_roaming); + } else if (g_str_equal (key, PROPERTY_NUMBER)) + mm_common_bearer_properties_set_number (properties, value); + else { + inner_error = g_error_new (MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Invalid properties string, unexpected key '%s'", + key); + break; + } + + key = words[++i]; + } + + /* If error, destroy the object */ + if (inner_error) { + g_propagate_error (error, inner_error); + g_object_unref (properties); + properties = NULL; + } + + g_strfreev (words); + return properties; +} + +/*****************************************************************************/ + +MMCommonBearerProperties * +mm_common_bearer_properties_new_from_dictionary (GVariant *dictionary, + GError **error) +{ + GError *inner_error = NULL; + GVariantIter iter; + gchar *key; + GVariant *value; + MMCommonBearerProperties *properties; + + properties = mm_common_bearer_properties_new (); + if (!dictionary) + return properties; + + g_variant_iter_init (&iter, dictionary); + while (!inner_error && + g_variant_iter_next (&iter, "{sv}", &key, &value)) { + if (g_str_equal (key, PROPERTY_APN)) + mm_common_bearer_properties_set_apn ( + properties, + g_variant_get_string (value, NULL)); + else if (g_str_equal (key, PROPERTY_USER)) + mm_common_bearer_properties_set_user ( + properties, + g_variant_get_string (value, NULL)); + else if (g_str_equal (key, PROPERTY_PASSWORD)) + mm_common_bearer_properties_set_password ( + properties, + g_variant_get_string (value, NULL)); + else if (g_str_equal (key, PROPERTY_IP_TYPE)) + mm_common_bearer_properties_set_ip_type ( + properties, + g_variant_get_string (value, NULL)); + else if (g_str_equal (key, PROPERTY_NUMBER)) + mm_common_bearer_properties_set_number ( + properties, + g_variant_get_string (value, NULL)); + else if (g_str_equal (key, PROPERTY_ALLOW_ROAMING)) + mm_common_bearer_properties_set_allow_roaming ( + properties, + g_variant_get_boolean (value)); + else { + /* Set inner error, will stop the loop */ + inner_error = g_error_new (MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Invalid properties dictionary, unexpected key '%s'", + key); + } + + g_free (key); + g_variant_unref (value); + } + + /* If error, destroy the object */ + if (inner_error) { + g_propagate_error (error, inner_error); + g_object_unref (properties); + properties = NULL; + } + + return properties; +} + +/*****************************************************************************/ + +MMCommonBearerProperties * +mm_common_bearer_properties_new (void) +{ + return (MM_COMMON_BEARER_PROPERTIES ( + g_object_new (MM_TYPE_COMMON_BEARER_PROPERTIES, NULL))); +} + +static void +mm_common_bearer_properties_init (MMCommonBearerProperties *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), + MM_TYPE_COMMON_BEARER_PROPERTIES, + MMCommonBearerPropertiesPrivate); + + /* Some defaults */ + self->priv->allow_roaming = TRUE; +} + +static void +finalize (GObject *object) +{ + MMCommonBearerProperties *self = MM_COMMON_BEARER_PROPERTIES (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_common_bearer_properties_parent_class)->finalize (object); +} + +static void +mm_common_bearer_properties_class_init (MMCommonBearerPropertiesClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (MMCommonBearerPropertiesPrivate)); + + object_class->finalize = finalize; +} diff --git a/libmm-common/mm-common-bearer-properties.h b/libmm-common/mm-common-bearer-properties.h new file mode 100644 index 00000000..474446de --- /dev/null +++ b/libmm-common/mm-common-bearer-properties.h @@ -0,0 +1,90 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org> + */ + +#ifndef MM_COMMON_BEARER_PROPERTIES_H +#define MM_COMMON_BEARER_PROPERTIES_H + +#include <ModemManager.h> +#include <glib-object.h> + +G_BEGIN_DECLS + +#define MM_TYPE_COMMON_BEARER_PROPERTIES (mm_common_bearer_properties_get_type ()) +#define MM_COMMON_BEARER_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_COMMON_BEARER_PROPERTIES, MMCommonBearerProperties)) +#define MM_COMMON_BEARER_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_COMMON_BEARER_PROPERTIES, MMCommonBearerPropertiesClass)) +#define MM_IS_COMMON_BEARER_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_COMMON_BEARER_PROPERTIES)) +#define MM_IS_COMMON_BEARER_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_COMMON_BEARER_PROPERTIES)) +#define MM_COMMON_BEARER_PROPERTIES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_COMMON_BEARER_PROPERTIES, MMCommonBearerPropertiesClass)) + +typedef struct _MMCommonBearerProperties MMCommonBearerProperties; +typedef struct _MMCommonBearerPropertiesClass MMCommonBearerPropertiesClass; +typedef struct _MMCommonBearerPropertiesPrivate MMCommonBearerPropertiesPrivate; + +struct _MMCommonBearerProperties { + GObject parent; + MMCommonBearerPropertiesPrivate *priv; +}; + +struct _MMCommonBearerPropertiesClass { + GObjectClass parent; +}; + +GType mm_common_bearer_properties_get_type (void); + +MMCommonBearerProperties *mm_common_bearer_properties_new (void); +MMCommonBearerProperties *mm_common_bearer_properties_new_from_string ( + const gchar *str, + GError **error); +MMCommonBearerProperties *mm_common_bearer_properties_new_from_dictionary ( + GVariant *dictionary, + GError **error); + +void mm_common_bearer_properties_set_apn ( + MMCommonBearerProperties *properties, + const gchar *apn); +void mm_common_bearer_properties_set_user ( + MMCommonBearerProperties *properties, + const gchar *user); +void mm_common_bearer_properties_set_password ( + MMCommonBearerProperties *properties, + const gchar *password); +void mm_common_bearer_properties_set_ip_type ( + MMCommonBearerProperties *properties, + const gchar *ip_type); +void mm_common_bearer_properties_set_allow_roaming ( + MMCommonBearerProperties *properties, + gboolean allow_roaming); +void mm_common_bearer_properties_set_number ( + MMCommonBearerProperties *properties, + const gchar *number); + +const gchar *mm_common_bearer_properties_get_apn ( + MMCommonBearerProperties *properties); +const gchar *mm_common_bearer_properties_get_user ( + MMCommonBearerProperties *properties); +const gchar *mm_common_bearer_properties_get_password ( + MMCommonBearerProperties *properties); +const gchar *mm_common_bearer_properties_get_ip_type ( + MMCommonBearerProperties *properties); +gboolean mm_common_bearer_properties_get_allow_roaming ( + MMCommonBearerProperties *properties); +const gchar *mm_common_bearer_properties_get_number ( + MMCommonBearerProperties *properties); + +GVariant *mm_common_bearer_properties_get_dictionary (MMCommonBearerProperties *self); + +G_END_DECLS + +#endif /* MM_COMMON_BEARER_PROPERTIES_H */ diff --git a/libmm-glib/Makefile.am b/libmm-glib/Makefile.am index 2b58d8cb..bdd4fba5 100644 --- a/libmm-glib/Makefile.am +++ b/libmm-glib/Makefile.am @@ -26,6 +26,8 @@ libmm_glib_la_SOURCES = \ mm-modem-simple.c \ mm-sim.h \ mm-sim.c \ + mm-bearer-properties.h \ + mm-bearer-properties.c \ mm-bearer.h \ mm-bearer.c diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c new file mode 100644 index 00000000..3e9a8f55 --- /dev/null +++ b/libmm-glib/mm-bearer-properties.c @@ -0,0 +1,173 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org> + */ + +#include "mm-bearer-properties.h" + +void +mm_bearer_properties_set_apn (MMBearerProperties *self, + const gchar *apn) +{ + g_return_if_fail (MM_IS_BEARER_PROPERTIES (self)); + + mm_common_bearer_properties_set_apn (self, apn); +} + +void +mm_bearer_properties_set_user (MMBearerProperties *self, + const gchar *user) +{ + g_return_if_fail (MM_IS_BEARER_PROPERTIES (self)); + + mm_common_bearer_properties_set_user (self, user); +} + +void +mm_bearer_properties_set_password (MMBearerProperties *self, + const gchar *password) +{ + g_return_if_fail (MM_IS_BEARER_PROPERTIES (self)); + + mm_common_bearer_properties_set_password (self, password); +} + +void +mm_bearer_properties_set_ip_type (MMBearerProperties *self, + const gchar *ip_type) +{ + g_return_if_fail (MM_IS_BEARER_PROPERTIES (self)); + + mm_common_bearer_properties_set_ip_type (self, ip_type); +} + +void +mm_bearer_properties_set_allow_roaming (MMBearerProperties *self, + gboolean allow_roaming) +{ + g_return_if_fail (MM_IS_BEARER_PROPERTIES (self)); + + mm_common_bearer_properties_set_allow_roaming (self, allow_roaming); +} + +void +mm_bearer_properties_set_number (MMBearerProperties *self, + const gchar *number) +{ + g_return_if_fail (MM_IS_BEARER_PROPERTIES (self)); + + mm_common_bearer_properties_set_number (self, number); +} + +const gchar * +mm_bearer_properties_get_apn (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return mm_common_bearer_properties_get_apn (self); +} + +gchar * +mm_bearer_properties_dup_apn (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return g_strdup (mm_common_bearer_properties_get_apn (self)); +} + +const gchar * +mm_bearer_properties_get_user (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return mm_common_bearer_properties_get_user (self); +} + +gchar * +mm_bearer_properties_dup_user (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return g_strdup (mm_common_bearer_properties_get_user (self)); +} + +const gchar * +mm_bearer_properties_get_password (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return mm_common_bearer_properties_get_password (self); +} + +gchar * +mm_bearer_properties_dup_password (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return g_strdup (mm_common_bearer_properties_get_password (self)); +} + +const gchar * +mm_bearer_properties_get_ip_type (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return mm_common_bearer_properties_get_ip_type (self); +} + +gchar * +mm_bearer_properties_dup_ip_type (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return g_strdup (mm_common_bearer_properties_get_ip_type (self)); +} + +gboolean +mm_bearer_properties_get_allow_roaming (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), FALSE); + + return mm_common_bearer_properties_get_allow_roaming (self); +} + +const gchar * +mm_bearer_properties_get_number (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return mm_common_bearer_properties_get_number (self); +} + +gchar * +mm_bearer_properties_dup_number (MMBearerProperties *self) +{ + g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), NULL); + + return g_strdup (mm_common_bearer_properties_get_number (self)); +} + +/*****************************************************************************/ + +MMBearerProperties * +mm_bearer_properties_new_from_string (const gchar *str, + GError **error) +{ + return mm_common_bearer_properties_new_from_string (str, error); +} + +MMBearerProperties * +mm_bearer_properties_new (void) +{ + return mm_common_bearer_properties_new (); +} diff --git a/libmm-glib/mm-bearer-properties.h b/libmm-glib/mm-bearer-properties.h new file mode 100644 index 00000000..25b9c685 --- /dev/null +++ b/libmm-glib/mm-bearer-properties.h @@ -0,0 +1,80 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org> + */ + +#ifndef MM_BEARER_PROPERTIES_H +#define MM_BEARER_PROPERTIES_H + +#include <ModemManager.h> +#include <glib-object.h> + +#include <libmm-common.h> + +G_BEGIN_DECLS + +typedef MMCommonBearerProperties MMBearerProperties; +#define MM_TYPE_BEARER_PROPERTIES(o) MM_TYPE_COMMON_BEARER_PROPERTIES (o) +#define MM_BEARER_PROPERTIES(o) MM_COMMON_BEARER_PROPERTIES(o) +#define MM_IS_BEARER_PROPERTIES(o) MM_IS_COMMON_BEARER_PROPERTIES(o) + +MMBearerProperties *mm_bearer_properties_new (void); +MMBearerProperties *mm_bearer_properties_new_from_string ( + const gchar *str, + GError **error); + +void mm_bearer_properties_set_apn ( + MMBearerProperties *properties, + const gchar *apn); +void mm_bearer_properties_set_user ( + MMBearerProperties *properties, + const gchar *user); +void mm_bearer_properties_set_password ( + MMBearerProperties *properties, + const gchar *password); +void mm_bearer_properties_set_ip_type ( + MMBearerProperties *properties, + const gchar *ip_type); +void mm_bearer_properties_set_allow_roaming ( + MMBearerProperties *properties, + gboolean allow_roaming); +void mm_bearer_properties_set_number ( + MMBearerProperties *properties, + const gchar *number); + +const gchar *mm_bearer_properties_get_apn ( + MMBearerProperties *properties); +gchar *mm_bearer_properties_dup_apn ( + MMBearerProperties *properties); +const gchar *mm_bearer_properties_get_user ( + MMBearerProperties *properties); +gchar *mm_bearer_properties_dup_user ( + MMBearerProperties *properties); +const gchar *mm_bearer_properties_get_password ( + MMBearerProperties *properties); +gchar *mm_bearer_properties_dup_password ( + MMBearerProperties *properties); +const gchar *mm_bearer_properties_get_ip_type ( + MMBearerProperties *properties); +gchar *mm_bearer_properties_dup_ip_type ( + MMBearerProperties *properties); +gboolean mm_bearer_properties_get_allow_roaming ( + MMBearerProperties *properties); +const gchar *mm_bearer_properties_get_number ( + MMBearerProperties *properties); +gchar *mm_bearer_properties_dup_number ( + MMBearerProperties *properties); + +G_END_DECLS + +#endif /* MM_BEARER_PROPERTIES_H */ diff --git a/libmm-glib/mm-bearer.c b/libmm-glib/mm-bearer.c index 28808584..fede005e 100644 --- a/libmm-glib/mm-bearer.c +++ b/libmm-glib/mm-bearer.c @@ -373,180 +373,25 @@ 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 * +MMBearerProperties * mm_bearer_get_properties (MMBearer *self) { + GError *error = NULL; MMBearerProperties *properties; g_return_val_if_fail (MM_IS_BEARER (self), NULL); - properties = g_object_get_data (G_OBJECT (self), - MM_BEARER_PROPERTIES_DATA); + properties = (mm_common_bearer_properties_new_from_dictionary ( + mm_gdbus_bearer_get_properties (MM_GDBUS_BEARER (self)), + &error)); 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); + g_warning ("Couldn't create properties: '%s'", error->message); + g_error_free (error); } 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. diff --git a/libmm-glib/mm-bearer.h b/libmm-glib/mm-bearer.h index 89c3345d..2ea4a6f5 100644 --- a/libmm-glib/mm-bearer.h +++ b/libmm-glib/mm-bearer.h @@ -24,7 +24,9 @@ #define _MM_BEARER_H_ #include <ModemManager.h> -#include <mm-gdbus-bearer.h> +#include <libmm-common.h> + +#include "mm-bearer-properties.h" G_BEGIN_DECLS @@ -36,14 +38,6 @@ G_BEGIN_DECLS */ typedef struct _MMBearerIpConfig MMBearerIpConfig; -/** - * MMBearerProperties: - * - * Addressing details for assignment to the data interface. - * This is an opaque struct. - */ -typedef struct _MMBearerProperties MMBearerProperties; - typedef MmGdbusBearer MMBearer; #define MM_TYPE_BEARER(o) MM_GDBUS_TYPE_BEARER (o) #define MM_BEARER(o) MM_GDBUS_BEARER(o) @@ -80,21 +74,7 @@ gboolean mm_bearer_disconnect_sync (MMBearer *self, GCancellable *cancellable, GError **error); -const MMBearerProperties *mm_bearer_get_properties (MMBearer *self); -MMBearerProperties *mm_bearer_dup_properties (MMBearer *self); - -const gchar *mm_bearer_properties_get_apn (const MMBearerProperties *properties); -gchar *mm_bearer_properties_dup_apn (const MMBearerProperties *properties); -const gchar *mm_bearer_properties_get_ip_type (const MMBearerProperties *properties); -gchar *mm_bearer_properties_dup_ip_type (const MMBearerProperties *properties); -const gchar *mm_bearer_properties_get_user (const MMBearerProperties *properties); -gchar *mm_bearer_properties_dup_user (const MMBearerProperties *properties); -const gchar *mm_bearer_properties_get_password (const MMBearerProperties *properties); -gchar *mm_bearer_properties_dup_password (const MMBearerProperties *properties); -const gchar *mm_bearer_properties_get_number (const MMBearerProperties *properties); -gchar *mm_bearer_properties_dup_number (const MMBearerProperties *properties); -gboolean mm_bearer_properties_get_allow_roaming (const MMBearerProperties *properties); -void mm_bearer_properties_free (MMBearerProperties *properties); +MMBearerProperties *mm_bearer_get_properties (MMBearer *self); const MMBearerIpConfig *mm_bearer_get_ipv4_config (MMBearer *self); MMBearerIpConfig *mm_bearer_dup_ipv4_config (MMBearer *self); diff --git a/libmm-glib/mm-modem.c b/libmm-glib/mm-modem.c index e6bec310..35ad65cd 100644 --- a/libmm-glib/mm-modem.c +++ b/libmm-glib/mm-modem.c @@ -1110,36 +1110,6 @@ create_bearer_context_complete_and_free (CreateBearerContext *ctx) g_slice_free (CreateBearerContext, ctx); } -static GVariant * -create_bearer_build_properties (const gchar *first_property_name, - va_list var_args) -{ - const gchar *key; - GVariantBuilder builder; - - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - - key = first_property_name; - while (key) { - if (g_str_equal (key, MM_BEARER_PROPERTY_ALLOW_ROAMING)) { - gboolean value; - - value = va_arg (var_args, gboolean); - g_variant_builder_add (&builder, "{sv}", key, g_variant_new_boolean (value)); - } else { - const gchar *value; - - /* If a key with NULL value is given, just ignore it. */ - value = va_arg (var_args, gchar *); - if (value) - g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value)); - } - - key = va_arg (var_args, gchar *); - } - return g_variant_ref_sink (g_variant_builder_end (&builder)); -} - /** * mm_modem_create_bearer_finish: * @self: A #MMModem. @@ -1215,11 +1185,10 @@ modem_create_bearer_ready (MMModem *self, /** * mm_modem_create_bearer: * @self: A #MMModem. + * @properties: A ##MMBearerProperties object with the properties to use. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. * @user_data: User data to pass to @callback. - * @first_property_name: Name of the first property to set. - * @...: Value for the first property, followed optionally by more name/value pairs, followed by %NULL. * * Asynchronously creates a new packet data bearer in the #MMModem. * @@ -1235,15 +1204,13 @@ modem_create_bearer_ready (MMModem *self, */ void mm_modem_create_bearer (MMModem *self, + MMBearerProperties *properties, GCancellable *cancellable, GAsyncReadyCallback callback, - gpointer user_data, - const gchar *first_property_name, - ...) + gpointer user_data) { CreateBearerContext *ctx; - va_list va_args; - GVariant *properties; + GVariant *dictionary; g_return_if_fail (MM_GDBUS_IS_MODEM (self)); @@ -1255,26 +1222,24 @@ mm_modem_create_bearer (MMModem *self, if (cancellable) ctx->cancellable = g_object_ref (cancellable); - va_start (va_args, first_property_name); - properties = create_bearer_build_properties (first_property_name, va_args); + dictionary = (mm_common_bearer_properties_get_dictionary ( + MM_COMMON_BEARER_PROPERTIES (properties))); mm_gdbus_modem_call_create_bearer ( self, - properties, + dictionary, cancellable, (GAsyncReadyCallback)modem_create_bearer_ready, ctx); - g_variant_unref (properties); - va_end (va_args); + g_variant_unref (dictionary); } /** * mm_modem_create_bearer_sync: * @self: A #MMModem. + * @properties: A ##MMBearerProperties object with the properties to use. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL. - * @first_property_name: Name of the first property to set. - * @...: Value for the first property, followed optionally by more name/value pairs, followed by %NULL. * * Synchronously creates a new packet data bearer in the #MMModem. * @@ -1290,23 +1255,20 @@ mm_modem_create_bearer (MMModem *self, */ MMBearer * mm_modem_create_bearer_sync (MMModem *self, + MMBearerProperties *properties, GCancellable *cancellable, - GError **error, - const gchar *first_property_name, - ...) + GError **error) { MMBearer *bearer = NULL; gchar *bearer_path = NULL; - va_list va_args; - GVariant *properties; + GVariant *dictionary; g_return_val_if_fail (MM_GDBUS_IS_MODEM (self), NULL); - va_start (va_args, first_property_name); - properties = create_bearer_build_properties (first_property_name, va_args); - + dictionary = (mm_common_bearer_properties_get_dictionary ( + MM_COMMON_BEARER_PROPERTIES (properties))); mm_gdbus_modem_call_create_bearer_sync (self, - properties, + dictionary, &bearer_path, cancellable, error); @@ -1322,8 +1284,7 @@ mm_modem_create_bearer_sync (MMModem *self, g_free (bearer_path); } - g_variant_unref (properties); - va_end (va_args); + g_variant_unref (dictionary); return bearer; } diff --git a/libmm-glib/mm-modem.h b/libmm-glib/mm-modem.h index 24982196..6029da58 100644 --- a/libmm-glib/mm-modem.h +++ b/libmm-glib/mm-modem.h @@ -24,10 +24,11 @@ #define _MM_MODEM_H_ #include <ModemManager.h> -#include <mm-gdbus-modem.h> +#include <libmm-common.h> #include "mm-sim.h" #include "mm-bearer.h" +#include "mm-bearer-properties.h" G_BEGIN_DECLS @@ -110,27 +111,18 @@ GList *mm_modem_list_bearers_sync (MMModem *self, GCancellable *cancellable, GError **error); -#define MM_BEARER_PROPERTY_APN "apn" /* string */ -#define MM_BEARER_PROPERTY_IP_TYPE "ip-type" /* string */ -#define MM_BEARER_PROPERTY_ALLOW_ROAMING "allow-roaming" /* boolean */ -#define MM_BEARER_PROPERTY_USER "user" /* string */ -#define MM_BEARER_PROPERTY_PASSWORD "password" /* string */ -#define MM_BEARER_PROPERTY_NUMBER "number" /* string */ - void mm_modem_create_bearer (MMModem *self, + MMBearerProperties *properties, GCancellable *cancellable, GAsyncReadyCallback callback, - gpointer user_data, - const gchar *first_property_name, - ...); + gpointer user_data); MMBearer *mm_modem_create_bearer_finish (MMModem *self, GAsyncResult *res, GError **error); MMBearer *mm_modem_create_bearer_sync (MMModem *self, + MMBearerProperties *properties, GCancellable *cancellable, - GError **error, - const gchar *first_property_name, - ...); + GError **error); void mm_modem_delete_bearer (MMModem *self, const gchar *bearer, |