Message ID | 2dcacefd7562e5785174f1e167fe76fd8f077a48.1268994938.git.shaharh@redhat.com |
---|---|
State | New |
Headers | show |
On Fri, 19 Mar 2010 12:58:43 +0200 Shahar Havivi <shaharh@redhat.com> wrote: > This new monitor command adding ability to handle which keyboard qemu will use > and to see which keyboard are currently available. > > > Signed-off-by: Shahar Havivi <shaharh@redhat.com> > --- > input.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > monitor.c | 8 ++++++ > qemu-monitor.hx | 17 +++++++++++++ > 3 files changed, 98 insertions(+), 0 deletions(-) > > diff --git a/input.c b/input.c > index 4b86f48..c883b5b 100644 > --- a/input.c > +++ b/input.c > @@ -337,3 +337,76 @@ void do_mouse_set(Monitor *mon, const QDict *qdict) > else > monitor_printf(mon, "Mouse at given index not found\n"); > } > + > +static void info_keyboard_iter(QObject *data, void *opaque) > +{ > + QDict *kbd; > + Monitor *mon = opaque; > + > + kbd = qobject_to_qdict(data); > + monitor_printf(mon, "%c Keyboard #%" PRId64 ": %s\n", > + (qdict_get_bool(kbd, "current") ? '*' : ' '), > + qdict_get_int(kbd, "index"), qdict_get_str(kbd, "name")); > +} > + > +void do_info_keyboard_print(Monitor *mon, const QObject *data) > +{ > + QList *kbd_list; > + > + kbd_list = qobject_to_qlist(data); > + if (qlist_empty(kbd_list)) { > + monitor_printf(mon, "No keyboard devices connected\n"); > + return; > + } > + > + qlist_iter(kbd_list, info_keyboard_iter, mon); > +} > + > +void do_info_keyboard(Monitor *mon, QObject **ret_data) > +{ Please, document the data you return, you can look at do_info_mice() for an example. > + QEMUPutKbdEntry *cursor; > + QList *kbd_list; > + int index = 0; > + > + kbd_list = qlist_new(); > + > + if (!qemu_put_kbd_event_head) { > + goto out; > + } > + > + cursor = qemu_put_kbd_event_head; > + while (cursor != NULL) { > + QObject *obj; > + obj = qobject_from_jsonf("{ 'name': %s, 'index': %d, 'current': %i }", > + cursor->qemu_put_kbd_name, > + index, cursor == qemu_put_kbd_event_current); > + qlist_append_obj(kbd_list, obj); > + index++; > + cursor = cursor->next; > + } > +out: > + *ret_data = QOBJECT(kbd_list); > +} > + > +void do_keyboard_set(Monitor *mon, const QDict *qdict) > +{ > + QEMUPutKbdEntry *cursor; > + int i = 0; > + int index = qdict_get_int(qdict, "index"); > + > + if (!qemu_put_kbd_event_head) { > + monitor_printf(mon, "No keyboard devices connected\n"); > + return; > + } > + > + cursor = qemu_put_kbd_event_head; > + while (cursor != NULL && index != i) { > + i++; > + cursor = cursor->next; > + } > + > + if (cursor != NULL) > + qemu_put_kbd_event_current = cursor; > + else > + monitor_printf(mon, "Keyboard at given index not found\n"); > +} > diff --git a/monitor.c b/monitor.c > index 0448a70..cc95b3d 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -2783,6 +2783,14 @@ static const mon_cmd_t info_cmds[] = { > .mhandler.info_new = do_info_mice, > }, > { > + .name = "keyboard", > + .args_type = "", > + .params = "", > + .help = "show which guest keyboard is receiving events", > + .user_print = do_info_keyboard_print, > + .mhandler.info_new = do_info_keyboard, > + }, > + { > .name = "vnc", > .args_type = "", > .params = "", > diff --git a/qemu-monitor.hx b/qemu-monitor.hx > index 5308f36..d86be17 100644 > --- a/qemu-monitor.hx > +++ b/qemu-monitor.hx > @@ -659,6 +659,23 @@ info mice > @end example > ETEXI > > + { > + .name = "keyboard_set", > + .args_type = "index:i", > + .params = "index", > + .help = "set which keyboard device receives events", > + .mhandler.cmd = do_keyboard_set, > + }, keyboard_set is not available under QMP, do you have an special reason to do so or you have just done like the do_mouse_set()? In any case, you should use mhandler.cmd_new as mhandler.cmd is going to be deprecated (which also means you should use qerror_report() to report errors). > + > +STEXI > +@item keyboard_set @var{index} > +@findex keyboard_set > +Set which keyboard device receives events at given @var{index}, index > +can be obtained with > +@example > +info keyboard > +@end example > +ETEXI > #ifdef HAS_AUDIO > { > .name = "wavcapture",
On Fri, Mar 19, 2010 at 05:22:05PM -0300, Luiz Capitulino wrote: > Date: Fri, 19 Mar 2010 17:22:05 -0300 > From: Luiz Capitulino <lcapitulino@redhat.com> > To: Shahar Havivi <shaharh@redhat.com> > Cc: Dor Laor <dlaor@redhat.com>, qemu-devel@nongnu.org > Subject: Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' > and 'info keybaord' > > On Fri, 19 Mar 2010 12:58:43 +0200 > Shahar Havivi <shaharh@redhat.com> wrote: > > > This new monitor command adding ability to handle which keyboard qemu will use > > and to see which keyboard are currently available. > > > > > > Signed-off-by: Shahar Havivi <shaharh@redhat.com> > > --- > > input.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > monitor.c | 8 ++++++ > > qemu-monitor.hx | 17 +++++++++++++ > > 3 files changed, 98 insertions(+), 0 deletions(-) > > > > diff --git a/input.c b/input.c > > index 4b86f48..c883b5b 100644 > > --- a/input.c > > +++ b/input.c > > @@ -337,3 +337,76 @@ void do_mouse_set(Monitor *mon, const QDict *qdict) > > else > > monitor_printf(mon, "Mouse at given index not found\n"); > > } > > + > > +static void info_keyboard_iter(QObject *data, void *opaque) > > +{ > > + QDict *kbd; > > + Monitor *mon = opaque; > > + > > + kbd = qobject_to_qdict(data); > > + monitor_printf(mon, "%c Keyboard #%" PRId64 ": %s\n", > > + (qdict_get_bool(kbd, "current") ? '*' : ' '), > > + qdict_get_int(kbd, "index"), qdict_get_str(kbd, "name")); > > +} > > + > > +void do_info_keyboard_print(Monitor *mon, const QObject *data) > > +{ > > + QList *kbd_list; > > + > > + kbd_list = qobject_to_qlist(data); > > + if (qlist_empty(kbd_list)) { > > + monitor_printf(mon, "No keyboard devices connected\n"); > > + return; > > + } > > + > > + qlist_iter(kbd_list, info_keyboard_iter, mon); > > +} > > + > > +void do_info_keyboard(Monitor *mon, QObject **ret_data) > > +{ > > Please, document the data you return, you can look at do_info_mice() > for an example. > > > + QEMUPutKbdEntry *cursor; > > + QList *kbd_list; > > + int index = 0; > > + > > + kbd_list = qlist_new(); > > + > > + if (!qemu_put_kbd_event_head) { > > + goto out; > > + } > > + > > + cursor = qemu_put_kbd_event_head; > > + while (cursor != NULL) { > > + QObject *obj; > > + obj = qobject_from_jsonf("{ 'name': %s, 'index': %d, 'current': %i }", > > + cursor->qemu_put_kbd_name, > > + index, cursor == qemu_put_kbd_event_current); > > + qlist_append_obj(kbd_list, obj); > > + index++; > > + cursor = cursor->next; > > + } > > +out: > > + *ret_data = QOBJECT(kbd_list); > > +} > > + > > +void do_keyboard_set(Monitor *mon, const QDict *qdict) > > +{ > > + QEMUPutKbdEntry *cursor; > > + int i = 0; > > + int index = qdict_get_int(qdict, "index"); > > + > > + if (!qemu_put_kbd_event_head) { > > + monitor_printf(mon, "No keyboard devices connected\n"); > > + return; > > + } > > + > > + cursor = qemu_put_kbd_event_head; > > + while (cursor != NULL && index != i) { > > + i++; > > + cursor = cursor->next; > > + } > > + > > + if (cursor != NULL) > > + qemu_put_kbd_event_current = cursor; > > + else > > + monitor_printf(mon, "Keyboard at given index not found\n"); > > +} > > diff --git a/monitor.c b/monitor.c > > index 0448a70..cc95b3d 100644 > > --- a/monitor.c > > +++ b/monitor.c > > @@ -2783,6 +2783,14 @@ static const mon_cmd_t info_cmds[] = { > > .mhandler.info_new = do_info_mice, > > }, > > { > > + .name = "keyboard", > > + .args_type = "", > > + .params = "", > > + .help = "show which guest keyboard is receiving events", > > + .user_print = do_info_keyboard_print, > > + .mhandler.info_new = do_info_keyboard, > > + }, > > + { > > .name = "vnc", > > .args_type = "", > > .params = "", > > diff --git a/qemu-monitor.hx b/qemu-monitor.hx > > index 5308f36..d86be17 100644 > > --- a/qemu-monitor.hx > > +++ b/qemu-monitor.hx > > @@ -659,6 +659,23 @@ info mice > > @end example > > ETEXI > > > > + { > > + .name = "keyboard_set", > > + .args_type = "index:i", > > + .params = "index", > > + .help = "set which keyboard device receives events", > > + .mhandler.cmd = do_keyboard_set, > > + }, > > keyboard_set is not available under QMP, do you have an special > reason to do so or you have just done like the do_mouse_set()? I use it just like the mouse. > > In any case, you should use mhandler.cmd_new as mhandler.cmd is > going to be deprecated (which also means you should use > qerror_report() to report errors). Thanks for the comment I will change it. Shahar. > > > + > > +STEXI > > +@item keyboard_set @var{index} > > +@findex keyboard_set > > +Set which keyboard device receives events at given @var{index}, index > > +can be obtained with > > +@example > > +info keyboard > > +@end example > > +ETEXI > > #ifdef HAS_AUDIO > > { > > .name = "wavcapture", > > >
diff --git a/input.c b/input.c index 4b86f48..c883b5b 100644 --- a/input.c +++ b/input.c @@ -337,3 +337,76 @@ void do_mouse_set(Monitor *mon, const QDict *qdict) else monitor_printf(mon, "Mouse at given index not found\n"); } + +static void info_keyboard_iter(QObject *data, void *opaque) +{ + QDict *kbd; + Monitor *mon = opaque; + + kbd = qobject_to_qdict(data); + monitor_printf(mon, "%c Keyboard #%" PRId64 ": %s\n", + (qdict_get_bool(kbd, "current") ? '*' : ' '), + qdict_get_int(kbd, "index"), qdict_get_str(kbd, "name")); +} + +void do_info_keyboard_print(Monitor *mon, const QObject *data) +{ + QList *kbd_list; + + kbd_list = qobject_to_qlist(data); + if (qlist_empty(kbd_list)) { + monitor_printf(mon, "No keyboard devices connected\n"); + return; + } + + qlist_iter(kbd_list, info_keyboard_iter, mon); +} + +void do_info_keyboard(Monitor *mon, QObject **ret_data) +{ + QEMUPutKbdEntry *cursor; + QList *kbd_list; + int index = 0; + + kbd_list = qlist_new(); + + if (!qemu_put_kbd_event_head) { + goto out; + } + + cursor = qemu_put_kbd_event_head; + while (cursor != NULL) { + QObject *obj; + obj = qobject_from_jsonf("{ 'name': %s, 'index': %d, 'current': %i }", + cursor->qemu_put_kbd_name, + index, cursor == qemu_put_kbd_event_current); + qlist_append_obj(kbd_list, obj); + index++; + cursor = cursor->next; + } +out: + *ret_data = QOBJECT(kbd_list); +} + +void do_keyboard_set(Monitor *mon, const QDict *qdict) +{ + QEMUPutKbdEntry *cursor; + int i = 0; + int index = qdict_get_int(qdict, "index"); + + if (!qemu_put_kbd_event_head) { + monitor_printf(mon, "No keyboard devices connected\n"); + return; + } + + cursor = qemu_put_kbd_event_head; + while (cursor != NULL && index != i) { + i++; + cursor = cursor->next; + } + + if (cursor != NULL) + qemu_put_kbd_event_current = cursor; + else + monitor_printf(mon, "Keyboard at given index not found\n"); +} diff --git a/monitor.c b/monitor.c index 0448a70..cc95b3d 100644 --- a/monitor.c +++ b/monitor.c @@ -2783,6 +2783,14 @@ static const mon_cmd_t info_cmds[] = { .mhandler.info_new = do_info_mice, }, { + .name = "keyboard", + .args_type = "", + .params = "", + .help = "show which guest keyboard is receiving events", + .user_print = do_info_keyboard_print, + .mhandler.info_new = do_info_keyboard, + }, + { .name = "vnc", .args_type = "", .params = "", diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 5308f36..d86be17 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -659,6 +659,23 @@ info mice @end example ETEXI + { + .name = "keyboard_set", + .args_type = "index:i", + .params = "index", + .help = "set which keyboard device receives events", + .mhandler.cmd = do_keyboard_set, + }, + +STEXI +@item keyboard_set @var{index} +@findex keyboard_set +Set which keyboard device receives events at given @var{index}, index +can be obtained with +@example +info keyboard +@end example +ETEXI #ifdef HAS_AUDIO { .name = "wavcapture",
This new monitor command adding ability to handle which keyboard qemu will use and to see which keyboard are currently available. Signed-off-by: Shahar Havivi <shaharh@redhat.com> --- input.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ monitor.c | 8 ++++++ qemu-monitor.hx | 17 +++++++++++++ 3 files changed, 98 insertions(+), 0 deletions(-)