aboutsummaryrefslogtreecommitdiff
path: root/ui/gtk.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-12-07 18:39:10 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2017-01-27 18:08:00 +0100
commit777357d758d937c9dd83082c39aff9f1e53e9ba3 (patch)
tree20b236bf5acc7dfc20b4358bb8072dfe983c0e2d /ui/gtk.c
parent5bf5adaeb7245d7037f29429fb231b4b602d5b50 (diff)
chardev: qom-ify
Turn Chardev into Object. qemu_chr_alloc() is replaced by the qemu_chardev_new() constructor. It will call qemu_char_open() to open/intialize the chardev with the ChardevCommon *backend settings. The CharDriver::create() callback is turned into a ChardevClass::open() which is called from the newly introduced qemu_chardev_open(). "chardev-gdb" and "chardev-hci" are internal chardev and aren't creatable directly with -chardev. Use a new internal flag to disable them. We may want to use TYPE_USER_CREATABLE interface instead, or perhaps allow -chardev usage. Although in general we keep typename and macros private, unless the type is being used by some other file, in this patch, all types and common helper macros for qemu-char.c are in char.h. This is to help transition now (some types must be declared early, while some aren't shared) and when splitting in several units. This is to be improved later. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'ui/gtk.c')
-rw-r--r--ui/gtk.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/ui/gtk.c b/ui/gtk.c
index 04df0ad6af..bdd831c268 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -187,6 +187,9 @@ typedef struct VCChardev {
bool echo;
} VCChardev;
+#define TYPE_CHARDEV_VC "chardev-vc"
+#define VC_CHARDEV(obj) OBJECT_CHECK(VCChardev, (obj), TYPE_CHARDEV_VC)
+
static void gd_grab_pointer(VirtualConsole *vc, const char *reason);
static void gd_ungrab_pointer(GtkDisplayState *s);
static void gd_grab_keyboard(VirtualConsole *vc, const char *reason);
@@ -1691,7 +1694,7 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
- VCChardev *vcd = (VCChardev *)chr;
+ VCChardev *vcd = VC_CHARDEV(chr);
VirtualConsole *vc = vcd->console;
vte_terminal_feed(VTE_TERMINAL(vc->vte.terminal), (const char *)buf, len);
@@ -1700,7 +1703,7 @@ static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
static void gd_vc_chr_set_echo(Chardev *chr, bool echo)
{
- VCChardev *vcd = (VCChardev *)chr;
+ VCChardev *vcd = VC_CHARDEV(chr);
VirtualConsole *vc = vcd->console;
if (vc) {
@@ -1714,23 +1717,14 @@ static int nb_vcs;
static Chardev *vcs[MAX_VCS];
static const CharDriver gd_vc_driver;
-static Chardev *vc_init(const CharDriver *driver,
- const char *id, ChardevBackend *backend,
- ChardevReturn *ret, bool *be_opened,
- Error **errp)
+static void gd_vc_open(Chardev *chr,
+ ChardevBackend *backend,
+ bool *be_opened,
+ Error **errp)
{
- ChardevVC *vc = backend->u.vc.data;
- ChardevCommon *common = qapi_ChardevVC_base(vc);
- Chardev *chr;
-
if (nb_vcs == MAX_VCS) {
error_setg(errp, "Maximum number of consoles reached");
- return NULL;
- }
-
- chr = qemu_chr_alloc(&gd_vc_driver, common, errp);
- if (!chr) {
- return NULL;
+ return;
}
vcs[nb_vcs++] = chr;
@@ -1739,16 +1733,27 @@ static Chardev *vc_init(const CharDriver *driver,
* stage, so defer OPENED events until they are fully initialized
*/
*be_opened = false;
+}
- return chr;
+static void char_gd_vc_class_init(ObjectClass *oc, void *data)
+{
+ ChardevClass *cc = CHARDEV_CLASS(oc);
+
+ cc->open = gd_vc_open;
+ cc->chr_write = gd_vc_chr_write;
+ cc->chr_set_echo = gd_vc_chr_set_echo;
}
-static const CharDriver gd_vc_driver = {
+static const TypeInfo char_gd_vc_type_info = {
+ .name = TYPE_CHARDEV_VC,
+ .parent = TYPE_CHARDEV,
.instance_size = sizeof(VCChardev),
+ .class_init = char_gd_vc_class_init,
+};
+
+static const CharDriver gd_vc_driver = {
.kind = CHARDEV_BACKEND_KIND_VC,
- .parse = qemu_chr_parse_vc, .create = vc_init,
- .chr_write = gd_vc_chr_write,
- .chr_set_echo = gd_vc_chr_set_echo,
+ .parse = qemu_chr_parse_vc,
};
static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
@@ -1786,7 +1791,7 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
GtkWidget *box;
GtkWidget *scrollbar;
GtkAdjustment *vadjustment;
- VCChardev *vcd = (VCChardev *)chr;
+ VCChardev *vcd = VC_CHARDEV(chr);
vc->s = s;
vc->vte.echo = vcd->echo;
@@ -2347,7 +2352,7 @@ void early_gtk_display_init(int opengl)
}
#if defined(CONFIG_VTE)
- /* overwrite the console.c vc driver */
+ type_register(&char_gd_vc_type_info);
register_char_driver(&gd_vc_driver);
#endif
}