[gvfs/mtp-backend: 7/64] MTP: Add stub gudev event handler.



commit 1bc4beb3e02b9da6379b1c9a39422705788c2db9
Author: Philip Langdale <philipl cloudera com>
Date:   Fri Aug 3 14:38:48 2012 -0700

    MTP: Add stub gudev event handler.
    
    Will be used to detect device plug/unplug events.

 daemon/Makefile.am      |    6 ++++++
 daemon/gvfsbackendmtp.c |   18 ++++++++++++++++++
 daemon/gvfsbackendmtp.h |    7 +++++++
 3 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 66f55e8..38561c0 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -225,8 +225,14 @@ gvfsd_mtp_CPPFLAGS = \
 	-DBACKEND_HEADER=gvfsbackendmtp.h \
 	-DDEFAULT_BACKEND_TYPE=mtp \
 	-DBACKEND_TYPES='"mtp", G_VFS_TYPE_BACKEND_MTP,'
+if USE_GUDEV
+gvfsd_mtp_CPPFLAGS += $(GUDEV_CFLAGS)
+endif
 
 gvfsd_mtp_LDADD = $(libraries) -lmtp
+if USE_GUDEV
+gvfsd_mtp_LDADD += $(GUDEV_LIBS)
+endif
 
 gvfsd_smb_SOURCES = \
 	gvfsbackendsmb.c gvfsbackendsmb.h libsmb-compat.h \
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index 653b52a..ce00772 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -103,6 +103,12 @@ g_vfs_backend_mtp_finalize (GObject *object)
  */
 
 static void
+on_uevent (GUdevClient *client, gchar *action, GUdevDevice *device, gpointer user_data)
+{
+  g_print ("on_uevent action %s, device %s\n", action, g_udev_device_get_device_file (device));
+}
+
+static void
 do_mount (GVfsBackend *backend,
            GVfsJobMount *job,
            GMountSpec *mount_spec,
@@ -122,6 +128,17 @@ do_mount (GVfsBackend *backend,
 
   LIBMTP_Init();
 
+  const char *subsystems[] = {"usb", NULL};
+  op_backend->gudev_client = g_udev_client_new (subsystems);
+  if (op_backend->gudev_client == NULL) {
+    GError *error;
+    g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Cannot create gudev client"));
+    g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+    g_error_free (error);
+    return;
+  }
+  g_signal_connect (op_backend->gudev_client, "uevent", G_CALLBACK (on_uevent), op_backend);
+
   g_vfs_job_succeeded (G_VFS_JOB (job));
 }
 
@@ -136,6 +153,7 @@ do_unmount (GVfsBackend *backend, GVfsJobUnmount *job,
   g_print ("(II) try_umount \n");
 
   op_backend = G_VFS_BACKEND_MTP (backend);
+  g_object_unref(op_backend->gudev_client);
   g_mount_spec_unref (op_backend->mount_spec);
   g_vfs_job_succeeded (G_VFS_JOB(job));
 }
diff --git a/daemon/gvfsbackendmtp.h b/daemon/gvfsbackendmtp.h
index fad3d91..1c64100 100644
--- a/daemon/gvfsbackendmtp.h
+++ b/daemon/gvfsbackendmtp.h
@@ -24,6 +24,9 @@
 
 #include <gvfsbackend.h>
 #include <gmountspec.h>
+#ifdef HAVE_GUDEV
+#include <gudev/gudev.h>
+#endif
 
 G_BEGIN_DECLS
 
@@ -42,6 +45,10 @@ struct _GVfsBackendMtp
   GVfsBackend parent_instance;
   GMountSpec *mount_spec;
 
+#ifdef HAVE_GUDEV
+  GUdevClient *gudev_client;
+#endif
+
   GMutex mutex;
   GHashTable *devices;
 };



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