[gvfs/gdbus] gdbus: Watch for metadata daemon going away



commit 79bc298e69d8a4ed6ce69519d96c9388f161a5eb
Author: Tomas Bzatek <tbzatek redhat com>
Date:   Fri May 18 18:08:04 2012 +0200

    gdbus: Watch for metadata daemon going away
    
    ...to reflect actual state of the shared proxy

 client/gdaemonfile.c |   26 ++++++++++++++++++++++++++
 client/gdaemonvfs.c  |   26 ++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/client/gdaemonfile.c b/client/gdaemonfile.c
index 514cf67..5c4f76b 100644
--- a/client/gdaemonfile.c
+++ b/client/gdaemonfile.c
@@ -2209,10 +2209,23 @@ g_daemon_file_query_writable_namespaces (GFile                      *file,
   return list;
 }
 
+static void
+metadata_daemon_vanished (GDBusConnection *connection,
+                          const gchar *name,
+                          gpointer user_data)
+{
+  guint *watcher_id = user_data;
+
+  g_private_replace (&metadata_proxy, NULL);
+  if (*watcher_id > 0)
+    g_bus_unwatch_name (*watcher_id);
+}
+
 static GVfsMetadata *
 get_metadata_proxy (GCancellable *cancellable, GError **error)
 {
   GVfsMetadata *proxy;
+  guint *watcher_id;
 
   proxy = g_private_get (&metadata_proxy);
   if (proxy == NULL)
@@ -2224,6 +2237,19 @@ get_metadata_proxy (GCancellable *cancellable, GError **error)
                                                     cancellable,
                                                     error);
       g_private_replace (&metadata_proxy, proxy);
+
+      if (proxy == NULL)
+        return NULL;
+
+      /* a place in memory to store the returned ID in */
+      watcher_id = g_malloc0 (sizeof (guint));
+      *watcher_id = g_bus_watch_name_on_connection (g_dbus_proxy_get_connection (G_DBUS_PROXY (proxy)),
+                                                    G_VFS_DBUS_METADATA_NAME,
+                                                    G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
+                                                    NULL,
+                                                    metadata_daemon_vanished,
+                                                    watcher_id,
+                                                    g_free);
     }
 
   return proxy;
diff --git a/client/gdaemonvfs.c b/client/gdaemonvfs.c
index cb36771..88a6ab9 100644
--- a/client/gdaemonvfs.c
+++ b/client/gdaemonvfs.c
@@ -1282,10 +1282,23 @@ _g_daemon_vfs_append_metadata_for_set (GVariantBuilder *builder,
   return res;
 }
 
+static void
+metadata_daemon_vanished (GDBusConnection *connection,
+                          const gchar *name,
+                          gpointer user_data)
+{
+  guint *watcher_id = user_data;
+
+  g_private_replace (&metadata_proxy, NULL);
+  if (*watcher_id > 0)
+    g_bus_unwatch_name (*watcher_id);
+}
+
 static GVfsMetadata *
 get_metadata_proxy (GError **error)
 {
   GVfsMetadata *proxy;
+  guint *watcher_id;
 
   proxy = g_private_get (&metadata_proxy);
   if (proxy == NULL)
@@ -1297,6 +1310,19 @@ get_metadata_proxy (GError **error)
                                                     NULL,
                                                     error);
       g_private_replace (&metadata_proxy, proxy);
+
+      if (proxy == NULL)
+        return NULL;
+
+      /* a place in memory to store the returned ID in */
+      watcher_id = g_malloc0 (sizeof (guint));
+      *watcher_id = g_bus_watch_name_on_connection (g_dbus_proxy_get_connection (G_DBUS_PROXY (proxy)),
+                                                    G_VFS_DBUS_METADATA_NAME,
+                                                    G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
+                                                    NULL,
+                                                    metadata_daemon_vanished,
+                                                    watcher_id,
+                                                    g_free);
     }
 
   return proxy;



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