char: make null_chr_write() the default method

All chardev must implement chr_write(), but parallel and null chardev
both use null_chr_write(). Move it to the base class, so we don't need
to export the function when splitting the chardev in respective files.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Marc-André Lureau 2016-12-12 13:41:40 +03:00
parent 32d955a422
commit eb314a9497
1 changed files with 13 additions and 8 deletions

View File

@ -522,6 +522,18 @@ static void char_init(Object *obj)
qemu_mutex_init(&chr->chr_write_lock); qemu_mutex_init(&chr->chr_write_lock);
} }
static int null_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
return len;
}
static void char_class_init(ObjectClass *oc, void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
cc->chr_write = null_chr_write;
}
static void char_finalize(Object *obj) static void char_finalize(Object *obj)
{ {
Chardev *chr = CHARDEV(obj); Chardev *chr = CHARDEV(obj);
@ -545,13 +557,9 @@ static const TypeInfo char_type_info = {
.instance_finalize = char_finalize, .instance_finalize = char_finalize,
.abstract = true, .abstract = true,
.class_size = sizeof(ChardevClass), .class_size = sizeof(ChardevClass),
.class_init = char_class_init,
}; };
static int null_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
return len;
}
static void null_chr_open(Chardev *chr, static void null_chr_open(Chardev *chr,
ChardevBackend *backend, ChardevBackend *backend,
bool *be_opened, bool *be_opened,
@ -565,7 +573,6 @@ static void char_null_class_init(ObjectClass *oc, void *data)
ChardevClass *cc = CHARDEV_CLASS(oc); ChardevClass *cc = CHARDEV_CLASS(oc);
cc->open = null_chr_open; cc->open = null_chr_open;
cc->chr_write = null_chr_write;
} }
static const TypeInfo char_null_type_info = { static const TypeInfo char_null_type_info = {
@ -4712,10 +4719,8 @@ static void char_parallel_class_init(ObjectClass *oc, void *data)
cc->parse = qemu_chr_parse_parallel; cc->parse = qemu_chr_parse_parallel;
cc->open = qmp_chardev_open_parallel; cc->open = qmp_chardev_open_parallel;
#if defined(__linux__) #if defined(__linux__)
cc->chr_write = null_chr_write;
cc->chr_ioctl = pp_ioctl; cc->chr_ioctl = pp_ioctl;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
cc->chr_write = null_chr_write;
cc->chr_ioctl = pp_ioctl; cc->chr_ioctl = pp_ioctl;
#endif #endif
} }