[brasero/gnome-2-28] Add a new function brasero_drive_is_locked ()



commit 20997d15b8609dcf63164163df98a1cfdd36956d
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Wed Oct 14 20:36:47 2009 +0200

    Add a new function brasero_drive_is_locked ()
    Instead of actually cancelling a probe thread before ejecting we now wait for it to end and delay any other further probe until we're done with ejecting.

 libbrasero-burn/brasero-enums.h  |    1 +
 libbrasero-media/brasero-drive.c |   79 +++++++++++++++++++++++++++++++++-----
 2 files changed, 70 insertions(+), 10 deletions(-)
---
diff --git a/libbrasero-burn/brasero-enums.h b/libbrasero-burn/brasero-enums.h
index a03593b..989d9d0 100644
--- a/libbrasero-burn/brasero-enums.h
+++ b/libbrasero-burn/brasero-enums.h
@@ -98,6 +98,7 @@ typedef enum {
 	BRASERO_BURN_ACTION_LEADOUT,
 	BRASERO_BURN_ACTION_START_RECORDING,
 	BRASERO_BURN_ACTION_FINISHED,
+	BRASERO_BURN_ACTION_EJECTING,
 	BRASERO_BURN_ACTION_LAST
 } BraseroBurnAction;
 
diff --git a/libbrasero-media/brasero-drive.c b/libbrasero-media/brasero-drive.c
index e2cbb40..3aa0a30 100644
--- a/libbrasero-media/brasero-drive.c
+++ b/libbrasero-media/brasero-drive.c
@@ -96,6 +96,7 @@ struct _BraseroDrivePrivate
 	guint probe_cancelled:1;
 
 	guint locked:1;
+	guint ejecting:1;
 	guint probe_waiting:1;
 };
 
@@ -209,7 +210,6 @@ brasero_drive_cancel_probing (BraseroDrive *drive)
 
 	g_mutex_lock (priv->mutex);
 	if (priv->probe) {
-
 		/* This to signal that we are cancelling */
 		priv->probe_cancelled = TRUE;
 		priv->initial_probe_cancelled = TRUE;
@@ -245,6 +245,24 @@ brasero_drive_cancel_probing (BraseroDrive *drive)
 	}
 }
 
+static void
+brasero_drive_wait_probing_thread (BraseroDrive *drive)
+{
+	BraseroDrivePrivate *priv;
+
+	priv = BRASERO_DRIVE_PRIVATE (drive);
+
+	g_mutex_lock (priv->mutex);
+	if (priv->probe) {
+		/* This is to wake up the thread if it
+		 * was asleep waiting to retry to get
+		 * hold of a handle to probe the drive */
+		g_cond_signal (priv->cond_probe);
+		g_cond_wait (priv->cond, priv->mutex);
+	}
+	g_mutex_unlock (priv->mutex);
+}
+
 /**
  * brasero_drive_eject:
  * @drive: #BraseroDrive
@@ -278,15 +296,20 @@ brasero_drive_eject (BraseroDrive *drive,
 
 	BRASERO_MEDIA_LOG ("Trying to eject drive");
 	if (priv->gdrive) {
-		/* Cancel any ongoing probing as it
+		/*Wait for any ongoing probing as it
 		 * would prevent the door from being
 		 * opened. */
-		brasero_drive_cancel_probing (drive);
+		brasero_drive_wait_probing_thread (drive);
 
+		priv->ejecting = TRUE;
 		res = brasero_gio_operation_eject_drive (priv->gdrive,
 							 priv->cancel,
 							 wait,
 							 error);
+		priv->ejecting = FALSE;
+		if (priv->probe_waiting)
+			brasero_drive_probe_inside (drive);
+
 		if (res)
 			return TRUE;
 
@@ -311,11 +334,18 @@ brasero_drive_eject (BraseroDrive *drive,
 		/* Cancel any ongoing probing as it
 		 * would prevent the door from being
 		 * opened. */
-		brasero_drive_cancel_probing (drive);
+		brasero_drive_wait_probing_thread (drive);
+
+		priv->ejecting = TRUE;
 		res = brasero_gio_operation_eject_volume (gvolume,
 							  priv->cancel,
 							  wait,
 							  error);
+
+		priv->ejecting = FALSE;
+		if (priv->probe_waiting)
+			brasero_drive_probe_inside (drive);
+
 		g_object_unref (gvolume);
 	}
 
@@ -453,12 +483,36 @@ brasero_drive_can_use_exclusively (BraseroDrive *drive)
 }
 
 /**
+ * brasero_drive_is_locked:
+ * @drive: a #BraseroDrive
+ * @reason: a #gchar or NULL. A string to indicate what the drive was locked for if return value is %TRUE
+ *
+ * Checks whether a #BraseroDrive is currently locked. Manual ejection shouldn't be possible any more.
+ *
+ * Since 2.29.0
+ *
+ * Return value: %TRUE if the drive is locked or %FALSE.
+ **/
+gboolean
+brasero_drive_is_locked (BraseroDrive *drive,
+                         gchar **reason)
+{
+	BraseroDrivePrivate *priv;
+
+	g_return_val_if_fail (drive != NULL, FALSE);
+	g_return_val_if_fail (BRASERO_IS_DRIVE (drive), FALSE);
+
+	priv = BRASERO_DRIVE_PRIVATE (drive);
+	return priv->locked;
+}
+
+/**
  * brasero_drive_lock:
  * @drive: a #BraseroDrive
  * @reason: a string to indicate what the drive was locked for
- * @reason_for_failure: a string to hold the reason why the locking failed
+ * @reason_for_failure: a string (or NULL) to hold the reason why the locking failed
  *
- * Locks a #BraseroDrive. Ejection shouldn't be possible any more.
+ * Locks a #BraseroDrive. Manual ejection shouldn't be possible any more.
  *
  * Return value: %TRUE if the drive was successfully locked or %FALSE.
  **/
@@ -530,7 +584,9 @@ brasero_drive_unlock (BraseroDrive *drive)
 		priv->locked = FALSE;
 
 		if (priv->probe_waiting) {
-			/* See if a probe was waiting */
+			BRASERO_MEDIA_LOG ("Probe on hold");
+
+			/* A probe was waiting */
 			priv->probe_waiting = FALSE;
 
 			BRASERO_MEDIA_LOG ("Probe on hold");
@@ -843,7 +899,9 @@ brasero_drive_probed_inside (gpointer data)
 	self = BRASERO_DRIVE (data);
 	priv = BRASERO_DRIVE_PRIVATE (self);
 
-	g_mutex_lock (priv->mutex);
+	if (!g_mutex_trylock (priv->mutex))
+		return TRUE;
+
 	priv->probe_id = 0;
 	g_mutex_unlock (priv->mutex);
 
@@ -1025,7 +1083,7 @@ brasero_drive_medium_gdrive_changed_cb (BraseroDrive *gdrive,
 	BraseroDrivePrivate *priv;
 
 	priv = BRASERO_DRIVE_PRIVATE (drive);
-	if (priv->locked) {
+	if (priv->locked || priv->ejecting) {
 		BRASERO_MEDIA_LOG ("Waiting for next unlocking of the drive to probe");
 
 		/* Since the drive was locked, it should
@@ -1039,6 +1097,7 @@ brasero_drive_medium_gdrive_changed_cb (BraseroDrive *gdrive,
 		return;
 	}
 
+	BRASERO_MEDIA_LOG ("GDrive changed");
 	brasero_drive_probe_inside (drive);
 }
 
@@ -1074,7 +1133,7 @@ brasero_drive_update_gdrive (BraseroDrive *drive,
 				  drive);
 	}
 
-	if (priv->locked) {
+	if (priv->locked || priv->ejecting) {
 		BRASERO_MEDIA_LOG ("Waiting for next unlocking of the drive to probe");
 
 		/* Since the drive was locked, it should



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