seat: Convert client list to linked list
This commit is contained in:
parent
9b7a12d90a
commit
fc7116ffad
3 changed files with 19 additions and 29 deletions
|
@ -7,11 +7,11 @@
|
||||||
|
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "linked_list.h"
|
#include "linked_list.h"
|
||||||
#include "list.h"
|
|
||||||
|
|
||||||
struct server;
|
struct server;
|
||||||
|
|
||||||
struct client {
|
struct client {
|
||||||
|
struct linked_list link; // seat::clients
|
||||||
struct server *server;
|
struct server *server;
|
||||||
struct event_source_fd *event_source;
|
struct event_source_fd *event_source;
|
||||||
struct connection connection;
|
struct connection connection;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "linked_list.h"
|
#include "linked_list.h"
|
||||||
#include "list.h"
|
|
||||||
|
|
||||||
struct client;
|
struct client;
|
||||||
|
|
||||||
|
@ -28,7 +27,7 @@ struct seat_device {
|
||||||
|
|
||||||
struct seat {
|
struct seat {
|
||||||
char *seat_name;
|
char *seat_name;
|
||||||
struct list clients;
|
struct linked_list clients;
|
||||||
struct client *active_client;
|
struct client *active_client;
|
||||||
struct client *next_client;
|
struct client *next_client;
|
||||||
|
|
||||||
|
|
43
seatd/seat.c
43
seatd/seat.c
|
@ -12,7 +12,7 @@
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "drm.h"
|
#include "drm.h"
|
||||||
#include "evdev.h"
|
#include "evdev.h"
|
||||||
#include "list.h"
|
#include "linked_list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "seat.h"
|
#include "seat.h"
|
||||||
|
@ -23,7 +23,7 @@ struct seat *seat_create(const char *seat_name, bool vt_bound) {
|
||||||
if (seat == NULL) {
|
if (seat == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
list_init(&seat->clients);
|
linked_list_init(&seat->clients);
|
||||||
seat->vt_bound = vt_bound;
|
seat->vt_bound = vt_bound;
|
||||||
seat->curttyfd = -1;
|
seat->curttyfd = -1;
|
||||||
seat->seat_name = strdup(seat_name);
|
seat->seat_name = strdup(seat_name);
|
||||||
|
@ -37,8 +37,8 @@ struct seat *seat_create(const char *seat_name, bool vt_bound) {
|
||||||
|
|
||||||
void seat_destroy(struct seat *seat) {
|
void seat_destroy(struct seat *seat) {
|
||||||
assert(seat);
|
assert(seat);
|
||||||
while (seat->clients.length > 0) {
|
while (!linked_list_empty(&seat->clients)) {
|
||||||
struct client *client = seat->clients.items[seat->clients.length - 1];
|
struct client *client = (struct client *)seat->clients.next;
|
||||||
// This will cause the client to remove itself from the seat
|
// This will cause the client to remove itself from the seat
|
||||||
assert(client->seat);
|
assert(client->seat);
|
||||||
client_kill(client);
|
client_kill(client);
|
||||||
|
@ -65,7 +65,7 @@ int seat_add_client(struct seat *seat, struct client *client) {
|
||||||
|
|
||||||
client->seat = seat;
|
client->seat = seat;
|
||||||
|
|
||||||
list_add(&seat->clients, client);
|
linked_list_insert(&seat->clients, &client->link);
|
||||||
log_debug("added client");
|
log_debug("added client");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -77,19 +77,7 @@ int seat_remove_client(struct client *client) {
|
||||||
struct seat *seat = client->seat;
|
struct seat *seat = client->seat;
|
||||||
|
|
||||||
// We must first remove the client to avoid reactivation
|
// We must first remove the client to avoid reactivation
|
||||||
bool found = false;
|
linked_list_remove(&client->link);
|
||||||
for (size_t idx = 0; idx < seat->clients.length; idx++) {
|
|
||||||
struct client *c = seat->clients.items[idx];
|
|
||||||
if (client == c) {
|
|
||||||
list_del(&seat->clients, idx);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
log_debug("client was not on the client list");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seat->next_client == client) {
|
if (seat->next_client == client) {
|
||||||
seat->next_client = NULL;
|
seat->next_client = NULL;
|
||||||
|
@ -108,7 +96,7 @@ int seat_remove_client(struct client *client) {
|
||||||
client->seat = NULL;
|
client->seat = NULL;
|
||||||
log_debug("removed client");
|
log_debug("removed client");
|
||||||
|
|
||||||
return found ? 0 : -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct seat_device *seat_find_device(struct client *client, int device_id) {
|
struct seat_device *seat_find_device(struct client *client, int device_id) {
|
||||||
|
@ -498,8 +486,10 @@ int seat_set_next_session(struct client *client, int session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct client *target = NULL;
|
struct client *target = NULL;
|
||||||
for (size_t idx = 0; idx < seat->clients.length; idx++) {
|
|
||||||
struct client *c = seat->clients.items[idx];
|
for (struct linked_list *elem = seat->clients.next; elem != &seat->clients;
|
||||||
|
elem = elem->next) {
|
||||||
|
struct client *c = (struct client *)elem;
|
||||||
if (client_get_session(c) == session) {
|
if (client_get_session(c) == session) {
|
||||||
target = c;
|
target = c;
|
||||||
break;
|
break;
|
||||||
|
@ -579,17 +569,18 @@ int seat_activate(struct seat *seat) {
|
||||||
// A specific client has been requested, use it
|
// A specific client has been requested, use it
|
||||||
next_client = seat->next_client;
|
next_client = seat->next_client;
|
||||||
seat->next_client = NULL;
|
seat->next_client = NULL;
|
||||||
} else if (seat->clients.length > 0 && seat->vt_bound) {
|
} else if (!linked_list_empty(&seat->clients) && seat->vt_bound) {
|
||||||
// No client is requested, try to find an applicable one
|
// No client is requested, try to find an applicable one
|
||||||
for (size_t idx = 0; idx < seat->clients.length; idx++) {
|
for (struct linked_list *elem = seat->clients.next; elem != &seat->clients;
|
||||||
struct client *client = seat->clients.items[idx];
|
elem = elem->next) {
|
||||||
|
struct client *client = (struct client *)elem;
|
||||||
if (client->seat_vt == vt) {
|
if (client->seat_vt == vt) {
|
||||||
next_client = client;
|
next_client = client;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (seat->clients.length > 0) {
|
} else if (!linked_list_empty(&seat->clients)) {
|
||||||
next_client = seat->clients.items[0];
|
next_client = (struct client *)seat->clients.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next_client == NULL) {
|
if (next_client == NULL) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue