From f66685d9dbae7e1d463efdbd2bf1ef2c5249831a Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Thu, 26 Dec 2019 16:03:04 -0300 Subject: [PATCH] weston-log: add function to avoid direct access to compositor members in non-core code If we use the function weston_log_context_add_log_scope() in non-core code, it's necessary to access weston_compositor::weston_log_ctx. This is not ideal, since the goal is to make core structs (weston_compositor, weston_surface, weston_output, etc) opaque. Add function weston_compositor_add_log_scope(), so non-core users are able to pass weston_compositor as argument instead of weston_compositor::weston_log_ctx. Signed-off-by: Leandro Ribeiro --- doc/sphinx/toc/libweston/log.rst | 10 +++---- include/libweston/weston-log.h | 10 ++++++- libweston/weston-log.c | 46 +++++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/doc/sphinx/toc/libweston/log.rst b/doc/sphinx/toc/libweston/log.rst index 2d48e489..c8bba7fb 100644 --- a/doc/sphinx/toc/libweston/log.rst +++ b/doc/sphinx/toc/libweston/log.rst @@ -26,11 +26,11 @@ Instantiation of the :type:`weston_log_context` object takes place using Log scopes ---------- -A scope represents a source for a data stream (i.e., a producer). You'll require -one as a way to generate data. Creating a log scope is done using -:func:`weston_log_ctx_add_log_scope()`. You can customize the scope -behaviour and you'll require at least a name and a description for the -scope. +A scope represents a source for a data stream (i.e., a producer). You'll +require one as a way to generate data. Creating a log scope is done using +:func:`weston_log_ctx_add_log_scope()` or +:func:`weston_compositor_add_log_scope()`. You can customize the scope +behaviour and you'll require at least a name and a description for the scope. .. note:: diff --git a/include/libweston/weston-log.h b/include/libweston/weston-log.h index 5b6ed1b1..70f6d347 100644 --- a/include/libweston/weston-log.h +++ b/include/libweston/weston-log.h @@ -55,7 +55,7 @@ struct weston_debug_stream; * * @param sub The subscription. * @param user_data The \c user_data argument given to - * weston_log_ctx_add_log_scope() + * weston_log_ctx_add_log_scope() or weston_compositor_add_log_scope(). * * @memberof weston_log_scope */ @@ -70,6 +70,14 @@ weston_log_ctx_add_log_scope(struct weston_log_context *log_ctx, weston_log_scope_cb destroy_subscription, void *user_data); +struct weston_log_scope * +weston_compositor_add_log_scope(struct weston_compositor *compositor, + const char *name, + const char *description, + weston_log_scope_cb new_subscription, + weston_log_scope_cb destroy_subscription, + void *user_data); + void weston_log_scope_destroy(struct weston_log_scope *scope); diff --git a/libweston/weston-log.c b/libweston/weston-log.c index 544e777f..80b6eed8 100644 --- a/libweston/weston-log.c +++ b/libweston/weston-log.c @@ -355,7 +355,8 @@ weston_log_subscription_remove(struct weston_log_subscription *sub) * matching against the \c name. * * @param log_ctx - * @param name the scope name, see weston_log_ctx_add_log_scope() + * @param name the scope name, see weston_log_ctx_add_log_scope() and + * weston_compositor_add_log_scope() * @returns NULL if none found, or a pointer to a weston_log_scope * * @ingroup internal-log @@ -644,6 +645,42 @@ weston_log_ctx_add_log_scope(struct weston_log_context *log_ctx, return scope; } +/** Register a new stream name, creating a log scope. + * + * @param compositor The compositor that contains the log context where the log + * scope will be linked. + * @param name The debug stream/scope name; must not be NULL. + * @param description The log scope description for humans; must not be NULL. + * @param new_subscription Optional callback when a client subscribes to this + * scope. + * @param destroy_subscription Optional callback when a client destroys the + * subscription. + * @param user_data Optional user data pointer for the callback. + * @returns A valid pointer on success, NULL on failure. + * + * This function works like weston_log_ctx_add_log_scope(), but the log scope + * created is linked to the log context of \c compositor. + * + * @memberof weston_compositor + * @sa weston_log_ctx_add_log_scope + */ +WL_EXPORT struct weston_log_scope * +weston_compositor_add_log_scope(struct weston_compositor *compositor, + const char *name, + const char *description, + weston_log_scope_cb new_subscription, + weston_log_scope_cb destroy_subscription, + void *user_data) +{ + struct weston_log_scope *scope; + scope = weston_log_ctx_add_log_scope(compositor->weston_log_ctx, + name, description, + new_subscription, + destroy_subscription, + user_data); + return scope; +} + /** Destroy a log scope * * @param scope The log scope to destroy; may be NULL. @@ -896,9 +933,10 @@ weston_log_scope_timestamp(struct weston_log_scope *scope, * to the scope \c scope_name. * * If \c scope_name has already been created (using - * weston_log_ctx_add_log_scope) the subscription will take place - * immediately, otherwise we store the subscription into a pending list. See - * also weston_log_ctx_add_log_scope(). + * weston_log_ctx_add_log_scope or weston_compositor_add_log_scope) the + * subscription will take place immediately, otherwise we store the + * subscription into a pending list. See also weston_log_ctx_add_log_scope() + * and weston_compositor_add_log_scope() * * @param log_ctx the log context, used for accessing pending list * @param subscriber the subscriber, which has to be created before