Commit Graph

175 Commits

Author SHA1 Message Date
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
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
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
73b6b90a35 m-lua-scripting/api: allow EventDispatcher.push_event() to accept event objects 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
c6c740e94a wplua: expose setmetatable / getmetatable in the sandbox 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
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
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
f1fbeaa661 m-lua-scripting: add fallback value for parse_{array|object}_safe() APIs 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
Julian Bouzas
a77fe0b021 settings: add APIs to parse all types safely 2023-04-17 07:47:09 -04:00
Ashok Sidipotu
72536261e9 policy-node.lua: Second round of cleanup.
- WirePlumber Lua now facilitates Lua libraries/modules, utilize this and create
  modules. Add some tests around this functionality.
- Create policy-hooks.lua containing all the hooks to find-target events
- Create policy-utils.lua module and push all the policy utility functions to it.
- Create common-utils.lua module and push the common utility functions to it.
- Remove all the above functionality from policy-node.lua and clean it up.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
270dc5c041 m-lua-scripting: push_event API to return the event created 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
535af7a33e m-lua-scripting: don't show warning if object key is not a string
The wp_spa_json_parse_string() API also works for strings without quotes.
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
6e31b47c28 event-dispatcher: Add an enumeration of default event hook priorities
This scheme provides for an orderly execution of hooks as the priorities
are controlled from one single place. Enumeration is defined in such a
way that new items can be added easily.

All the event hooks are changed to get the priorities from this
enumeration.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
ff833b138d event-dispatcher: log event and hook names and chains
- Add a new variable "name" in WpEventHook and use it to log all the
  hooks(by name) picked up in _push_event(). This gives a clear picture
  if hook is registered for a given event.
- Form a name for an event and a chain of events for an event run, log
  both of them. This gives a clear picture of the events executed and
  order in which they are dispatched.
- Similarly build hooks chain and print it in _source_dispatch(), this
  gives a clear picture of the hooks picked and the order in which they
  are dispatched.
- Log only the dispatchable(with hooks) events, this de-clutters
  the log messages.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
4d1a86ced1 m-lua-scripting: Fix bug in WpEvent referencing
While calling async execute closure, take a reference to the WpEvent
object before pushing it to the Lua stack. Otherwise Lua garbage
collector frees it, which leads to invalid memory access.
2023-04-17 07:47:09 -04:00
George Kiagiadakis
d72f31e803 lua: add EventInterest convenience constructor for declaring interest on events 2023-04-17 07:47:09 -04:00
George Kiagiadakis
4c7cb5145d lua: implement EventDispatcher.push_event 2023-04-17 07:47:09 -04:00
George Kiagiadakis
5c2565c9b1 lua: add WpAsyncEventHook bindings 2023-04-17 07:47:09 -04:00
George Kiagiadakis
60c5982cd0 lua: add bindings for event / hook / dispatcher 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
3a25bc14d2 lib: Add _get_float() wpsettings API
- also add the corresponding C & Lua tests.
2023-04-17 07:44:19 -04:00
George Kiagiadakis
893e44c51e lua: fix number of returned values in Settings.apply_rule 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
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
Julian Bouzas
c8be8d91be m-lua-scripting: increase refcount of export_core before pushing into the Lua state 2023-02-10 10:54:52 -05:00
Julian Bouzas
6b761c03e1 m-lua-scripting: ignore string/integer table keys when constructing a JSON Array/Object 2023-01-04 11:20:14 -05:00
Dylan Aïssi
5d9fb9f678 Fix typo: numner to number 2022-12-14 10:51:52 +01:00
George Kiagiadakis
efaaf3b43a lua: add Core.get_vm_type() method 2022-06-28 14:06:48 +03:00
Julian Bouzas
0996f5a5ca spa-json: add wp_spa_json_to_string() API
Since the string length returned by wp_spa_pod_get_data() does not always match
the size of the actual json object because it is stored in contiguous memory, we
cannot always rely on that API to get the json string data.

The new wp_spa_pod_to_string() always allocates a new string with the same
length as the json size, guaranteeing that the string returned always represents
the json object, regardless of whether it is nested or not. It is always
recommented to use wp_spa_pod_to_string() unless you know what you are doing.
2022-06-27 10:07:16 +00:00
Julian Bouzas
04198820f1 device: add new wp_spa_device_managed_object_new_iterator API 2022-06-27 08:52:36 +00:00
Michael Olbrich
13b85bd4a2 m-lua-scripting: fix object refcounting
7908b8d7be2a2992c57cd549054eda7ce46e4b44 ("m-lua-scripting: allow
converting GValue holding NULL objects to Lua") accidentally added a second
refcount. As a result, the objects are never freeded.

Remove the second refcount to fix this.
2022-05-24 11:40:35 +02:00
Julian Bouzas
c2f31bb550 m-lua-scripting: allow converting GValue holding NULL objects to Lua 2022-05-19 07:43:12 -04:00