Received: from eggs.gnu.org ([2001:4830:134:3::10]:43010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZn4B-0007r5-9C for qemu-devel@nongnu.org; Wed, 09 Sep 2015 17:38:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZn46-0004Ep-EG for qemu-devel@nongnu.org; Wed, 09 Sep 2015 17:38:07 -0400 Received: from mail-qk0-x22d.google.com ([2607:f8b0:400d:c09::22d]:34032) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZn46-0004El-89 for qemu-devel@nongnu.org; Wed, 09 Sep 2015 17:38:02 -0400 Received: by qkfq186 with SMTP id q186so10769147qkf.1 for ; Wed, 09 Sep 2015 14:38:02 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: <8737yocap6.fsf@blackfin.pond.sub.org> Date: Wed, 9 Sep 2015 17:37:59 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <16D5C709-5630-4919-BE13-6B1DB4B860F8@gmail.com> References: <65D87A2B-B94F-4236-A9BB-D0F0B7FCF96B@gmail.com> <26B5A68C-92C9-4528-BA17-4A282DCFF035@gmail.com> <87fv2og36d.fsf@blackfin.pond.sub.org> <9F6A7240-9CB8-41E2-AB87-B74CD7961191@gmail.com> <8737yocap6.fsf@blackfin.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add Mount image file menu item List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Peter Maydell , qemu-devel qemu-devel On Sep 9, 2015, at 3:29 AM, Markus Armbruster wrote: > Programmingkid writes: >=20 >> On Sep 8, 2015, at 2:46 PM, Markus Armbruster wrote: >>=20 >>> Programmingkid writes: >>>=20 >>>> On Sep 8, 2015, at 12:17 PM, Peter Maydell wrote: >>>>=20 >>>>> On 2 September 2015 at 01:56, Programmingkid >>>>> wrote: >>>>>> Add "Mount Image File..." and a "Eject Image File" menu items to >>>>>> cocoa interface. This patch makes sharing files between the >>>>>> host and the guest user-friendly. >>>>>>=20 >>>>>> The "Mount Image File..." menu item displays a dialog box having = the >>>>>> user pick an image file to use in QEMU. The image file is setup = as >>>>>> a USB flash drive. The user can do the equivalent of removing the >>>>>> flash drive by selecting the file in the "Eject Image File" = submenu. >>>>>>=20 >>>>>> Signed-off-by: John Arbuckle >>>>>>=20 >>>>>> --- >>>>>> ui/cocoa.m | 212 >>>>>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- >>>>>> 1 files changed, 210 insertions(+), 1 deletions(-) >>>>>>=20 >>>>>> diff --git a/ui/cocoa.m b/ui/cocoa.m >>>>>> index 334e6f6..6c0ec18 100644 >>>>>> --- a/ui/cocoa.m >>>>>> +++ b/ui/cocoa.m >>>>>> @@ -52,6 +52,9 @@ >>>>>> #endif >>>>>>=20 >>>>>>=20 >>>>>>=20 >>>>>> #define cgrect(nsrect) (*(CGRect *)&(nsrect)) >>>>>> +#define USB_DISK_ID "USB_DISK" >>>>>> +#define EJECT_IMAGE_FILE_TAG 2099 >>>>>>=20 >>>>>>=20 >>>>>>=20 >>>>>> typedef struct { >>>>>> int width; >>>>>> @@ -263,6 +266,43 @@ static void handleAnyDeviceErrors(Error * = err) >>>>>> } >>>>>> } >>>>>>=20 >>>>>>=20 >>>>>>=20 >>>>>> +/* Sends a command to the monitor console */ >>>>>> +static void sendMonitorCommand(const char * commandString) >>>>>> +{ >>>>>> + int index; >>>>>> + char * consoleName; >>>>>> + static QemuConsole *monitor; >>>>>> + >>>>>> + /* If the monitor console hasn't been found yet */ >>>>>> + if(!monitor) { >>>>>> + index =3D 0; >>>>>> + /* Find the monitor console */ >>>>>> + while (qemu_console_lookup_by_index(index) !=3D NULL) { >>>>>> + consoleName =3D >>>>>> qemu_console_get_label(qemu_console_lookup_by_index(index)); >>>>>> + if(strstr(consoleName, "monitor")) { >>>>>> + monitor =3D qemu_console_lookup_by_index(index); >>>>>> + break; >>>>>> + } >>>>>> + index++; >>>>>> + } >>>>>> + } >>>>>> + >>>>>> + /* If the monitor console was not found */ >>>>>> + if(!monitor) { >>>>>> + NSBeep(); >>>>>> + QEMU_Alert(@"Failed to find the monitor console!"); >>>>>> + return; >>>>>> + } >>>>>> + >>>>>> + /* send each letter in the commandString to the monitor */ >>>>>> + for (index =3D 0; index < strlen(commandString); index++) { >>>>>> + kbd_put_keysym_console(monitor, commandString[index]); >>>>>> + } >>>>>=20 >>>>> We're doing this by sending a string to the human monitor? >>>=20 >>> No way :) >>>=20 >>> You should not send a string to a monitor (QMP or HMP) just because = you >>> can't be bothered to look up the proper C interfaces. >>=20 >> I wouldn't say it like that. I did try to find the functions I = needed, >> but didn't succeed. >=20 > I shouldn't have said "just because you can't be bothered", since I > don't know whether you tried. My apologies. >=20 > What I needed to tell you was that this method is not going to be > accepted, preferrably before you sink more of your time into it. >=20 > My first try[1]: "Sure you want to do that, and not call the C = interface > instead?" This is the exceedingly polite version (for a German) of = "bad > idea, drop it". Followed by an explanation how to find the C = interface > to use. No reply. >=20 > Second try[2]: "On the flip side, you'll never get a patch abusing > handle_hmp_command() or handle_qmp_command() as internal interface > committed." This was in context of you discussing the bad idea = further, > with Max. No reply to that part. Okay, still not blunt enough. >=20 > Third try[3]: "No way :)". Blunt enough to get the point across? >=20 >> Didn't you say yourself you don't want to see gui patches that change >> other code? >> My research indicated there would have to be changes to other files = if >> I did try to use >> the C interface functions. =20 >>=20 >> For example, the function add_init_drive() in device-hotplug.c looked >> really good. The >> problem was that it is a static function. Since you don't want = changes >> made to other >> files, I decided not to use it.=20 >=20 > Let me clarify my attitude to integrated GUIs once more: >=20 > 1. We shouldn't do it (my opinion, not the project's, obviously). >=20 > 2. As long as we do it anyway, it shouldn't interfere with our two = core > missions: user space component for hypervisors, machine emulator. >=20 > 2a. It shouldn't mess up core code. >=20 > 2b. It shouldn't waste time of core contributors. >=20 > Now, the fact that I've been wasting my time (and my employer's money) > by trying to teach you finding the proper interfaces should show that = 2b > isn't absolute. More like guidelines, anyway. More like "shouldn't > waste too much time". Likewise 2a: simple changes can be okay. If = not, > review will lead you to how it needs to be done instead. >=20 > See below for advice on add_init_drive(). >=20 >>>>> That definitely doesn't seem like the right way to do this >>>>> (and there might not even be a human monitor to talk to)... >>>>=20 >>>> Under what situation is the human monitor not available?=20 >>>>=20 >>>> Would you know what function I should use in place of the commands = the >>>> patch uses? >>>=20 >>> I explained that already for QMP: >>> http://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00008.html >>>=20 >>> The mapping from HMP to the C interfaces can be more complex. Going >>> from QMP to C is easier. >>=20 >> The problem with QMP is that it is so difficult to use. It could be >> made to be more >> user-friendly. I will try to use it anyways in my next patch. Thank = you. >=20 > Going from QMP to C is easier, because QMP commands should always be > straightforward wrappers around an internal C interface you can use. >=20 > Of course, you can try to find the proper C interfaces from HMP, too. > Find the HMP command handler in hmp-commands.hx. Drill down until you > hit the internal interface that is also used by QMP. In simple cases, > it's obvious, e.g. hmp_drive_backup() calls qmp_drive_backup(). > However, there are cases where the HMP command does non-trivial > HMP-specific stuff, and you have to find your way through it to the > proper internal interface. Worse, there are a few hairy cases left > where HMP still isn't what it should be, namely a wrapper around the > internal C interface for QMP. >=20 > Creating block backends is one of these. At this time, = add_init_drive() > is just a hotplug helper function, not an internal interface. The > internal interfaces are further down: blockdev_init(). This is one > layer below the internal C interface for QMP qmp_blockdev_add(), = because > the HMP commands behave differently for historical reasons (read: > they're messed up, but we won't change them until the ongoing work on > the QMP commands is complete). >=20 >=20 > [1] Subject: Re: [Qemu-devel] function to execute qmp commands > Date: Tue, 01 Sep 2015 08:19:02 +0200 > Message-ID: <87lhcqbr1l.fsf@blackfin.pond.sub.org> >=20 > [2] Subject: Re: [Qemu-devel] Mount image file feature > Date: Thu, 03 Sep 2015 11:46:29 +0200 > Message-ID: <878u8nygwa.fsf@blackfin.pond.sub.org> >=20 > [3] Subject: Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add Mount image file > menu item > Date: Tue, 08 Sep 2015 20:46:02 +0200 > Message-ID: <87fv2og36d.fsf@blackfin.pond.sub.org> Thank you very much for caring. I appreciate all the help I can receive. = I so like my idea of sending a command to QEMU as if the user typed it himself. It is so easy = to maintain. So=20 easy to use. So expandable. But given that two maintainers have told me = that I can't do this, the idea has to be abandoned.=20 The C interface idea sounds good, but trying to figure out how to make = any of the handler functions work is very difficult. Just trying to make the QDict and = QObject variables is just too much. It needs to be a lot easier than this. That leaves QMP. I am trying to figure it out. This is my attempt so = far: Error **errp; char *commandBuffer; commandBuffer =3D g_strdup_printf("{ \"execute\": \"quit\" }"); qmp_query_command_line_options(false, commandBuffer, errp); printf("Program should quit now\n"); For some reason it didn't work. What am I doing wrong? Examples would = really help.=