Commit Graph

411 Commits

Author SHA1 Message Date
George Kiagiadakis
3fa5228d22 meson: move the common CFLAGS to project-wide scope 2024-03-09 15:58:01 +02:00
George Kiagiadakis
655a24acf0 scripts: remove cutils.evaluateRulesApplyProperties()
Cache the rules in a global variable in each script, as JSON,
and use JsonUtils directly to evaluate them. This will allow us to
close the WpConf in the future after loading the scripts.

Also change the order of the return values of the match_rules_apply_properties
function to be able to easily ignore the number of changed values,
which is useless in most cases.
2024-03-04 16:33:14 +00:00
Julian Bouzas
ee366446b6 conf: fix settings schema typos
Fixes #583
2024-03-04 09:03:51 -05:00
George Kiagiadakis
c841ec97a8 conf: drop all the _get_value() functions and remove the fallback from _get_section()
We do not use these APIs, so there's no point in keeping them.

Realistically, every component that needs a section just does its
own parsing on it, so the _get_value() functions are not needed.

The fallback in _get_section() is also not needed, as we always
pass NULL and then test for it. In Lua, however, it seems we are
using the fallback to return an empty object, so that getting
a section does not expand to multiple lines of code. For that reason,
I have kept the syntax there and implemented it in the bindings layer.
2024-03-04 07:07:56 +00:00
George Kiagiadakis
60382df63f conf: refactor configuration loading
Changes:

- Configuration files are no longer located by libpipewire,
  which allows us to control the paths that are being looked up.
  This is a requirement for installations where pipewire and
  wireplumber are built using different prefixes, in which case
  the configuration files of wireplumber end up being installed in
  a place that libpipewire doesn't look into...

- The location of conf files is now again $prefix/share/wireplumber,
  /etc/wireplumber and $XDG_CONFIG_HOME/wireplumber, instead of using
  the pipewire directories. Also, since the previous commits, we now
  also support $XDG_CONFIG_DIRS/wireplumber (typically /etc/xdg/wireplumber)
  and $XDG_DATA_DIRS/wireplumber for system-wide configuration.

- Since libpipewire doesn't expose the parser, we now also do the
  parsing of sections ourselves. This has the advantage that we can
  optimize it a bit for our use case.

- The WpConf API has changed to not be a singleton and it is a
  property of WpCore instead. The configuration is now expected
  to be opened before the core is created, which allows the caller
  to identify configuration errors in advance. By not being a singleton,
  we can also reuse the WpConf API to open other SPA-JSON files.

- WpConf also now has a lazy loading mechanism. The configuration
  files are mmap'ed and the various sections are located in advance,
  but not parsed until they are actually requested. Also, the sections
  are not copied in memory, unlike what happens in libpipewire. They
  are only copied when merging is needed.

- WpCore now disables loading of a configuration file in pw_context,
  if a WpConf is provided. This is to have complete control here.
  The 'context.spa-libs' and 'context.modules' sections are still
  loaded, but we load them in WpConf and pass them down to pw_context
  for parsing. If a WpConf is not provided, pw_context is left to load
  the default configuration file (client.conf normally).
2024-03-04 07:07:56 +00:00
George Kiagiadakis
ccdca1ffb4 tests/wp/spa-json: add "undefined" parser unit test 2024-03-04 07:07:56 +00:00
George Kiagiadakis
3dc837c370 WpLookupDirs: remove the flag for looking into G_TEST_SRCDIR
Instead, make it so that WIREPLUMBER_*_DIR environment variables can
contain a list of directories to look into. This is safer and,
as a bonus, allows for more control over the lookup directories.
Using the G_TEST_SRCDIR variable can cause problems for tests of other
projects that use libwireplumber and may also lead to unexpected
behavior by not being obvious that this causes wireplumber to skip
looking in its standard directories...

This also brings back WIREPLUMBER_CONFIG_DIR, which is going to be
needed again for the upcoming WpConf changes.
2024-03-04 07:07:56 +00:00
Julian Bouzas
578b85584c settings: fix all coverity scan defects 2024-02-29 07:23:58 -05:00
Julian Bouzas
8935837cda scripts: remove settings-manager and use the Settings API
The settings manager is not needed anymore because the WpSettings Lua API
returns now the default value from the schema if the setting is not found.
2024-02-28 10:20:31 -05:00
Julian Bouzas
f2e7a41175 m-lua-scripting: complete Lua Settings API
This patch adds the new WpSettings API in Lua.
2024-02-28 10:20:26 -05:00
Julian Bouzas
424a8e5263 settings: add API to set, reset, save, delete and iterate settings
Also improves and refactor the settings unit test to test all the new API added.
2024-02-28 10:20:20 -05:00
Julian Bouzas
a23248847a metadata: remove wp_metadata_iterator_item_extract() API
Similar to WpPropertiesItem, this implements a new WpMetadataItem type that is
returned when iterating metadata
2024-02-28 08:15:17 -05:00
George Kiagiadakis
475ec4944d lib/settings: make the WpSettings object a non-singleton
This doesn't need to be a singleton, since we have the core registration
API available publicly nowadays. Makes things more clean for the API,
following the pattern of WpPlugin and WpSiFactory and simplifies the
built-in settings component in the internal component loader :)
2024-02-10 17:48:23 +02:00
George Kiagiadakis
7a13189ce4 tests/wp/events.c: replace g_assert() with g_assert_true()
Fixes: #565
2024-02-01 17:45:44 +02:00
George Kiagiadakis
cc4549134a script-tester: load the new settings-instance component 2024-01-29 12:57:35 +02:00
George Kiagiadakis
74bfe4baa3 script-tester: simplify the load_component() function 2024-01-29 12:56:46 +02:00
George Kiagiadakis
03098c88bb bt-pinephone.lua: remove useless variable assignments
This is a copy/paste from the code that now lives in apply-routes.lua,
but there is no point since the route here is a real route param and
not a route_info structure.
2024-01-08 12:28:21 +02:00
George Kiagiadakis
c2d125b0da Merge branch 'master' into next 2023-12-23 18:34:00 +02:00
George Kiagiadakis
4593245fbb comp-loader: add support for wireplumber.components.rules
This is a new rules section that allows defining rules to modify
component definitions. This is useful to add repetitive dependencies,
for example, as in the case of "type = script/lua" that always requires
the "support.lua-scripting" feature. This can also be useful to modify
other component properties, such as the arguments, in overriding
configuration files, without needing to redefine the whole components
section.
2023-11-14 12:42:32 +02:00
George Kiagiadakis
42b64bfc28 spa-json: rename _from_string() to _wrap_string() and add new "from" variants
The previous naming convention was confusing because it did not make
it explicit that the string is not being copied. We had this wrong already
in the Lua bindings and thanks to some miracle it hasn't backfired so far
(it was using the "wrap" behaviour with a string that doesn't stay alive).

In some places we actually need the "copy" behaviour and in some other
places we need the "wrap" behaviour, so let's have both variants available.
2023-11-14 12:36:10 +02:00
George Kiagiadakis
e88fa840f2 lua: json: add optional argument in the json parse() method to limit the number of recursions
This allows partially parsing a json object, allowing some parts to be
passed on as strings to another component that does its own parsing
(ex. a pipewire module)
2023-11-10 11:27:13 +02:00
George Kiagiadakis
18ea9606d2 tests: fix script-tester to work with the metadata.lua changes 2023-11-08 20:37:13 +02:00
George Kiagiadakis
a6dd60ff83 conf: remove wp_conf_apply_rules() 2023-11-07 16:36:49 +02:00
George Kiagiadakis
fbecc50319 lua: api: bind json-utils functions 2023-11-07 16:36:49 +02:00
George Kiagiadakis
89ac416e99 lib: add new json-utils set of functions
The purpose is to wrap some utilities that pipewire provides that use JSON.

Start by wrapping pw_conf_match_rules(), which despite its name, it has nothing
to do with the configuration object. It operates directly on JSON and can be
useful to work with match rules outside the context of configuration files.
2023-11-07 16:36:49 +02:00
Pauli Virtanen
0809a89442 tests: script-tester: fix locking of test-server
Calling functions on test server must lock the thread loop, otherwise
the concurrency causes corruptiont in module-protocol-native and you get
bogus messages etc.
2023-11-01 21:00:55 +02:00
George Kiagiadakis
1e40108d94 linking-utils: rename unwrap_find_target_event -> unwrap_select_target_event 2023-09-30 12:06:40 +03:00
Ashok Sidipotu
d4f3e2bdca tests: replace "policy" with "linking" 2023-09-26 10:09:47 +03:00
George Kiagiadakis
0d8dfc8187 tests: add test for glob patterns in hook dependencies 2023-09-24 00:23:34 +03:00
Julian Bouzas
56017fdbe6 scripts: use filter-utils to implement smart filter policy 2023-09-03 14:33:34 +00:00
Julian Bouzas
d383762812 device: remove echo-cancel configuration
This will be possible to do with the new filter-utils.lua design.
2023-09-03 14:33:34 +00:00
Duncan Overbruck
15f5d84d47 tests: add event dispatch order test for same priority events 2023-09-03 17:30:03 +03:00
George Kiagiadakis
67f9f63520 Merge branch '0.4' into next 2023-09-01 19:12:20 +03:00
Julian Bouzas
227dd97036 m-lua-scripting: always parse JSON to String if its type is not recognized
This allows parsing JSON strings without quotes.
2023-08-11 14:48:13 -04:00
George Kiagiadakis
98cd13284c tests: wait for the cores to connect before starting
Otherwise we end up executing the test without
an established connection
2023-07-04 15:09:31 +03:00
George Kiagiadakis
f94519a67a tests: upgrade failure notices to criticals
It's not very clear that these are the cause of failure when you look
at the logs
2023-07-04 14:57:26 +03:00
George Kiagiadakis
84d3382292 config: make it possible to have feature profiles
A profile is a list of features set to required/optional/disabled
which governs which components are getting loaded, given a static
components list with well-defined dependencies
2023-06-23 20:15:26 +03:00
George Kiagiadakis
a982b7917c tests: reduce logs coming from libpipewire
These tests are meant to catch wireplumber issues, so the libpipewire
logs are not very interesting and just make it hard to go through
the interesting bits
2023-06-23 18:01:26 +03:00
George Kiagiadakis
a0497b4256 Merge branch '0.4' into next 2023-06-21 20:59:04 +03:00
George Kiagiadakis
19cfd37da6 comp-loader: register the component & feature only if it activates successfully
Fixes #470
See also !503
2023-06-20 17:20:01 +03:00
George Kiagiadakis
db5bd534ce tests: do not explicitly free f->base.conf_file
This is done inside wp_base_test_fixture_teardown() now, as it should.
2023-06-20 12:39:29 +03:00
George Kiagiadakis
e738076cb0 conf: refactor component loading to use a dependency system
Each component can now list required and optional dependencies,
using the component feature names to match other components.
In addition, each component feature can be declared as required, optional
or disabled, making optional components easier to deal with.
The component flags (ifexists, nofail) have been removed.

Using virtual components, this system also allows easier customization
of which components should be loaded for a specific configuration,
without requiring the user to copy the list of components and edit it.

Also bump the required glib version to 2.68 for g_assert_cmpstrv()
2023-06-20 12:39:29 +03:00
George Kiagiadakis
9c2d25b985 tests: add component loader unit test 2023-06-20 12:39:29 +03:00
George Kiagiadakis
8a8cd97ca8 core: make the object registration functions public
This allows registering arbitrary objects on the core's registry and
finding them later, without having to add API for each and every object.

I think this is useful enough to have it public, even though it's
probably not going to be used that much... The rationale here is to
allow registering custom component loaders without having to make them
subclass WpPlugin or to create custom API for registering component
loaders specifically.

Also, remove the wp_plugin_register() and wp_si_factory_register()
functions, since they are not going to be used much in the future.
The idea is to let the component loader do the registration under the
scenes, as the component is getting loaded.
2023-06-20 12:39:29 +03:00
George Kiagiadakis
c7cb193588 core: introduce the notion of provided features on components
Each component can optionally "provide" a feature, which is basically
a string that describes the feature (ex. "support.dbus"). If the
component loads successfully, the feature is marked as provided and
can be tested for its presence with wp_core_test_feature()
2023-06-20 12:39:29 +03:00
George Kiagiadakis
add310d9eb dbus: refactor WpDBus into a plugin called dbus-connection
Now that we have proper module load order, we can have this shared
dbus connection in a module instead of the library. The module has
to be loaded before any other modules that need it, obviously.
2023-06-20 12:39:29 +03:00
Julian Bouzas
e24e52c6d3 spa-json: encode the string directly into the builder
Some special characters like '\v' are encoded using 6 characters, which
currently does not work because the VLA size asumes a maximum of 4 characters
per encoded special character. This patch refactors this logic to avoid using
VLAs at all and encodes the string directly into the builder.

See #471
2023-06-19 12:03:23 -04:00
Julian Bouzas
e91a9583d8 spa-json: Fix conditional jump on uninitialised value when adding empty strings to builder
Similar to wp_spa_json_builder_add_property(), we need to make sure the dst
array in wp_spa_json_builder_add_string() has room for the null character
because builder_add() expects it.

Fixes #471
2023-06-19 08:07:02 -04:00
Duncan Overbruck
575030aaf3 tests: add conf test for equal matches 2023-06-17 20:07:11 +02:00
George Kiagiadakis
55fc845098 component-loader: make wp_core_load_component_finish() return a boolean
There is no reason to return the component object... all components
are supposed to be long-lived objects that are referenced by the
registry and there is API to find them. The caller is only interested
in the success or failure of the operation.
2023-05-28 21:07:15 +03:00