#include <sys/ioctl.h>
#include "standard-headers/linux/input.h"
+#include "qom/object.h"
static bool linux_is_button(unsigned int lnx)
{
}
#define TYPE_INPUT_LINUX "input-linux"
-#define INPUT_LINUX(obj) \
- OBJECT_CHECK(InputLinux, (obj), TYPE_INPUT_LINUX)
-#define INPUT_LINUX_GET_CLASS(obj) \
- OBJECT_GET_CLASS(InputLinuxClass, (obj), TYPE_INPUT_LINUX)
-#define INPUT_LINUX_CLASS(klass) \
- OBJECT_CLASS_CHECK(InputLinuxClass, (klass), TYPE_INPUT_LINUX)
+OBJECT_DECLARE_SIMPLE_TYPE(InputLinux,
+ INPUT_LINUX)
-typedef struct InputLinux InputLinux;
-typedef struct InputLinuxClass InputLinuxClass;
struct InputLinux {
Object parent;
QTAILQ_ENTRY(InputLinux) next;
};
-struct InputLinuxClass {
- ObjectClass parent_class;
-};
static QTAILQ_HEAD(, InputLinux) inputs = QTAILQ_HEAD_INITIALIZER(inputs);
rc = ioctl(il->fd, EVIOCGBIT(0, sizeof(evtmap)), &evtmap);
if (rc < 0) {
- error_setg(errp, "%s: failed to read event bits", il->evdev);
- goto err_close;
+ goto err_read_event_bits;
}
if (evtmap & (1 << EV_REL)) {
relmap = 0;
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
+ if (rc < 0) {
+ goto err_read_event_bits;
+ }
if (relmap & (1 << REL_X)) {
il->has_rel_x = true;
}
if (evtmap & (1 << EV_ABS)) {
absmap = 0;
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
+ if (rc < 0) {
+ goto err_read_event_bits;
+ }
if (absmap & (1 << ABS_X)) {
il->has_abs_x = true;
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
+ if (rc < 0) {
+ error_setg(errp, "%s: failed to get get absolute X value",
+ il->evdev);
+ goto err_close;
+ }
il->abs_x_min = absinfo.minimum;
il->abs_x_max = absinfo.maximum;
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
+ if (rc < 0) {
+ error_setg(errp, "%s: failed to get get absolute Y value",
+ il->evdev);
+ goto err_close;
+ }
il->abs_y_min = absinfo.minimum;
il->abs_y_max = absinfo.maximum;
}
if (evtmap & (1 << EV_KEY)) {
memset(keymap, 0, sizeof(keymap));
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
+ if (rc < 0) {
+ goto err_read_event_bits;
+ }
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
+ if (rc < 0) {
+ error_setg(errp, "%s: failed to get global key state", il->evdev);
+ goto err_close;
+ }
for (i = 0; i < KEY_CNT; i++) {
if (keymap[i / 8] & (1 << (i % 8))) {
if (linux_is_button(i)) {
il->initialized = true;
return;
+err_read_event_bits:
+ error_setg(errp, "%s: failed to read event bits", il->evdev);
+
err_close:
close(il->fd);
return;
if (il->initialized) {
QTAILQ_REMOVE(&inputs, il, next);
+ qemu_set_fd_handler(il->fd, NULL, NULL, NULL);
close(il->fd);
}
g_free(il->evdev);
static void input_linux_instance_init(Object *obj)
{
- object_property_add_str(obj, "evdev",
- input_linux_get_evdev,
- input_linux_set_evdev, NULL);
- object_property_add_bool(obj, "grab_all",
- input_linux_get_grab_all,
- input_linux_set_grab_all, NULL);
- object_property_add_bool(obj, "repeat",
- input_linux_get_repeat,
- input_linux_set_repeat, NULL);
- object_property_add_enum(obj, "grab-toggle", "GrabToggleKeys",
- &GrabToggleKeys_lookup,
- input_linux_get_grab_toggle,
- input_linux_set_grab_toggle, NULL);
}
static void input_linux_class_init(ObjectClass *oc, void *data)
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
ucc->complete = input_linux_complete;
+
+ object_class_property_add_str(oc, "evdev",
+ input_linux_get_evdev,
+ input_linux_set_evdev);
+ object_class_property_add_bool(oc, "grab_all",
+ input_linux_get_grab_all,
+ input_linux_set_grab_all);
+ object_class_property_add_bool(oc, "repeat",
+ input_linux_get_repeat,
+ input_linux_set_repeat);
+ object_class_property_add_enum(oc, "grab-toggle", "GrabToggleKeys",
+ &GrabToggleKeys_lookup,
+ input_linux_get_grab_toggle,
+ input_linux_set_grab_toggle);
}
static const TypeInfo input_linux_info = {
.name = TYPE_INPUT_LINUX,
.parent = TYPE_OBJECT,
- .class_size = sizeof(InputLinuxClass),
.class_init = input_linux_class_init,
.instance_size = sizeof(InputLinux),
.instance_init = input_linux_instance_init,