diff options
Diffstat (limited to 'libmm-glib')
-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 |
7 files changed, 288 insertions, 255 deletions
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, |