weston-log: Add a advertised list of debug scopes

This introduces a new list that is being checked up when advertising
or when the client attempts to bind a debug scope.

This would allow for a way in which the frontend can determine which
debug scopes the weston-debug protocol can advertise or the client
using the protocol can bind to.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
This commit is contained in:
Marius Vlad 2025-03-07 16:25:07 +02:00
parent 762e286a44
commit 2dd870adac
5 changed files with 89 additions and 1 deletions

View file

@ -4438,6 +4438,22 @@ weston_log_setup_scopes(struct weston_log_context *log_ctx,
free(tokenize);
}
static void
weston_log_print_all_advertised_scopes(struct weston_compositor *ec)
{
struct weston_log_scope *nscope = NULL;
weston_log("Currently advertised debug scopes:\n");
while ((nscope = weston_log_scopes_iterate(ec->weston_log_ctx, nscope))) {
const char *name = weston_log_scope_get_name(nscope);
const char *desc = weston_log_scope_get_description(nscope);
if (weston_log_scope_to_be_advertised(ec->weston_log_ctx, name))
weston_log_continue(STAMP_SPACE "'%s' - %s", name, desc);
}
}
static void
flight_rec_key_binding_handler(struct weston_keyboard *keyboard,
const struct timespec *time, uint32_t key,
@ -4814,6 +4830,9 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
load_additional_modules(wet);
if (debug_protocol)
weston_log_print_all_advertised_scopes(wet.compositor);
section = weston_config_get_section(config, "keyboard", NULL, NULL);
weston_config_section_get_bool(section, "numlock-on", &numlock_on, false);
if (numlock_on) {

View file

@ -1401,6 +1401,7 @@ struct weston_compositor {
struct weston_log_scope *debug_scene;
struct weston_log_scope *timeline;
struct weston_log_scope *libseat_debug;
struct weston_log_filtered *advertised_log_scopes;
struct content_protection *content_protection;

View file

@ -146,6 +146,12 @@ struct weston_log_scope *
weston_log_scopes_iterate(struct weston_log_context *log_ctx,
struct weston_log_scope *nscope);
void
weston_add_scope_to_advertised_list(struct weston_log_context *ctx,
const char *name);
bool
weston_log_scope_to_be_advertised(struct weston_log_context *ctx, const char *name);
#ifdef __cplusplus
}
#endif

View file

@ -244,6 +244,10 @@ weston_debug_subscribe(struct wl_client *client,
log_ctx = wl_resource_get_user_data(global_resource);
version = wl_resource_get_version(global_resource);
/* verify that we can actually bind to this scope name */
if (!weston_log_scope_to_be_advertised(log_ctx, name))
goto fail;
stream_resource = wl_resource_create(client,
&weston_debug_stream_v1_interface,
version, new_stream_id);

View file

@ -69,6 +69,7 @@ struct weston_log_context {
struct wl_listener compositor_destroy_listener;
struct wl_list scope_list; /**< weston_log_scope::compositor_link */
struct wl_list pending_subscription_list; /**< weston_log_subscription::source_link */
struct wl_list advertised_debug_list; /** weston_debug_scope_advertised::link */
};
/** weston-log message scope
@ -118,6 +119,15 @@ struct weston_log_subscription {
void *data;
};
struct weston_debug_scope_advertised {
const char *name;
struct wl_list link; /** weston_log_context::advertised_debug_list */
};
static void
weston_destroy_scopes_from_advertised_list(struct weston_log_context *ctx);
static struct weston_log_subscription *
find_pending_subscription(struct weston_log_context *log_ctx,
const char *scope_name)
@ -372,8 +382,10 @@ weston_debug_protocol_advertise_scopes(struct weston_log_context *log_ctx,
struct wl_resource *res)
{
struct weston_log_scope *scope;
wl_list_for_each(scope, &log_ctx->scope_list, compositor_link)
weston_debug_v1_send_available(res, scope->name, scope->desc);
if (weston_log_scope_to_be_advertised(log_ctx, scope->name))
weston_debug_v1_send_available(res, scope->name, scope->desc);
}
/** Disable debug-protocol
@ -413,6 +425,7 @@ weston_log_ctx_create(void)
wl_list_init(&log_ctx->scope_list);
wl_list_init(&log_ctx->pending_subscription_list);
wl_list_init(&log_ctx->compositor_destroy_listener.link);
wl_list_init(&log_ctx->advertised_debug_list);
return log_ctx;
}
@ -449,6 +462,8 @@ weston_log_ctx_destroy(struct weston_log_context *log_ctx)
weston_log_subscription_destroy_pending(pending_sub);
}
weston_destroy_scopes_from_advertised_list(log_ctx);
/* pending_subscription_list should be empty at this point */
free(log_ctx);
@ -522,6 +537,22 @@ weston_compositor_is_debug_protocol_enabled(struct weston_compositor *wc)
return wc->weston_log_ctx->global != NULL;
}
WL_EXPORT bool
weston_log_scope_to_be_advertised(struct weston_log_context *ctx, const char *name)
{
struct weston_debug_scope_advertised *entry;
if (wl_list_empty(&ctx->advertised_debug_list))
return true;
wl_list_for_each(entry, &ctx->advertised_debug_list, link) {
if (!strcmp(entry->name, name))
return true;
}
return false;
}
/** Register a new stream name, creating a log scope.
*
* @param log_ctx The weston_log_context where to add.
@ -670,6 +701,33 @@ weston_compositor_add_log_scope(struct weston_compositor *compositor,
return scope;
}
WL_EXPORT void
weston_add_scope_to_advertised_list(struct weston_log_context *ctx, const char *name)
{
struct weston_debug_scope_advertised *advertised_scope;
if (!name || !*name)
return;
advertised_scope = zalloc(sizeof(*advertised_scope));
advertised_scope->name = strdup(name);
wl_list_insert(&ctx->advertised_debug_list, &advertised_scope->link);
}
static void
weston_destroy_scopes_from_advertised_list(struct weston_log_context *ctx)
{
struct weston_debug_scope_advertised *entry, *tmp_entry;
wl_list_for_each_safe(entry, tmp_entry, &ctx->advertised_debug_list, link) {
free((char *) entry->name);
wl_list_remove(&entry->link);
free(entry);
}
}
/** Destroy a log scope
*
* @param scope The log scope to destroy; may be NULL.