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 <leandrohr@riseup.net>
This commit is contained in:
Leandro Ribeiro 2019-12-26 16:03:04 -03:00 committed by Pekka Paalanen
parent ac691a89cd
commit f66685d9db
3 changed files with 56 additions and 10 deletions

View File

@ -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::

View File

@ -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);

View File

@ -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