[PATCH weston 02/17] evdev: roughly split udev-related code out

Pekka Paalanen ppaalanen at gmail.com
Thu Jul 5 03:32:59 PDT 2012


Just do the major code move, and hack things up to compile still.

Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
 src/Makefile.am          |    2 +
 src/compositor-drm.c     |    2 +-
 src/compositor-openwfd.c |    2 +-
 src/evdev.c              |  224 +----------------------------------------
 src/evdev.h              |   24 ++---
 src/udev-evdev.c         |  251 ++++++++++++++++++++++++++++++++++++++++++++++
 src/udev-evdev.h         |   47 +++++++++
 7 files changed, 316 insertions(+), 236 deletions(-)
 create mode 100644 src/udev-evdev.c
 create mode 100644 src/udev-evdev.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 282df73..b8928a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -113,6 +113,8 @@ drm_backend_la_SOURCES =			\
 	evdev.h					\
 	evdev-private.h				\
 	evdev-touchpad.c			\
+	udev-evdev.c				\
+	udev-evdev.h				\
 	launcher-util.c				\
 	launcher-util.h				\
 	libbacklight.c				\
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 4dffa1d..62f21f3 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -39,7 +39,7 @@
 #include <libbacklight.h>
 
 #include "compositor.h"
-#include "evdev.h"
+#include "udev-evdev.h"
 #include "launcher-util.h"
 #include "log.h"
 
diff --git a/src/compositor-openwfd.c b/src/compositor-openwfd.c
index 38bdd35..a684168 100644
--- a/src/compositor-openwfd.c
+++ b/src/compositor-openwfd.c
@@ -34,8 +34,8 @@
 #include <gbm.h>
 
 #include "compositor.h"
-#include "evdev.h"
 #include "log.h"
+#include "udev-evdev.h"
 
 struct wfd_compositor {
 	struct weston_compositor base;
diff --git a/src/evdev.c b/src/evdev.c
index 3355192..40058d1 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -33,7 +33,7 @@
 #include "launcher-util.h"
 #include "log.h"
 
-static void
+void
 evdev_led_update(struct weston_seat *seat_base, enum weston_led leds)
 {
 	static const struct {
@@ -455,7 +455,7 @@ evdev_configure_device(struct evdev_input_device *device)
 	return 0;
 }
 
-static struct evdev_input_device *
+struct evdev_input_device *
 evdev_input_device_create(struct evdev_seat *master,
 			  struct wl_display *display, const char *path)
 {
@@ -522,46 +522,7 @@ err0:
 	return NULL;
 }
 
-static const char default_seat[] = "seat0";
-
-static void
-device_added(struct udev_device *udev_device, struct evdev_seat *master)
-{
-	struct weston_compositor *c;
-	const char *devnode;
-	const char *device_seat;
-
-	device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
-	if (!device_seat)
-		device_seat = default_seat;
-
-	if (strcmp(device_seat, master->seat_id))
-		return;
-
-	c = master->base.compositor;
-	devnode = udev_device_get_devnode(udev_device);
-	evdev_input_device_create(master, c->wl_display, devnode);
-}
-
-static void
-device_removed(struct evdev_input_device *device)
-{
-	struct evdev_dispatch *dispatch;
-
-	dispatch = device->dispatch;
-	if (dispatch)
-		dispatch->interface->destroy(dispatch);
-
-	wl_event_source_remove(device->source);
-	wl_list_remove(&device->link);
-	if (device->mtdev)
-		mtdev_close_delete(device->mtdev);
-	close(device->fd);
-	free(device->devnode);
-	free(device);
-}
-
-static void
+void
 evdev_notify_keyboard_focus(struct evdev_seat *seat)
 {
 	struct evdev_input_device *device;
@@ -599,182 +560,3 @@ evdev_notify_keyboard_focus(struct evdev_seat *seat)
 
 	wl_array_release(&keys);
 }
-
-void
-evdev_add_devices(struct udev *udev, struct weston_seat *seat_base)
-{
-	struct evdev_seat *seat = (struct evdev_seat *) seat_base;
-	struct udev_enumerate *e;
-	struct udev_list_entry *entry;
-	struct udev_device *device;
-	const char *path, *sysname;
-
-	e = udev_enumerate_new(udev);
-	udev_enumerate_add_match_subsystem(e, "input");
-	udev_enumerate_scan_devices(e);
-	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
-		path = udev_list_entry_get_name(entry);
-		device = udev_device_new_from_syspath(udev, path);
-
-		sysname = udev_device_get_sysname(device);
-		if (strncmp("event", sysname, 5) != 0) {
-			udev_device_unref(device);
-			continue;
-		}
-
-		device_added(device, seat);
-
-		udev_device_unref(device);
-	}
-	udev_enumerate_unref(e);
-
-	evdev_notify_keyboard_focus(seat);
-
-	if (wl_list_empty(&seat->devices_list)) {
-		weston_log(
-			"warning: no input devices on entering Weston. "
-			"Possible causes:\n"
-			"\t- no permissions to read /dev/input/event*\n"
-			"\t- seats misconfigured "
-			"(Weston backend option 'seat', "
-			"udev device property ID_SEAT)\n");
-	}
-}
-
-static int
-evdev_udev_handler(int fd, uint32_t mask, void *data)
-{
-	struct evdev_seat *master = data;
-	struct udev_device *udev_device;
-	struct evdev_input_device *device, *next;
-	const char *action;
-	const char *devnode;
-
-	udev_device = udev_monitor_receive_device(master->udev_monitor);
-	if (!udev_device)
-		return 1;
-
-	action = udev_device_get_action(udev_device);
-	if (action) {
-		if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0)
-			return 0;
-
-		if (!strcmp(action, "add")) {
-			device_added(udev_device, master);
-		}
-		else if (!strcmp(action, "remove")) {
-			devnode = udev_device_get_devnode(udev_device);
-			wl_list_for_each_safe(device, next,
-					      &master->devices_list, link)
-				if (!strcmp(device->devnode, devnode)) {
-					device_removed(device);
-					break;
-				}
-		}
-	}
-	udev_device_unref(udev_device);
-
-	return 0;
-}
-
-int
-evdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base)
-{
-	struct evdev_seat *master = (struct evdev_seat *) seat_base;
-	struct wl_event_loop *loop;
-	struct weston_compositor *c = master->base.compositor;
-	int fd;
-
-	master->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
-	if (!master->udev_monitor) {
-		weston_log("udev: failed to create the udev monitor\n");
-		return 0;
-	}
-
-	udev_monitor_filter_add_match_subsystem_devtype(master->udev_monitor,
-			"input", NULL);
-
-	if (udev_monitor_enable_receiving(master->udev_monitor)) {
-		weston_log("udev: failed to bind the udev monitor\n");
-		udev_monitor_unref(master->udev_monitor);
-		return 0;
-	}
-
-	loop = wl_display_get_event_loop(c->wl_display);
-	fd = udev_monitor_get_fd(master->udev_monitor);
-	master->udev_monitor_source =
-		wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
-				     evdev_udev_handler, master);
-	if (!master->udev_monitor_source) {
-		udev_monitor_unref(master->udev_monitor);
-		return 0;
-	}
-
-	return 1;
-}
-
-void
-evdev_disable_udev_monitor(struct weston_seat *seat_base)
-{
-	struct evdev_seat *seat = (struct evdev_seat *) seat_base;
-
-	if (!seat->udev_monitor)
-		return;
-
-	udev_monitor_unref(seat->udev_monitor);
-	seat->udev_monitor = NULL;
-	wl_event_source_remove(seat->udev_monitor_source);
-	seat->udev_monitor_source = NULL;
-}
-
-void
-evdev_input_create(struct weston_compositor *c, struct udev *udev,
-		   const char *seat_id)
-{
-	struct evdev_seat *seat;
-
-	seat = malloc(sizeof *seat);
-	if (seat == NULL)
-		return;
-
-	memset(seat, 0, sizeof *seat);
-	weston_seat_init(&seat->base, c);
-	seat->base.led_update = evdev_led_update;
-
-	wl_list_init(&seat->devices_list);
-	seat->seat_id = strdup(seat_id);
-	if (!evdev_enable_udev_monitor(udev, &seat->base)) {
-		free(seat->seat_id);
-		free(seat);
-		return;
-	}
-
-	evdev_add_devices(udev, &seat->base);
-
-	c->seat = &seat->base;
-}
-
-void
-evdev_remove_devices(struct weston_seat *seat_base)
-{
-	struct evdev_seat *seat = (struct evdev_seat *) seat_base;
-	struct evdev_input_device *device, *next;
-
-	wl_list_for_each_safe(device, next, &seat->devices_list, link)
-		device_removed(device);
-
-	notify_keyboard_focus_out(&seat->base.seat);
-}
-
-void
-evdev_input_destroy(struct weston_seat *seat_base)
-{
-	struct evdev_seat *seat = (struct evdev_seat *) seat_base;
-
-	evdev_remove_devices(seat_base);
-	evdev_disable_udev_monitor(&seat->base);
-
-	wl_list_remove(&seat->base.link);
-	free(seat->seat_id);
-	free(seat);
-}
diff --git a/src/evdev.h b/src/evdev.h
index 8e3214d..07c52e4 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -20,23 +20,21 @@
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <libudev.h>
+#ifndef WESTON_EVDEV_H
+#define WESTON_EVDEV_H
 
-void
-evdev_add_devices(struct udev *udev, struct weston_seat *seat_base);
+struct wl_display;
+struct evdev_seat;
+struct evdev_input_device;
 
-void
-evdev_remove_devices(struct weston_seat *seat_base);
+struct evdev_input_device *
+evdev_input_device_create(struct evdev_seat *master,
+			  struct wl_display *display, const char *path);
 
 void
-evdev_input_create(struct weston_compositor *c, struct udev *udev,
-		   const char *seat);
+evdev_notify_keyboard_focus(struct evdev_seat *seat);
 
 void
-evdev_input_destroy(struct weston_seat *seat);
+evdev_led_update(struct weston_seat *seat_base, enum weston_led leds);
 
-int
-evdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base);
-
-void
-evdev_disable_udev_monitor(struct weston_seat *seat_base);
+#endif /* WESTON_EVDEV_H */
diff --git a/src/udev-evdev.c b/src/udev-evdev.c
new file mode 100644
index 0000000..279eb86
--- /dev/null
+++ b/src/udev-evdev.c
@@ -0,0 +1,251 @@
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <mtdev.h>
+
+#include "compositor.h"
+#include "evdev.h"
+#include "evdev-private.h"
+#include "udev-evdev.h"
+#include "log.h"
+
+
+static const char default_seat[] = "seat0";
+
+static void
+device_added(struct udev_device *udev_device, struct evdev_seat *master)
+{
+	struct weston_compositor *c;
+	const char *devnode;
+	const char *device_seat;
+
+	device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
+	if (!device_seat)
+		device_seat = default_seat;
+
+	if (strcmp(device_seat, master->seat_id))
+		return;
+
+	c = master->base.compositor;
+	devnode = udev_device_get_devnode(udev_device);
+	evdev_input_device_create(master, c->wl_display, devnode);
+}
+
+static void
+device_removed(struct evdev_input_device *device)
+{
+	struct evdev_dispatch *dispatch;
+
+	dispatch = device->dispatch;
+	if (dispatch)
+		dispatch->interface->destroy(dispatch);
+
+	wl_event_source_remove(device->source);
+	wl_list_remove(&device->link);
+	if (device->mtdev)
+		mtdev_close_delete(device->mtdev);
+	close(device->fd);
+	free(device->devnode);
+	free(device);
+}
+
+void
+evdev_add_devices(struct udev *udev, struct weston_seat *seat_base)
+{
+	struct evdev_seat *seat = (struct evdev_seat *) seat_base;
+	struct udev_enumerate *e;
+	struct udev_list_entry *entry;
+	struct udev_device *device;
+	const char *path, *sysname;
+
+	e = udev_enumerate_new(udev);
+	udev_enumerate_add_match_subsystem(e, "input");
+	udev_enumerate_scan_devices(e);
+	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
+		path = udev_list_entry_get_name(entry);
+		device = udev_device_new_from_syspath(udev, path);
+
+		sysname = udev_device_get_sysname(device);
+		if (strncmp("event", sysname, 5) != 0) {
+			udev_device_unref(device);
+			continue;
+		}
+
+		device_added(device, seat);
+
+		udev_device_unref(device);
+	}
+	udev_enumerate_unref(e);
+
+	evdev_notify_keyboard_focus(seat);
+
+	if (wl_list_empty(&seat->devices_list)) {
+		weston_log(
+			"warning: no input devices on entering Weston. "
+			"Possible causes:\n"
+			"\t- no permissions to read /dev/input/event*\n"
+			"\t- seats misconfigured "
+			"(Weston backend option 'seat', "
+			"udev device property ID_SEAT)\n");
+	}
+}
+
+static int
+evdev_udev_handler(int fd, uint32_t mask, void *data)
+{
+	struct evdev_seat *master = data;
+	struct udev_device *udev_device;
+	struct evdev_input_device *device, *next;
+	const char *action;
+	const char *devnode;
+
+	udev_device = udev_monitor_receive_device(master->udev_monitor);
+	if (!udev_device)
+		return 1;
+
+	action = udev_device_get_action(udev_device);
+	if (action) {
+		if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0)
+			return 0;
+
+		if (!strcmp(action, "add")) {
+			device_added(udev_device, master);
+		}
+		else if (!strcmp(action, "remove")) {
+			devnode = udev_device_get_devnode(udev_device);
+			wl_list_for_each_safe(device, next,
+					      &master->devices_list, link)
+				if (!strcmp(device->devnode, devnode)) {
+					device_removed(device);
+					break;
+				}
+		}
+	}
+	udev_device_unref(udev_device);
+
+	return 0;
+}
+
+int
+evdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base)
+{
+	struct evdev_seat *master = (struct evdev_seat *) seat_base;
+	struct wl_event_loop *loop;
+	struct weston_compositor *c = master->base.compositor;
+	int fd;
+
+	master->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
+	if (!master->udev_monitor) {
+		weston_log("udev: failed to create the udev monitor\n");
+		return 0;
+	}
+
+	udev_monitor_filter_add_match_subsystem_devtype(master->udev_monitor,
+			"input", NULL);
+
+	if (udev_monitor_enable_receiving(master->udev_monitor)) {
+		weston_log("udev: failed to bind the udev monitor\n");
+		udev_monitor_unref(master->udev_monitor);
+		return 0;
+	}
+
+	loop = wl_display_get_event_loop(c->wl_display);
+	fd = udev_monitor_get_fd(master->udev_monitor);
+	master->udev_monitor_source =
+		wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
+				     evdev_udev_handler, master);
+	if (!master->udev_monitor_source) {
+		udev_monitor_unref(master->udev_monitor);
+		return 0;
+	}
+
+	return 1;
+}
+
+void
+evdev_disable_udev_monitor(struct weston_seat *seat_base)
+{
+	struct evdev_seat *seat = (struct evdev_seat *) seat_base;
+
+	if (!seat->udev_monitor)
+		return;
+
+	udev_monitor_unref(seat->udev_monitor);
+	seat->udev_monitor = NULL;
+	wl_event_source_remove(seat->udev_monitor_source);
+	seat->udev_monitor_source = NULL;
+}
+
+void
+evdev_input_create(struct weston_compositor *c, struct udev *udev,
+		   const char *seat_id)
+{
+	struct evdev_seat *seat;
+
+	seat = malloc(sizeof *seat);
+	if (seat == NULL)
+		return;
+
+	memset(seat, 0, sizeof *seat);
+	weston_seat_init(&seat->base, c);
+	seat->base.led_update = evdev_led_update;
+
+	wl_list_init(&seat->devices_list);
+	seat->seat_id = strdup(seat_id);
+	if (!evdev_enable_udev_monitor(udev, &seat->base)) {
+		free(seat->seat_id);
+		free(seat);
+		return;
+	}
+
+	evdev_add_devices(udev, &seat->base);
+
+	c->seat = &seat->base;
+}
+
+void
+evdev_remove_devices(struct weston_seat *seat_base)
+{
+	struct evdev_seat *seat = (struct evdev_seat *) seat_base;
+	struct evdev_input_device *device, *next;
+
+	wl_list_for_each_safe(device, next, &seat->devices_list, link)
+		device_removed(device);
+
+	notify_keyboard_focus_out(&seat->base.seat);
+}
+
+void
+evdev_input_destroy(struct weston_seat *seat_base)
+{
+	struct evdev_seat *seat = (struct evdev_seat *) seat_base;
+
+	evdev_remove_devices(seat_base);
+	evdev_disable_udev_monitor(&seat->base);
+
+	wl_list_remove(&seat->base.link);
+	free(seat->seat_id);
+	free(seat);
+}
diff --git a/src/udev-evdev.h b/src/udev-evdev.h
new file mode 100644
index 0000000..7a88c2d
--- /dev/null
+++ b/src/udev-evdev.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef UDEV_EVDEV_H
+#define UDEV_EVDEV_H
+
+#include <libudev.h>
+
+void
+evdev_add_devices(struct udev *udev, struct weston_seat *seat_base);
+
+void
+evdev_remove_devices(struct weston_seat *seat_base);
+
+void
+evdev_input_create(struct weston_compositor *c, struct udev *udev,
+		   const char *seat);
+
+void
+evdev_input_destroy(struct weston_seat *seat);
+
+int
+evdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base);
+
+void
+evdev_disable_udev_monitor(struct weston_seat *seat_base);
+
+#endif /* UDEV_EVDEV_H */
-- 
1.7.8.6



More information about the wayland-devel mailing list