[PATCH weston v2 1/4] udev-seat: Refactor out seat lookup and possible creation

Rob Bradford robert.bradford at intel.com
Tue Jun 25 10:56:40 PDT 2013


From: Rob Bradford <rob at linux.intel.com>

This change spills the code for looking up a seat by name and then
potentially creating it if it doesn't exist into a new function called
udev_seat_get_named.

This change allows us to reuse this code when looking up the seat
when parsing seat constraints per output.
---
 src/udev-seat.c | 29 ++++++++++++++++++++---------
 src/udev-seat.h |  2 ++
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/udev-seat.c b/src/udev-seat.c
index a8790b3..bd25535 100644
--- a/src/udev-seat.c
+++ b/src/udev-seat.c
@@ -66,18 +66,11 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
 	if (!seat_name)
 		seat_name = default_seat_name;
 
-	wl_list_for_each(seat, &c->seat_list, base.link) {
-		if (strcmp(seat->base.seat_name, seat_name) == 0)
-			goto seat_found;
-	}
+	seat = udev_seat_get_named(c, seat_name);
 
-	seat = udev_seat_create(c, seat_name);
-
-	if (!seat)
+	if (seat == NULL)
 		return -1;
 
-seat_found:
-
 	/* Use non-blocking mode so that we can loop on read on
 	 * evdev_device_data() until all events on the fd are
 	 * read.  mtdev_get() also expects this. */
@@ -350,3 +343,21 @@ udev_seat_destroy(struct udev_seat *seat)
 	weston_seat_release(&seat->base);
 	free(seat);
 }
+
+struct udev_seat *
+udev_seat_get_named(struct weston_compositor *c, const char *seat_name)
+{
+	struct udev_seat *seat;
+
+	wl_list_for_each(seat, &c->seat_list, base.link) {
+		if (strcmp(seat->base.seat_name, seat_name) == 0)
+			return seat;
+	}
+
+	seat = udev_seat_create(c, seat_name);
+
+	if (!seat)
+		return NULL;
+
+	return seat;
+}
diff --git a/src/udev-seat.h b/src/udev-seat.h
index 7dd5987..3543e7c 100644
--- a/src/udev-seat.h
+++ b/src/udev-seat.h
@@ -48,4 +48,6 @@ int udev_input_init(struct udev_input *input,
 		    const char *seat_id);
 void udev_input_destroy(struct udev_input *input);
 
+struct udev_seat *udev_seat_get_named(struct weston_compositor *c,
+				      const char *seat_name);
 #endif
-- 
1.8.3.1



More information about the wayland-devel mailing list