Commit graph

818 commits

Author SHA1 Message Date
George Kiagiadakis
2d3d5256b9 lua: add new Log.open_topic() API
This allows lua scripts to work with log topics. A topic must be
opened at the top of the file, in global scope, and subsequently
all log commands should be executed on the returned object instead
of the Log global table
2023-05-16 20:42:28 +03: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
Julian Bouzas
c61d1e4245 component-loader: make wp_core_load_component() API asynchronous
This change completely refactors the way components are loaded in wireplumber:
- The module_init() function must return a GObject now. This object is either
a WpPlugin or a WpSiFactory in the current modules.
- When the component loader initializes a module, it automatically registers
the WpPlugin or WpSiFactory with their respective methods. There is no need
to register the WpPlugin or WpSiFactory in the module now.
- The wp_core_load_component() API has been refactored to be asynchronows. This
allows the component loader to automatically activate WpPlugin objects, and
therefore allows the application to directly get the WpPlugin without having
to find it. This simplifies a lot of things.
- The 'ifexists' and 'nofail' component flags now work even if the respective
WpPlugin could not be activated.
- The code that loads components in main.c has also been simplified a lot,
and the option to load dangling components has also been removed.
2023-04-17 07:48:18 -04:00
Julian Bouzas
6259a3a0fa m-lua-scripting: remove handling of 'config/lua' files
Not needed anymore as the configuration is written in JSON now.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
7c2e713c9d m-metadata: remove module-metadata and replace it with a simple lua script 2023-04-17 07:48:18 -04:00
Julian Bouzas
d2123827f7 scripts: use the event stack to handle virtual session items
This removes both the policy-virtual-client.lua and policy-virtual-device.lua
scripts, and creates a new linking/find-virtual-target.lua script to link
clients with virtual session items if one of them can be found. In addition to
this, this patch also ports the policy-virtual-client-links.lua into a new
scripts/rescan-virtual-links.lua to use the event stack. The idea is for the
scripts/link-target.lua to create all links but only activate non virtual links,
and for the scripts/rescan-virtual-links.lua to activate/deactivate virtual
links based on role priorities.
2023-04-17 07:48:18 -04:00
Julian Bouzas
fb855b00cf Rename endpoint concept to virtual session item 2023-04-17 07:48:18 -04:00
Julian Bouzas
9004362cda lib: remove WpEndpoint and WpSiEndpoint APIs 2023-04-17 07:48:18 -04:00
Julian Bouzas
360e0b3eaf scripts: use WpConf API to get configuration values
This patch also moves nested configuration objects that are not considered
settings from the wireplumber.settings section to its own configuration
section (eg the rules array, the spa plugin properties, etc...). This allows
those objects to be merged with other same sections defined in other files.
2023-04-17 07:48:18 -04:00
Julian Bouzas
fdcd280120 m-settings: use WpConf to get the wireplumber settings 2023-04-17 07:48:18 -04:00
Julian Bouzas
a7a7e614db m-lua-scripting: add WpConf Lua API 2023-04-17 07:48:18 -04:00
George Kiagiadakis
3779a92fcc lua: AsyncEventHook: allow hooks to handle transition errors
When in error, attempt to execute a step called "error", if it exists.
This is rarely needed, but it might be useful in some cases to cleanup
some state, rolling back changes, when something fails.
2023-04-17 07:48:18 -04:00
Ashok Sidipotu
1b09061b9d tests: settings: run all the tests with default metadata
There is no need to use an exclusive metadata just for tests, remove it to
simplify the code.
2023-04-17 07:48:18 -04:00
Ashok Sidipotu
fcfae4eeb3 lib/wp: add a new search folder to locate the Lua Test scripts 2023-04-17 07:48:18 -04:00
George Kiagiadakis
153c019343 m-std-event-source: separate rescan events for linking and default-nodes
Call the event "rescan-for-<context>", where <context> is either
"linking" or "default-nodes" and can be expanded in the future.

Add an additional hook in default-nodes to trigger the
rescan-for-default-nodes event when sources and sinks come and go.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
dc196df239 m-std-event-source: fix state names in node-state-changed event
We need to use the enum nicknames ("idle"), not the enum names
("WP_NODE_STATE_IDLE"). This makes suspend-node work again.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
dbca5783d0 m-std-event-source: don't crash in disable() if the core is not available
When the core is shutting down, the weak reference to it is cleared before
we have a change to use it, but it's ok because everything is getting destroyed
at this point, including the hook that we want to unregister.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
08a9d39295 events: rename find-target-si-and-link to select-target
And make sure it does not get prefixed with the subject type
2023-04-17 07:48:18 -04:00
George Kiagiadakis
73b6b90a35 m-lua-scripting/api: allow EventDispatcher.push_event() to accept event objects 2023-04-17 07:48:18 -04:00
George Kiagiadakis
8e9faa6a25 m-default-nodes-api: revert to the version from master, without hooks
But keep the additional comments and debug statement improvements.
Also, merge the stuff from common.h, which was previously shared
with m-default-nodes.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
2325178d5c default-nodes: port to a set of scripts with hooks 2023-04-17 07:48:18 -04:00
George Kiagiadakis
b5d8a7982f scripts: split/refactor the policy-device-routes script into smaller hooks 2023-04-17 07:48:18 -04:00
George Kiagiadakis
7ae4fca46b m-std-event-source: add a "create-event" action
This allows the calling script to also attach event data before
pushing the event on the dispatcher
2023-04-17 07:48:18 -04:00
George Kiagiadakis
9891758c70 remove policy-device-profile and m-default-profile 2023-04-17 07:48:18 -04:00
George Kiagiadakis
f99c3005f2 scripts: rewrite policy-device-profile and m-default-profile into a set of hooks
... excluding the persistent profile functionality for now (I am not convinced)
2023-04-17 07:48:18 -04:00
George Kiagiadakis
ffa85840ac event: move cancelling of events on pw-proxy-destroyed to m-std-event-source
It is really out of place to do this inside WpEvent, as it is not
a generic action. It should only happen for some events.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
3a23fb451a event-dispatcher: refactor to use before/after dependencies on hooks
* Remove entirely the hook priority numbers and use before/after dependencies
* Split the WpEvent code out of WpEventDispatcher
* Add methods on WpEvent to interface with it from the WpEventDispatcher.
  As a bonus, we can now also implement tooling to inspect which hooks would
  in theory run for an event and write tests around that
* Removed some internal debugging facilities and log calls, will redo it later.
* Using spa_list now for the list of hooks, to reduce the number of allocations
  happening in the "hook collection" algorithm
* Switched some internal data to use g_new0 instead of g_slice_new0
* Added g_free to free WpEvent structures... surprisingly, we were leaking them
  before
2023-04-17 07:48:18 -04:00
George Kiagiadakis
b100bdda4a event-hook: remove the exec type property & enumeration
With the latest changes, we can implement the "after-events" type
with external code that pushes a very low priority event that is
the "rescan" event.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
bcb4e80723 m-std-event-source: use type-specific event names and multiple object managers
It is better to have type-specific event names to minimize the amount
of constraint string matches we do on hooks, as most hooks (if not all)
are interested on specific types of objects only.

Similarly, use a different object manager for each object type to
minimize the performance impact of iterations and lookups, as all
such actions are interested in only 1 object type every time.

Port all existing hooks to the new event names and the get-object-manager API.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
c6c740e94a wplua: expose setmetatable / getmetatable in the sandbox 2023-04-17 07:48:18 -04:00
George Kiagiadakis
374e4ecaff m-standard-event-source: simplify push_event, removing the subject_type
This avoids having to determine the subject type prior to pushing
an event from lua code and makes the call more convenient

Also add a debug statement to trace calls to push_event
2023-04-17 07:48:18 -04:00
George Kiagiadakis
515b3f07d1 m-lua-scripting: api: bind WpEvent set_data/get_data 2023-04-17 07:48:18 -04:00
George Kiagiadakis
55122b84b4 m-standard-event-source: add "schedule-rescan" action signal
This can be used anywhere else in the codebase to push a "rescan-session"
event, making sure that there is only one such event pushed on the stack,
no matter how many times this is called.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
24db3fe24a event-hook: rewrite the hook priorities enum
Hooks need to have a priority relative to the event they are executed on,
so it does not make much sense to have all kinds of different priorities
based also on the event type and/or the module where they are defined.
Also, it wouldn't be acceptable to have such an enumeration on the public API.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
e2b9cb0b5e m-standard-event-source: export the push_event function as an action signal 2023-04-17 07:48:18 -04:00
George Kiagiadakis
252c5b4935 m-standard-event-source: refactor around a central "push_event" function
Also redo some priorities and rename the object-changed event
to metadata-changed
2023-04-17 07:48:18 -04:00
George Kiagiadakis
79d8c9f5d9 m-standard-event-source: pass self as the event's source object 2023-04-17 07:48:18 -04:00
George Kiagiadakis
ab1668af15 m-standard-event-source: add object-manager property 2023-04-17 07:48:18 -04:00
George Kiagiadakis
b2f2e3f745 m-standard-event-source: add SiLink to the object type & priority list
Just to avoid warnings for now
2023-04-17 07:48:18 -04:00
George Kiagiadakis
48635cb780 m-standard-event-source: manage all kinds of session items in the om
So that we can also work with SiLink objects with this object manager
2023-04-17 07:48:18 -04:00
George Kiagiadakis
c0322cb34f m-standard-event-source: remove the devices object manager
That makes no sense to have. The only script that uses this can easily
be rewriten so that it uses object-added/removed instead.
2023-04-17 07:48:18 -04:00
Ashok Sidipotu
c0905c233f m-settings: trigger init of WpSettings object
After the creation of metadata with config data, m-settings will also need to
trigger the init of WpSettings Object/API. Earlier this was done in main.c as
part of init transition but the logic there is much more generalized now and so
it has been moved here.
2023-04-17 07:48:18 -04:00
Ashok Sidipotu
85900fba64 m-lua-scripting: support dangling components
- Dangling components are those not present in the json config files but present
in the wireplumber lookup folders.
2023-04-17 07:48:18 -04:00
Julian Bouzas
78b0dd58db conf: move endpoints into wireplumber.settings 2023-04-17 07:48:18 -04:00
Julian Bouzas
f1fbeaa661 m-lua-scripting: add fallback value for parse_{array|object}_safe() APIs 2023-04-17 07:48:18 -04:00
Julian Bouzas
3c26f278cd module-settings: refactor to only load state file when plugin is enabled
Also fixes issues with persistent.settings not working if no changes have
happened.
2023-04-17 07:48:18 -04:00
Ashok Sidipotu
40a1c3b948 m-lua-scripting: Return the event in the push_event API 2023-04-17 07:48:18 -04:00
Julian Bouzas
d0e27ac82e settings: remove wp_settings_get_all() API
Not used anymore. It is better to use parse_object_safe() Lua API instead.
2023-04-17 07:48:18 -04:00
Ashok Sidipotu
6762de3990 policy-{bluetooth|device-profile|device-routes}.lua: Optimize for Event stack
- Sharpen the hooks.
- Make settings live, apply them when they are changed.
- Move some of the common functions to common_utils.lua
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
8e7611fa9f m-default-nodes{-api}: Correct the critical log msg 2023-04-17 07:47:09 -04:00