qdev: Move HMP command completion from monitor to softmmu/

This moves the completion code from MAINTAINERS sections "Human
Monitor (HMP)" and "QMP" to section "QOM".

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20230124121946.1139465-26-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2023-01-24 13:19:39 +01:00
parent 5bd26d78d9
commit 9c9c5ce7f7
2 changed files with 82 additions and 82 deletions

View File

@ -1206,88 +1206,6 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
return ret; return ret;
} }
void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
{
GSList *list, *elt;
size_t len;
if (nb_args != 2) {
return;
}
len = strlen(str);
readline_set_completion_index(rs, len);
list = elt = object_class_get_list(TYPE_DEVICE, false);
while (elt) {
DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
TYPE_DEVICE);
if (dc->user_creatable) {
readline_add_completion_of(rs, str,
object_class_get_name(OBJECT_CLASS(dc)));
}
elt = elt->next;
}
g_slist_free(list);
}
static int qdev_add_hotpluggable_device(Object *obj, void *opaque)
{
GSList **list = opaque;
DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
if (dev == NULL) {
return 0;
}
if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
*list = g_slist_append(*list, dev);
}
return 0;
}
static GSList *qdev_build_hotpluggable_device_list(Object *peripheral)
{
GSList *list = NULL;
object_child_foreach(peripheral, qdev_add_hotpluggable_device, &list);
return list;
}
static void peripheral_device_del_completion(ReadLineState *rs,
const char *str)
{
Object *peripheral = container_get(qdev_get_machine(), "/peripheral");
GSList *list, *item;
list = qdev_build_hotpluggable_device_list(peripheral);
if (!list) {
return;
}
for (item = list; item; item = g_slist_next(item)) {
DeviceState *dev = item->data;
if (dev->id) {
readline_add_completion_of(rs, str, dev->id);
}
}
g_slist_free(list);
}
void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
{
if (nb_args != 2) {
return;
}
readline_set_completion_index(rs, strlen(str));
peripheral_device_del_completion(rs, str);
}
static int static int
compare_mon_cmd(const void *a, const void *b) compare_mon_cmd(const void *a, const void *b)
{ {

View File

@ -973,6 +973,88 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
hmp_handle_error(mon, err); hmp_handle_error(mon, err);
} }
void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
{
GSList *list, *elt;
size_t len;
if (nb_args != 2) {
return;
}
len = strlen(str);
readline_set_completion_index(rs, len);
list = elt = object_class_get_list(TYPE_DEVICE, false);
while (elt) {
DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
TYPE_DEVICE);
if (dc->user_creatable) {
readline_add_completion_of(rs, str,
object_class_get_name(OBJECT_CLASS(dc)));
}
elt = elt->next;
}
g_slist_free(list);
}
static int qdev_add_hotpluggable_device(Object *obj, void *opaque)
{
GSList **list = opaque;
DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
if (dev == NULL) {
return 0;
}
if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
*list = g_slist_append(*list, dev);
}
return 0;
}
static GSList *qdev_build_hotpluggable_device_list(Object *peripheral)
{
GSList *list = NULL;
object_child_foreach(peripheral, qdev_add_hotpluggable_device, &list);
return list;
}
static void peripheral_device_del_completion(ReadLineState *rs,
const char *str)
{
Object *peripheral = container_get(qdev_get_machine(), "/peripheral");
GSList *list, *item;
list = qdev_build_hotpluggable_device_list(peripheral);
if (!list) {
return;
}
for (item = list; item; item = g_slist_next(item)) {
DeviceState *dev = item->data;
if (dev->id) {
readline_add_completion_of(rs, str, dev->id);
}
}
g_slist_free(list);
}
void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
{
if (nb_args != 2) {
return;
}
readline_set_completion_index(rs, strlen(str));
peripheral_device_del_completion(rs, str);
}
BlockBackend *blk_by_qdev_id(const char *id, Error **errp) BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
{ {
DeviceState *dev; DeviceState *dev;