[brasero/gnome-2-28] Postpone any probing while the drive is locked
- From: Philippe Rouquier <philippr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [brasero/gnome-2-28] Postpone any probing while the drive is locked
- Date: Sat, 3 Oct 2009 12:02:07 +0000 (UTC)
commit 04d579c028adf9a04802789bf27f13ce62c359b2
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date: Fri Oct 2 10:36:56 2009 +0200
Postpone any probing while the drive is locked
libbrasero-media/brasero-drive.c | 83 ++++++++++++++++++++++++++++++--------
1 files changed, 66 insertions(+), 17 deletions(-)
---
diff --git a/libbrasero-media/brasero-drive.c b/libbrasero-media/brasero-drive.c
index daba8c5..3ad7a9d 100644
--- a/libbrasero-media/brasero-drive.c
+++ b/libbrasero-media/brasero-drive.c
@@ -90,6 +90,9 @@ struct _BraseroDrivePrivate
guint probed:1;
guint has_medium:1;
guint probe_cancelled:1;
+
+ guint locked:1;
+ guint probe_waiting:1;
};
#define BRASERO_DRIVE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_DRIVE, BraseroDrivePrivate))
@@ -112,6 +115,9 @@ G_DEFINE_TYPE (BraseroDrive, brasero_drive, G_TYPE_OBJECT);
#define BRASERO_DRIVE_OPEN_ATTEMPTS 5
+static void
+brasero_drive_probe_inside (BraseroDrive *drive);
+
/**
* brasero_drive_get_gdrive:
* @drive: a #BraseroDrive
@@ -195,6 +201,8 @@ brasero_drive_cancel_probing (BraseroDrive *drive)
priv = BRASERO_DRIVE_PRIVATE (drive);
+ priv->probe_waiting = FALSE;
+
g_mutex_lock (priv->mutex);
if (priv->probe) {
/* This to signal that we are cancelling */
@@ -457,11 +465,12 @@ brasero_drive_lock (BraseroDrive *drive,
return FALSE;
result = (brasero_sbc_medium_removal (handle, 1, NULL) == BRASERO_SCSI_OK);
- if (!result) {
- BRASERO_MEDIA_LOG ("Device failed to lock");
+ if (result) {
+ BRASERO_MEDIA_LOG ("Device locked");
+ priv->locked = TRUE;
}
else
- BRASERO_MEDIA_LOG ("Device locked");
+ BRASERO_MEDIA_LOG ("Device failed to lock");
brasero_device_handle_close (handle);
return result;
@@ -496,13 +505,21 @@ brasero_drive_unlock (BraseroDrive *drive)
return FALSE;
result = (brasero_sbc_medium_removal (handle, 0, NULL) == BRASERO_SCSI_OK);
- if (!result) {
- BRASERO_MEDIA_LOG ("Device failed to unlock");
+ if (result) {
+ BRASERO_MEDIA_LOG ("Device unlocked");
+ priv->locked = FALSE;
+
+ if (priv->probe_waiting) {
+ /* See if a probe was waiting */
+ priv->probe_waiting = FALSE;
+ brasero_drive_probe_inside (drive);
+ }
}
else
- BRASERO_MEDIA_LOG ("Device unlocked");
+ BRASERO_MEDIA_LOG ("Device failed to unlock");
brasero_device_handle_close (handle);
+
return result;
}
@@ -974,6 +991,7 @@ brasero_drive_probe_inside (BraseroDrive *drive)
}
else
BRASERO_MEDIA_LOG ("Ongoing probe");
+
g_mutex_unlock (priv->mutex);
}
@@ -981,6 +999,23 @@ static void
brasero_drive_medium_gdrive_changed_cb (BraseroDrive *gdrive,
BraseroDrive *drive)
{
+ BraseroDrivePrivate *priv;
+
+ priv = BRASERO_DRIVE_PRIVATE (drive);
+ if (priv->locked) {
+ BRASERO_MEDIA_LOG ("Waiting for next unlocking of the drive to probe");
+
+ /* Since the drive was locked, it should
+ * not be possible that the medium
+ * actually changed.
+ * This allows to avoid probing while
+ * we are burning something.
+ * Delay the probe until brasero_drive_unlock ()
+ * is called. */
+ priv->probe_waiting = TRUE;
+ return;
+ }
+
brasero_drive_probe_inside (drive);
}
@@ -1011,6 +1046,20 @@ brasero_drive_update_gdrive (BraseroDrive *drive,
drive);
}
+ if (priv->locked) {
+ BRASERO_MEDIA_LOG ("Waiting for next unlocking of the drive to probe");
+
+ /* Since the drive was locked, it should
+ * not be possible that the medium
+ * actually changed.
+ * This allows to avoid probing while
+ * we are burning something.
+ * Delay the probe until brasero_drive_unlock ()
+ * is called. */
+ priv->probe_waiting = TRUE;
+ return;
+ }
+
brasero_drive_probe_inside (drive);
}
@@ -1041,20 +1090,20 @@ brasero_drive_reprobe (BraseroDrive *drive)
g_drive_poll_for_media (priv->gdrive, NULL, NULL, NULL);
}
- if (!priv->medium)
- return;
+ priv->probe_waiting = FALSE;
BRASERO_MEDIA_LOG ("Reprobing inserted medium");
+ if (priv->medium) {
+ /* remove current medium */
+ medium = priv->medium;
+ priv->medium = NULL;
- /* remove current medium */
- medium = priv->medium;
- priv->medium = NULL;
-
- g_signal_emit (drive,
- drive_signals [MEDIUM_REMOVED],
- 0,
- medium);
- g_object_unref (medium);
+ g_signal_emit (drive,
+ drive_signals [MEDIUM_REMOVED],
+ 0,
+ medium);
+ g_object_unref (medium);
+ }
brasero_drive_probe_inside (drive);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]