diff mbox series

[v2,36/37] ui/dbus: register D-Bus VC handler

Message ID 20211009210838.2219430-37-marcandre.lureau@redhat.com
State New
Headers show
Series Add D-Bus display backend | expand

Commit Message

Marc-André Lureau Oct. 9, 2021, 9:08 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Export the default consoles over the D-Bus chardev.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 ui/dbus.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

Comments

Philippe Mathieu-Daudé Dec. 17, 2021, 1:35 p.m. UTC | #1
On 10/9/21 23:08, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Export the default consoles over the D-Bus chardev.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  ui/dbus.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)

> +static void
> +dbus_vc_parse(QemuOpts *opts, ChardevBackend *backend,
> +              Error **errp)
> +{
> +    DBusVCClass *klass = DBUS_VC_CLASS(object_class_by_name(TYPE_CHARDEV_VC));
> +    const char *name = qemu_opt_get(opts, "name");
> +    const char *id = qemu_opts_id(opts);
> +
> +    if (name == NULL) {
> +        name = "";

Could also drop this assignation, and:

> +        if (g_str_has_prefix(id, "compat_monitor")) {
> +            name = "org.qemu.monitor.hmp.0";
> +        }

           else

> +        if (g_str_has_prefix(id, "serial")) {
> +            name = "org.qemu.console.serial.0";
> +        }

           else {
              name = "";
           }

> +        if (!qemu_opt_set(opts, "name", name, errp)) {
> +            return;
> +        }
> +    }
> +
> +    klass->parent_parse(opts, backend, errp);
> +}

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Marc-André Lureau Dec. 17, 2021, 2:21 p.m. UTC | #2
On Fri, Dec 17, 2021 at 5:35 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 10/9/21 23:08, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > Export the default consoles over the D-Bus chardev.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  ui/dbus.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 53 insertions(+)
>
> > +static void
> > +dbus_vc_parse(QemuOpts *opts, ChardevBackend *backend,
> > +              Error **errp)
> > +{
> > +    DBusVCClass *klass = DBUS_VC_CLASS(object_class_by_name(TYPE_CHARDEV_VC));
> > +    const char *name = qemu_opt_get(opts, "name");
> > +    const char *id = qemu_opts_id(opts);
> > +
> > +    if (name == NULL) {
> > +        name = "";
>
> Could also drop this assignation, and:
>
> > +        if (g_str_has_prefix(id, "compat_monitor")) {
> > +            name = "org.qemu.monitor.hmp.0";
> > +        }
>
>            else
>
> > +        if (g_str_has_prefix(id, "serial")) {
> > +            name = "org.qemu.console.serial.0";
> > +        }
>
>            else {
>               name = "";
>            }
>

done

> > +        if (!qemu_opt_set(opts, "name", name, errp)) {
> > +            return;
> > +        }
> > +    }
> > +
> > +    klass->parent_parse(opts, backend, errp);
> > +}
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>

thanks
diff mbox series

Patch

diff --git a/ui/dbus.c b/ui/dbus.c
index 38d6ccc607..97248ceadb 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -352,6 +352,57 @@  dbus_display_class_init(ObjectClass *oc, void *data)
                                    get_gl_mode, set_gl_mode);
 }
 
+#define TYPE_CHARDEV_VC "chardev-vc"
+
+typedef struct DBusVCClass {
+    DBusChardevClass parent_class;
+
+    void (*parent_parse)(QemuOpts *opts, ChardevBackend *b, Error **errp);
+} DBusVCClass;
+
+DECLARE_CLASS_CHECKERS(DBusVCClass, DBUS_VC,
+                       TYPE_CHARDEV_VC)
+
+static void
+dbus_vc_parse(QemuOpts *opts, ChardevBackend *backend,
+              Error **errp)
+{
+    DBusVCClass *klass = DBUS_VC_CLASS(object_class_by_name(TYPE_CHARDEV_VC));
+    const char *name = qemu_opt_get(opts, "name");
+    const char *id = qemu_opts_id(opts);
+
+    if (name == NULL) {
+        name = "";
+        if (g_str_has_prefix(id, "compat_monitor")) {
+            name = "org.qemu.monitor.hmp.0";
+        }
+        if (g_str_has_prefix(id, "serial")) {
+            name = "org.qemu.console.serial.0";
+        }
+        if (!qemu_opt_set(opts, "name", name, errp)) {
+            return;
+        }
+    }
+
+    klass->parent_parse(opts, backend, errp);
+}
+
+static void
+dbus_vc_class_init(ObjectClass *oc, void *data)
+{
+    DBusVCClass *klass = DBUS_VC_CLASS(oc);
+    ChardevClass *cc = CHARDEV_CLASS(oc);
+
+    klass->parent_parse = cc->parse;
+    cc->parse = dbus_vc_parse;
+}
+
+static const TypeInfo dbus_vc_type_info = {
+    .name = TYPE_CHARDEV_VC,
+    .parent = TYPE_CHARDEV_DBUS,
+    .class_init = dbus_vc_class_init,
+};
+
 static void
 early_dbus_init(DisplayOptions *opts)
 {
@@ -365,6 +416,8 @@  early_dbus_init(DisplayOptions *opts)
 
         display_opengl = 1;
     }
+
+    type_register(&dbus_vc_type_info);
 }
 
 static void