summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2016-05-16 08:02:02 -0700
committerPhilip Langdale <philipl@overt.org>2016-11-04 21:38:14 -0700
commit07c635a0ed402d6fb7c309c83dbdb9c21fad93bc (patch)
tree2c3dfda0a7e8c30830cc54d6147bfbb977c8994a
parent5637d4284295b961de2744a5a11026c71a9a45b0 (diff)
downloadgvfs-07c635a0ed402d6fb7c309c83dbdb9c21fad93bc.tar.gz
mtp: Use libusb interruption mechanism
Now that libusb 1.0.21 is finally out, there is a way to explicitly interrupt a thread that is waiting for events. This allows us to use a long timeout on our event waiting, which we can interrupt, rather than a short, one second, timeout. The only nuance is that we need to link against libusb directly to be able to use the interrupt mechanism. This is a little bit ugly, but is necessary unless libmtp wraps the interruption call.
-rw-r--r--configure.ac20
-rw-r--r--daemon/Makefile.am4
-rw-r--r--daemon/gvfsbackendmtp.c11
3 files changed, 33 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 8c91fc4f..bef758ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -478,6 +478,25 @@ AC_SUBST(BLURAY_CFLAGS)
AC_SUBST(BLURAY_LIBS)
AM_CONDITIONAL([HAVE_BLURAY], [test "$msg_bluray" = "yes"])
+dnl ************************************************
+dnl *** Check if we should build with libusb-1.0 ***
+dnl ************************************************
+AC_ARG_ENABLE([libusb], [AS_HELP_STRING([--disable-libusb],[build without libusb support])])
+msg_libusb=no
+
+if test "x$enable_libusb" != "xno"; then
+ PKG_CHECK_EXISTS([libusb-1.0 >= 1.0.21], [msg_libusb=yes])
+
+ if test "x$msg_libusb" = "xyes"; then
+ PKG_CHECK_MODULES([LIBUSB], [libusb-1.0 >= 1.0.21])
+ AC_DEFINE([HAVE_LIBUSB], 1, [Define to 1 if libusb is going to be built])
+ fi
+fi
+
+AC_SUBST(LIBUSB_CFLAGS)
+AC_SUBST(LIBUSB_LIBS)
+AM_CONDITIONAL([HAVE_LIBUSB], [test "$msg_libusb" = "yes"])
+
dnl *************************
dnl *** Check for libmtp ***
dnl *************************
@@ -901,6 +920,7 @@ echo "
Gphoto2 support: $msg_gphoto2
MTP support: $msg_libmtp
Polkit support: $msg_admin
+ USB support: $msg_libusb
archive support: $msg_archive
AFC support: $msg_afc
AFP support: $msg_afp
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 801c58db..963a721f 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -505,9 +505,9 @@ gvfsd_mtp_CPPFLAGS = \
-DDEFAULT_BACKEND_TYPE=mtp \
-DMAX_JOB_THREADS=1 \
-DBACKEND_TYPES='"mtp", G_VFS_TYPE_BACKEND_MTP,' \
- $(GUDEV_CFLAGS) $(LIBMTP_CFLAGS)
+ $(GUDEV_CFLAGS) $(LIBMTP_CFLAGS) $(LIBUSB_CFLAGS)
-gvfsd_mtp_LDADD = $(libraries) $(GUDEV_LIBS) $(LIBMTP_LIBS) \
+gvfsd_mtp_LDADD = $(libraries) $(GUDEV_LIBS) $(LIBMTP_LIBS) $(LIBUSB_LIBS) \
$(top_builddir)/common/libgvfscommon-gphoto2.la
gvfsd_http_SOURCES = \
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index 7570b6ab..dddc4d56 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -34,6 +34,9 @@
#include <gio/gio.h>
#include <libmtp.h>
+#if HAVE_LIBUSB
+#include <libusb.h>
+#endif
#include "gvfsbackendmtp.h"
#include "gvfsicon.h"
@@ -76,7 +79,11 @@
* Constants
************************************************/
+#if HAVE_LIBUSB
+#define EVENT_POLL_PERIOD { 3600, 0 }
+#else
#define EVENT_POLL_PERIOD { 1, 0 }
+#endif
/************************************************
* Private Types
@@ -959,6 +966,10 @@ do_unmount (GVfsBackend *backend, GVfsJobUnmount *job,
g_atomic_int_set (&op_backend->unmount_started, TRUE);
+#if HAVE_LIBUSB
+ libusb_interrupt_event_handler (NULL);
+#endif
+
#ifdef HAVE_LIBMTP_1_1_12
/* Thread will terminate after flag is set. */
g_thread_join (op_backend->event_thread);