Commit Graph

18 Commits

Author SHA1 Message Date
George Kiagiadakis
eb2d6efcd4 state: add save_after_timeout() method to replace all custom timeout code
This was a common pattern that we had in many places, so it makes sense
to consolidate it.
2024-01-04 16:38:33 +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
5c3032c064 core: change the component arguments to be WpSpaJson instead of GVariant
This allows us to pass entire JSON objects from the config file
down to the modules / scripts without any conversion
2023-05-25 18:29:58 +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
fdcd280120 m-settings: use WpConf to get the wireplumber settings 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
Julian Bouzas
78b0dd58db conf: move endpoints into wireplumber.settings 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
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
3011a1c07e m-settings: Fix the crash with empty settings
Add a null check when iterator gets the value to detect the end of the
JSON object, this will ensure the rest of the code that operates on the
value is bypassed.

Still it must be noted that an empty setting screws up the following
settings and behavior is undefined, this is the limiation in the
spa-json parsing.
2023-04-17 07:44:19 -04:00
Ashok Sidipotu
2f60077460 endpoints: Switch endpoints config to JSON
- Move the endpoints defination to wireplumber.conf under a new section
  in the form of two JSON objects, namely endpoints and
  endpoints-roles.
- Treat the endpoint objects as settings, for the sake of loading,
  parsing and querying.
- m-settings loads the objects and WpSettings parses them as any other
  settings.
- Make the following changes in endpoint scripts.
   - Get the endpoint settings using the _get_string() API.
   - Parse and use the data.
   - Remove references to the config/lua
- Remove the endpoints defination in config/lua
2023-04-17 07:44:19 -04:00
Ashok Sidipotu
b76baca520 wireplumber.conf: split up the wireplumber config
- create wireplumber.conf.d and create a file each for a group
  of settings.
- distrube the "wireplumber.components" section as well into these
  files
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
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
Ashok Sidipotu
e9391b195f m-settings: Module to handle JSON config settings.
- parse settings from .conf file.
- create "sm-settings" metadata and copy settings as key value pairs
  to it.
- put in place "persistent" behavior, control it with a special
  setting.
- when persistent behavior is enabled.

  - create a state file and update settings to it.
  - monitor changes in the metadata and update the settings to state
    file.
2023-04-17 07:44:19 -04:00