Use unregister facility in dbus-glib 0.82 and misc life-cycle fixes
authorDavid Zeuthen <davidz@redhat.com>
Wed, 28 Oct 2009 02:23:33 +0000 (22:23 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 28 Oct 2009 02:23:33 +0000 (22:23 -0400)
configure.ac
src/devkit-disks-daemon.c
src/devkit-disks-device.c

index 6953405..48d3320 100644 (file)
@@ -136,7 +136,7 @@ PKG_CHECK_MODULES(DBUS, [dbus-1 >= 1.0])
 AC_SUBST(DBUS_CFLAGS)
 AC_SUBST(DBUS_LIBS)
 
-PKG_CHECK_MODULES(DBUS_GLIB, [dbus-glib-1 >= 0.74])
+PKG_CHECK_MODULES(DBUS_GLIB, [dbus-glib-1 >= 0.82])
 AC_SUBST(DBUS_GLIB_CFLAGS)
 AC_SUBST(DBUS_GLIB_LIBS)
 
index 746161a..6acd387 100644 (file)
@@ -636,6 +636,8 @@ device_changed (DevkitDisksDaemon *daemon, GUdevDevice *d, gboolean synthesized)
         native_path = g_udev_device_get_sysfs_path (d);
         device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
         if (device != NULL) {
+                gboolean keep_device;
+
                 g_print ("**** CHANGING %s\n", native_path);
 
                 /* The device file (udev rules) and/or sysfs path ('move' uevent) may actually change so
@@ -647,24 +649,29 @@ device_changed (DevkitDisksDaemon *daemon, GUdevDevice *d, gboolean synthesized)
                 g_warn_if_fail (g_hash_table_remove (daemon->priv->map_device_file_to_device,
                                                      device->priv->device_file));
 
-                if (!devkit_disks_device_changed (device, d, synthesized)) {
+                keep_device = devkit_disks_device_changed (device, d, synthesized);
+
+                g_assert (devkit_disks_device_local_get_device_file (device) != NULL);
+                g_assert (devkit_disks_device_local_get_native_path (device) != NULL);
+                g_assert (g_strcmp0 (native_path, devkit_disks_device_local_get_native_path (device)) == 0);
+
+                /* now add the things back to the global hashtables - it's important that we
+                 * do this *before* calling device_remove() - otherwise it will never remove
+                 * the device
+                 */
+                g_hash_table_insert (daemon->priv->map_device_file_to_device,
+                                     g_strdup (devkit_disks_device_local_get_device_file (device)),
+                                     g_object_ref (device));
+                g_hash_table_insert (daemon->priv->map_native_path_to_device,
+                                     g_strdup (devkit_disks_device_local_get_native_path (device)),
+                                     g_object_ref (device));
+
+                if (!keep_device) {
                         g_print ("**** CHANGE TRIGGERED REMOVE %s\n", native_path);
                         device_remove (daemon, d);
                 } else {
                         g_print ("**** CHANGED %s\n", native_path);
 
-                        g_assert (devkit_disks_device_local_get_device_file (device) != NULL);
-                        g_assert (devkit_disks_device_local_get_native_path (device) != NULL);
-                        g_assert (g_strcmp0 (native_path, devkit_disks_device_local_get_native_path (device)) == 0);
-
-                        /* now add the things back to the global hashtables */
-                        g_hash_table_insert (daemon->priv->map_device_file_to_device,
-                                             g_strdup (devkit_disks_device_local_get_device_file (device)),
-                                             g_object_ref (device));
-                        g_hash_table_insert (daemon->priv->map_native_path_to_device,
-                                             g_strdup (devkit_disks_device_local_get_native_path (device)),
-                                             g_object_ref (device));
-
                         devkit_disks_daemon_local_update_poller (daemon);
                         devkit_disks_daemon_local_update_spindown (daemon);
                 }
@@ -777,12 +784,12 @@ device_remove (DevkitDisksDaemon *daemon, GUdevDevice *d)
                 g_warn_if_fail (g_hash_table_remove (daemon->priv->map_dev_t_to_device,
                                                      GINT_TO_POINTER (device->priv->dev)));
 
-                devkit_disks_device_removed (device);
-
                 g_print ("**** EMITTING REMOVED for %s\n", device->priv->native_path);
                 g_signal_emit (daemon, signals[DEVICE_REMOVED_SIGNAL], 0,
                                devkit_disks_device_local_get_object_path (device));
 
+                devkit_disks_device_removed (device);
+
                 g_object_unref (device);
 
                 devkit_disks_daemon_local_update_poller (daemon);
index f4fcbfb..584fd02 100644 (file)
@@ -1283,18 +1283,12 @@ register_disks_device (DevkitDisksDevice *device)
 
         device->priv->object_path = compute_object_path (device->priv->native_path);
 
+        /* safety first */
         if (dbus_g_connection_lookup_g_object (device->priv->system_bus_connection,
                                                device->priv->object_path) != NULL) {
-                /* TODO: see devkit_disks_device_removed() for where we want to unregister the object but
-                 * we're missing the API. So do it manually here if we are forced to do so...
-                 */
-
-                g_print ("**** HACK: Wanting to register object at path `%s' but there is already an "
-                         "object there. Using a hack to move it out of the way.\n",
+                g_error ("**** HACK: Wanting to register object at path `%s' but there is already an "
+                         "object there. This is an internal error in the daemon. Aborting.\n",
                          device->priv->object_path);
-
-                dbus_connection_unregister_object_path (dbus_g_connection_get_connection (device->priv->system_bus_connection),
-                                                        device->priv->object_path);
         }
 
         dbus_g_connection_register_g_object (device->priv->system_bus_connection,
@@ -2873,7 +2867,10 @@ update_info_in_idle_cb (gpointer user_data)
 {
         UpdateInfoInIdleData *data = user_data;
 
-        update_info (data->device);
+        /* this indirectly calls update_info and also removes the device
+         * if it wants to be removed (e.g. if update_info() returns FALSE)
+         */
+        devkit_disks_daemon_local_synthesize_changed (data->device->priv->daemon, data->device);
 
         return FALSE; /* remove source */
 }
@@ -3483,11 +3480,10 @@ devkit_disks_device_removed (DevkitDisksDevice *device)
 
         device->priv->removed = TRUE;
 
-        /* TODO: this is in a yet to be released version of dbus-glib, use it when available
-
         dbus_g_connection_unregister_g_object (device->priv->system_bus_connection,
                                                G_OBJECT (device));
-        */
+        g_assert (dbus_g_connection_lookup_g_object (device->priv->system_bus_connection,
+                                                     device->priv->object_path) == NULL);
 
         /* device is now removed; update all slaves and holders */
         for (n = 0; n < device->priv->slaves_objpath->len; n++) {