aboutsummaryrefslogtreecommitdiff
path: root/backends/msmouse.c
diff options
context:
space:
mode:
Diffstat (limited to 'backends/msmouse.c')
-rw-r--r--backends/msmouse.c72
1 files changed, 38 insertions, 34 deletions
diff --git a/backends/msmouse.c b/backends/msmouse.c
index 733ca80f48..d2c3162f1e 100644
--- a/backends/msmouse.c
+++ b/backends/msmouse.c
@@ -31,18 +31,23 @@
#define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6)
typedef struct {
- CharDriverState *chr;
+ Chardev parent;
+
QemuInputHandlerState *hs;
int axis[INPUT_AXIS__MAX];
bool btns[INPUT_BUTTON__MAX];
bool btnc[INPUT_BUTTON__MAX];
uint8_t outbuf[32];
int outlen;
-} MouseState;
+} MouseChardev;
+
+#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse"
+#define MOUSE_CHARDEV(obj) \
+ OBJECT_CHECK(MouseChardev, (obj), TYPE_CHARDEV_MSMOUSE)
-static void msmouse_chr_accept_input(CharDriverState *chr)
+static void msmouse_chr_accept_input(Chardev *chr)
{
- MouseState *mouse = chr->opaque;
+ MouseChardev *mouse = MOUSE_CHARDEV(chr);
int len;
len = qemu_chr_be_can_write(chr);
@@ -60,7 +65,7 @@ static void msmouse_chr_accept_input(CharDriverState *chr)
}
}
-static void msmouse_queue_event(MouseState *mouse)
+static void msmouse_queue_event(MouseChardev *mouse)
{
unsigned char bytes[4] = { 0x40, 0x00, 0x00, 0x00 };
int dx, dy, count = 3;
@@ -97,7 +102,7 @@ static void msmouse_queue_event(MouseState *mouse)
static void msmouse_input_event(DeviceState *dev, QemuConsole *src,
InputEvent *evt)
{
- MouseState *mouse = (MouseState *)dev;
+ MouseChardev *mouse = MOUSE_CHARDEV(dev);
InputMoveEvent *move;
InputBtnEvent *btn;
@@ -121,24 +126,24 @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src,
static void msmouse_input_sync(DeviceState *dev)
{
- MouseState *mouse = (MouseState *)dev;
+ MouseChardev *mouse = MOUSE_CHARDEV(dev);
+ Chardev *chr = CHARDEV(dev);
msmouse_queue_event(mouse);
- msmouse_chr_accept_input(mouse->chr);
+ msmouse_chr_accept_input(chr);
}
-static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int len)
+static int msmouse_chr_write(struct Chardev *s, const uint8_t *buf, int len)
{
/* Ignore writes to mouse port */
return len;
}
-static void msmouse_chr_free(struct CharDriverState *chr)
+static void char_msmouse_finalize(Object *obj)
{
- MouseState *mouse = chr->opaque;
+ MouseChardev *mouse = MOUSE_CHARDEV(obj);
qemu_input_handler_unregister(mouse->hs);
- g_free(mouse);
}
static QemuInputHandler msmouse_handler = {
@@ -148,39 +153,38 @@ static QemuInputHandler msmouse_handler = {
.sync = msmouse_input_sync,
};
-static CharDriverState *qemu_chr_open_msmouse(const char *id,
- ChardevBackend *backend,
- ChardevReturn *ret,
- bool *be_opened,
- Error **errp)
+static void msmouse_chr_open(Chardev *chr,
+ ChardevBackend *backend,
+ bool *be_opened,
+ Error **errp)
{
- ChardevCommon *common = backend->u.msmouse.data;
- MouseState *mouse;
- CharDriverState *chr;
+ MouseChardev *mouse = MOUSE_CHARDEV(chr);
- chr = qemu_chr_alloc(common, errp);
- if (!chr) {
- return NULL;
- }
- chr->chr_write = msmouse_chr_write;
- chr->chr_free = msmouse_chr_free;
- chr->chr_accept_input = msmouse_chr_accept_input;
*be_opened = false;
-
- mouse = g_new0(MouseState, 1);
mouse->hs = qemu_input_handler_register((DeviceState *)mouse,
&msmouse_handler);
+}
- mouse->chr = chr;
- chr->opaque = mouse;
+static void char_msmouse_class_init(ObjectClass *oc, void *data)
+{
+ ChardevClass *cc = CHARDEV_CLASS(oc);
- return chr;
+ cc->open = msmouse_chr_open;
+ cc->chr_write = msmouse_chr_write;
+ cc->chr_accept_input = msmouse_chr_accept_input;
}
+static const TypeInfo char_msmouse_type_info = {
+ .name = TYPE_CHARDEV_MSMOUSE,
+ .parent = TYPE_CHARDEV,
+ .instance_size = sizeof(MouseChardev),
+ .instance_finalize = char_msmouse_finalize,
+ .class_init = char_msmouse_class_init,
+};
+
static void register_types(void)
{
- register_char_driver("msmouse", CHARDEV_BACKEND_KIND_MSMOUSE, NULL,
- qemu_chr_open_msmouse);
+ type_register_static(&char_msmouse_type_info);
}
type_init(register_types);