summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2013-12-13 11:37:31 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2014-01-09 11:13:53 +1000
commit1ee5b28c6e207d168b230f8287721d5b19c8a804 (patch)
treec30594c1a457a656664dd66b7e4a64bbdc75f50a
parentcd6a65bf3758286ec8fdb1a99eeab1a5a5588cf6 (diff)
Abstract the backend interface away
Remove the fixed calls into the udev backend and provide a basic interface instead that allows other backends to hook into device/seat creation. This enables multiple backends, specifically a path-based backend that is needed for X.Org drivers. This patch should have no visible functional changes. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/libinput-private.h14
-rw-r--r--src/libinput.c16
-rw-r--r--src/udev-seat.c104
-rw-r--r--src/udev-seat.h6
4 files changed, 82 insertions, 58 deletions
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 529e0020..5e11bb96 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -26,6 +26,12 @@
#include "libinput.h"
#include "libinput-util.h"
+struct libinput_interface_backend {
+ int (*resume)(struct libinput *libinput);
+ void (*suspend)(struct libinput *libinput);
+ void (*destroy)(struct libinput *libinput);
+};
+
struct libinput {
int epoll_fd;
struct list source_destroy_list;
@@ -39,9 +45,12 @@ struct libinput {
size_t events_out;
const struct libinput_interface *interface;
+ const struct libinput_interface_backend *interface_backend;
void *user_data;
};
+typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat);
+
struct libinput_seat {
struct libinput *libinput;
struct list link;
@@ -49,6 +58,7 @@ struct libinput_seat {
void *user_data;
int refcount;
char *name;
+ libinput_seat_destroy_func destroy;
};
struct libinput_device {
@@ -66,6 +76,7 @@ struct libinput_source;
int
libinput_init(struct libinput *libinput,
const struct libinput_interface *interface,
+ const struct libinput_interface_backend *interface_backend,
void *user_data);
struct libinput_source *
@@ -88,7 +99,8 @@ close_restricted(struct libinput *libinput, int fd);
void
libinput_seat_init(struct libinput_seat *seat,
struct libinput *libinput,
- const char *name);
+ const char *name,
+ libinput_seat_destroy_func destroy);
void
libinput_device_init(struct libinput_device *device,
diff --git a/src/libinput.c b/src/libinput.c
index e9c6d5c6..1d99e42c 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -33,7 +33,6 @@
#include "libinput.h"
#include "libinput-private.h"
#include "evdev.h"
-#include "udev-seat.h"
enum libinput_event_class {
LIBINPUT_EVENT_CLASS_BASE,
@@ -366,6 +365,7 @@ libinput_remove_source(struct libinput *libinput,
int
libinput_init(struct libinput *libinput,
const struct libinput_interface *interface,
+ const struct libinput_interface_backend *interface_backend,
void *user_data)
{
libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC);;
@@ -380,6 +380,7 @@ libinput_init(struct libinput *libinput,
}
libinput->interface = interface;
+ libinput->interface_backend = interface_backend;
libinput->user_data = user_data;
list_init(&libinput->source_destroy_list);
list_init(&libinput->seat_list);
@@ -413,6 +414,8 @@ libinput_destroy(struct libinput *libinput)
if (libinput == NULL)
return;
+ libinput->interface_backend->destroy(libinput);
+
while ((event = libinput_get_event(libinput)))
libinput_event_destroy(event);
@@ -496,11 +499,13 @@ close_restricted(struct libinput *libinput, int fd)
void
libinput_seat_init(struct libinput_seat *seat,
struct libinput *libinput,
- const char *name)
+ const char *name,
+ libinput_seat_destroy_func destroy)
{
seat->refcount = 1;
seat->libinput = libinput;
seat->name = strdup(name);
+ seat->destroy = destroy;
list_init(&seat->devices_list);
}
@@ -513,8 +518,9 @@ libinput_seat_ref(struct libinput_seat *seat)
static void
libinput_seat_destroy(struct libinput_seat *seat)
{
+ list_remove(&seat->link);
free(seat->name);
- udev_seat_destroy((struct udev_seat *) seat);
+ seat->destroy(seat);
}
LIBINPUT_EXPORT void
@@ -957,13 +963,13 @@ libinput_get_user_data(struct libinput *libinput)
LIBINPUT_EXPORT int
libinput_resume(struct libinput *libinput)
{
- return udev_input_enable((struct udev_input *) libinput);
+ return libinput->interface_backend->resume(libinput);
}
LIBINPUT_EXPORT void
libinput_suspend(struct libinput *libinput)
{
- udev_input_disable((struct udev_input *) libinput);
+ libinput->interface_backend->suspend(libinput);
}
LIBINPUT_EXPORT void
diff --git a/src/udev-seat.c b/src/udev-seat.c
index 5753ad41..a78be437 100644
--- a/src/udev-seat.c
+++ b/src/udev-seat.c
@@ -198,9 +198,42 @@ out:
udev_device_unref(udev_device);
}
-int
-udev_input_enable(struct udev_input *input)
+static void
+udev_input_remove_devices(struct udev_input *input)
+{
+ struct evdev_device *device, *next;
+ struct udev_seat *seat;
+
+ list_for_each(seat, &input->base.seat_list, base.link) {
+ list_for_each_safe(device, next,
+ &seat->base.devices_list, base.link) {
+ close_restricted(&input->base, device->fd);
+ evdev_device_remove(device);
+ }
+ }
+}
+
+
+static void
+udev_input_disable(struct libinput *libinput)
{
+ struct udev_input *input = (struct udev_input*)libinput;
+
+ if (!input->udev_monitor)
+ return;
+
+ udev_monitor_unref(input->udev_monitor);
+ input->udev_monitor = NULL;
+ libinput_remove_source(&input->base, input->udev_monitor_source);
+ input->udev_monitor_source = NULL;
+
+ udev_input_remove_devices(input);
+}
+
+static int
+udev_input_enable(struct libinput *libinput)
+{
+ struct udev_input *input = (struct udev_input*)libinput;
struct udev *udev = input->udev;
int fd;
@@ -235,7 +268,7 @@ udev_input_enable(struct udev_input *input)
}
if (udev_input_add_devices(input, udev) < 0) {
- udev_input_disable(input);
+ udev_input_disable(libinput);
return -1;
}
@@ -243,48 +276,27 @@ udev_input_enable(struct udev_input *input)
}
static void
-udev_input_remove_devices(struct udev_input *input)
-{
- struct evdev_device *device, *next;
- struct udev_seat *seat;
-
- list_for_each(seat, &input->base.seat_list, base.link) {
- list_for_each_safe(device, next,
- &seat->base.devices_list, base.link) {
- close_restricted(&input->base, device->fd);
- evdev_device_remove(device);
- }
- }
-}
-
-void
-udev_input_disable(struct udev_input *input)
-{
- if (!input->udev_monitor)
- return;
-
- udev_monitor_unref(input->udev_monitor);
- input->udev_monitor = NULL;
- libinput_remove_source(&input->base, input->udev_monitor_source);
- input->udev_monitor_source = NULL;
-
- udev_input_remove_devices(input);
-}
-
-void
-udev_input_destroy(struct udev_input *input)
+udev_input_destroy(struct libinput *input)
{
struct libinput_seat *seat, *next;
+ struct udev_input *udev_input = (struct udev_input*)input;
if (input == NULL)
return;
udev_input_disable(input);
- list_for_each_safe(seat, next, &input->base.seat_list, link) {
+ list_for_each_safe(seat, next, &input->seat_list, link) {
libinput_seat_unref(seat);
}
- udev_unref(input->udev);
- free(input->seat_id);
+ udev_unref(udev_input->udev);
+ free(udev_input->seat_id);
+}
+
+static void
+udev_seat_destroy(struct libinput_seat *seat)
+{
+ struct udev_seat *useat = (struct udev_seat*)seat;
+ free(useat);
}
static struct udev_seat *
@@ -296,20 +308,13 @@ udev_seat_create(struct udev_input *input, const char *seat_name)
if (!seat)
return NULL;
- libinput_seat_init(&seat->base, &input->base, seat_name);
+ libinput_seat_init(&seat->base, &input->base, seat_name, udev_seat_destroy);
list_insert(&input->base.seat_list, &seat->base.link);
notify_added_seat(&seat->base);
return seat;
}
-void
-udev_seat_destroy(struct udev_seat *seat)
-{
- list_remove(&seat->base.link);
- free(seat);
-}
-
static struct udev_seat *
udev_seat_get_named(struct udev_input *input, const char *seat_name)
{
@@ -328,6 +333,12 @@ udev_seat_get_named(struct udev_input *input, const char *seat_name)
return seat;
}
+static const struct libinput_interface_backend interface_backend = {
+ .resume = udev_input_enable,
+ .suspend = udev_input_disable,
+ .destroy = udev_input_destroy,
+};
+
LIBINPUT_EXPORT struct libinput *
libinput_create_from_udev(const struct libinput_interface *interface,
void *user_data,
@@ -343,7 +354,8 @@ libinput_create_from_udev(const struct libinput_interface *interface,
if (!input)
return NULL;
- if (libinput_init(&input->base, interface, user_data) != 0) {
+ if (libinput_init(&input->base, interface,
+ &interface_backend, user_data) != 0) {
free(input);
return NULL;
}
@@ -351,7 +363,7 @@ libinput_create_from_udev(const struct libinput_interface *interface,
input->udev = udev_ref(udev);
input->seat_id = strdup(seat_id);
- if (udev_input_enable(input) < 0) {
+ if (udev_input_enable(&input->base) < 0) {
udev_unref(udev);
libinput_destroy(&input->base);
free(input);
diff --git a/src/udev-seat.h b/src/udev-seat.h
index a60a109f..37cf7c98 100644
--- a/src/udev-seat.h
+++ b/src/udev-seat.h
@@ -41,10 +41,4 @@ struct udev_input {
char *seat_id;
};
-int udev_input_enable(struct udev_input *input);
-void udev_input_disable(struct udev_input *input);
-void udev_input_destroy(struct udev_input *input);
-
-void udev_seat_destroy(struct udev_seat *seat);
-
#endif