18 Commits

Author SHA1 Message Date
Barnabás Pőcze
89b6766cd6 transition: ensure single completion and finish
At the moment, the same transition can be completed multiple times
(assuming sufficiently high reference count):

  return_error()
  finish()
  return_error()

The consequence of that is that the transition closure will be
invoked multiple times. This is unexpected.

Add some guards against completing a transition or calling finish()
multiple times.

Fixes #628
2024-05-18 01:36:39 +02:00
Barnabás Pőcze
1ddfbc532c transition: fix memory leak when error is already set
Fixes: 18377fbf82 ("transition: don't allow _return_error() to be called recursively")
2024-05-18 00:46:58 +02:00
George Kiagiadakis
4736d56557 log: implement a log topics system, like pipewire
The intention is to make checks for enabled log topics faster.

Every topic has its own structure that is statically defined in the file
where the logs are printed from. The structure is initialized transparently
when it is first used and it contains all the log level flags for the levels
that this topic should print messages. It is then checked on the wp_log()
macro before printing the message.

Topics from SPA/PipeWire are also handled natively, so messages are printed
directly without checking if the topic is enabled, since the PipeWire and SPA
macros do the checking themselves.

Messages coming from GLib are checked inside the handler.

An internal WpLogFields object is used to manage the state of each log
message, populating all the fields appropriately from the place they
are coming from (wp_log, spa_log, glib log), formatting the message and
then printing it. For printing to the journald, we still use the glib
message handler, converting all the needed fields to GLogField on demand.
That message handler does not do any checks for the topic or the level, so
we can just call it to send the message.
2023-05-16 20:42:28 +03:00
George Kiagiadakis
18377fbf82 transition: don't allow _return_error() to be called recursively 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
8fd8b01b7a lib: Introduce WpSettings API
- WpSettings is a singleton object which attaches itself to the core
  and registry, it provides a get_instance () for its clients.
- WpSettings provides API to get/set wireplumber settings and rules.
- main.c loads the new object and makes sure it is available for
  for all the modules and scripts. This is achieved by introducing
  a new activation step.
- Add the lua bindings for get_setting API.
2023-04-17 07:44:19 -04:00
Pauli Virtanen
0a605f666c wp: fix behavior of transitions before advanced for first time
wp_transition_get_completed incorrectly returns TRUE for transitions
that have not been advanced at least once, and hence are obviously not
completed.  This is because transitions start at STEP_NONE, and
completed transition is also indicated by STEP_NONE.

Fix this by adding a private flag to track whether transition was
started.

Fixes object managers sometimes missing object-changed events. How that
happens is the following:

- object activation transitions are advanced in idle callback
- they are aborted on registry global removal events
- registry global removal event can arrive before the idle callback
- wp_object_abort_activation uses wp_transition_get_completed to
  determine whether transition was completed, but it returned bogus
  values on transitions that hadn't been started.
2022-03-05 23:43:02 +02:00
Peter Hutterer
9208ea051c Fix some typos 2021-11-18 12:09:57 +00:00
Jason Francis
ed8346e77d docs: Add brief descriptions to all functions
This ensures all of these functions are picked up by g-ir-scanner.
2021-06-02 17:38:34 +00:00
George Kiagiadakis
b812e912d2 docs: fix C API documentation to work nicely with doxygen & sphinx 2021-05-25 14:19:53 +03:00
Raghavendra
d692f06f0d docs: api: Replace hotdoc specific commands with Doxygen specific commands 2021-05-25 14:19:53 +03:00
George Kiagiadakis
257d5cba47 wp: rename debug.{h,c} to log.{h,c}
Also rename the intermediate lua api table WpDebug -> WpLog

Keeps things more consistent with the function names (wp_log*),
with the lua api (Log.*) and with pipewire using log.{h,c} as well.
After all, these functions are for logging...
2021-05-06 15:50:07 +03:00
George Kiagiadakis
7eed2acd76 lib: documentation fixes 2021-03-04 19:10:10 +02:00
George Kiagiadakis
2f3f5f8e66 lib: refactor WpProxy
This is an attempt to unclutter the API of WpProxy and
split functionality into smaller pieces, making it easier
to work with.

In this new class layout, we have the following classes:

- WpObject: base class for everything; handles activating
|           and deactivating "features"
|- WpProxy: base class for anything that wraps a pw_proxy;
 |          handles events from pw_proxy and nothing more
 |- WpGlobalProxy: handles integration with the registry

All the other classes derive from WpGlobalProxy. The reason
for separating WpGlobalProxy from WpProxy, though, is that
classes such as WpImplNode / WpSpaDevice can also derive from
WpProxy now, without interfacing with the registry.

All objects that come with an "info" structure and have properties
and/or params also implement the WpPipewireObject interface. This
provides the API to query properties and get/set params. Essentially,
this is implemented by all classes except WpMetadata (pw_metadata
does not have info)

This interface is implemented on each object separately, using
a private "mixin", which is a set of vfunc implementations and helper
functions (and macros) to facilitate the implementation of this interface.

A notable difference to the old WpProxy is that now features can be
deactivated, so it is possible to enable something and later disable
it again.

This commit disables modules, tests, tools, etc, to avoid growing the
patch more, while ensuring that the project compiles.
2020-11-13 19:54:48 +02:00
George Kiagiadakis
268b7dd0a9 transition: stop and return error if cancelled by the GCancellable 2020-10-22 13:27:29 +03:00
George Kiagiadakis
43711828ce transition: add the ability to use a GClosure instead of a GAsyncReadyCallback 2020-05-08 19:23:23 +03:00
George Kiagiadakis
9ca342f89f debug: update all library code to use the new debug system
+ enable the new log writer on the executables
+ enable structured logging in the tests
2020-04-14 18:31:17 +03:00
George Kiagiadakis
79a39e98c9 transition: call execute_step() with _STEP_ERROR in error conditions
This allows the implementation to rollback changes, cancel jobs, etc
2020-03-31 16:11:08 +03:00
George Kiagiadakis
5f169d190f lib: implement a new WpTransition class
This is an asynchronous operation class, like GTask,
but it is made to execute several operations underneath,
using a state machine, instead of just a single operation.
2020-03-29 15:02:59 +03:00