gvfs r1091 - in trunk: . daemon



Author: alexl
Date: Thu Jan 10 15:00:31 2008
New Revision: 1091
URL: http://svn.gnome.org/viewvc/gvfs?rev=1091&view=rev

Log:
2008-01-10  Alexander Larsson  <alexl redhat com>

        * daemon/gvfsbackend.h:
        * daemon/gvfsmonitor.[ch]:
        * daemon/gvfsbackendcomputer.c:
        * daemon/gvfsbackendtrash.c:
	Make GVfsMonitor API simpler for users.



Modified:
   trunk/ChangeLog
   trunk/daemon/gvfsbackend.h
   trunk/daemon/gvfsbackendcomputer.c
   trunk/daemon/gvfsbackendtrash.c
   trunk/daemon/gvfsmonitor.c
   trunk/daemon/gvfsmonitor.h

Modified: trunk/daemon/gvfsbackend.h
==============================================================================
--- trunk/daemon/gvfsbackend.h	(original)
+++ trunk/daemon/gvfsbackend.h	Thu Jan 10 15:00:31 2008
@@ -376,7 +376,7 @@
 							  gpointer            user_data);
 const char *g_vfs_backend_get_backend_type               (GVfsBackend        *backend);
 const char *g_vfs_backend_get_display_name               (GVfsBackend        *backend);
-const char *g_vfs_backend_get_stable_name                  (GVfsBackend        *backend);
+const char *g_vfs_backend_get_stable_name                (GVfsBackend        *backend);
 const char *g_vfs_backend_get_icon_name                  (GVfsBackend        *backend);
 GMountSpec *g_vfs_backend_get_mount_spec                 (GVfsBackend        *backend);
 GVfsDaemon *g_vfs_backend_get_daemon                     (GVfsBackend        *backend);

Modified: trunk/daemon/gvfsbackendcomputer.c
==============================================================================
--- trunk/daemon/gvfsbackendcomputer.c	(original)
+++ trunk/daemon/gvfsbackendcomputer.c	Thu Jan 10 15:00:31 2008
@@ -264,8 +264,8 @@
               filename = g_strconcat ("/", new->filename, NULL);
               g_vfs_monitor_emit_event (backend->root_monitor,
                                         G_FILE_MONITOR_EVENT_CHANGED,
-                                        backend->mount_spec, filename,
-                                        NULL, NULL);
+                                        filename,
+                                        NULL);
               g_free (filename);
             }
           
@@ -277,8 +277,8 @@
           filename = g_strconcat ("/", old->filename, NULL);
           g_vfs_monitor_emit_event (backend->root_monitor,
                                     G_FILE_MONITOR_EVENT_DELETED,
-                                    backend->mount_spec, filename,
-                                    NULL, NULL);
+                                    filename,
+                                    NULL);
           g_free (filename);
           oldl = oldl->next;
         }
@@ -287,8 +287,8 @@
           filename = g_strconcat ("/", new->filename, NULL);
           g_vfs_monitor_emit_event (backend->root_monitor,
                                     G_FILE_MONITOR_EVENT_CREATED,
-                                    backend->mount_spec, filename,
-                                    NULL, NULL);
+                                    filename,
+                                    NULL);
           g_free (filename);
           newl = newl->next;
         }
@@ -518,7 +518,7 @@
                            backend,
                            NULL, 0);
 
-  computer_backend->root_monitor = g_vfs_monitor_new (g_vfs_backend_get_daemon (backend));
+  computer_backend->root_monitor = g_vfs_monitor_new (backend);
   
   recompute_files (computer_backend);
 

Modified: trunk/daemon/gvfsbackendtrash.c
==============================================================================
--- trunk/daemon/gvfsbackendtrash.c	(original)
+++ trunk/daemon/gvfsbackendtrash.c	Thu Jan 10 15:00:31 2008
@@ -826,8 +826,8 @@
           name = g_strconcat ("/", l->data, NULL);
           g_vfs_monitor_emit_event (vfs_monitor,
                                     G_FILE_MONITOR_EVENT_DELETED,
-                                    trash_backend->mount_spec, name,
-                                    NULL, NULL);
+                                    name,
+                                    NULL);
           g_free (name);
         }
       g_list_free (removed);
@@ -837,8 +837,8 @@
           name = g_strconcat ("/", l->data, NULL);
           g_vfs_monitor_emit_event (vfs_monitor,
                                     G_FILE_MONITOR_EVENT_CREATED,
-                                    trash_backend->mount_spec, name,
-                                    NULL, NULL);
+                                    name,
+                                    NULL);
           g_free (name);
         }
       g_list_free (added);
@@ -849,8 +849,8 @@
           /* "fullness" changed => icon change */
           g_vfs_monitor_emit_event (vfs_monitor,
                                     G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED,
-                                    trash_backend->mount_spec, "/",
-                                    NULL, NULL);
+                                    "/",
+                                    NULL);
         }
       
       g_object_unref (vfs_monitor);
@@ -864,8 +864,8 @@
           /* "fullness" changed => icon change */
           g_vfs_monitor_emit_event (file_vfs_monitor,
                                     G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED,
-                                    trash_backend->mount_spec, "/",
-                                    NULL, NULL);
+                                    "/",
+                                    NULL);
         }
       
       g_object_unref (file_vfs_monitor);
@@ -1298,7 +1298,6 @@
   GObject *monitor;
   GFile *base_file;
   char *base_path;
-  GMountSpec *mount_spec;
 } MonitorProxy;
 
 static void
@@ -1306,7 +1305,6 @@
 {
   g_object_unref (proxy->monitor);
   g_object_unref (proxy->base_file);
-  g_mount_spec_unref (proxy->mount_spec);
   g_free (proxy->base_path);
   g_free (proxy);
 }
@@ -1336,29 +1334,20 @@
                GFileMonitorEvent event_type,
                MonitorProxy *proxy)
 {
-  GMountSpec *file_spec;
   char *file_path;
-  GMountSpec *other_file_spec;
   char *other_file_path;
 
-  file_spec = proxy->mount_spec;
   file_path = proxy_get_trash_path (proxy, file);
 
   if (other_file)
-    {
-      other_file_spec = proxy->mount_spec;
-      other_file_path = proxy_get_trash_path (proxy, other_file);
-    }
+    other_file_path = proxy_get_trash_path (proxy, other_file);
   else
-    {
-      other_file_spec = NULL;
-      other_file_path = NULL;
-    }
+    other_file_path = NULL;
   
   g_vfs_monitor_emit_event (proxy->vfs_monitor,
                             event_type,
-                            file_spec, file_path,
-                            other_file_spec, other_file_path);
+                            file_path,
+                            other_file_path);
 
   g_free (file_path);
   g_free (other_file_path);
@@ -1528,7 +1517,7 @@
   G_LOCK (root_monitor);
   if (trash_backend->vfs_monitor == NULL)
     {
-      trash_backend->vfs_monitor = g_vfs_monitor_new (g_vfs_backend_get_daemon (backend));
+      trash_backend->vfs_monitor = g_vfs_monitor_new (backend);
       created = TRUE;
     }
   
@@ -1589,11 +1578,10 @@
       if (monitor)
         {
           proxy = g_new0 (MonitorProxy, 1); 
-          proxy->vfs_monitor = g_vfs_monitor_new (g_vfs_backend_get_daemon (backend));
+          proxy->vfs_monitor = g_vfs_monitor_new (backend);
           proxy->monitor = G_OBJECT (monitor);
           proxy->base_path = g_strdup (filename);
           proxy->base_file = g_object_ref (file);
-          proxy->mount_spec = g_mount_spec_ref (G_VFS_BACKEND_TRASH (backend)->mount_spec);
           
           g_object_set_data_full (G_OBJECT (proxy->vfs_monitor), "monitor-proxy", proxy,
                                   (GDestroyNotify) monitor_proxy_free);
@@ -1637,7 +1625,7 @@
       /* The trash:/// root */
       G_LOCK (root_monitor);
       if (trash_backend->file_vfs_monitor == NULL)
-        trash_backend->file_vfs_monitor = g_vfs_monitor_new (g_vfs_backend_get_daemon (backend));
+        trash_backend->file_vfs_monitor = g_vfs_monitor_new (backend);
 
       vfs_monitor = trash_backend->file_vfs_monitor;
       g_object_add_weak_pointer (G_OBJECT (vfs_monitor), (gpointer *)&trash_backend->file_vfs_monitor);
@@ -1665,11 +1653,10 @@
       if (monitor)
         {
           proxy = g_new0 (MonitorProxy, 1); 
-          proxy->vfs_monitor = g_vfs_monitor_new (g_vfs_backend_get_daemon (backend));
+          proxy->vfs_monitor = g_vfs_monitor_new (backend);
           proxy->monitor = G_OBJECT (monitor);
           proxy->base_path = g_strdup (filename);
           proxy->base_file = g_object_ref (file);
-          proxy->mount_spec = g_mount_spec_ref (G_VFS_BACKEND_TRASH (backend)->mount_spec);
           
           g_object_set_data_full (G_OBJECT (proxy->vfs_monitor), "monitor-proxy", proxy, (GDestroyNotify) monitor_proxy_free);
           g_signal_connect (monitor, "changed", G_CALLBACK (proxy_changed), proxy);

Modified: trunk/daemon/gvfsmonitor.c
==============================================================================
--- trunk/daemon/gvfsmonitor.c	(original)
+++ trunk/daemon/gvfsmonitor.c	Thu Jan 10 15:00:31 2008
@@ -47,6 +47,9 @@
 /* TODO: Real P_() */
 #define P_(_x) (_x)
 
+
+/* TODO: Handle a connection dying and unregister its subscription */
+
 typedef struct {
   DBusConnection *connection;
   char *id;
@@ -56,6 +59,8 @@
 struct _GVfsMonitorPrivate
 {
   GVfsDaemon *daemon;
+  GVfsBackend *backend; /* weak ref */
+  GMountSpec *mount_spec;
   char *object_path;
   GList *subscribers;
 };
@@ -65,6 +70,25 @@
 
 G_DEFINE_TYPE (GVfsMonitor, g_vfs_monitor, G_TYPE_OBJECT)
 
+static void unsubscribe (GVfsMonitor *monitor,
+			 Subscriber *subscriber);
+
+static void
+backend_died (GVfsMonitor *monitor,
+	      GObject     *old_backend)
+{
+  Subscriber *subscriber;
+  GList *l;
+  
+  monitor->priv->backend = NULL;
+
+  while (monitor->priv->subscribers != NULL)
+    {
+      subscriber = l->data;
+      unsubscribe (monitor, subscriber);
+    }
+}
+
 static void
 g_vfs_monitor_finalize (GObject *object)
 {
@@ -72,10 +96,17 @@
 
   monitor = G_VFS_MONITOR (object);
 
+  if (monitor->priv->backend)
+    g_object_weak_unref (G_OBJECT (monitor->priv->backend),
+			 (GWeakNotify)backend_died,
+			 monitor);
+
   g_vfs_daemon_unregister_path (monitor->priv->daemon, monitor->priv->object_path);
+  g_object_unref (monitor->priv->daemon);
+
+  g_mount_spec_unref (monitor->priv->mount_spec);
   
   g_free (monitor->priv->object_path);
-  g_object_unref (monitor->priv->daemon);
   
   if (G_OBJECT_CLASS (g_vfs_monitor_parent_class)->finalize)
     (*G_OBJECT_CLASS (g_vfs_monitor_parent_class)->finalize) (object);
@@ -99,12 +130,38 @@
   monitor->priv = G_TYPE_INSTANCE_GET_PRIVATE (monitor,
 					       G_TYPE_VFS_MONITOR,
 					       GVfsMonitorPrivate);
-
   
   id = g_atomic_int_exchange_and_add (&path_counter, 1);
   monitor->priv->object_path = g_strdup_printf (OBJ_PATH_PREFIX"%d", id);
 }
 
+static gboolean
+matches_subscriber (Subscriber *subscriber,
+		    DBusConnection *connection,
+		    const char *object_path,
+		    const char *dbus_id)
+{
+  return (subscriber->connection == connection &&
+	  strcmp (subscriber->object_path, object_path) == 0 &&
+	  ((dbus_id == NULL && subscriber->id == NULL) ||
+	   (dbus_id != NULL && subscriber->id != NULL &&
+	    strcmp (subscriber->id, dbus_id) == 0)));
+}
+
+static void
+unsubscribe (GVfsMonitor *monitor,
+	     Subscriber *subscriber)
+{
+  dbus_connection_unref (subscriber->connection);
+  g_free (subscriber->id);
+  g_free (subscriber->object_path);
+  g_free (subscriber);
+  g_object_unref (monitor);
+  
+  monitor->priv->subscribers = g_list_remove (monitor->priv->subscribers, subscriber);
+  
+}
+
 static DBusHandlerResult
 vfs_monitor_message_callback (DBusConnection  *connection,
 			      DBusMessage     *message,
@@ -161,8 +218,6 @@
 	  dbus_error_free (&derror);
 	  
 	  dbus_connection_send (connection, reply, NULL);
-
-	  /* TODO: Handle connection dying and unregister subscription */
 	}
       else
 	{
@@ -170,19 +225,12 @@
 	    {
 	      subscriber = l->data;
 
-	      if (subscriber->connection == connection &&
-		  strcmp (subscriber->object_path, object_path) == 0 &&
-		  ((dbus_message_get_sender (message) == NULL && subscriber->id == NULL) ||
-		   (dbus_message_get_sender (message) != NULL && subscriber->id != NULL &&
-		    strcmp (subscriber->id, dbus_message_get_sender (message)) == 0)))
+	      if (matches_subscriber (subscriber,
+				      connection,
+				      object_path,
+				      dbus_message_get_sender (message)))
 		{
-		  dbus_connection_unref (subscriber->connection);
-		  g_free (subscriber->id);
-		  g_free (subscriber->object_path);
-		  g_free (subscriber);
-		  g_object_unref (monitor);
-
-		  monitor->priv->subscribers = g_list_delete_link (monitor->priv->subscribers, l);
+		  unsubscribe (monitor, subscriber);
 		  break;
 		}
 	    }
@@ -196,15 +244,23 @@
 }
 
 GVfsMonitor *
-g_vfs_monitor_new (GVfsDaemon *daemon)
+g_vfs_monitor_new (GVfsBackend *backend)
 {
   GVfsMonitor *monitor;
+  GVfsDaemon *daemon;
   
   monitor = g_object_new (G_TYPE_VFS_MONITOR, NULL);
 
-  monitor->priv->daemon = g_object_ref (daemon);
+  monitor->priv->backend = backend;
+
+  g_object_weak_ref (G_OBJECT (backend),
+		     (GWeakNotify)backend_died,
+		     monitor);
+  
+  monitor->priv->daemon = g_object_ref (g_vfs_backend_get_daemon (backend));
+  monitor->priv->mount_spec = g_mount_spec_ref (g_vfs_backend_get_mount_spec (backend));
 
-  g_vfs_daemon_register_path (daemon,
+  g_vfs_daemon_register_path (monitor->priv->daemon,
 			      monitor->priv->object_path,
 			      vfs_monitor_message_callback,
 			      monitor);
@@ -221,9 +277,7 @@
 void
 g_vfs_monitor_emit_event (GVfsMonitor       *monitor,
 			  GFileMonitorEvent  event_type,
-			  GMountSpec        *file_spec,
 			  const char        *file_path,
-			  GMountSpec        *other_file_spec,
 			  const char        *other_file_path)
 {
   GList *l;
@@ -247,12 +301,12 @@
       dbus_message_iter_append_basic (&iter,
 				      DBUS_TYPE_UINT32,
 				      &event_type_dbus);
-      g_mount_spec_to_dbus (&iter, file_spec);
+      g_mount_spec_to_dbus (&iter, monitor->priv->mount_spec);
       _g_dbus_message_iter_append_cstring (&iter, file_path);
 
-      if (other_file_spec && other_file_path)
+      if (other_file_path)
 	{
-	  g_mount_spec_to_dbus (&iter, other_file_spec);
+	  g_mount_spec_to_dbus (&iter, monitor->priv->mount_spec);
 	  _g_dbus_message_iter_append_cstring (&iter, other_file_path);
 	}
 

Modified: trunk/daemon/gvfsmonitor.h
==============================================================================
--- trunk/daemon/gvfsmonitor.h	(original)
+++ trunk/daemon/gvfsmonitor.h	Thu Jan 10 15:00:31 2008
@@ -25,8 +25,7 @@
 
 #include <glib-object.h>
 #include <gio/gio.h>
-#include <gmountspec.h>
-#include <gvfsdaemon.h>
+#include <gvfsbackend.h>
 
 G_BEGIN_DECLS
 
@@ -56,13 +55,11 @@
 
 GType g_vfs_monitor_get_type (void) G_GNUC_CONST;
 
-GVfsMonitor* g_vfs_monitor_new             (GVfsDaemon        *daemon);
+GVfsMonitor* g_vfs_monitor_new             (GVfsBackend       *backend);
 const char * g_vfs_monitor_get_object_path (GVfsMonitor       *monitor);
 void         g_vfs_monitor_emit_event      (GVfsMonitor       *monitor,
 					    GFileMonitorEvent  event_type,
-					    GMountSpec        *file_spec,
 					    const char        *file_path,
-					    GMountSpec        *other_file_spec,
 					    const char        *other_file_path);
 
 G_END_DECLS



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