Commit Graph

30 Commits

Author SHA1 Message Date
Marius Vlad 4bc7bd73d7 libweston/weston-log: Add a iterator helper for debug scope
This adds three new helpers: one to iterate over all debug scopes
created/added and other two are for simpler getters for the scope name
and the description.

Included with this change is also a simple test to retrieve them.

This is an alternative to using the debug scope list advertised when
using the weston-debug private extension. libweston users can use this
directly to know which scopes they can subscribe to, and there's no need
to have a client implementation for the weston-debug protocol.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2023-05-30 11:05:14 +00:00
Marius Vlad 7932664b3b weston-log: Fix documentation for weston_log_subscription_create
Introduced with e0a858a5f2, commit 'weston-debug: Introduce
weston_log_subscription and weston_log_subscriber objects'. We don't
really return a weston_log_subscription so let's remove it.

Some newer doxygen detects this and we are treating warning as errors.

Fixes #594

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-07-01 17:20:18 +03:00
Marius Vlad e9fe66a91c weston-log: Extract helper for generating a time stamp
As we might be needing it for other scopes extract the time stamp
genration into a helper.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-03-10 17:11:31 +02:00
Maxime Roussin-Bélanger 1d009c248e libweston: fix typos
Signed-off-by: Maxime Roussin-Bélanger <maxime.roussinbelanger@gmail.com>
2021-02-24 10:01:17 -05:00
Leandro Ribeiro d65483ec75 weston-log-wayland: make stream_destroy() use weston_log_subscriber_release()
Make stream_destroy() use weston_log_subscriber_release().
This avoids code duplication and allow us to destroy
weston_log_subscriber_get_only_subscription(), since it's
being used only in this case and it's internal.

Calls for weson_log_subscriber_release() leads to
weston_log_debug_wayland_to_destroy(), which should not
send an error event when the stream has already been closed.

Also, stream_destroy() shouldn't lead to an event error, as
it is a wl_resource destroy handler. So close the stream before
calling weston_log_subscriber_release() in stream_destroy()

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-02-10 10:53:50 +00:00
Leandro Ribeiro 97d2d69909 weston-log: share code between weston_log_scope_destroy() and weston_log_subscriber_release()
Both weston_log_scope_destroy() and weston_log_subscriber_release()
have calls for destroy_subscription(). We can move this call to
weston_log_subscription_destroy() without losing anything and
avoiding repetition.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-02-10 10:53:50 +00:00
Leandro Ribeiro 23491cd931 weston-log: destroy subscriptions with destruction of subscribers
The subscription is directly related to both the log scope and
the subscriber. It makes no sense to destroy one of them and
keep the subscriptions living.

We only had code to destroy subscription with
the destruction of log scopes. Add code to destroy
subscriptions with destruction of subscribers.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-02-10 10:53:50 +00:00
Leandro Ribeiro 1ded661aac weston-log: merge functions that destroy different types of subscribers
Log subscriber API is not type-safe. File and flight recorder
subscribers are created with functions that return
weston_log_subscriber objects. But there's a problem: to destroy
these objects you have to call the right function for each type
of subscriber, and a user calling the wrong destroy function
wouldn't get a warning.

Merge functions that destroy different types of subscribers, making
the log subscriber API type-safe.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-02-10 10:53:50 +00:00
Leandro Ribeiro 8c02ea1069 weston-log: rename weston_log_subscriber::destroy to destroy_subscription
weston_log_subscriber has a member named destroy. There are
other structs (weston_output, for instance) that have this
member, and by convention it is a pointer to a function
that destroys the struct.

In weston_log_subscriber it is being used to destroy
subscriptions of the debug protocol, and not the subscriber,
so this name is misleading. Rename it to destroy_subscription.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-02-10 10:53:50 +00:00
Leandro Ribeiro 4ec38d18b3 weston-log: replace weston_log_ctx_compositor_destroy() by weston_log_ctx_destroy()
The function weston_log_ctx_compositor_destroy(), which destroys struct
weston_log_context, takes weston_compositor as argument. We may have a
weston_log_context unlinked from a weston_compositor and currently there
is no way to destroy it.

Add function weston_log_ctx_destroy(), what makes the destruction of
weston_log_context independent of weston_compositor.

With this change, one could destroy a weston_compositor and keep the
related weston_log_context (since now weston_log_context can be destroyed
without the need of a weston_compositor). But if weston_compositor gets
destroyed it's also necessary to destroy weston_log_context::global,
as the debug protocol depends on the compositor. So a listener has been
added to the destroy signal of weston_compositor.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-01-29 12:08:54 -03:00
Leandro Ribeiro 4f13595aa7 weston-log: rename weston_log_ctx_compositor_create() to weston_log_ctx_create()
Since weston_log_ctx_compositor_create() does not have any relation
with weston_compositor, rename it to weston_log_ctx_create().

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-01-29 12:08:54 -03:00
Leandro Ribeiro bd9c0a6ff5 weston-log: fold weston_log_ctx_compositor_setup() into weston_compositor_create()
The function weston_log_ctx_compositor_setup() is being called only inside
weston_compositor_create() and it is so tiny that the code gets easier to
follow if it gets folded in weston_compositor_create().

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-01-29 12:08:54 -03:00
Leandro Ribeiro f66685d9db 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>
2020-01-29 09:55:24 +00:00
Leandro Ribeiro ac691a89cd weston-log: rename the confusing function name weston_compositor_add_log_scope()
There's a function named weston_compositor_add_log_scope()
but it doesn't take a struct weston_compositor argument.

Rename it to weston_log_ctx_add_log_scope(), as
the log_scope is being added to a log_context.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-01-29 09:55:24 +00:00
Leandro Ribeiro f014964f6f weston-log: rename the confusing function name weston_compositor_log_scope_destroy()
There's a function named weston_compositor_log_scope_destroy()
but it doesn't take a struct weston_compositor argument.

Rename it to weston_log_scope_destroy(), as the argument is a
struct weston_log_scope.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-01-27 13:43:24 -03:00
Leandro Ribeiro 5976dbbbb5 weston-log: rename the confusing function name weston_compositor_add_log_scope()
There's a function named weston_compositor_add_log_scope()
but it doesn't take a struct weston_compositor argument.

Rename it to weston_log_ctx_add_log_scope(), as
the log_scope is being added to a log_context.

Also, bump libweston_major to 9.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-01-27 13:42:42 -03:00
Marius Vlad f68ee07880 weston-log: Avoid prefix-matching the scope name when checking for a
pending subscription

It limits to scope name to an exact match.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Reported-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-11-05 17:08:17 +02:00
Marius Vlad d0d89d0d5f weston-log: Add a subscription iterator
Helper to retrieve next available subscription as to avoid exposing the
subscription, which is an opaque (internal) class of the logging
framework.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
2019-10-17 19:42:55 +03:00
Marius Vlad 410d0bc0b2 weston-log-internal: Allow to hang-off data over the subscription
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-10-17 19:42:55 +03:00
Marius Vlad 9bb1c3a3c2 weston-log: Add 'destroy_subscription' callback for the subscription
As 'new_subscription' can create additional objects, 'destroy_subscription'
will be needed when cleaning up.

As this requires a libweston_major bump (noticed by @pq), bump it up to
8.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
2019-10-17 19:42:55 +03:00
Marius Vlad 0c7beb0b67 weston-log: 'new_subscriber' is actually 'new_subscription'
The callback is executed when the subscription is created, so it doesn't
really have a proper name.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-10-17 19:42:54 +03:00
Pekka Paalanen c232f8d934 Unify the include style of shared/ headers
When all shared/ headers are included in the same way, we can drop unnecessary
include seach paths from the compiler.

This include style was chosen because it is prevalent in the code base. Doing
anything different would have been a bigger patch.

This also means that we need to keep the project root directory in the include
search path, which means that one could accidentally include private headers
with

	#include "libweston/dbus.h"

or even

	#include <libweston/dbus.h>

IMO such problem is smaller than the churn caused by any of the alternatives,
and we should be able to catch those in review. We might even be able to catch
those with grep in CI if necessary.

The "bad" include style was found with:
$ for h in shared/*.h; do git grep -F $(basename $h); done | grep -vF '"shared/'

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-10-04 16:04:48 +03:00
Marius Vlad 843b238551 weston-log: Return bytes written for 'printf()' and 'vprintf()' functions
Information is needed for 'vlog()' and 'vlog_continue()' (others
depend on them).

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-08-19 12:40:42 +03:00
Marius Vlad 8b8b803a46 weston-log: Start adding documentation for the logging/debugging framework
Adds initial grouping for sphinx/breathe for the logging/debugging
framework. We add a few groups: log (public API), internal-log (private API,
not exported) and debug-protocol, specific to the weston
debug protocol.

In latest version of breathe, '\memberof' command is recognized as such.
But it conflicts with '\ingroup' command and can't be used in the same
time (leading to duplicate symbols), so we follow a simple rule: object
tagging with '\ingroup' then use '\memberof' command for the functions
that work on that object.

There's also a caveat here: we have objects that are private (opaque)
but the functions are public. For those cases we resort to using
'internal-log' for the object (class) and 'log' for the functions.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-07-18 13:34:04 +03:00
Marius Vlad 3d3ba9594e weston-log: Removed compositor_destroy_listener from the log context
Nobody is using it.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-07-18 13:34:04 +03:00
Marius Vlad ef4c268f68 weston-log: Remove weston_log() calls from weston-log
Avoids a potential dependency on the log scope being set-up before
actually creating the scope. Destroy part of the log context could
suffer from the same issue if the log scope is destroyed before.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-07-18 13:34:04 +03:00
Marius Vlad dad882a12e weston-log: Rename scope's 'begin_cb' callback to 'new_subscriber'
Rather than using 'begin_cb' rename it to a more suitable name.

Further more instead of using the scope use the subscription to pass as
an argument. The source scope is attached to the subscription when
creating it so we can access it that way.

This also adds a _complete and a _printf method for the subscription
such that the callbacks can use to write data to only _that_
subscription and to close/complete it, otherwise writing to a scope
results in writing to all subscriptions for that scope which is not
correct.

In the same time, the scope counter-parts of _write and _complete will
now use the subscription function as well.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniels@collabora.com>
2019-07-18 13:32:23 +03:00
Marius Vlad 5ae0e621be weston-log/weston-log-wayland: Inline private subscription functions
This avoids duplicated bits, by calling the scopes's callback (if any)
and adding the subscription to the scope's subscription list. Further
more, the scope's name when creating the subscription is not needed so
removed that as well.

In mirror, also inline removing of subscription for scope's subscription
list. Fix a potential corner case when the user can request a
subscription to an invalid scope in stream_destroy().

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-07-18 10:49:39 +03:00
Marius Vlad 9f71a4ad85 weston-log: Introduce subscribe functionality
As described in e10c9f89826bb: "weston-debug: Introduce...", the
subscriber object need further functionality to make use of it.

Current form of the weston-debug protocol would not need this, as it
creates underneath a new subscriber each time a client connects and
subscriptions are created/destroyed automatically with the help of
wayland protocol. For other types of streams, we require to manually
create a subscriber and to subscribe to log scopes.

This patch introduces the ability to create subscriptions, and
implicitly to subscribe to (previously created) scopes.

In the event the scope(s) are not created we temporary store the
subscription as a pending one: a subscription for which a scope doesn't
exist at the time of the subscription. When the scope for which the
subscription has been created we take care to create the subscription as
well.

While at it the documentation bits are modified accommodate the subscribe
method and its further functionality.

Lastly, it removes an unlikely case when a scope is not created so we
avoid any kind of dandling (pending) subscription in case there is
subscription to it. We can only do something about in the destroy part
of the scope.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-07-18 10:49:39 +03:00
Marius Vlad c901e8913e weston-debug: Rename weston-debug to weston-log to better reflect its purpose
No changes in functionality have been made.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-07-18 10:49:39 +03:00