hal/hald/linux block_class_device.c,1.25,1.26

David Zeuthen david at pdx.freedesktop.org
Sun May 30 16:29:46 PDT 2004


Update of /cvs/hal/hal/hald/linux
In directory pdx:/tmp/cvs-serv2783/hald/linux

Modified Files:
	block_class_device.c 
Log Message:
2004-05-31  David Zeuthen  <david at fubar.dk>

	* AUTHORS: Added Joe Shaw

	* hald/linux/block_class_device.c (detect_media): Add code for 
	checking whether the eject button is pressed on an optical drive.
	If detected the condition 'EjectPressed' is emitted on the disc
	HalDevice with a single string representing the device file.
	Also remove BAR and FOO debug statements from earlier development
	sessions. Yay.



Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- a/block_class_device.c	27 May 2004 19:13:39 -0000	1.25
+++ b/block_class_device.c	30 May 2004 23:29:44 -0000	1.26
@@ -401,6 +401,7 @@
 	g_object_unref (device);
 }
 
+
 /** Check for media on a block device that is not a volume
  *
  *  @param  d                   Device to inspect; can be any device, but
@@ -457,8 +458,13 @@
 	else {
 		int drive;
 		dbus_bool_t got_disc = FALSE;
+		dbus_bool_t eject_pressed = FALSE;
+		struct request_sense sense;
+		struct cdrom_generic_command cgc;
+		unsigned char buffer[8];
+		int ret;
 
-		fd = open (device_file, O_RDONLY | O_NONBLOCK | O_EXCL);
+		fd = open (device_file, O_RDONLY | O_NONBLOCK);
 
 		if (fd == -1) {
 			/* open failed */
@@ -466,6 +472,42 @@
 			return FALSE;
 		}
 
+		/* Check whether the 'eject' button is pressed - supposedly
+		 * only works on MMC-2 drivers and higher...
+		 *
+		 * From http://www.ussg.iu.edu/hypermail/linux/kernel/0202.0/att-0603/01-cd_poll.c
+		 */
+		
+		memset (&cgc, 0, sizeof(struct cdrom_generic_command));
+		memset (buffer, 0, sizeof(buffer));		
+		cgc.cmd[0] = GPCMD_GET_EVENT_STATUS_NOTIFICATION;
+		cgc.cmd[1] = 1;
+		cgc.cmd[4] = 16;
+		cgc.cmd[8] = sizeof (buffer);
+		memset (&sense, 0, sizeof (sense));
+		cgc.timeout = 600;
+		cgc.buffer = buffer;
+		cgc.buflen = sizeof (buffer);
+		cgc.data_direction = CGC_DATA_READ;
+		cgc.sense = &sense;
+		cgc.quiet = 1;
+		ret = ioctl (fd, CDROM_SEND_PACKET, &cgc);
+		if (ret < 0) {
+			HAL_ERROR (("GPCMD_GET_EVENT_STATUS_NOTIFICATION failed, errno=%d", errno));
+		} else {
+			if ((buffer[4]&0x0f) == 0x01) {
+				HAL_INFO (("Eject pressed on udi=%s!", 
+					   hal_device_get_udi (d)));
+				/* handle later */
+				eject_pressed = TRUE;
+				
+			}
+		}
+
+		/* Check if a disc is in the drive
+		 *
+		 * @todo Use API above if MMC-2 or higher drive
+		 */
 		drive = ioctl (fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
 		switch (drive) {
 			/* explicit fallthrough */
@@ -523,6 +565,21 @@
 				hal_device_get_udi (d));
 		}
 
+		
+		/* handle eject if we already got a disc */
+		if (child != NULL && eject_pressed ) {
+			device_send_signal_condition (
+				child,
+				"EjectPressed",
+				DBUS_TYPE_STRING,
+				hal_device_property_get_string (
+					child,
+					"block.device"),
+				DBUS_TYPE_INVALID);
+			
+
+		}
+
 		if (child == NULL) {
 			int type;
 			char udi[256];
@@ -712,8 +769,6 @@
 				}
 			}
 
-			HAL_INFO (("BAR"));
-
 			if (disc_is_appendable (fd)) {
 				hal_device_property_set_bool (
 					child, 
@@ -721,8 +776,6 @@
 					TRUE);
 			}
 
-			HAL_INFO (("FOO"));
-
 			close(fd);
 
 			detect_fs (child);





More information about the hal-commit mailing list