[network-manager-applet/nma-0-9-8] bluetooth: more gracefully handle new and old ModemManager



commit 06bad12e17cbeda5af8de38765c171aa7fa35ab6
Author: Dan Williams <dcbw redhat com>
Date:   Wed Feb 20 11:06:05 2013 -0600

    bluetooth: more gracefully handle new and old ModemManager
    
    Calling dun_error() is a terminal condition and the operation
    should not proceed after that.  So only call dun_error() when
    setting up our D-Bus service proxies if both new and old MM
    can't be contacted.
    
    Previously when the plugin was built with MM1 support, but MM1
    wasn't running, an error message would be displayed but the
    DUN setup would continue to run.

 src/gnome-bluetooth/nma-bt-device.c |   50 ++++++++++++++++++++++++++--------
 1 files changed, 38 insertions(+), 12 deletions(-)
---
diff --git a/src/gnome-bluetooth/nma-bt-device.c b/src/gnome-bluetooth/nma-bt-device.c
index 968dc89..512c5cc 100644
--- a/src/gnome-bluetooth/nma-bt-device.c
+++ b/src/gnome-bluetooth/nma-bt-device.c
@@ -781,10 +781,35 @@ dun_timeout_cb (gpointer user_data)
        return FALSE;
 }
 
+static gboolean
+_name_has_owner (DBusGConnection *bus, const char *name)
+{
+       DBusGProxy *proxy;
+       gboolean has_owner = FALSE;
+
+       g_return_val_if_fail (name != NULL, FALSE);
+
+       proxy = dbus_g_proxy_new_for_name (bus,
+                                          "org.freedesktop.DBus",
+                                          "/org/freedesktop/DBus",
+                                          "org.freedesktop.DBus");
+       g_assert (proxy);
+
+       dbus_g_proxy_call (proxy, "NameHasOwner", NULL,
+                          G_TYPE_STRING, name,
+                          G_TYPE_INVALID,
+                          G_TYPE_BOOLEAN, &has_owner,
+                          G_TYPE_INVALID);
+       g_object_unref (proxy);
+
+       return has_owner;
+}
+
 static void
 dun_start (NmaBtDevice *self)
 {
        NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self);
+       gboolean have_mm = FALSE, have_mm1 = TRUE;
 
        g_message ("%s: starting DUN device discovery...", __func__);
 
@@ -796,6 +821,7 @@ dun_start (NmaBtDevice *self)
                                                    MM_PATH,
                                                    MM_INTERFACE);
        g_assert (priv->mm_proxy);
+       have_mm = _name_has_owner (priv->bus, MM_SERVICE);
 
        dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED,
                                           G_TYPE_NONE,
@@ -816,21 +842,13 @@ dun_start (NmaBtDevice *self)
 #if WITH_MODEM_MANAGER_1
        /* ModemManager1 stuff */
        {
-               GError *error = NULL;
-
-               priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
-               if (!priv->dbus_connection) {
-                       dun_error (self, __func__, error, _("error getting bus connection"));
-                       g_error_free (error);
-               } else {
+               priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
+               if (priv->dbus_connection) {
                        priv->modem_manager_1 = mm_manager_new_sync (priv->dbus_connection,
                                                                     G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
                                                                     NULL,
-                                                                    &error);
-                       if (!priv->modem_manager_1) {
-                               dun_error (self, __func__, error, "error creating modem manager");
-                               g_error_free (error);
-                       } else {
+                                                                    NULL);
+                       if (priv->modem_manager_1) {
                                g_signal_connect (priv->modem_manager_1,
                                                  "object-added",
                                                  G_CALLBACK (modem_object_added),
@@ -841,9 +859,17 @@ dun_start (NmaBtDevice *self)
                                                  self);
                        }
                }
+
+               have_mm1 = !!priv->modem_manager_1;
        }
 #endif
 
+       /* Ensure at least one of ModemManager or ModemManager1 are around */
+       if (!have_mm && !have_mm1) {
+               dun_error (self, __func__, NULL, _("ModemManager is not running"));
+               return;
+       }
+
        /* Bluez */
        priv->dun_proxy = dbus_g_proxy_new_for_name (priv->bus,
                                                     BLUEZ_SERVICE,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]