Message ID | 1258489944-12159-13-git-send-email-lcapitulino@redhat.com |
---|---|
State | New |
Headers | show |
Luiz Capitulino <lcapitulino@redhat.com> writes: > Each device is represented by a QDict. The returned QObject is a QList > of all devices. > > This commit should not change user output. > > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> > --- > monitor.c | 3 ++- > qemu-char.c | 43 +++++++++++++++++++++++++++++++++++++++++-- > qemu-char.h | 4 +++- > 3 files changed, 46 insertions(+), 4 deletions(-) > > diff --git a/monitor.c b/monitor.c > index e4fed10..a0a9281 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -2040,7 +2040,8 @@ static const mon_cmd_t info_cmds[] = { > .args_type = "", > .params = "", > .help = "show the character devices", > - .mhandler.info = qemu_chr_info, > + .user_print = qemu_chr_info_print, > + .mhandler.info_new = qemu_chr_info, > }, > { > .name = "block", > diff --git a/qemu-char.c b/qemu-char.c > index 5a81e8f..7fcde98 100644 > --- a/qemu-char.c > +++ b/qemu-char.c > @@ -32,6 +32,7 @@ > #include "hw/usb.h" > #include "hw/baum.h" > #include "hw/msmouse.h" > +#include "qemu-objects.h" > > #include <unistd.h> > #include <fcntl.h> > @@ -2465,13 +2466,51 @@ void qemu_chr_close(CharDriverState *chr) > qemu_free(chr); > } > > -void qemu_chr_info(Monitor *mon) > +static void qemu_chr_print_qlist(QObject *obj, void *opaque) Why *_qlist? It prints a qdict, which happens to be a list element, but this function doesn't know that. > { > + QDict *chr_dict; > + Monitor *mon = opaque; > + > + chr_dict = qobject_to_qdict(obj); > + monitor_printf(mon, "%s: filename=%s\n", qdict_get_str(chr_dict, "label"), > + qdict_get_str(chr_dict, "filename")); > +} > + > +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data) > +{ > + qlist_iter(qobject_to_qlist(ret_data), qemu_chr_print_qlist, mon); > +} [...]
On Fri, 20 Nov 2009 15:10:20 +0100 Markus Armbruster <armbru@redhat.com> wrote: > Luiz Capitulino <lcapitulino@redhat.com> writes: > > > Each device is represented by a QDict. The returned QObject is a QList > > of all devices. > > > > This commit should not change user output. > > > > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> > > --- > > monitor.c | 3 ++- > > qemu-char.c | 43 +++++++++++++++++++++++++++++++++++++++++-- > > qemu-char.h | 4 +++- > > 3 files changed, 46 insertions(+), 4 deletions(-) > > > > diff --git a/monitor.c b/monitor.c > > index e4fed10..a0a9281 100644 > > --- a/monitor.c > > +++ b/monitor.c > > @@ -2040,7 +2040,8 @@ static const mon_cmd_t info_cmds[] = { > > .args_type = "", > > .params = "", > > .help = "show the character devices", > > - .mhandler.info = qemu_chr_info, > > + .user_print = qemu_chr_info_print, > > + .mhandler.info_new = qemu_chr_info, > > }, > > { > > .name = "block", > > diff --git a/qemu-char.c b/qemu-char.c > > index 5a81e8f..7fcde98 100644 > > --- a/qemu-char.c > > +++ b/qemu-char.c > > @@ -32,6 +32,7 @@ > > #include "hw/usb.h" > > #include "hw/baum.h" > > #include "hw/msmouse.h" > > +#include "qemu-objects.h" > > > > #include <unistd.h> > > #include <fcntl.h> > > @@ -2465,13 +2466,51 @@ void qemu_chr_close(CharDriverState *chr) > > qemu_free(chr); > > } > > > > -void qemu_chr_info(Monitor *mon) > > +static void qemu_chr_print_qlist(QObject *obj, void *opaque) > > Why *_qlist? It prints a qdict, which happens to be a list element, but > this function doesn't know that. It does know, as it was written with the purpose of printing the elements of a qlist.
Luiz Capitulino <lcapitulino@redhat.com> writes: > On Fri, 20 Nov 2009 15:10:20 +0100 > Markus Armbruster <armbru@redhat.com> wrote: > >> Luiz Capitulino <lcapitulino@redhat.com> writes: >> >> > Each device is represented by a QDict. The returned QObject is a QList >> > of all devices. >> > >> > This commit should not change user output. >> > >> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> >> > --- >> > monitor.c | 3 ++- >> > qemu-char.c | 43 +++++++++++++++++++++++++++++++++++++++++-- >> > qemu-char.h | 4 +++- >> > 3 files changed, 46 insertions(+), 4 deletions(-) >> > >> > diff --git a/monitor.c b/monitor.c >> > index e4fed10..a0a9281 100644 >> > --- a/monitor.c >> > +++ b/monitor.c [...] >> > @@ -2465,13 +2466,51 @@ void qemu_chr_close(CharDriverState *chr) >> > qemu_free(chr); >> > } >> > >> > -void qemu_chr_info(Monitor *mon) >> > +static void qemu_chr_print_qlist(QObject *obj, void *opaque) >> >> Why *_qlist? It prints a qdict, which happens to be a list element, but >> this function doesn't know that. > > It does know, as it was written with the purpose of printing the elements > of a qlist. You knew it when you wrote it, but the function itself has nothing to do with lists. Elsewhere, you call such functions *_dict(), which makes sense to me, because it prints a dictionary, or *_iter(), which I is also okay.
diff --git a/monitor.c b/monitor.c index e4fed10..a0a9281 100644 --- a/monitor.c +++ b/monitor.c @@ -2040,7 +2040,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the character devices", - .mhandler.info = qemu_chr_info, + .user_print = qemu_chr_info_print, + .mhandler.info_new = qemu_chr_info, }, { .name = "block", diff --git a/qemu-char.c b/qemu-char.c index 5a81e8f..7fcde98 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -32,6 +32,7 @@ #include "hw/usb.h" #include "hw/baum.h" #include "hw/msmouse.h" +#include "qemu-objects.h" #include <unistd.h> #include <fcntl.h> @@ -2465,13 +2466,51 @@ void qemu_chr_close(CharDriverState *chr) qemu_free(chr); } -void qemu_chr_info(Monitor *mon) +static void qemu_chr_print_qlist(QObject *obj, void *opaque) { + QDict *chr_dict; + Monitor *mon = opaque; + + chr_dict = qobject_to_qdict(obj); + monitor_printf(mon, "%s: filename=%s\n", qdict_get_str(chr_dict, "label"), + qdict_get_str(chr_dict, "filename")); +} + +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data) +{ + qlist_iter(qobject_to_qlist(ret_data), qemu_chr_print_qlist, mon); +} + +/** + * qemu_chr_info(): Character devices information + * + * Each device is represented by a QDict. The returned QObject is a QList + * of all devices. + * + * The QDict contains the following: + * + * - "label": device's label + * - "filename": device's file + * + * Example: + * + * [ { "label": "monitor", "filename", "stdio" }, + * { "label": "serial0", "filename": "vc" } ] + */ +void qemu_chr_info(Monitor *mon, QObject **ret_data) +{ + QList *chr_list; CharDriverState *chr; + chr_list = qlist_new(); + QTAILQ_FOREACH(chr, &chardevs, next) { - monitor_printf(mon, "%s: filename=%s\n", chr->label, chr->filename); + QObject *obj = qobject_from_jsonf("{ 'label': %s, 'filename': %s }", + chr->label, chr->filename); + qlist_append_obj(chr_list, obj); } + + *ret_data = QOBJECT(chr_list); } CharDriverState *qemu_chr_find(const char *name) diff --git a/qemu-char.h b/qemu-char.h index 9957db1..48f54d8 100644 --- a/qemu-char.h +++ b/qemu-char.h @@ -5,6 +5,7 @@ #include "qemu-queue.h" #include "qemu-option.h" #include "qemu-config.h" +#include "qobject.h" /* character device */ @@ -87,7 +88,8 @@ int qemu_chr_can_read(CharDriverState *s); void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len); int qemu_chr_get_msgfd(CharDriverState *s); void qemu_chr_accept_input(CharDriverState *s); -void qemu_chr_info(Monitor *mon); +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data); +void qemu_chr_info(Monitor *mon, QObject **ret_data); CharDriverState *qemu_chr_find(const char *name); extern int term_escape_char;
Each device is represented by a QDict. The returned QObject is a QList of all devices. This commit should not change user output. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> --- monitor.c | 3 ++- qemu-char.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qemu-char.h | 4 +++- 3 files changed, 46 insertions(+), 4 deletions(-)