From: Markus Armbruster <armbru@redhat.com>
To: Programmingkid <programmingkidx@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
qemu-devel qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add Mount image file menu item
Date: Thu, 10 Sep 2015 09:17:24 +0200 [thread overview]
Message-ID: <877fny216j.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <2B86F391-FA17-49B1-BB80-23570170FEC5@gmail.com> (Programmingkid's message of "Wed, 9 Sep 2015 19:34:12 -0400")
Programmingkid <programmingkidx@gmail.com> writes:
> On Sep 9, 2015, at 6:25 PM, Eric Blake wrote:
>
>> On 09/09/2015 03:37 PM, Programmingkid wrote:
>>
>>>
>>> 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
>>> 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.
>>
>> Even emulating typing into the QMP interface is a non-starter. Just
>> call the same functions that QMP would eventually call.
>
> That is a lot easier said than done.
Most of the time, it's actually a lot easier than creating a monitor,
constructing a command safely (mind the quoting rules), feeding it to
the monitor, receiving the reply, parsing the reply, and having fun with
manual memory management along the way.
For an exception, see below.
>>> 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 = g_strdup_printf("{ \"execute\": \"quit\" }");
>>> qmp_query_command_line_options(false, commandBuffer, errp);
>>> printf("Program should quit now\n");
>>>
>>
>> If you type the QMP command:
>>
>> { "execute": "query-command-line-options", "arguments": { "option":
>> "quit" } }
>>
>> then that will result in calling:
>>
>> Error *err;
>> qmp_query_command_line_options(true, "quit", &err);
>>
>> which will set err (because '-quit' is not a command line option).
>>
>> But if you are worried about constructing a QDict (which is a subset of
>> QObject), you are probably trying to call the wrong interface.
>
> That may be so. I need to do the equivalent of "device_add" and "device_del".
> You have any ideas how to do it in C?
That's the exception. See further below.
>> In qmp-commands.hx, the command 'query-command-line-options' is tied to
>> qmp_marshal_query_command_line_options (well, after Markus' latest
>> patches are applied; in current qemu.git it is still named
>> qmp_marshal_input_query_command_line_options). That is the generated
>> function that takes QDict, and then calls into the much nicer interface
>> of qmp_query_command_line_options() that has already broken out all the
>> arguments into straight-forward parameters.
>
> I just wish it was as easy as qmp("{ \"execute\" : \"<some command> \"}");
What's difficult about any of the following?
qmp_system_reset(&err);
qmp_query_command_line_options(false, NULL, &err);
qmp_device_del("my-dev-id", &err);
Each of them is about as simple as it gets.
The sad exceptions are the QMP commands defined with 'gen': false. For
these, you have to use a much less convenient interface, of the form
void qmp_FOO(QDict *qdict, QObject **ret_data, Error **errp);
Matches the QMP wire format closely. qdict corrsponds to the
"arguments" JSON object, ret_data corresponds to the success response's
"return" JSON value, and errp corresponds do the error response.
There are only a few such commands, and we're working on reducing their
number further. The hardest nut, however, is device_add.
> If you know a way to execute a qmp command by using a function that
> takes a string,
> please let me know.
If there was one, it wouldn't be the C interface you should use.
next prev parent reply other threads:[~2015-09-10 7:17 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-02 0:56 [Qemu-devel] [PATCH] ui/cocoa.m: Add Mount image file menu item Programmingkid
2015-09-02 9:05 ` Markus Armbruster
2015-09-08 16:17 ` Peter Maydell
2015-09-08 16:39 ` Programmingkid
2015-09-08 16:54 ` Peter Maydell
2015-09-08 18:46 ` Markus Armbruster
2015-09-09 3:02 ` Programmingkid
2015-09-09 7:29 ` Markus Armbruster
2015-09-09 21:37 ` Programmingkid
2015-09-09 22:25 ` Eric Blake
2015-09-09 22:31 ` Eric Blake
2015-09-09 23:35 ` Programmingkid
2015-09-09 23:34 ` Programmingkid
2015-09-10 7:17 ` Markus Armbruster [this message]
2015-09-10 3:28 ` Programmingkid
2015-09-10 7:21 ` Markus Armbruster
2015-09-10 16:22 ` Programmingkid
2015-09-10 17:15 ` Markus Armbruster
2015-09-10 17:40 ` Programmingkid
2015-09-11 7:09 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877fny216j.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=programmingkidx@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.