20 Commits

Author SHA1 Message Date
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
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
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
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
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
Ashok Sidipotu
b172ae915f test/settings.lua: fix the assert failure in the callback API tests
The callback for the last test was getting called with non-string type and this
fails the test. fix it by sending string in correct format.

This test failure was not failing the "make test" this is known limitation in the test
setup. The limitation here is only with the last assert statement.
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
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
Ashok Sidipotu
cfd51d9fe2 lib: wpsettings: Add _register_callback () API 2023-04-17 07:44:19 -04:00
Ashok Sidipotu
067b1954e3 tests: Add tests for JSON array of strings
Bluetooth has a setting that would need JSON array of strings and so
these tests help prepare the ground.
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
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
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