2021-08-09 16:57:19 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2022-04-26 09:43:54 +02:00
|
|
|
#include <string.h>
|
2021-08-09 16:57:19 +02:00
|
|
|
#include <wayland-server-core.h>
|
2022-04-26 09:43:10 +02:00
|
|
|
#include <wlr/util/addon.h>
|
2022-12-22 16:59:04 +01:00
|
|
|
#include <wlr/util/log.h>
|
2021-08-09 16:57:19 +02:00
|
|
|
|
|
|
|
void wlr_addon_set_init(struct wlr_addon_set *set) {
|
2023-07-07 14:34:56 +02:00
|
|
|
*set = (struct wlr_addon_set){0};
|
2021-08-09 16:57:19 +02:00
|
|
|
wl_list_init(&set->addons);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_addon_set_finish(struct wlr_addon_set *set) {
|
2023-10-08 12:21:00 +02:00
|
|
|
while (!wl_list_empty(&set->addons)) {
|
|
|
|
struct wl_list *link = set->addons.next;
|
|
|
|
struct wlr_addon *addon = wl_container_of(link, addon, link);
|
|
|
|
const struct wlr_addon_interface *impl = addon->impl;
|
2021-08-09 16:57:19 +02:00
|
|
|
addon->impl->destroy(addon);
|
2023-10-08 12:21:00 +02:00
|
|
|
if (set->addons.next == link) {
|
|
|
|
wlr_log(WLR_ERROR, "Dangling addon: %s", impl->name);
|
|
|
|
abort();
|
|
|
|
}
|
2021-08-09 16:57:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set,
|
|
|
|
const void *owner, const struct wlr_addon_interface *impl) {
|
2022-11-25 23:29:41 +01:00
|
|
|
assert(impl);
|
2023-07-07 14:34:56 +02:00
|
|
|
*addon = (struct wlr_addon){
|
|
|
|
.impl = impl,
|
|
|
|
.owner = owner,
|
|
|
|
};
|
2021-08-09 16:57:19 +02:00
|
|
|
struct wlr_addon *iter;
|
|
|
|
wl_list_for_each(iter, &set->addons, link) {
|
2021-08-11 12:35:20 +02:00
|
|
|
if (iter->owner == addon->owner && iter->impl == addon->impl) {
|
|
|
|
assert(0 && "Can't have two addons of the same type with the same owner");
|
2021-08-09 16:57:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wl_list_insert(&set->addons, &addon->link);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_addon_finish(struct wlr_addon *addon) {
|
2021-08-11 12:35:20 +02:00
|
|
|
wl_list_remove(&addon->link);
|
2021-08-09 16:57:19 +02:00
|
|
|
}
|
|
|
|
|
2021-08-11 12:35:20 +02:00
|
|
|
struct wlr_addon *wlr_addon_find(struct wlr_addon_set *set, const void *owner,
|
|
|
|
const struct wlr_addon_interface *impl) {
|
2021-08-09 16:57:19 +02:00
|
|
|
struct wlr_addon *addon;
|
|
|
|
wl_list_for_each(addon, &set->addons, link) {
|
2021-08-11 12:35:20 +02:00
|
|
|
if (addon->owner == owner && addon->impl == impl) {
|
2021-08-09 16:57:19 +02:00
|
|
|
return addon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|