[gvfs] ProxyVolumeMonitor: Load list of installed remote monitors via dbus
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs] ProxyVolumeMonitor: Load list of installed remote monitors via dbus
- Date: Mon, 26 Jan 2015 17:18:29 +0000 (UTC)
commit 2592a8ed424906528e90677ef47b040d2b4d8383
Author: Alexander Larsson <alexl redhat com>
Date: Mon Jan 26 15:59:05 2015 +0100
ProxyVolumeMonitor: Load list of installed remote monitors via dbus
We used to just load the files from this, but that does not work in
a sandboxed environment. For backwards compat we keep loading
the old files if the dbus api is not implemented yet.
common/gvfsmonitorimpl.c | 2 -
common/org.gtk.vfs.xml | 3 ++
daemon/gvfsdaemon.c | 33 +++++++++++++++++++
monitor/proxy/gproxyvolumemonitor.c | 60 ++++++++++++++++++++++++++++++++++-
4 files changed, 95 insertions(+), 3 deletions(-)
---
diff --git a/common/gvfsmonitorimpl.c b/common/gvfsmonitorimpl.c
index 79a5ff7..062379b 100644
--- a/common/gvfsmonitorimpl.c
+++ b/common/gvfsmonitorimpl.c
@@ -44,8 +44,6 @@ GVfsMonitorImplementation *
g_vfs_monitor_implementation_from_dbus (GVariant *value)
{
GVfsMonitorImplementation *impl;
- const gchar *key;
- const gchar *mount_prefix;
GVariantIter *iter;
GVariant *v;
diff --git a/common/org.gtk.vfs.xml b/common/org.gtk.vfs.xml
index f8975d9..5030bb5 100644
--- a/common/org.gtk.vfs.xml
+++ b/common/org.gtk.vfs.xml
@@ -42,6 +42,9 @@
<arg type='o' name='obj_path' direction='in'/>
<arg type='a{sv}' name='reply' direction='out'/>
</method>
+ <method name="ListMonitorImplementations">
+ <arg type='a(ssbia{sv})' name='monitors' direction='out'/>
+ </method>
</interface>
<!--
diff --git a/daemon/gvfsdaemon.c b/daemon/gvfsdaemon.c
index 0187223..f0865b0 100644
--- a/daemon/gvfsdaemon.c
+++ b/daemon/gvfsdaemon.c
@@ -42,6 +42,7 @@
#include <gvfsjobopenforread.h>
#include <gvfsjobopenforwrite.h>
#include <gvfsjobunmount.h>
+#include <gvfsmonitorimpl.h>
enum {
PROP_0
@@ -110,6 +111,9 @@ static gboolean handle_cancel (GVfsDBusDaemon *objec
GDBusMethodInvocation *invocation,
guint arg_serial,
gpointer user_data);
+static gboolean handle_list_monitor_implementations (GVfsDBusDaemon *object,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean daemon_handle_mount (GVfsDBusMountable *object,
GDBusMethodInvocation *invocation,
GVariant *arg_mount_spec,
@@ -264,6 +268,7 @@ g_vfs_daemon_init (GVfsDaemon *daemon)
daemon->daemon_skeleton = gvfs_dbus_daemon_skeleton_new ();
g_signal_connect (daemon->daemon_skeleton, "handle-get-connection", G_CALLBACK (handle_get_connection),
daemon);
g_signal_connect (daemon->daemon_skeleton, "handle-cancel", G_CALLBACK (handle_cancel), daemon);
+ g_signal_connect (daemon->daemon_skeleton, "handle-list-monitor-implementations", G_CALLBACK
(handle_list_monitor_implementations), daemon);
error = NULL;
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (daemon->daemon_skeleton),
@@ -952,6 +957,34 @@ handle_cancel (GVfsDBusDaemon *object,
}
static gboolean
+handle_list_monitor_implementations (GVfsDBusDaemon *object,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ GList *impls, *l;
+ GVariantBuilder builder;
+
+ impls = g_vfs_list_monitor_implementations ();
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+
+ for (l = impls; l != NULL; l = l->next)
+ {
+ GVfsMonitorImplementation *impl = l->data;
+
+ g_variant_builder_add_value (&builder, g_vfs_monitor_implementation_to_dbus (impl));
+ }
+
+ g_list_free_full (impls, (GDestroyNotify)g_vfs_monitor_implementation_free);
+
+ gvfs_dbus_daemon_complete_list_monitor_implementations (object,
+ invocation,
+ g_variant_builder_end (&builder));
+
+ return TRUE;
+}
+
+static gboolean
daemon_handle_mount (GVfsDBusMountable *object,
GDBusMethodInvocation *invocation,
GVariant *arg_mount_spec,
diff --git a/monitor/proxy/gproxyvolumemonitor.c b/monitor/proxy/gproxyvolumemonitor.c
index ee8818c..6f14121 100644
--- a/monitor/proxy/gproxyvolumemonitor.c
+++ b/monitor/proxy/gproxyvolumemonitor.c
@@ -43,6 +43,8 @@
#include "gproxymountoperation.h"
#include "gvfsvolumemonitordbus.h"
#include "gvfsmonitorimpl.h"
+#include "gvfsdbus.h"
+#include "gvfsdaemonprotocol.h"
G_LOCK_DEFINE_STATIC(proxy_vm);
@@ -1430,6 +1432,7 @@ void
g_proxy_volume_monitor_register (GIOModule *module)
{
GList *impls, *l;
+ gboolean res, got_list;
/* first register the abstract base type... */
g_proxy_volume_monitor_register_type (G_TYPE_MODULE (module));
@@ -1445,7 +1448,62 @@ g_proxy_volume_monitor_register (GIOModule *module)
* - and if so the priority
*/
- impls = g_vfs_list_monitor_implementations ();
+ impls = NULL;
+ got_list = FALSE;
+
+ G_LOCK (proxy_vm);
+ res = g_proxy_volume_monitor_setup_session_bus_connection ();
+ G_UNLOCK (proxy_vm);
+
+ if (res)
+ {
+ GVfsDBusDaemon *proxy;
+ GError *error = NULL;
+
+ proxy = gvfs_dbus_daemon_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ G_VFS_DBUS_DAEMON_NAME,
+ G_VFS_DBUS_DAEMON_PATH,
+ NULL,
+ &error);
+ if (proxy != NULL)
+ {
+ GVariant *monitors, *child;
+ GVfsMonitorImplementation *impl;
+ int i;
+
+ if (gvfs_dbus_daemon_call_list_monitor_implementations_sync (proxy,
+ &monitors, NULL, &error))
+ {
+ got_list = TRUE;
+ for (i = 0; i < g_variant_n_children (monitors); i++)
+ {
+ child = g_variant_get_child_value (monitors, i);
+ impl = g_vfs_monitor_implementation_from_dbus (child);
+ impls = g_list_prepend (impls, impl);
+ g_variant_unref (child);
+ }
+ g_variant_unref (monitors);
+ }
+ else
+ {
+ if (!g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD))
+ g_warning ("Error: %s\n", error->message);
+ g_error_free (error);
+ }
+ }
+ else
+ {
+ g_warning ("Error: %s\n", error->message);
+ g_error_free (error);
+ }
+ }
+
+ /* Fall back on the old non-dbus version for compatibility with older
+ versions of the services */
+ if (!got_list)
+ impls = g_vfs_list_monitor_implementations ();
+
for (l = impls; l != NULL; l = l->next)
{
GVfsMonitorImplementation *impl = l->data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]