[PATCH 28/60] ui/console-vc: extract vt100_input() from vc_chr_write()

Marc-André Lureau posted 60 patches 2 weeks, 6 days ago
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, John Snow <jsnow@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Jan Kiszka <jan.kiszka@web.de>, Phil Dennis-Jordan <phil@philjordan.eu>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Gerd Hoffmann <kraxel@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Samuel Tardieu <sam@rfc1149.net>, Igor Mitsyanko <i.mitsyanko@gmail.com>, "Hervé Poussineau" <hpoussin@reactos.org>, Aleksandar Rikalo <arikalo@gmail.com>, Laurent Vivier <laurent@vivier.eu>, Thomas Huth <th.huth+qemu@posteo.eu>, BALATON Zoltan <balaton@eik.bme.hu>, "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Alistair Francis <alistair@alistair23.me>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Fabiano Rosas <farosas@suse.de>
[PATCH 28/60] ui/console-vc: extract vt100_input() from vc_chr_write()
Posted by Marc-André Lureau 2 weeks, 6 days ago
Move the VT100 input processing logic out of vc_chr_write() into a new
vt100_input() function that operates on QemuVT100 directly, rather than
going through the Chardev/VCChardev layers. This continues the effort
to decouple the VT100 emulation from the chardev backend, making the
VT100 layer self-contained and reusable.

vc_chr_write() becomes a thin wrapper that extracts the QemuVT100 from
the chardev and delegates to vt100_input().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 ui/console-vc.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/ui/console-vc.c b/ui/console-vc.c
index 87881c072ee..3ef492c2d4c 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -1058,29 +1058,35 @@ static void vt100_putchar(QemuVT100 *vt, int ch)
 DECLARE_INSTANCE_CHECKER(VCChardev, VC_CHARDEV,
                          TYPE_CHARDEV_VC)
 
-static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static int vt100_input(QemuVT100 *vt, const uint8_t *buf, int len)
 {
-    VCChardev *drv = VC_CHARDEV(chr);
-    QemuTextConsole *s = drv->console;
     int i;
 
-    s->vt.update_x0 = s->vt.width * FONT_WIDTH;
-    s->vt.update_y0 = s->vt.height * FONT_HEIGHT;
-    s->vt.update_x1 = 0;
-    s->vt.update_y1 = 0;
-    vt100_show_cursor(&s->vt, 0);
+    vt->update_x0 = vt->width * FONT_WIDTH;
+    vt->update_y0 = vt->height * FONT_HEIGHT;
+    vt->update_x1 = 0;
+    vt->update_y1 = 0;
+    vt100_show_cursor(vt, 0);
     for(i = 0; i < len; i++) {
-        vt100_putchar(&s->vt, buf[i]);
+        vt100_putchar(vt, buf[i]);
     }
-    vt100_show_cursor(&s->vt, 1);
-    if (s->vt.update_x0 < s->vt.update_x1) {
-        vt100_image_update(&s->vt, s->vt.update_x0, s->vt.update_y0,
-                           s->vt.update_x1 - s->vt.update_x0,
-                           s->vt.update_y1 - s->vt.update_y0);
+    vt100_show_cursor(vt, 1);
+    if (vt->update_x0 < vt->update_x1) {
+        vt100_image_update(vt, vt->update_x0, vt->update_y0,
+                           vt->update_x1 - vt->update_x0,
+                           vt->update_y1 - vt->update_y0);
     }
     return len;
 }
 
+static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
+{
+    VCChardev *drv = VC_CHARDEV(chr);
+    QemuTextConsole *s = drv->console;
+
+    return vt100_input(&s->vt, buf, len);
+}
+
 void vt100_update_cursor(void)
 {
     QemuVT100 *vt;

-- 
2.53.0


Re: [PATCH 28/60] ui/console-vc: extract vt100_input() from vc_chr_write()
Posted by Philippe Mathieu-Daudé 5 days, 11 hours ago
On 17/3/26 09:50, Marc-André Lureau wrote:
> Move the VT100 input processing logic out of vc_chr_write() into a new
> vt100_input() function that operates on QemuVT100 directly, rather than
> going through the Chardev/VCChardev layers. This continues the effort
> to decouple the VT100 emulation from the chardev backend, making the
> VT100 layer self-contained and reusable.
> 
> vc_chr_write() becomes a thin wrapper that extracts the QemuVT100 from
> the chardev and delegates to vt100_input().
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   ui/console-vc.c | 34 ++++++++++++++++++++--------------
>   1 file changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/ui/console-vc.c b/ui/console-vc.c
> index 87881c072ee..3ef492c2d4c 100644
> --- a/ui/console-vc.c
> +++ b/ui/console-vc.c
> @@ -1058,29 +1058,35 @@ static void vt100_putchar(QemuVT100 *vt, int ch)
>   DECLARE_INSTANCE_CHECKER(VCChardev, VC_CHARDEV,
>                            TYPE_CHARDEV_VC)
>   
> -static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
> +static int vt100_input(QemuVT100 *vt, const uint8_t *buf, int len)

Maybe use size_t len for the new method, otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

>   {
> -    VCChardev *drv = VC_CHARDEV(chr);
> -    QemuTextConsole *s = drv->console;
>       int i;
>   
> -    s->vt.update_x0 = s->vt.width * FONT_WIDTH;
> -    s->vt.update_y0 = s->vt.height * FONT_HEIGHT;
> -    s->vt.update_x1 = 0;
> -    s->vt.update_y1 = 0;
> -    vt100_show_cursor(&s->vt, 0);
> +    vt->update_x0 = vt->width * FONT_WIDTH;
> +    vt->update_y0 = vt->height * FONT_HEIGHT;
> +    vt->update_x1 = 0;
> +    vt->update_y1 = 0;
> +    vt100_show_cursor(vt, 0);
>       for(i = 0; i < len; i++) {
> -        vt100_putchar(&s->vt, buf[i]);
> +        vt100_putchar(vt, buf[i]);
>       }
> -    vt100_show_cursor(&s->vt, 1);
> -    if (s->vt.update_x0 < s->vt.update_x1) {
> -        vt100_image_update(&s->vt, s->vt.update_x0, s->vt.update_y0,
> -                           s->vt.update_x1 - s->vt.update_x0,
> -                           s->vt.update_y1 - s->vt.update_y0);
> +    vt100_show_cursor(vt, 1);
> +    if (vt->update_x0 < vt->update_x1) {
> +        vt100_image_update(vt, vt->update_x0, vt->update_y0,
> +                           vt->update_x1 - vt->update_x0,
> +                           vt->update_y1 - vt->update_y0);
>       }
>       return len;
>   }
>   
> +static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
> +{
> +    VCChardev *drv = VC_CHARDEV(chr);
> +    QemuTextConsole *s = drv->console;
> +
> +    return vt100_input(&s->vt, buf, len);
> +}