[gvfs/mtp-backend: 45/64] MTP: Heartbeat callback to avoid connection timing out.



commit bbc8ad11b924cf0dd67038044c3bff30c986e591
Author: Philip Langdale <philipl cloudera com>
Date:   Fri Oct 12 17:12:28 2012 -0700

    MTP: Heartbeat callback to avoid connection timing out.

 daemon/gvfsbackendmtp.c |   19 +++++++++++++++++++
 daemon/gvfsbackendmtp.h |    1 +
 2 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index d641b25..46cc913 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -329,6 +329,16 @@ check_event (gpointer user_data)
 }
 #endif
 
+static gboolean
+mtp_heartbeat (GVfsBackendMtp *backend)
+{
+  if (g_mutex_trylock (&backend->mutex)) {
+    LIBMTP_Dump_Device_Info(backend->device);
+    g_mutex_unlock (&backend->mutex);
+  }
+  return TRUE;
+}
+
 static void
 do_mount (GVfsBackend *backend,
            GVfsJobMount *job,
@@ -404,6 +414,9 @@ do_mount (GVfsBackend *backend,
 
     g_vfs_job_succeeded (G_VFS_JOB (job));
 
+    op_backend->hb_id =
+      g_timeout_add_seconds (900, (GSourceFunc)mtp_heartbeat, op_backend);
+
 #if HAVE_LIBMTP_READ_EVENT
     g_thread_new ("events", check_event, backend);
 #endif
@@ -422,9 +435,15 @@ do_unmount (GVfsBackend *backend, GVfsJobUnmount *job,
   DEBUG ("(I) do_umount");
 
   op_backend = G_VFS_BACKEND_MTP (backend);
+
+  g_source_remove (op_backend->hb_id);
   g_object_unref (op_backend->gudev_client);
   g_free (op_backend->dev_path);
+
+  g_mutex_lock (&G_VFS_BACKEND_MTP (backend)->mutex);
   LIBMTP_Release_Device (op_backend->device);
+  g_mutex_unlock (&G_VFS_BACKEND_MTP (backend)->mutex);
+
   g_vfs_job_succeeded (G_VFS_JOB (job));
 
   DEBUG ("(I) do_umount done.");
diff --git a/daemon/gvfsbackendmtp.h b/daemon/gvfsbackendmtp.h
index bcae313..93c1cb9 100644
--- a/daemon/gvfsbackendmtp.h
+++ b/daemon/gvfsbackendmtp.h
@@ -54,6 +54,7 @@ struct _GVfsBackendMtp
   char *dev_path;
 
   GHashTable *monitors;
+  guint hb_id;
 };
 
 struct _GVfsBackendMtpClass



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