Skip to content

Commit

Permalink
monitor: Add ringbuf_write and ringbuf_read argument completion
Browse files Browse the repository at this point in the history
Export chr_is_ringbuf() function. Also remove left-over function prototypes
while at it.

Signed-off-by: Hani Benhabiles <[email protected]>
Signed-off-by: Luiz Capitulino <[email protected]>
  • Loading branch information
kroosec authored and Luiz Capitulino committed Jun 11, 2014
1 parent b87ef35 commit 8e59777
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions hmp-commands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ ETEXI
.params = "device data",
.help = "Write to a ring buffer character device",
.mhandler.cmd = hmp_ringbuf_write,
.command_completion = ringbuf_write_completion,
},
STEXI
Expand All @@ -868,6 +869,7 @@ ETEXI
.params = "device size",
.help = "Read from a ring buffer character device",
.mhandler.cmd = hmp_ringbuf_read,
.command_completion = ringbuf_write_completion,
},
STEXI
Expand Down
2 changes: 2 additions & 0 deletions hmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,7 @@ void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str);
void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str);
void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);

#endif
3 changes: 1 addition & 2 deletions include/sysemu/char.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,8 @@ void qemu_chr_add_handlers(CharDriverState *s,
void qemu_chr_be_generic_open(CharDriverState *s);
void qemu_chr_accept_input(CharDriverState *s);
int qemu_chr_add_client(CharDriverState *s, int fd);
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);
bool chr_is_ringbuf(const CharDriverState *chr);

QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);

Expand Down
39 changes: 39 additions & 0 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -4412,6 +4412,45 @@ void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
qapi_free_ChardevInfoList(start);
}

static void ringbuf_completion(ReadLineState *rs, const char *str)
{
size_t len;
ChardevInfoList *list, *start;

len = strlen(str);
readline_set_completion_index(rs, len);

start = list = qmp_query_chardev(NULL);
while (list) {
ChardevInfo *chr_info = list->value;

if (!strncmp(chr_info->label, str, len)) {
CharDriverState *chr = qemu_chr_find(chr_info->label);
if (chr && chr_is_ringbuf(chr)) {
readline_add_completion(rs, chr_info->label);
}
}
list = list->next;
}
qapi_free_ChardevInfoList(start);
}

void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str)
{
if (nb_args != 2) {
return;
}
ringbuf_completion(rs, str);
}

void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str)
{
if (nb_args != 2) {
return;
}
ringbuf_completion(rs, str);
}

void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
{
size_t len;
Expand Down
2 changes: 1 addition & 1 deletion qemu-char.c
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,7 @@ static CharDriverState *qemu_chr_open_ringbuf(ChardevRingbuf *opts,
return NULL;
}

static bool chr_is_ringbuf(const CharDriverState *chr)
bool chr_is_ringbuf(const CharDriverState *chr)
{
return chr->chr_write == ringbuf_chr_write;
}
Expand Down

0 comments on commit 8e59777

Please sign in to comment.