Commit Graph

148 Commits

Author SHA1 Message Date
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
George Kiagiadakis
2eed279c9d i18n: remove the module and embed the gettext calls into the lua api
There is no need to have this as an optional module, since libintl
is a hard dependency of both PipeWire and GLib. This way we can keep
things a bit simpler and faster (no string copies and plugin lookups)

Bump meson dependency to 0.59 to benefit of the libintl lookup that
is now built into meson's dependency() function.
2022-05-10 15:16:09 +03:00
Julian Bouzas
07179452e2 m-lua-scripting: add WpSiAdapter APIs 2022-05-05 08:09:21 +00:00
George Kiagiadakis
81af8c2069 lua: sandbox: remove all traces of the minimal_std flag, as it's no longer used 2022-04-23 20:14:59 +03:00
George Kiagiadakis
ecb6100b77 m-lua-scripting: wrap every script in a WpPlugin and expose async activation api
This allows scripts to declare when they have finished their loading,
so we can now also know when wireplumber is done loading and ready to
handle clients

Related to !313
2022-04-23 20:14:59 +03:00
George Kiagiadakis
031bc65c20 lua: sandbox: relax the sandbox to allow more functionality in scripts
This enables the debug and coroutine libraries and some more functions
that are not really so risky to have around

Related to #121
2022-04-23 20:14:59 +03:00
George Kiagiadakis
9387ce0d95 wplua: implement reference counting of the lua_State 2022-04-23 20:14:59 +03:00
George Kiagiadakis
9c22f6076a wplua: enable the use of require() to load lua libraries from scripts/lib 2022-04-23 20:14:59 +03:00
George Kiagiadakis
e1d0240bc9 wplua: split the functionality of the load functions into smaller functions
The load functions used to do 3 things:
- push the sandbox function on the stack
- load the file and push it as a function on the stack
- call the sandbox (or the file)

Now there are separate functions to do these 3:
- wplua_push_sandbox
- wplua_load_*
- wplua_pcall
2022-04-23 20:14:59 +03:00
Pauli Virtanen
bbe9ac00f3 modules: add m-i18n
Add simple gettext i18n module.

Add Lua script API functions I18n.gettext, I18n.ngettext.
2022-04-11 19:20:43 +03:00
George Kiagiadakis
17a257ddbe wplua: move under modules/module-lua-scripting
It's unlikely that wplua will ever be useful outside the context
of module-lua-scripting, so let's move it to keep all the code in one place
2022-03-24 09:47:59 +02:00
George Kiagiadakis
ca906362cd lua-scripting: expose WpImplMetadata on the API 2022-02-03 13:04:55 +02:00
Julian Bouzas
b0ddd6f890 m-lua-scripting: add Json.Raw constructor 2022-01-26 09:53:24 -05:00
Julian Bouzas
46ab414a04 spa-json: fix coverity scan issues 2022-01-25 21:18:16 -05:00
Julian Bouzas
20187e07b5 m-lua-scripting: add WpSpaJson API 2022-01-25 07:20:35 -05:00
Ashok Sidipotu
784c405c31 wp: support loading optional modules
-some modules will not be available during runtime, due to
  external dependencies.
 -these modules can now be marked optional.
 -loading of these optional modules will be attempted and if
  they are not available, wp will recover and will not be
  terminated.
2021-10-14 06:27:53 +00:00
Nicolai Syvertsen
27a6970de5 lua/api: fix impl_module_new arg parse 2021-10-13 17:25:51 +00:00
George Kiagiadakis
30407f9930 lua/api: add bindings for client:send_error() 2021-10-13 11:18:51 +03:00
George Kiagiadakis
5ce2dd3e66 lua/pod: add bindings for fixate() and filter() 2021-10-13 11:18:14 +03:00
Julian Bouzas
711d1ee686 spa-pod: add support for custom Id properties
Allows creating and parsing Pod Objects with custom properties.
2021-09-21 12:29:54 -04:00
George Kiagiadakis
2a5f9c51f2 lua/api: fix object constructors to fail gracefully 2021-09-15 12:51:47 +03:00
George Kiagiadakis
27ed36c2da wp: make the config file lookup methods more generic
* Make the flags public and give them nicer names
* Pass down the flags from the caller, so the caller can now explicitly
  ask for looking into specific directories
* Rename the methods
* Remove and inline the wp_get_xdg_config_dir() method, since it's only
  used internally
* Refactor the lookup dirs ordering to get both WIREPLUMBER_*_DIR env
  variables to replace all the other directories. Previously, we were looking
  for scripts in WIREPLUMBER_DATA_DIR, but we were also looking in /etc at
  the same time (with precedence, even), which could result in unexpected
  behaviour. Now, if a WIREPLUMBER environment variable is specified,
  we only look in there.
2021-08-19 10:06:37 +03:00
Arun Raghavan
129b44bb0c doc: Add WpImplModule docs for the C and Lua API 2021-08-18 16:04:39 +00:00
Arun Raghavan
ef29018c55 m-lua-scripting: Add WpImplModule bindings 2021-08-18 16:04:39 +00:00
Julian Bouzas
9b8a876662 m-lua-scripting: add GLib access Lua API 2021-08-10 11:50:51 +03:00
jakobrs
92d99f4a75 dump_table: Sort keys before printing 2021-08-10 07:50:01 +00:00
jakobrs
86bfdbea13 Fix not-equals verb having the wrong number of arguments in Lua API 2021-08-08 20:45:56 +02:00
George Kiagiadakis
9ebea2976d wp: refactor and rename wp_iter_conf_files() to use WpIterator
This also corrects the logic of loading config files in m-lua-scripting.
Previously, if an error occured within the iteration function,
the error was not properly propagated to the caller because -EINVAL
was being added to nfiles instead of checked.
2021-07-20 14:42:42 +03:00