From nobody Thu Nov 28 09:59:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693828507; cv=none; d=zohomail.com; s=zohoarc; b=AU8sH7z9WzjcrxU4l3mnivM3qTDIPXg3b9yuExpV4NRmNjAmy/6vLCjeZXD13/WJud+KSE5kfgjA04W1Ryt/OSfpHl/lTwigfSaziXzlwISB/o+AEHydY5Au1Jc/ze8iGFHnX+cl9IOfKZWhiqHrAwo+hyiL7dCpoAVENiJsgHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693828507; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TB0O1dRHTMx2WuGanxMBCP0v8ue79JTrzZpX+r3PJmg=; b=K1WaK9SAhkl7bYpsQXPawskz1HhUtmO9VxnnfOE61OEPZ9fH2Nl8KDP6LDSrrZFaGPryuC06F9yxm7Hg+gBKdFoC0XmmoFSEA1SLsC9wstOSyXsPZi94+W/XotF814K2YCkzF5s2r+oGbJKgdred0AFxx05C7BDxsLEGQ0n7RRY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169382850787683.11631613359543; Mon, 4 Sep 2023 04:55:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qd89y-0003NK-IC; Mon, 04 Sep 2023 07:54:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qd89k-0003D6-9v for qemu-devel@nongnu.org; Mon, 04 Sep 2023 07:54:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qd89h-0008RJ-Uv for qemu-devel@nongnu.org; Mon, 04 Sep 2023 07:54:12 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-413-3wutt9YBNdq5JkD1X1iQ4g-1; Mon, 04 Sep 2023 07:54:06 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEB2784AF9D for ; Mon, 4 Sep 2023 11:54:05 +0000 (UTC) Received: from localhost (unknown [10.39.208.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E3B640C206F; Mon, 4 Sep 2023 11:54:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693828449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TB0O1dRHTMx2WuGanxMBCP0v8ue79JTrzZpX+r3PJmg=; b=cwvcJJ91hfbsF+aXC0Ou5+rVMvW4xA3Zl42md+WOYhvx8rPfcuJhUUQFTmrC4O+KnnMWQX GAI4t1IL8rLZVnIhlqzWQbCF69+rj37jgnpFRQODxi2iVlYxbhmztJwXq9eWhb/qWIQ4pO 8YtmRLpeYci5zFrKmFREM/b9ISOE+5Q= X-MC-Unique: 3wutt9YBNdq5JkD1X1iQ4g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann Subject: [PULL 18/52] ui/console: change new_console() to use object initialization Date: Mon, 4 Sep 2023 15:52:15 +0400 Message-ID: <20230904115251.4161397-19-marcandre.lureau@redhat.com> In-Reply-To: <20230904115251.4161397-1-marcandre.lureau@redhat.com> References: <20230904115251.4161397-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693828509074100014 From: Marc-Andr=C3=A9 Lureau Object construction should be done in respective object instance and class handlers. Introduce qemu_console_register() to split out the registration logic. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20230830093843.3531473-19-marcandre.lureau@redhat.com> --- ui/console.c | 92 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/ui/console.c b/ui/console.c index 14fb38c661..bdecfe7306 100644 --- a/ui/console.c +++ b/ui/console.c @@ -27,6 +27,7 @@ #include "hw/qdev-core.h" #include "qapi/error.h" #include "qapi/qapi-commands-ui.h" +#include "qapi/visitor.h" #include "qemu/coroutine.h" #include "qemu/fifo8.h" #include "qemu/error-report.h" @@ -1253,39 +1254,24 @@ static void text_console_update(void *opaque, conso= le_ch_t *chardata) } } =20 -static QemuConsole *new_console(console_type_t console_type, uint32_t head) +static void +qemu_console_register(QemuConsole *c, console_type_t console_type) { - DisplayState *ds =3D get_alloc_displaystate(); - Object *obj; - QemuConsole *s; int i; =20 - obj =3D object_new(TYPE_QEMU_CONSOLE); - s =3D QEMU_CONSOLE(obj); - qemu_co_queue_init(&s->dump_queue); - s->head =3D head; - object_property_add_link(obj, "device", TYPE_DEVICE, - (Object **)&s->device, - object_property_allow_set_link, - OBJ_PROP_LINK_STRONG); - object_property_add_uint32_ptr(obj, "head", &s->head, - OBJ_PROP_FLAG_READ); - if (!active_console || ((active_console->console_type !=3D GRAPHIC_CON= SOLE) && - (console_type =3D=3D GRAPHIC_CONSOLE))) { - active_console =3D s; + (console_type =3D=3D GRAPHIC_CONSOLE))) { + active_console =3D c; } - s->ds =3D ds; - s->console_type =3D console_type; - s->window_id =3D -1; + c->console_type =3D console_type; =20 if (QTAILQ_EMPTY(&consoles)) { - s->index =3D 0; - QTAILQ_INSERT_TAIL(&consoles, s, next); + c->index =3D 0; + QTAILQ_INSERT_TAIL(&consoles, c, next); } else if (console_type !=3D GRAPHIC_CONSOLE || phase_check(PHASE_MACH= INE_READY)) { QemuConsole *last =3D QTAILQ_LAST(&consoles); - s->index =3D last->index + 1; - QTAILQ_INSERT_TAIL(&consoles, s, next); + c->index =3D last->index + 1; + QTAILQ_INSERT_TAIL(&consoles, c, next); } else { /* * HACK: Put graphical consoles before text consoles. @@ -1293,41 +1279,75 @@ static QemuConsole *new_console(console_type_t cons= ole_type, uint32_t head) * Only do that for coldplugged devices. After initial device * initialization we will not renumber the consoles any more. */ - QemuConsole *c =3D QTAILQ_FIRST(&consoles); + QemuConsole *it =3D QTAILQ_FIRST(&consoles); =20 - while (QTAILQ_NEXT(c, next) !=3D NULL && - c->console_type =3D=3D GRAPHIC_CONSOLE) { - c =3D QTAILQ_NEXT(c, next); + while (QTAILQ_NEXT(it, next) !=3D NULL && + it->console_type =3D=3D GRAPHIC_CONSOLE) { + it =3D QTAILQ_NEXT(it, next); } - if (c->console_type =3D=3D GRAPHIC_CONSOLE) { + if (it->console_type =3D=3D GRAPHIC_CONSOLE) { /* have no text consoles */ - s->index =3D c->index + 1; - QTAILQ_INSERT_AFTER(&consoles, c, s, next); + c->index =3D it->index + 1; + QTAILQ_INSERT_AFTER(&consoles, it, c, next); } else { - s->index =3D c->index; - QTAILQ_INSERT_BEFORE(c, s, next); + c->index =3D it->index; + QTAILQ_INSERT_BEFORE(it, c, next); /* renumber text consoles */ - for (i =3D s->index + 1; c !=3D NULL; c =3D QTAILQ_NEXT(c, nex= t), i++) { - c->index =3D i; + for (i =3D c->index + 1; it !=3D NULL; it =3D QTAILQ_NEXT(it, = next), i++) { + it->index =3D i; } } } - return s; } =20 static void qemu_console_finalize(Object *obj) { + /* TODO: should unregister from consoles and free itself */ +} + +static void +qemu_console_prop_get_head(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + QemuConsole *c =3D QEMU_CONSOLE(obj); + + visit_type_uint32(v, name, &c->head, errp); } =20 static void qemu_console_class_init(ObjectClass *oc, void *data) { + object_class_property_add_link(oc, "device", TYPE_DEVICE, + offsetof(QemuConsole, device), + object_property_allow_set_link, + OBJ_PROP_LINK_STRONG); + object_class_property_add(oc, "head", "uint32", + qemu_console_prop_get_head, + NULL, NULL, NULL); } =20 static void qemu_console_init(Object *obj) { + QemuConsole *c =3D QEMU_CONSOLE(obj); + DisplayState *ds =3D get_alloc_displaystate(); + + qemu_co_queue_init(&c->dump_queue); + c->ds =3D ds; + c->window_id =3D -1; +} + +static QemuConsole *new_console(console_type_t console_type, + uint32_t head) +{ + QemuConsole *c =3D QEMU_CONSOLE(object_new(TYPE_QEMU_CONSOLE)); + + c->head =3D head; + /* TODO: move to console_init() once there is a type hierarchy */ + qemu_console_register(c, console_type); + + return c; } =20 #ifdef WIN32 --=20 2.41.0