summaryrefslogtreecommitdiff
path: root/ui/console.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/console.c
parent5bf5adaeb7245d7037f29429fb231b4b602d5b50 (diff)
downloadqemu-777357d758d937c9dd83082c39aff9f1e53e9ba3.tar.gz
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/console.c')
-rw-r--r--ui/console.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/ui/console.c b/ui/console.c
index c8ee164ffe..fe03a666f7 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1051,9 +1051,12 @@ typedef struct VCChardev {
QemuConsole *console;
} VCChardev;
+#define TYPE_CHARDEV_VC "chardev-vc"
+#define VC_CHARDEV(obj) OBJECT_CHECK(VCChardev, (obj), TYPE_CHARDEV_VC)
+
static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
- VCChardev *drv = (VCChardev *)chr;
+ VCChardev *drv = VC_CHARDEV(chr);
QemuConsole *s = drv->console;
int i;
@@ -1964,7 +1967,7 @@ int qemu_console_get_height(QemuConsole *con, int fallback)
static void vc_chr_set_echo(Chardev *chr, bool echo)
{
- VCChardev *drv = (VCChardev *)chr;
+ VCChardev *drv = VC_CHARDEV(chr);
QemuConsole *s = drv->console;
s->echo = echo;
@@ -2005,7 +2008,7 @@ static const GraphicHwOps text_console_ops = {
static void text_console_do_init(Chardev *chr, DisplayState *ds)
{
- VCChardev *drv = (VCChardev *)chr;
+ VCChardev *drv = VC_CHARDEV(chr);
QemuConsole *s = drv->console;
int g_width = 80 * FONT_WIDTH;
int g_height = 24 * FONT_HEIGHT;
@@ -2058,24 +2061,17 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)
static const CharDriver vc_driver;
-static Chardev *vc_chr_init(const CharDriver *driver,
- const char *id, ChardevBackend *backend,
- ChardevReturn *ret, bool *be_opened,
- Error **errp)
+static void vc_chr_open(Chardev *chr,
+ ChardevBackend *backend,
+ bool *be_opened,
+ Error **errp)
{
ChardevVC *vc = backend->u.vc.data;
- ChardevCommon *common = qapi_ChardevVC_base(vc);
- Chardev *chr;
- VCChardev *drv;
+ VCChardev *drv = VC_CHARDEV(chr);
QemuConsole *s;
unsigned width = 0;
unsigned height = 0;
- chr = qemu_chr_alloc(&vc_driver, common, errp);
- if (!chr) {
- return NULL;
- }
-
if (vc->has_width) {
width = vc->width;
} else if (vc->has_cols) {
@@ -2097,13 +2093,11 @@ static Chardev *vc_chr_init(const CharDriver *driver,
}
if (!s) {
- g_free(chr);
error_setg(errp, "cannot create text console");
- return NULL;
+ return;
}
s->chr = chr;
- drv = (VCChardev *)chr;
drv->console = s;
if (display_state) {
@@ -2114,8 +2108,6 @@ static Chardev *vc_chr_init(const CharDriver *driver,
* stage, so defer OPENED events until they are fully initialized
*/
*be_opened = false;
-
- return chr;
}
void qemu_console_resize(QemuConsole *s, int width, int height)
@@ -2193,19 +2185,39 @@ static const TypeInfo qemu_console_info = {
.class_size = sizeof(QemuConsoleClass),
};
-static const CharDriver vc_driver = {
+static void char_vc_class_init(ObjectClass *oc, void *data)
+{
+ ChardevClass *cc = CHARDEV_CLASS(oc);
+
+ cc->open = vc_chr_open;
+ cc->chr_write = vc_chr_write;
+ cc->chr_set_echo = vc_chr_set_echo;
+}
+
+static const TypeInfo char_vc_type_info = {
+ .name = TYPE_CHARDEV_VC,
+ .parent = TYPE_CHARDEV,
.instance_size = sizeof(VCChardev),
+ .class_init = char_vc_class_init,
+};
+
+void qemu_console_early_init(void)
+{
+ /* set the default vc driver */
+ if (!object_class_by_name(TYPE_CHARDEV_VC)) {
+ type_register(&char_vc_type_info);
+ register_char_driver(&vc_driver);
+ }
+}
+
+static const CharDriver vc_driver = {
.kind = CHARDEV_BACKEND_KIND_VC,
.parse = qemu_chr_parse_vc,
- .create = vc_chr_init,
- .chr_write = vc_chr_write,
- .chr_set_echo = vc_chr_set_echo,
};
static void register_types(void)
{
type_register_static(&qemu_console_info);
- register_char_driver(&vc_driver);
}
type_init(register_types);