Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item

2015-10-13 Thread Programmingkid

On Oct 13, 2015, at 4:44 PM, Peter Maydell wrote:

> On 26 September 2015 at 04:01, Programmingkid  
> wrote:
>> Add a menu item to the Machine menu called "Use Real CDROM". It gives the 
>> user
>> the ability to use a real CDROM disc with QEMU by simply selecting a menu 
>> item.
>> 
>> Signed-off-by: John Arbuckle 
> 
> This feature is not present in any of our other UI frontends,
> and the implementation makes assumptions about the names of
> block devices in the models (ie that if it has "cd" in the name
> anywhere it's a CD). I also don't have a mac with a CD drive
> so I have no way of testing it.
> 
> I'm afraid that I think that this comes under the heading of
> "features that should be in the VM management layer, not QEMU
> itself", so I would prefer not to take it into QEMU.

Mac OS X users don't have any VM management layer. That is pretty much
a Linux-only feature. What we do have is the cocoa interface. 




Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item

2015-10-13 Thread Peter Maydell
On 26 September 2015 at 04:01, Programmingkid  wrote:
> Add a menu item to the Machine menu called "Use Real CDROM". It gives the user
> the ability to use a real CDROM disc with QEMU by simply selecting a menu 
> item.
>
> Signed-off-by: John Arbuckle 

This feature is not present in any of our other UI frontends,
and the implementation makes assumptions about the names of
block devices in the models (ie that if it has "cd" in the name
anywhere it's a CD). I also don't have a mac with a CD drive
so I have no way of testing it.

I'm afraid that I think that this comes under the heading of
"features that should be in the VM management layer, not QEMU
itself", so I would prefer not to take it into QEMU.

thanks
-- PMM



Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item

2015-09-26 Thread Programmingkid

On Sep 26, 2015, at 6:49 PM, Namsun Ch'o wrote:

>> Actually on Mac OS X, /dev/cdrom always points to the optical drive.
>> It is how QEMU is programmed.
> 
> Is this only for Mac? I must have missed that.

Yes, it is for the Macintosh's cocoa interface.



Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item

2015-09-26 Thread Namsun Ch'o
> Actually on Mac OS X, /dev/cdrom always points to the optical drive.
> It is how QEMU is programmed.

Is this only for Mac? I must have missed that.



Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item

2015-09-26 Thread Programmingkid

On Sep 26, 2015, at 1:45 AM, Namsun Ch'o wrote:

>> Add a menu item to the Machine menu called "Use Real CDROM". It gives the
>> user the ability to use a real CDROM with QEMU by simply selecting a menu
>> item.
> 
>> NSASCIIStringEncoding];
>> +qmp_change_blockdev(device, "/dev/cdrom", "raw", &err);
>> +handleAnyDeviceErrors(err);
> 
> Not all systems put their CDROM in /dev/cdrom. And you can already select the
> machine's real CDROM hardware by doing -cdrom /dev/cdrom (or /dev/sr0, etc).
> Examples of device files for CDROMs on other systems:
> 
> /dev/sr0
> /dev/cd0
> /dev/sdc0
> /dev/acd0c
> /dev/cdrom0
> /dev/disk1s0
> /dev/scsi/sc0d
> /dev/dsk/c1t0d0s0
> /dev/rdsk/dks0d1vh
> 
> And of course many of the numbers here increment on systems with multiple
> drives. There is seriously an insane amount of variation of the names of CDROM
> drives. Don't assume that it will only be /dev/cdrom and hardcode it that way.


Actually on Mac OS X, /dev/cdrom always points to the optical drive. It is how 
QEMU is programmed.


Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item

2015-09-25 Thread Namsun Ch'o
> Add a menu item to the Machine menu called "Use Real CDROM". It gives the
> user the ability to use a real CDROM with QEMU by simply selecting a menu
> item.

> NSASCIIStringEncoding];
> +qmp_change_blockdev(device, "/dev/cdrom", "raw", &err);
> +handleAnyDeviceErrors(err);

Not all systems put their CDROM in /dev/cdrom. And you can already select the
machine's real CDROM hardware by doing -cdrom /dev/cdrom (or /dev/sr0, etc).
Examples of device files for CDROMs on other systems:

/dev/sr0
/dev/cd0
/dev/sdc0
/dev/acd0c
/dev/cdrom0
/dev/disk1s0
/dev/scsi/sc0d
/dev/dsk/c1t0d0s0
/dev/rdsk/dks0d1vh

And of course many of the numbers here increment on systems with multiple
drives. There is seriously an insane amount of variation of the names of CDROM
drives. Don't assume that it will only be /dev/cdrom and hardcode it that way.



[Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item

2015-09-25 Thread Programmingkid
Add a menu item to the Machine menu called "Use Real CDROM". It gives the user
the ability to use a real CDROM disc with QEMU by simply selecting a menu item.

Signed-off-by: John Arbuckle 

---
 ui/cocoa.m |   87 
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 334e6f6..7586ba3 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -829,6 +829,7 @@ QemuCocoaView *cocoaView;
 - (void)powerDownQEMU:(id)sender;
 - (void)ejectDeviceMedia:(id)sender;
 - (void)changeDeviceMedia:(id)sender;
+- (void)useRealCDROM:(id)sender;
 @end
 
 @implementation QemuCocoaAppController
@@ -1125,6 +1126,16 @@ QemuCocoaView *cocoaView;
 }
 }
 
+/* Has QEMU use the real CDROM drive */
+- (void)useRealCDROM:(id)sender
+{
+Error *err = NULL;
+const char *device = [[sender representedObject] cStringUsingEncoding:
+ 
NSASCIIStringEncoding];
+qmp_change_blockdev(device, "/dev/cdrom", "raw", &err);
+handleAnyDeviceErrors(err);
+}
+
 @end
 
 
@@ -1338,6 +1349,79 @@ static void add_console_menu_entries(void)
 }
 }
 
+/*
+ * Determines if the emulator has a CDROM drive.
+ * Can only be called after the addRemovableDevicesMenuItems() function has 
been
+ * called.
+ */
+static bool emulatorHasCDROM(void)
+{
+int index;
+NSString *title;
+NSArray *menu_item_array;
+NSMenu *menu;
+menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
+menu_item_array = [menu itemArray];
+if (!menu_item_array) {
+NSBeep();
+QEMU_Alert(@"Failed to obtain Machine menu items!");
+return false;
+}
+/* Start at the first removable device menu item */
+for (index = 7; index < [menu_item_array count]; index++) {
+title = [[menu_item_array objectAtIndex: index] title];
+if ([title rangeOfString: @"cd"].location != NSNotFound) {
+return true;
+}
+}
+return false;
+}
+
+/* Find the CDROM's name */
+static NSString *getCDName(void)
+{
+int index, end_of_string_index;
+NSString *title, *return_value;
+NSArray *menu_item_array;
+NSMenu *menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
+menu_item_array = [menu itemArray];
+if (!menu_item_array) {
+NSBeep();
+QEMU_Alert(@"Failed to obtain Machine menu items!");
+return nil;
+}
+/* Start at the first removable device menu item */
+for (index = 7; index < [menu_item_array count]; index++) {
+title = [[menu_item_array objectAtIndex: index] title];
+if ([title rangeOfString: @"cd"].location != NSNotFound) {
+return_value = [[title componentsSeparatedByString: @" "]
+  objectAtIndex: 
1];
+end_of_string_index = [return_value rangeOfString: @"."].location;
+return_value = [return_value substringToIndex: 
end_of_string_index];
+return return_value;
+}
+}
+return nil;
+}
+
+/* Add the "Use Real CDROM" menu item */
+static void addRealCDMenuItem(void)
+{
+NSMenu *machine_menu;
+NSMenuItem *menu_item;
+machine_menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
+if (!machine_menu) {
+NSBeep();
+QEMU_Alert(@"Could not find Machine Menu!");
+return;
+}
+menu_item = [[NSMenuItem alloc] initWithTitle: @"Use Real CDROM"
+  action: @selector(useRealCDROM:)
+   keyEquivalent: @""];
+[menu_item setRepresentedObject: getCDName()];
+[machine_menu insertItem: menu_item atIndex: 7];
+}
+
 /* Make menu items for all removable devices.
  * Each device is given an 'Eject' and 'Change' menu item.
  */
@@ -1433,4 +1517,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen)
  * find out what removable devices it has.
  */
 addRemovableDevicesMenuItems();
+if(emulatorHasCDROM()) {
+addRealCDMenuItem();
+}
 }
-- 
1.7.5.4