[gvfs] cdda backend: support and prefer gudev
- From: David Zeuthen <davidz src gnome org>
- To: svn-commits-list gnome org
- Subject: [gvfs] cdda backend: support and prefer gudev
- Date: Wed, 8 Jul 2009 17:27:04 +0000 (UTC)
commit ebaa763b87523cb39076a5ea98065300cf154d43
Author: Martin Pitt <martin pitt ubuntu com>
Date: Sat Jun 20 15:18:23 2009 +0200
cdda backend: support and prefer gudev
Change build system to check for libgudev, and use it (and prefer over hal) in
the cdda backend. As before, if neither hal nor gudev are available, cdda is
not built.
http://bugzilla.gnome.org/show_bug.cgi?id=586409
configure.ac | 25 +++++++++++++++--
daemon/Makefile.am | 14 ++++++++-
daemon/gvfsbackendcdda.c | 66 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 98 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 016b37e..3149309 100644
--- a/configure.ac
+++ b/configure.ac
@@ -284,6 +284,25 @@ AC_SUBST(HAL_CFLAGS)
AM_CONDITIONAL(USE_HAL, [test "$msg_hal" = "yes"])
+dnl **********************
+dnl *** Check for gudev ***
+dnl **********************
+AC_ARG_ENABLE(gudev, [ --disable-gudev build without gudev support])
+msg_gudev=no
+GUDEV_REQUIRED=001
+
+if test "x$enable_gudev" != "xno"; then
+ PKG_CHECK_EXISTS([gudev-1.0 >= $GUDEV_REQUIRED], msg_gudev=yes)
+
+ if test "x$msg_gudev" = "xyes"; then
+ PKG_CHECK_MODULES(GUDEV, [gudev-1.0 >= $GUDEV_REQUIRED])
+ AC_DEFINE(HAVE_GUDEV, 1, [Define to 1 if gudev is available])
+ fi
+fi
+AC_SUBST(GUDEV_CFLAGS)
+AC_SUBST(GUDEV_LIBS)
+AM_CONDITIONAL(USE_GUDEV, [test "$msg_gudev" = "yes"])
+
dnl **************************************************
dnl *** Check if we should build with CDDA backend ***
dnl **************************************************
@@ -292,11 +311,11 @@ msg_cdda=no
CDDA_LIBS=
CDDA_CFLAGS=
-if test "x$enable_cdda" != "xno"; then
- PKG_CHECK_EXISTS(libcdio_paranoia >= 0.78.2 hal >= $HAL_REQUIRED, msg_cdda=yes)
+if test "x$enable_cdda" != "xno" -a \( "x$msg_hal" = "xyes" -o "x$msg_gudev" = "xyes" \); then
+ PKG_CHECK_EXISTS(libcdio_paranoia >= 0.78.2, msg_cdda=yes)
if test "x$msg_cdda" = "xyes"; then
- PKG_CHECK_MODULES(CDDA, libcdio_paranoia hal >= $HAL_REQUIRED)
+ PKG_CHECK_MODULES(CDDA, libcdio_paranoia)
AC_DEFINE(HAVE_CDDA, 1, [Define to 1 if CDDA is going to be built])
fi
fi
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 1c0d725..b1d4b37 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -13,6 +13,7 @@ INCLUDES = \
$(OBEXFTP_CFLAGS) $(XML_CFLAGS) \
$(KEYRING_CFLAGS) \
-DDBUS_API_SUBJECT_TO_CHANGE \
+ -DG_UDEV_API_IS_SUBJECT_TO_CHANGE \
-DLIBEXEC_DIR=\"$(libexecdir)/\" \
-DMOUNTABLE_DIR=\"$(mountdir)/\" \
-DGVFS_LOCALEDIR=\""$(localedir)"\" \
@@ -358,10 +359,19 @@ gvfsd_cdda_CPPFLAGS = \
-DBACKEND_HEADER=gvfsbackendcdda.h \
-DDEFAULT_BACKEND_TYPE=cdda \
-DMAX_JOB_THREADS=1 \
- $(CDDA_CFLAGS) $(HAL_CFLAGS) \
- -DBACKEND_TYPES='"cdda", G_VFS_TYPE_BACKEND_CDDA,'
+ -DBACKEND_TYPES='"cdda", G_VFS_TYPE_BACKEND_CDDA,' \
+ $(CDDA_CFLAGS)
+if USE_GUDEV
+gvfsd_cdda_CPPFLAGS += $(GUDEV_CFLAGS)
+else
+gvfsd_cdda_CPPFLAGS += $(HAL_CFLAGS)
+endif
+if USE_GUDEV
+gvfsd_cdda_LDADD = $(libraries) $(CDDA_LIBS) $(GUDEV_LIBS)
+else
gvfsd_cdda_LDADD = $(libraries) $(CDDA_LIBS) $(HAL_LIBS)
+endif
gvfsd_gphoto2_SOURCES = \
gvfsbackendgphoto2.c gvfsbackendgphoto2.h \
diff --git a/daemon/gvfsbackendcdda.c b/daemon/gvfsbackendcdda.c
index e1871c6..41cd4b6 100644
--- a/daemon/gvfsbackendcdda.c
+++ b/daemon/gvfsbackendcdda.c
@@ -37,8 +37,15 @@
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
-#include <libhal.h>
-#include <dbus/dbus.h>
+#ifdef HAVE_GUDEV
+ #include <gudev/gudev.h>
+#elif defined(HAVE_HAL)
+ #include <libhal.h>
+ #include <dbus/dbus.h>
+#else
+ #error Needs hal or gudev
+#endif
+
#include "gvfsbackendcdda.h"
#include "gvfsjobopenforread.h"
@@ -91,9 +98,13 @@ struct _GVfsBackendCdda
{
GVfsBackend parent_instance;
+#ifdef HAVE_GUDEV
+ GUdevClient *gudev_client;
+#elif defined(HAVE_HAL)
DBusConnection *dbus_connection;
LibHalContext *hal_ctx;
char *hal_udi;
+#endif
guint64 size;
@@ -184,6 +195,27 @@ fetch_metadata (GVfsBackendCdda *cdda_backend)
cdio_destroy (cdio);
}
+#ifdef HAVE_GUDEV
+static void
+on_uevent (GUdevClient *client, gchar *action, GUdevDevice *device, gpointer user_data)
+{
+ GVfsBackendCdda *cdda_backend = G_VFS_BACKEND_CDDA (user_data);
+ const gchar *u_dev = g_udev_device_get_device_file (device);
+
+ /* we unmount ourselves if the changed device is "our's" and it either gets
+ * removed or changed to "no media" */
+ if (cdda_backend->device_path == NULL || g_strcmp0 (cdda_backend->device_path, u_dev) != 0)
+ return;
+ if (strcmp (action, "remove") == 0 || (strcmp (action, "change") == 0 &&
+ g_udev_device_get_property_as_int (device, "ID_CDROM_MEDIA") != 1))
+ {
+ /*g_warning ("we have been removed!");*/
+ /* TODO: need a cleaner way to force unmount ourselves */
+ exit (1);
+ }
+}
+
+#elif defined(HAVE_HAL)
static void
find_udi_for_device (GVfsBackendCdda *cdda_backend)
{
@@ -237,6 +269,7 @@ _hal_device_removed (LibHalContext *hal_ctx, const char *udi)
exit (1);
}
}
+#endif
static void
g_vfs_backend_cdda_finalize (GObject *object)
@@ -287,6 +320,26 @@ do_mount (GVfsBackend *backend,
//g_warning ("do_mount %p", cdda_backend);
+#ifdef HAVE_GUDEV
+ /* setup gudev */
+ const char *subsystems[] = {"block", NULL};
+ GUdevDevice *gudev_device;
+
+ cdda_backend->gudev_client = g_udev_client_new (subsystems);
+ if (cdda_backend->gudev_client == NULL)
+ {
+ release_device (cdda_backend);
+ release_metadata (cdda_backend);
+ 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 (cdda_backend->gudev_client, "uevent", G_CALLBACK (on_uevent), cdda_backend);
+
+#elif defined(HAVE_HAL)
+
/* setup libhal */
dbus_error_init (&dbus_error);
@@ -329,6 +382,7 @@ do_mount (GVfsBackend *backend,
libhal_ctx_set_device_removed (cdda_backend->hal_ctx, _hal_device_removed);
libhal_ctx_set_user_data (cdda_backend->hal_ctx, cdda_backend);
+#endif
/* setup libcdio */
@@ -346,7 +400,15 @@ do_mount (GVfsBackend *backend,
cdda_backend->device_path = g_strdup_printf ("/dev/%s", host);
+#ifdef HAVE_GUDEV
+ gudev_device = g_udev_client_query_by_device_file (cdda_backend->gudev_client, cdda_backend->device_path);
+ if (gudev_device != NULL)
+ cdda_backend->size = g_udev_device_get_sysfs_attr_as_uint64 (gudev_device, "size") * 512;
+ g_object_unref (gudev_device);
+
+#elif defined(HAVE_HAL)
find_udi_for_device (cdda_backend);
+#endif
cdda_backend->drive = cdio_cddap_identify (cdda_backend->device_path, 0, NULL);
if (cdda_backend->drive == NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]