2 This file is part of systemd.
4 Copyright 2011 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
23 #include "logind-device.h"
26 Device* device_new(Manager *m, const char *sysfs, bool master) {
36 d->sysfs = strdup(sysfs);
40 if (hashmap_put(m->devices, d->sysfs, d) < 0) {
47 dual_timestamp_get(&d->timestamp);
52 static void device_detach(Device *d) {
61 while ((sd = d->session_devices))
62 session_device_free(sd);
65 LIST_REMOVE(devices, d->seat->devices, d);
68 if (!seat_has_master_device(s)) {
69 seat_add_to_gc_queue(s);
70 seat_send_changed(s, "CanGraphical", NULL);
74 void device_free(Device *d) {
79 hashmap_remove(d->manager->devices, d->sysfs);
85 void device_attach(Device *d, Seat *s) {
99 had_master = seat_has_master_device(s);
101 /* We keep the device list sorted by the "master" flag. That is, master
102 * devices are at the front, other devices at the tail. As there is no
103 * way to easily add devices at the list-tail, we need to iterate the
104 * list to find the first non-master device when adding non-master
105 * devices. We assume there is only a few (normally 1) master devices
106 * per seat, so we iterate only a few times. */
108 if (d->master || !s->devices)
109 LIST_PREPEND(devices, s->devices, d);
111 LIST_FOREACH(devices, i, s->devices) {
112 if (!i->devices_next || !i->master) {
113 LIST_INSERT_AFTER(devices, s->devices, i, d);
119 if (!had_master && d->master)
120 seat_send_changed(s, "CanGraphical", NULL);