gvfs r1090 - in trunk: . daemon



Author: alexl
Date: Thu Jan 10 14:04:49 2008
New Revision: 1090
URL: http://svn.gnome.org/viewvc/gvfs?rev=1090&view=rev

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

        * daemon/gvfsmonitor.c:
	Remove freeing of initial ref after delay.

        * daemon/gvfsjobcreatemonitor.[ch]:
	Set the monitor as result here, not only the obj path.
	Nicer and allows better lifetime handling.
	If returning a obj ref, keep the monitor alive for
	some time to allow a subscribe request.
	
        * daemon/gvfsbackendcomputer.c:
        * daemon/gvfsbackendtrash.c:
	Update to the new APIs



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

Modified: trunk/daemon/gvfsbackendcomputer.c
==============================================================================
--- trunk/daemon/gvfsbackendcomputer.c	(original)
+++ trunk/daemon/gvfsbackendcomputer.c	Thu Jan 10 14:04:49 2008
@@ -712,8 +712,8 @@
       return TRUE;
     }
   
-  g_vfs_job_create_monitor_set_obj_path (job,
-                                         g_vfs_monitor_get_object_path (computer_backend->root_monitor));
+  g_vfs_job_create_monitor_set_monitor (job,
+                                        computer_backend->root_monitor);
   g_vfs_job_succeeded (G_VFS_JOB (job));
 
   return TRUE;

Modified: trunk/daemon/gvfsbackendtrash.c
==============================================================================
--- trunk/daemon/gvfsbackendtrash.c	(original)
+++ trunk/daemon/gvfsbackendtrash.c	Thu Jan 10 14:04:49 2008
@@ -1532,7 +1532,7 @@
       created = TRUE;
     }
   
-  vfs_monitor = g_object_ref (trash_backend->vfs_monitor);
+  vfs_monitor = trash_backend->vfs_monitor;
   G_UNLOCK (root_monitor);
   
   if (created)
@@ -1565,8 +1565,8 @@
       /* The trash:/// root */
       vfs_monitor = do_create_root_monitor (backend);
       
-      g_vfs_job_create_monitor_set_obj_path (job,
-                                             g_vfs_monitor_get_object_path (vfs_monitor));
+      g_vfs_job_create_monitor_set_monitor (job,
+                                            vfs_monitor);
       g_vfs_job_succeeded (G_VFS_JOB (job));
       
       g_object_unref (vfs_monitor);
@@ -1595,11 +1595,13 @@
           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_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);
 
-          g_vfs_job_create_monitor_set_obj_path (job,
-                                                 g_vfs_monitor_get_object_path (proxy->vfs_monitor));
+          g_vfs_job_create_monitor_set_monitor (job,
+                                                proxy->vfs_monitor);
+          g_object_unref (proxy->vfs_monitor);
 
           g_vfs_job_succeeded (G_VFS_JOB (job));
         }
@@ -1637,12 +1639,11 @@
       if (trash_backend->file_vfs_monitor == NULL)
         trash_backend->file_vfs_monitor = g_vfs_monitor_new (g_vfs_backend_get_daemon (backend));
 
-      vfs_monitor = g_object_ref (trash_backend->file_vfs_monitor);
+      vfs_monitor = trash_backend->file_vfs_monitor;
       g_object_add_weak_pointer (G_OBJECT (vfs_monitor), (gpointer *)&trash_backend->file_vfs_monitor);
       G_UNLOCK (root_monitor);
       
-      g_vfs_job_create_monitor_set_obj_path (job,
-                                             g_vfs_monitor_get_object_path (vfs_monitor));
+      g_vfs_job_create_monitor_set_monitor (job, vfs_monitor);
       g_vfs_job_succeeded (G_VFS_JOB (job));
       g_object_unref (vfs_monitor);
     }
@@ -1673,8 +1674,9 @@
           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);
 
-          g_vfs_job_create_monitor_set_obj_path (job,
-                                                 g_vfs_monitor_get_object_path (proxy->vfs_monitor));
+          g_vfs_job_create_monitor_set_monitor (job,
+                                                proxy->vfs_monitor);
+          g_object_unref (proxy->vfs_monitor);
 
           g_vfs_job_succeeded (G_VFS_JOB (job));
         }

Modified: trunk/daemon/gvfsjobcreatemonitor.c
==============================================================================
--- trunk/daemon/gvfsjobcreatemonitor.c	(original)
+++ trunk/daemon/gvfsjobcreatemonitor.c	Thu Jan 10 14:04:49 2008
@@ -50,7 +50,8 @@
   job = G_VFS_JOB_CREATE_MONITOR (object);
   
   g_free (job->filename);
-  g_free (job->object_path);
+  if (job->monitor)
+    g_object_unref (job->monitor);
   
   if (G_OBJECT_CLASS (g_vfs_job_create_monitor_parent_class)->finalize)
     (*G_OBJECT_CLASS (g_vfs_job_create_monitor_parent_class)->finalize) (object);
@@ -120,10 +121,10 @@
 }
 
 void
-g_vfs_job_create_monitor_set_obj_path (GVfsJobCreateMonitor *job,
-				       const char           *object_path)
+g_vfs_job_create_monitor_set_monitor (GVfsJobCreateMonitor *job,
+				      GVfsMonitor *monitor)
 {
-  job->object_path = g_strdup (object_path);
+  job->monitor = g_object_ref (monitor);
 }
 
 static void
@@ -201,6 +202,19 @@
     }
 }
 
+static gboolean
+unref_monitor_timeout (gpointer data)
+{
+  GVfsMonitor *monitor = data;
+
+  /* Unref the refcount for the VfsMonitor that we returned.
+     If we didn't get an initial subscriber this is where we free the
+     monitor */
+  g_object_unref (monitor);
+  
+  return FALSE;
+}
+
 /* Might be called on an i/o thread */
 static DBusMessage *
 create_reply (GVfsJob *job,
@@ -210,12 +224,22 @@
   GVfsJobCreateMonitor *op_job = G_VFS_JOB_CREATE_MONITOR (job);
   DBusMessage *reply;
   DBusMessageIter iter;
+  const char *obj_path;
 
   reply = dbus_message_new_method_return (message);
+
+  /* Keep the monitor alive for at least 5 seconds
+     to allow for a subscribe call to come in and bump
+     the refcount */
+  g_object_ref (op_job->monitor);
+  g_timeout_add (5000,
+		 unref_monitor_timeout,
+		 op_job->monitor);
   
+  obj_path = g_vfs_monitor_get_object_path (op_job->monitor);
   dbus_message_iter_init_append (reply, &iter);
   _g_dbus_message_append_args (reply,
-			       DBUS_TYPE_OBJECT_PATH, &op_job->object_path,
+			       DBUS_TYPE_OBJECT_PATH, &obj_path,
 			       0);
   
   return reply;

Modified: trunk/daemon/gvfsjobcreatemonitor.h
==============================================================================
--- trunk/daemon/gvfsjobcreatemonitor.h	(original)
+++ trunk/daemon/gvfsjobcreatemonitor.h	Thu Jan 10 14:04:49 2008
@@ -27,6 +27,7 @@
 #include <gvfsjob.h>
 #include <gvfsjobdbus.h>
 #include <gvfsbackend.h>
+#include <gvfsmonitor.h>
 
 G_BEGIN_DECLS
 
@@ -47,8 +48,8 @@
   GVfsBackend *backend;
   char *filename;
   GFileMonitorFlags flags;
-  
-  char *object_path;
+
+  GVfsMonitor *monitor;
 };
 
 struct _GVfsJobCreateMonitorClass
@@ -58,12 +59,12 @@
 
 GType g_vfs_job_create_monitor_get_type (void) G_GNUC_CONST;
 
-GVfsJob *g_vfs_job_create_monitor_new          (DBusConnection       *connection,
-						DBusMessage          *message,
-						GVfsBackend          *backend,
-						gboolean              is_directory);
-void     g_vfs_job_create_monitor_set_obj_path (GVfsJobCreateMonitor *job,
-						const char           *object_path);
+GVfsJob *g_vfs_job_create_monitor_new         (DBusConnection       *connection,
+					       DBusMessage          *message,
+					       GVfsBackend          *backend,
+					       gboolean              is_directory);
+void     g_vfs_job_create_monitor_set_monitor (GVfsJobCreateMonitor *job,
+					       GVfsMonitor          *monitor);
 
 G_END_DECLS
 

Modified: trunk/daemon/gvfsmonitor.c
==============================================================================
--- trunk/daemon/gvfsmonitor.c	(original)
+++ trunk/daemon/gvfsmonitor.c	Thu Jan 10 14:04:49 2008
@@ -105,20 +105,6 @@
   monitor->priv->object_path = g_strdup_printf (OBJ_PATH_PREFIX"%d", id);
 }
 
-static gboolean
-vfs_monitor_initial_unref (gpointer data)
-{
-  GVfsMonitor *monitor = data;
-
-  /* Unref the initial refcount for the VfsMonitor. If we
-     didn't get an initial subscriber this is where we free the
-     monitor */
-     
-  g_object_unref (monitor);
-  
-  return FALSE;
-}
-
 static DBusHandlerResult
 vfs_monitor_message_callback (DBusConnection  *connection,
 			      DBusMessage     *message,
@@ -223,10 +209,6 @@
 			      vfs_monitor_message_callback,
 			      monitor);
 
-  g_timeout_add (5000,
-		 vfs_monitor_initial_unref,
-		 monitor);
-
   return monitor;  
 }
 
@@ -236,7 +218,6 @@
   return monitor->priv->object_path;
 }
 
-
 void
 g_vfs_monitor_emit_event (GVfsMonitor       *monitor,
 			  GFileMonitorEvent  event_type,



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