From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIHgq-0001vG-HD for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:37:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIHgg-00066l-Df for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:37:08 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:42482 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIHgg-000655-3X for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:36:58 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Fri, 15 Aug 2014 15:35:54 +0200 Message-Id: <1408109759-1100-23-git-send-email-benoit.canet@nodalink.com> In-Reply-To: <1408109759-1100-1-git-send-email-benoit.canet@nodalink.com> References: <1408109759-1100-1-git-send-email-benoit.canet@nodalink.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 22/26] monitor: Extract hardware dependent completion function from monitor.c to monitor-system.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Signed-off-by: Beno=C3=AEt Canet --- monitor-system.c | 283 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ monitor.c | 281 -------------------------------------------------= ----- 2 files changed, 283 insertions(+), 281 deletions(-) diff --git a/monitor-system.c b/monitor-system.c index bc5e8f4..19c7ba5 100644 --- a/monitor-system.c +++ b/monitor-system.c @@ -49,6 +49,8 @@ #include "net/slirp.h" #include "sysemu/blockdev.h" #include "qemu/config-file.h" +#include "block/snapshot.h" +#include "block/qapi.h" =20 /* for pic/irq_info */ #if defined(TARGET_SPARC) @@ -2522,3 +2524,284 @@ void qmp_rtc_reset_reinjection(Error **errp) error_set(errp, QERR_FEATURE_DISABLED, "rtc-reset-reinjection"); } #endif + +void netdev_add_completion(ReadLineState *rs, int nb_args, const char *s= tr) +{ + size_t len; + int i; + + if (nb_args !=3D 2) { + return; + } + len =3D strlen(str); + readline_set_completion_index(rs, len); + for (i =3D 0; NetClientOptionsKind_lookup[i]; i++) { + add_completion_option(rs, str, NetClientOptionsKind_lookup[i]); + } +} + +void device_add_completion(ReadLineState *rs, int nb_args, const char *s= tr) +{ + GSList *list, *elt; + size_t len; + + if (nb_args !=3D 2) { + return; + } + + len =3D strlen(str); + readline_set_completion_index(rs, len); + list =3D elt =3D object_class_get_list(TYPE_DEVICE, false); + while (elt) { + const char *name; + DeviceClass *dc =3D OBJECT_CLASS_CHECK(DeviceClass, elt->data, + TYPE_DEVICE); + name =3D object_class_get_name(OBJECT_CLASS(dc)); + + if (!dc->cannot_instantiate_with_device_add_yet + && !strncmp(name, str, len)) { + readline_add_completion(rs, name); + } + elt =3D elt->next; + } + g_slist_free(list); +} + +void object_add_completion(ReadLineState *rs, int nb_args, const char *s= tr) +{ + GSList *list, *elt; + size_t len; + + if (nb_args !=3D 2) { + return; + } + + len =3D strlen(str); + readline_set_completion_index(rs, len); + list =3D elt =3D object_class_get_list(TYPE_USER_CREATABLE, false); + while (elt) { + const char *name; + + name =3D object_class_get_name(OBJECT_CLASS(elt->data)); + if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE= )) { + readline_add_completion(rs, name); + } + elt =3D elt->next; + } + g_slist_free(list); +} + +static void device_del_bus_completion(ReadLineState *rs, BusState *bus, + const char *str, size_t len) +{ + BusChild *kid; + + QTAILQ_FOREACH(kid, &bus->children, sibling) { + DeviceState *dev =3D kid->child; + BusState *dev_child; + + if (dev->id && !strncmp(str, dev->id, len)) { + readline_add_completion(rs, dev->id); + } + + QLIST_FOREACH(dev_child, &dev->child_bus, sibling) { + device_del_bus_completion(rs, dev_child, str, len); + } + } +} + +void device_del_completion(ReadLineState *rs, int nb_args, const char *s= tr) +{ + size_t len; + + if (nb_args !=3D 2) { + return; + } + + len =3D strlen(str); + readline_set_completion_index(rs, len); + device_del_bus_completion(rs, sysbus_get_default(), str, len); +} + +void object_del_completion(ReadLineState *rs, int nb_args, const char *s= tr) +{ + ObjectPropertyInfoList *list, *start; + size_t len; + + if (nb_args !=3D 2) { + return; + } + len =3D strlen(str); + readline_set_completion_index(rs, len); + + start =3D list =3D qmp_qom_list("/objects", NULL); + while (list) { + ObjectPropertyInfo *info =3D list->value; + + if (!strncmp(info->type, "child<", 5) + && !strncmp(info->name, str, len)) { + readline_add_completion(rs, info->name); + } + list =3D list->next; + } + qapi_free_ObjectPropertyInfoList(start); +} + +void sendkey_completion(ReadLineState *rs, int nb_args, const char *str) +{ + int i; + char *sep; + size_t len; + + if (nb_args !=3D 2) { + return; + } + sep =3D strrchr(str, '-'); + if (sep) { + str =3D sep + 1; + } + len =3D strlen(str); + readline_set_completion_index(rs, len); + for (i =3D 0; i < Q_KEY_CODE_MAX; i++) { + if (!strncmp(str, QKeyCode_lookup[i], len)) { + readline_add_completion(rs, QKeyCode_lookup[i]); + } + } +} + +void watchdog_action_completion(ReadLineState *rs, int nb_args, const ch= ar *str) +{ + if (nb_args !=3D 2) { + return; + } + readline_set_completion_index(rs, strlen(str)); + add_completion_option(rs, str, "reset"); + add_completion_option(rs, str, "shutdown"); + add_completion_option(rs, str, "poweroff"); + add_completion_option(rs, str, "pause"); + add_completion_option(rs, str, "debug"); + add_completion_option(rs, str, "none"); +} + +void migrate_set_capability_completion(ReadLineState *rs, int nb_args, + const char *str) +{ + size_t len; + + len =3D strlen(str); + readline_set_completion_index(rs, len); + if (nb_args =3D=3D 2) { + int i; + for (i =3D 0; i < MIGRATION_CAPABILITY_MAX; i++) { + const char *name =3D MigrationCapability_lookup[i]; + if (!strncmp(str, name, len)) { + readline_add_completion(rs, name); + } + } + } else if (nb_args =3D=3D 3) { + add_completion_option(rs, str, "on"); + add_completion_option(rs, str, "off"); + } +} + +void host_net_add_completion(ReadLineState *rs, int nb_args, const char = *str) +{ + int i; + size_t len; + if (nb_args !=3D 2) { + return; + } + len =3D strlen(str); + readline_set_completion_index(rs, len); + for (i =3D 0; host_net_devices[i]; i++) { + if (!strncmp(host_net_devices[i], str, len)) { + readline_add_completion(rs, host_net_devices[i]); + } + } +} + +void host_net_remove_completion(ReadLineState *rs, int nb_args, const ch= ar *str) +{ + NetClientState *ncs[255]; + int count, i, len; + + len =3D strlen(str); + readline_set_completion_index(rs, len); + if (nb_args =3D=3D 2) { + count =3D qemu_find_net_clients_except(NULL, ncs, + NET_CLIENT_OPTIONS_KIND_NON= E, 255); + for (i =3D 0; i < count; i++) { + int id; + char name[16]; + + if (net_hub_id_for_client(ncs[i], &id)) { + continue; + } + snprintf(name, sizeof(name), "%d", id); + if (!strncmp(str, name, len)) { + readline_add_completion(rs, name); + } + } + return; + } else if (nb_args =3D=3D 3) { + count =3D qemu_find_net_clients_except(NULL, ncs, + NET_CLIENT_OPTIONS_KIND_NIC= , 255); + for (i =3D 0; i < count; i++) { + const char *name; + + name =3D ncs[i]->name; + if (!strncmp(str, name, len)) { + readline_add_completion(rs, name); + } + } + return; + } +} + +static void vm_completion(ReadLineState *rs, const char *str) +{ + size_t len; + BlockDriverState *bs =3D NULL; + + len =3D strlen(str); + readline_set_completion_index(rs, len); + while ((bs =3D bdrv_next(bs))) { + SnapshotInfoList *snapshots, *snapshot; + + if (!bdrv_can_snapshot(bs)) { + continue; + } + if (bdrv_query_snapshot_info_list(bs, &snapshots, NULL)) { + continue; + } + snapshot =3D snapshots; + while (snapshot) { + char *completion =3D snapshot->value->name; + if (!strncmp(str, completion, len)) { + readline_add_completion(rs, completion); + } + completion =3D snapshot->value->id; + if (!strncmp(str, completion, len)) { + readline_add_completion(rs, completion); + } + snapshot =3D snapshot->next; + } + qapi_free_SnapshotInfoList(snapshots); + } + +} + +void delvm_completion(ReadLineState *rs, int nb_args, const char *str) +{ + if (nb_args =3D=3D 2) { + vm_completion(rs, str); + } +} + +void loadvm_completion(ReadLineState *rs, int nb_args, const char *str) +{ + if (nb_args =3D=3D 2) { + vm_completion(rs, str); + } +} + diff --git a/monitor.c b/monitor.c index 37a20cc..bc67e7a 100644 --- a/monitor.c +++ b/monitor.c @@ -71,7 +71,6 @@ #include "qmp-commands.h" #include "hmp.h" #include "qemu/thread.h" -#include "block/qapi.h" #include "qapi/qmp-event.h" #include "qapi-event.h" =20 @@ -1891,91 +1890,6 @@ void chardev_add_completion(ReadLineState *rs, int= nb_args, const char *str) qapi_free_ChardevBackendInfoList(start); } =20 -void netdev_add_completion(ReadLineState *rs, int nb_args, const char *s= tr) -{ - size_t len; - int i; - - if (nb_args !=3D 2) { - return; - } - len =3D strlen(str); - readline_set_completion_index(rs, len); - for (i =3D 0; NetClientOptionsKind_lookup[i]; i++) { - add_completion_option(rs, str, NetClientOptionsKind_lookup[i]); - } -} - -void device_add_completion(ReadLineState *rs, int nb_args, const char *s= tr) -{ - GSList *list, *elt; - size_t len; - - if (nb_args !=3D 2) { - return; - } - - len =3D strlen(str); - readline_set_completion_index(rs, len); - list =3D elt =3D object_class_get_list(TYPE_DEVICE, false); - while (elt) { - const char *name; - DeviceClass *dc =3D OBJECT_CLASS_CHECK(DeviceClass, elt->data, - TYPE_DEVICE); - name =3D object_class_get_name(OBJECT_CLASS(dc)); - - if (!dc->cannot_instantiate_with_device_add_yet - && !strncmp(name, str, len)) { - readline_add_completion(rs, name); - } - elt =3D elt->next; - } - g_slist_free(list); -} - -void object_add_completion(ReadLineState *rs, int nb_args, const char *s= tr) -{ - GSList *list, *elt; - size_t len; - - if (nb_args !=3D 2) { - return; - } - - len =3D strlen(str); - readline_set_completion_index(rs, len); - list =3D elt =3D object_class_get_list(TYPE_USER_CREATABLE, false); - while (elt) { - const char *name; - - name =3D object_class_get_name(OBJECT_CLASS(elt->data)); - if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE= )) { - readline_add_completion(rs, name); - } - elt =3D elt->next; - } - g_slist_free(list); -} - -static void device_del_bus_completion(ReadLineState *rs, BusState *bus, - const char *str, size_t len) -{ - BusChild *kid; - - QTAILQ_FOREACH(kid, &bus->children, sibling) { - DeviceState *dev =3D kid->child; - BusState *dev_child; - - if (dev->id && !strncmp(str, dev->id, len)) { - readline_add_completion(rs, dev->id); - } - - QLIST_FOREACH(dev_child, &dev->child_bus, sibling) { - device_del_bus_completion(rs, dev_child, str, len); - } - } -} - void chardev_remove_completion(ReadLineState *rs, int nb_args, const cha= r *str) { size_t len; @@ -2038,201 +1952,6 @@ void ringbuf_write_completion(ReadLineState *rs, = int nb_args, const char *str) ringbuf_completion(rs, str); } =20 -void device_del_completion(ReadLineState *rs, int nb_args, const char *s= tr) -{ - size_t len; - - if (nb_args !=3D 2) { - return; - } - - len =3D strlen(str); - readline_set_completion_index(rs, len); - device_del_bus_completion(rs, sysbus_get_default(), str, len); -} - -void object_del_completion(ReadLineState *rs, int nb_args, const char *s= tr) -{ - ObjectPropertyInfoList *list, *start; - size_t len; - - if (nb_args !=3D 2) { - return; - } - len =3D strlen(str); - readline_set_completion_index(rs, len); - - start =3D list =3D qmp_qom_list("/objects", NULL); - while (list) { - ObjectPropertyInfo *info =3D list->value; - - if (!strncmp(info->type, "child<", 5) - && !strncmp(info->name, str, len)) { - readline_add_completion(rs, info->name); - } - list =3D list->next; - } - qapi_free_ObjectPropertyInfoList(start); -} - -void sendkey_completion(ReadLineState *rs, int nb_args, const char *str) -{ - int i; - char *sep; - size_t len; - - if (nb_args !=3D 2) { - return; - } - sep =3D strrchr(str, '-'); - if (sep) { - str =3D sep + 1; - } - len =3D strlen(str); - readline_set_completion_index(rs, len); - for (i =3D 0; i < Q_KEY_CODE_MAX; i++) { - if (!strncmp(str, QKeyCode_lookup[i], len)) { - readline_add_completion(rs, QKeyCode_lookup[i]); - } - } -} - -void watchdog_action_completion(ReadLineState *rs, int nb_args, const ch= ar *str) -{ - if (nb_args !=3D 2) { - return; - } - readline_set_completion_index(rs, strlen(str)); - add_completion_option(rs, str, "reset"); - add_completion_option(rs, str, "shutdown"); - add_completion_option(rs, str, "poweroff"); - add_completion_option(rs, str, "pause"); - add_completion_option(rs, str, "debug"); - add_completion_option(rs, str, "none"); -} - -void migrate_set_capability_completion(ReadLineState *rs, int nb_args, - const char *str) -{ - size_t len; - - len =3D strlen(str); - readline_set_completion_index(rs, len); - if (nb_args =3D=3D 2) { - int i; - for (i =3D 0; i < MIGRATION_CAPABILITY_MAX; i++) { - const char *name =3D MigrationCapability_lookup[i]; - if (!strncmp(str, name, len)) { - readline_add_completion(rs, name); - } - } - } else if (nb_args =3D=3D 3) { - add_completion_option(rs, str, "on"); - add_completion_option(rs, str, "off"); - } -} - -void host_net_add_completion(ReadLineState *rs, int nb_args, const char = *str) -{ - int i; - size_t len; - if (nb_args !=3D 2) { - return; - } - len =3D strlen(str); - readline_set_completion_index(rs, len); - for (i =3D 0; host_net_devices[i]; i++) { - if (!strncmp(host_net_devices[i], str, len)) { - readline_add_completion(rs, host_net_devices[i]); - } - } -} - -void host_net_remove_completion(ReadLineState *rs, int nb_args, const ch= ar *str) -{ - NetClientState *ncs[255]; - int count, i, len; - - len =3D strlen(str); - readline_set_completion_index(rs, len); - if (nb_args =3D=3D 2) { - count =3D qemu_find_net_clients_except(NULL, ncs, - NET_CLIENT_OPTIONS_KIND_NON= E, 255); - for (i =3D 0; i < count; i++) { - int id; - char name[16]; - - if (net_hub_id_for_client(ncs[i], &id)) { - continue; - } - snprintf(name, sizeof(name), "%d", id); - if (!strncmp(str, name, len)) { - readline_add_completion(rs, name); - } - } - return; - } else if (nb_args =3D=3D 3) { - count =3D qemu_find_net_clients_except(NULL, ncs, - NET_CLIENT_OPTIONS_KIND_NIC= , 255); - for (i =3D 0; i < count; i++) { - const char *name; - - name =3D ncs[i]->name; - if (!strncmp(str, name, len)) { - readline_add_completion(rs, name); - } - } - return; - } -} - -static void vm_completion(ReadLineState *rs, const char *str) -{ - size_t len; - BlockDriverState *bs =3D NULL; - - len =3D strlen(str); - readline_set_completion_index(rs, len); - while ((bs =3D bdrv_next(bs))) { - SnapshotInfoList *snapshots, *snapshot; - - if (!bdrv_can_snapshot(bs)) { - continue; - } - if (bdrv_query_snapshot_info_list(bs, &snapshots, NULL)) { - continue; - } - snapshot =3D snapshots; - while (snapshot) { - char *completion =3D snapshot->value->name; - if (!strncmp(str, completion, len)) { - readline_add_completion(rs, completion); - } - completion =3D snapshot->value->id; - if (!strncmp(str, completion, len)) { - readline_add_completion(rs, completion); - } - snapshot =3D snapshot->next; - } - qapi_free_SnapshotInfoList(snapshots); - } - -} - -void delvm_completion(ReadLineState *rs, int nb_args, const char *str) -{ - if (nb_args =3D=3D 2) { - vm_completion(rs, str); - } -} - -void loadvm_completion(ReadLineState *rs, int nb_args, const char *str) -{ - if (nb_args =3D=3D 2) { - vm_completion(rs, str); - } -} - static void monitor_find_completion_by_table(Monitor *mon, const MonitorCommand *cmd_t= able, char **args, --=20 2.1.0.rc1