From: Luiz Capitulino <lcapitulino@redhat.com>
To: Adam Litke <agl@us.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [RFC] New API for asynchronous monitor commands
Date: Mon, 25 Jan 2010 13:02:41 -0200 [thread overview]
Message-ID: <20100125130241.1f1d603e@doriath> (raw)
In-Reply-To: <1264428045.24893.22.camel@aglitke>
On Mon, 25 Jan 2010 08:00:45 -0600
Adam Litke <agl@us.ibm.com> wrote:
> On Mon, 2010-01-25 at 11:08 -0200, Luiz Capitulino wrote:
> > > @@ -85,11 +91,19 @@ typedef struct mon_cmd_t {
> > > union {
> > > void (*info)(Monitor *mon);
> > > void (*info_new)(Monitor *mon, QObject **ret_data);
> > > + int (*info_async)(Monitor *mon, QMPCompletion *cb, void *opaque);
> > > void (*cmd)(Monitor *mon, const QDict *qdict);
> > > void (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data);
> > > + int (*cmd_async)(Monitor *mon, const QDict *params,
> > > + QMPCompletion *cb, void *opaque);
> > > } mhandler;
> > > + int async;
> > > } mon_cmd_t;
> >
> > Is 'async' really needed, can't use 'info_async' or 'cmd_async'?
>
> Yes. Otherwise the code cannot tell the difference between a monitor
> command that uses cmd_new and a one using the cmd_async. They both pass
> the monitor_handler_ported() test. Unless there is some underhanded way
> of determining which union type is in use for mhandler, we are stuck
> with the extra variable -- that is, unless we port all cmd_new cmds to
> the new async API :)
The async member can stay then :)
> > > +static void do_async_info_handler(Monitor *mon, const mon_cmd_t *cmd);
> > > +static void do_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd,
> > > + const QDict *params);
> > > +
> >
> > Isn't it possible to avoid this forward declarations?
>
> Sure, but I found the code more readable when I could define the
> handlers near monitor_call_handler(). However, I dislike forward
> declarations as much as the next guy. I'll make it go away.
The real solution is to split this code in more files.
> > > +static void qmp_monitor_complete(void *opaque, QObject *ret_data)
> > > +{
> > > + Monitor *mon = (Monitor *)opaque;
> > > + monitor_protocol_emitter(mon, ret_data);
> > > +}
> >
> > You should free ret_data as well with:
> >
> > qobject_decref(ret_data);
>
> Hmm. The way I saw this working was like so:
>
> do_async_cmd_handler()
> cmd->mhandler.cmd_async()
> dispatch_async_cmd()
> ...
> command_completion_event()
> QObject *ret_data = qobject_from_jsonf("'foo': 'bar'");
> QMPCompletion(opaque, ret_data);
> qobject_decref(ret_data);
>
> In other words, the qobject ret_data is created by the caller of the
> QMPCompletion callback. Therefore, it seemed natural to let that
> routine clean up the qobject rather than letting the callback "consume"
> it. I realize that this patch makes it impossible to infer the above
> explanation since an example async command implementation was not
> provided. Since you designed the qobject interfaces, you have the best
> idea on how it should work. Does the above make sense?
Yes, it does. No need to change.
next prev parent reply other threads:[~2010-01-25 15:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-22 19:03 [Qemu-devel] [RFC] New API for asynchronous monitor commands Adam Litke
2010-01-22 23:17 ` [Qemu-devel] " Anthony Liguori
2010-01-24 10:55 ` Avi Kivity
2010-01-25 13:10 ` Luiz Capitulino
2010-01-24 10:59 ` [Qemu-devel] " Avi Kivity
2010-01-24 14:01 ` Anthony Liguori
2010-01-24 14:19 ` Avi Kivity
2010-01-25 13:12 ` Luiz Capitulino
2010-01-25 13:08 ` [Qemu-devel] " Luiz Capitulino
2010-01-25 14:00 ` Adam Litke
2010-01-25 15:02 ` Luiz Capitulino [this message]
2010-01-25 14:15 ` Anthony Liguori
2010-01-25 14:51 ` Luiz Capitulino
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=20100125130241.1f1d603e@doriath \
--to=lcapitulino@redhat.com \
--cc=agl@us.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).