usb: usb-serial QOMify

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
master
Gonglei 2015-05-06 20:55:36 +08:00 committed by Gerd Hoffmann
parent d371cbc778
commit cdf0d7694d
1 changed files with 28 additions and 17 deletions

View File

@ -103,6 +103,9 @@ typedef struct {
CharDriverState *cs;
} USBSerialState;
#define TYPE_USB_SERIAL "usb-serial-dev"
#define USB_SERIAL_DEV(obj) OBJECT_CHECK(USBSerialState, (obj), TYPE_USB_SERIAL)
enum {
STR_MANUFACTURER = 1,
STR_PRODUCT_SERIAL,
@ -473,7 +476,7 @@ static void usb_serial_event(void *opaque, int event)
static void usb_serial_realize(USBDevice *dev, Error **errp)
{
USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
USBSerialState *s = USB_SERIAL_DEV(dev);
Error *local_err = NULL;
usb_desc_create_serial(dev);
@ -576,26 +579,40 @@ static Property serial_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
static void usb_serial_dev_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
uc->realize = usb_serial_realize;
uc->handle_reset = usb_serial_handle_reset;
uc->handle_control = usb_serial_handle_control;
uc->handle_data = usb_serial_handle_data;
dc->vmsd = &vmstate_usb_serial;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
}
static const TypeInfo usb_serial_dev_type_info = {
.name = TYPE_USB_SERIAL,
.parent = TYPE_USB_DEVICE,
.instance_size = sizeof(USBSerialState),
.abstract = true,
.class_init = usb_serial_dev_class_init,
};
static void usb_serial_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
uc->realize = usb_serial_realize;
uc->product_desc = "QEMU USB Serial";
uc->usb_desc = &desc_serial;
uc->handle_reset = usb_serial_handle_reset;
uc->handle_control = usb_serial_handle_control;
uc->handle_data = usb_serial_handle_data;
dc->vmsd = &vmstate_usb_serial;
dc->props = serial_properties;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
}
static const TypeInfo serial_info = {
.name = "usb-serial",
.parent = TYPE_USB_DEVICE,
.instance_size = sizeof(USBSerialState),
.parent = TYPE_USB_SERIAL,
.class_init = usb_serial_class_initfn,
};
@ -609,26 +626,20 @@ static void usb_braille_class_initfn(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
uc->realize = usb_serial_realize;
uc->product_desc = "QEMU USB Braille";
uc->usb_desc = &desc_braille;
uc->handle_reset = usb_serial_handle_reset;
uc->handle_control = usb_serial_handle_control;
uc->handle_data = usb_serial_handle_data;
dc->vmsd = &vmstate_usb_serial;
dc->props = braille_properties;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
}
static const TypeInfo braille_info = {
.name = "usb-braille",
.parent = TYPE_USB_DEVICE,
.instance_size = sizeof(USBSerialState),
.parent = TYPE_USB_SERIAL,
.class_init = usb_braille_class_initfn,
};
static void usb_serial_register_types(void)
{
type_register_static(&usb_serial_dev_type_info);
type_register_static(&serial_info);
usb_legacy_register("usb-serial", "serial", usb_serial_init);
type_register_static(&braille_info);