37 Commits

Author SHA1 Message Date
Julian Bouzas
00e5c0d7f8 settings: log warnings if setting does not exist in the schema 2024-03-04 09:03:51 -05:00
Julian Bouzas
578b85584c settings: fix all coverity scan defects 2024-02-29 07:23:58 -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
d61bf89969 lib/settings: reorder functions to follow the pattern of other files 2024-02-10 16:42:15 +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
83e47ab7c2 tree-wide: refactor active feature checks to use _test_active_features()
Similar to 5fc7e68d10, it's wrong to test
multiple flags with a simple & operation. In some cases we had this wrong.
2023-11-08 12:23:00 +02:00
George Kiagiadakis
6d7232a1fd settings: correct class description 2023-09-26 10:00:43 +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
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
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
Ashok Sidipotu
d9d3a49f5a settings: remove unnecessary log message 2023-04-17 07:48:18 -04:00
Julian Bouzas
1da43c6031 settings: append matches if the rule name matches 2023-04-17 07:48:18 -04:00
Julian Bouzas
89dcd64003 settings: make sure WpSpaJson is valid after doing wp_iterator_next() 2023-04-17 07:48:18 -04:00
Julian Bouzas
b84261773a settings: make sure WpSpaJson is not NULL when checking its type 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
Julian Bouzas
d28d7d4278 settings: use WpSpaJson instead of raw string in WpSettingsChangedCallback
Avoids users to construct a WpSpaJson every time the callback is triggered.
2023-04-17 07:47:09 -04:00
Julian Bouzas
a77fe0b021 settings: add APIs to parse all types safely 2023-04-17 07:47:09 -04:00
Julian Bouzas
51b78e3572 settings: don't show warning if rule or action are empty objects 2023-04-17 07:47:09 -04:00
Julian Bouzas
2f1aece8b6 settings: remove _get_{boolean|int|float|string}() APIs
They is really no needed with the new _get() API and the WpSpaJson API. In C,
users can use 'wp_spa_json_parse_{boolean|int|float|string}()' APIs to parse the
WpSpaJson. In Lua, users can just do 'Settings.get(setting, m):parse()'.
2023-04-17 07:47:09 -04:00
Julian Bouzas
d79c0f45d5 settings: fix code format 2023-04-17 07:47:09 -04:00
Julian Bouzas
271b6931de settings: fix memory leaks 2023-04-17 07:47:09 -04:00
Julian Bouzas
1a98155599 settings: add new _get_all() API 2023-04-17 07:47:09 -04:00
Julian Bouzas
2223cd47d4 settings: use WpSpaJson to parse the settings
We need to use WpSpaJson to parse the values in WpSettings. This is because the
wireplumber configuration is written in JSON, so WpSettings should only hold
JSON values. To fix this, 2 API changes have been done:

- wp_settings_get_int() only accepts gint values, instead of gint64 values. This
is because the WpSpaJson API only parses int values, like spa_json_parse_int().

- wp_settings_get_string() now returns a newly allocated string, this is because
the string needs to be decoded in case it has quotes.
2023-04-17 07:47:09 -04:00
Julian Bouzas
bef5b2ef04 settings: use TRUE/FALSE instead of true/false 2023-04-17 07:47:09 -04:00
Ashok Sidipotu
cfd51d9fe2 lib: wpsettings: Add _register_callback () API 2023-04-17 07:44:19 -04:00
Ashok Sidipotu
2ef76f823a bluez.lua: Switch bluez lua monitor to wpsettings
- Monitor to use the JSON APIs and move away from config/lua
- Enhance logic in wpsettings to parse settings which are JSON arrays,
  some of the bluetooth properties are JSON arrays and parsing
  logic confused them for a rule.
- Add corresponding tests around this logic as well.
2023-04-17 07:44:19 -04:00
Ashok Sidipotu
3a25bc14d2 lib: Add _get_float() wpsettings API
- also add the corresponding C & Lua tests.
2023-04-17 07:44:19 -04:00
George Kiagiadakis
5cefe9e800 settings: fix doxygen/g-i strings/commands and link them to the sphinx site 2023-04-17 07:44:19 -04:00
Ashok Sidipotu
161c43b71a lua monitors: switch to wpsetttings
- switch alsa.lua, v4l2.lua & libcamera.lua
- remove the config/lua references for these scripts
- fix the wpsettings deps parsing bug.
2023-04-17 07:44:19 -04:00
Ashok Sidipotu
7d304096e5 lib: Add _get_{int,string}() APIs
- add integer and string version of the APIs,
- Also Refine the APIs, return value to indicate the setting existance
  and a new param to return the value of the setting.
- add their lua bindings as well, in lua binding the return value nil
  indicates that the setting is not defnied.
- Add corresponding C and lua tests as well.
- Add a few handy debug msgs.
2023-04-17 07:44:19 -04:00
Ashok Sidipotu
a4f16a98f0 main: Add support for deps flag in loading modules
- support loading modules dependent on wireplumber settings in JSON
  config.
- load the settings module before parsing wireplumber.components,
  so that dependencies can be fetched during parsing.
- access lua scripts are switched to JSON based config and lua configs
  are removed.
2023-04-17 07:44:19 -04:00
Ashok Sidipotu
a5d62b7bbd lib: Add wp_settings_apply_rule() API
- add C based tests
- add lua binding for the API and corresponding lua tests
- address comments from previous commits
2023-04-17 07:44:19 -04:00
Ashok Sidipotu
75c61f9388 lib: Add parsing logic for rules
- unlike pipewire, rules will be parsed during the bootup time, i.e
  during the creation of the wpsettings object.
- The rules are parsed into the wpinterest objects and stored in the
  wpsettings object, they will be eventually used to service the
  apply_rule() API.
- Support pipewire syntax of rules defination in this version.
2023-04-17 07:44:19 -04:00
Ashok Sidipotu
4d7ce2292e tests: Add tests for WpSettings object
- settings.c tests conf file loading & parsing, metadata updates,
  wpsetttings object creation and its API.
- settings.lua tests the API from lua scripts.
- Add a sample settings.conf file, this file contains sections copied
  over from client.conf along with the settings section. Add a file
  each for wp side and lua side of scripts.
- Make changes in base test infrastructure to take a custom conf file.
- Enhance the wp_settings_get_instance_api() to be take metadata_name
  parameter. So, Wpsetttings is now a singleton instance for a given
  metadata file.
- Enhance the m-settings module also to be take metadata_name parameter.
  this is handy for lua side of tests as its cumbersome to do this is
  lua.
2023-04-17 07:44:19 -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