896 Commits

Author SHA1 Message Date
Ashok Sidipotu
a6328cf2c1 m-lua-scripting: correct typo 2024-05-08 14:20:16 +00:00
Tom Hughes
ae983e6fd7 Improve monitoring of seat state
If the user is reported as active then check that they have at
least one active seat and downgrade the status to online if not.

This ensures that a remote login session won't be interpreted as
the user being active on a local seat.
2024-05-08 13:58:16 +00:00
Pauli Virtanen
2fb055f43d log: add wp_logt_checked taking WpLogTopic, to decide on debug messages
Make decision on whether to show code location in journal messages based
on whether the WpLogTopic would enable DEBUG level messages.

Add wp_logt_checked API to take WpLogTopic as input to make this
possible, and deprecate wp_log_checked.
2024-05-03 13:46:52 +00:00
Stefan Ursella
709eecb21f lua: json: fix error ouput 2024-04-30 05:32:33 +00:00
Stefan Ursella
fd7a1af7ff lua: json: add method to merge json containers 2024-04-30 05:32:33 +00:00
James Calligeros
d77edf70e9 lua: allow Conf methods to be indexed or called
Given that we are allowing Conf() to instantiate a new WpConf,
the methods on the class need to be callable in reference to Self while
maintaining API compatibility with being indexable from the table as a
static method.

Allow this by checking if the first argument passed in is userdata.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
2024-04-17 18:31:09 +10:00
James Calligeros
f769ea8f30 lua: add constructor and file ops for WpConf
This exposes the ability to load a SPA-JSON representation of a WpConf
object from an arbitrary file on disk to the Lua API

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
2024-04-17 18:31:04 +10:00
George Kiagiadakis
8892204f24 wplua/sandbox: support mixing static methods and constructors in class identifiers
Global class identifiers, such as "Node", "SessionItem", "Conf", etc
are so far defined either as methods, which are constructors for
the GObject class, or as tables, which contain "static" methods, i.e.
methods that can be called without an instance.

In some cases, we may want to mix a class being both instantiatable
with a constructor and also have static methods. To support this,
allow the class identifier be declared as a table with the constructor
being defined as the "__new" method. This change allows calling the
table as a method and execute "__new" underneath.

For instance:
```
json = Conf.get_section_as_json("foobar") -- static method
conf = Conf("/foo/bar") -- constructor, equivalent to Conf.__new("/foo/bar")
```

See also !629
2024-04-09 13:15:50 +00:00
George Kiagiadakis
f69d25631d m-portal-permissionstore: improve the warnings printed due to remote errors
Demote the NotFound error returned by Lookup(), as it seems common to be
printed if the permission has not been configured.
2024-03-25 13:51:46 +02:00
George Kiagiadakis
053d2ae69c m-lua-scripting: downgrade notice to debug when printing operation errors
These errors are propagated to the caller, so it's the caller's
responsibility to print them appropriately, if necessary. Printing
a notice also here is only confusing.

A debug mesage is still be useful for developers to understand the flow.
2024-03-25 09:55:59 +02:00
George Kiagiadakis
c89316e52c linking: improve link failure & debug messages 2024-03-25 09:55:13 +02:00
Julian Bouzas
291d3cd9a2 m-settings: remove all persistent settings if key is null
The wp_settings_delete_all() API internally uses wp_metadata_clear() to clear
all the keys in the persistent-sm-settings metadata object. This call emits
the metadata changed signal with both 'key' and 'value' set to NULL. When that
happens, we need to clear all settings from the state file.
2024-03-23 09:39:45 +00:00
Julian Bouzas
b16763f8d4 m-settings: clear schema settings metadata when plugin is disabled 2024-03-23 09:39:45 +00:00
George Kiagiadakis
50497cea03 m-std-event-source: cancel events when the node associated with the si dies
It is possible that a node is destroyed while the select-target
event is ongoing. In that case, the next hook to run will likely crash.
Fix this by cancelling events automatically when their subject
is a session-item associated with a node, as soon as the node is destroyed.

See !619
2024-03-22 15:35:22 +02:00
George Kiagiadakis
d0b7dde4e9 log: make the log topic flags an enumeration and publicly documented
Fixes: #591
2024-03-18 16:39:45 +02:00
George Kiagiadakis
7d217e37ce si-linkables: do not fully reset when the underlying proxy is destroyed
Reset back to the session item's "configured" state instead of clearing
the si properties completely. This allows the "session-item-removed"
event to be dispatched with all the original properties of the node
intact, for constraint matching purposes.

Fixes #588
2024-03-12 12:44:32 +02:00
George Kiagiadakis
3fa5228d22 meson: move the common CFLAGS to project-wide scope 2024-03-09 15:58:01 +02:00
Julian Bouzas
9da732d88c m-mixer-api: use gboolean instead of bool
The WpSpaPodParser always expects gboolean for boolean values. We should never
use bool in WirePlumber unless strictly necessary.

Fixes #584
2024-03-04 17:22:03 +00:00
George Kiagiadakis
655a24acf0 scripts: remove cutils.evaluateRulesApplyProperties()
Cache the rules in a global variable in each script, as JSON,
and use JsonUtils directly to evaluate them. This will allow us to
close the WpConf in the future after loading the scripts.

Also change the order of the return values of the match_rules_apply_properties
function to be able to easily ignore the number of changed values,
which is useless in most cases.
2024-03-04 16:33:14 +00:00
George Kiagiadakis
3fbf1286e6 lua: change the Conf API to have methods for getting sections as specific types
In some cases we need to get a section as JSON, so that we can pass it
down to the rules parser, while in other cases we neeed to get it as a
table to use it natively, and in that case we even need to differentiate
between it being an object, an array or an object with WpProperties.

Make it also possible to optionally pass tables with default values to
the functions so that we can get rid of cutils.get_config_section()
as well.
2024-03-04 16:33:14 +00:00
George Kiagiadakis
c841ec97a8 conf: drop all the _get_value() functions and remove the fallback from _get_section()
We do not use these APIs, so there's no point in keeping them.

Realistically, every component that needs a section just does its
own parsing on it, so the _get_value() functions are not needed.

The fallback in _get_section() is also not needed, as we always
pass NULL and then test for it. In Lua, however, it seems we are
using the fallback to return an empty object, so that getting
a section does not expand to multiple lines of code. For that reason,
I have kept the syntax there and implemented it in the bindings layer.
2024-03-04 07:07:56 +00:00
George Kiagiadakis
60382df63f conf: refactor configuration loading
Changes:

- Configuration files are no longer located by libpipewire,
  which allows us to control the paths that are being looked up.
  This is a requirement for installations where pipewire and
  wireplumber are built using different prefixes, in which case
  the configuration files of wireplumber end up being installed in
  a place that libpipewire doesn't look into...

- The location of conf files is now again $prefix/share/wireplumber,
  /etc/wireplumber and $XDG_CONFIG_HOME/wireplumber, instead of using
  the pipewire directories. Also, since the previous commits, we now
  also support $XDG_CONFIG_DIRS/wireplumber (typically /etc/xdg/wireplumber)
  and $XDG_DATA_DIRS/wireplumber for system-wide configuration.

- Since libpipewire doesn't expose the parser, we now also do the
  parsing of sections ourselves. This has the advantage that we can
  optimize it a bit for our use case.

- The WpConf API has changed to not be a singleton and it is a
  property of WpCore instead. The configuration is now expected
  to be opened before the core is created, which allows the caller
  to identify configuration errors in advance. By not being a singleton,
  we can also reuse the WpConf API to open other SPA-JSON files.

- WpConf also now has a lazy loading mechanism. The configuration
  files are mmap'ed and the various sections are located in advance,
  but not parsed until they are actually requested. Also, the sections
  are not copied in memory, unlike what happens in libpipewire. They
  are only copied when merging is needed.

- WpCore now disables loading of a configuration file in pw_context,
  if a WpConf is provided. This is to have complete control here.
  The 'context.spa-libs' and 'context.modules' sections are still
  loaded, but we load them in WpConf and pass them down to pw_context
  for parsing. If a WpConf is not provided, pw_context is left to load
  the default configuration file (client.conf normally).
2024-03-04 07:07:56 +00:00
George Kiagiadakis
c8feaad7a9 base-dirs: add XDG_CONFIG/DATA_DIRS and CONFIGURATION & DATA groups
This adds support for the system-wide locations for configuration and
data files, as defined by the XDG Base Directory Specification.

In addition, it adds two flag groups, CONFIGURATION and DATA, to the
base-dirs system, so that we don't have to hard-code the combinations
of flags everywhere.
2024-03-04 07:07:56 +00:00
George Kiagiadakis
a95cbda846 base-dirs: change the function signatures to prefix with wp_base_dirs_*
... and fix the arguments order and the documentation
2024-03-04 07:07:56 +00:00
George Kiagiadakis
3dc837c370 WpLookupDirs: remove the flag for looking into G_TEST_SRCDIR
Instead, make it so that WIREPLUMBER_*_DIR environment variables can
contain a list of directories to look into. This is safer and,
as a bonus, allows for more control over the lookup directories.
Using the G_TEST_SRCDIR variable can cause problems for tests of other
projects that use libwireplumber and may also lead to unexpected
behavior by not being obvious that this causes wireplumber to skip
looking in its standard directories...

This also brings back WIREPLUMBER_CONFIG_DIR, which is going to be
needed again for the upcoming WpConf changes.
2024-03-04 07:07:56 +00:00
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
138591c449 m-settings: load all settings in sm-metadata
If a setting is not in the configuration file, use its default value.
2024-02-28 10:20:26 -05:00
Julian Bouzas
a492d23019 m-settings: add settings schema to metadata
This patch improves module-settings to load the settings schema into a
'schema-sm-settings' metadata for clients to know what values types and range
are accepted for each particular setting. This settings schema is defined in
the wireplumber.conf, under a new section called 'wireplumber.settings.schema'.
2024-02-28 08:15:21 -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
Julian Bouzas
22f51336aa module-settings: don't remove setting from sm-settings if it was removed from persistent-sm-settings
Similar to 'default.audio.sink', a setting from sm-settings should never be
removed when the associated persistent setting is removed. Only settings from
persistent-sm-settings can be removed, like 'default.configured.audio.sink'.
2024-02-07 11:43:42 -05:00
Julian Bouzas
1d2fe9b62d module-settings: remove 'settings.persistent' option
This patch removes the 'settings.persistent' option from the configuration as it
only allowed making settings persistent globally instead of individually. This
issue has been addressed in a simpler way by creating a 'persistent-sm-settings'
metadata. If a user wants to make a setting persistent, he can change the
'persistent-sm-settings' metadata object, if the user does not want to make a
persistent change, he can use the 'sm-settings' metadata object. Any changes in
the 'persistent-sm-settings' metadata will be also reflected in the 'sm-settings'
metadata object.
2024-02-02 14:02:49 -05:00
George Kiagiadakis
bdc7839ff2 m-settings: rename persistent.settings to settings.persistent
This makes it more consistent with the nomenclature of other settings
2024-01-29 11:55:18 +02:00
George Kiagiadakis
a511c54c5c m-settings: split out the WpSettings instance loading to a new built-in component
When running multi-instance setups or when clients like wpctl want to
access the WpSettings instance, it makes no sense to load the entire
module-settings, which will also create sm-settings metadata instances.
2024-01-29 11:55:18 +02:00
Pauli Virtanen
d8a345a30c log: rename back to wp_log_set_level 2024-01-13 16:33:05 +00:00
Pauli Virtanen
82df32b0b0 m-lua-scripting: register/unregister log topics 2024-01-13 16:33:05 +00:00
George Kiagiadakis
7bd4032a28 lua: hooks: record the entire 'after' array
Previously we were ignoring the last element in the 'after' arrays
because of a wrong loop limit
2024-01-08 12:28:21 +02:00
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
Pauli Virtanen
6037a6af94 m-log-settings: add module for changing log level at runtime
Pipewire server uses the global "settings" metadata for adjusting its
own log level.

Make it a convention that clients may watch "log.level" in this metadata
with their client id as subject, for setting their own log level
dynamically.

Watch the global "settings" metadata for "log.level" changes for our id.
On changes, set our log level accordingly.
2023-12-24 17:59:59 +02:00
George Kiagiadakis
c2d125b0da Merge branch 'master' into next 2023-12-23 18:34:00 +02:00
George Kiagiadakis
4feebfc3a3 m-lua-scripting: add Core.get_properties() method 2023-12-08 12:28:24 +02:00
Julian Bouzas
78fe6f1ef9 m-si-audio-adapter: make sure format task is finished even if ports were already configured
Currently, if the adapter node already has its ports configured when wireplumber
starts (For example a virtual node), the async _set_ports_format() call is never
completed because the node ports have not changed, stalling the event stack.
This fixes the issue by checking the Props param after configuring the ports,
and completes the task if there is one pending and the node already has ports
available.

Fixes #527
2023-11-28 10:59:15 +00:00
George Kiagiadakis
0a7bd4fe86 si-standard-link: remove the "passive" property
PipeWire no longer uses the link.passive property, so there's no
point in adding it here. The node.passive property is used directly.
2023-11-20 12:00:54 +02:00
George Kiagiadakis
5b1ff7377f si-audio-endpoint: mark the nodes as passive instead of marking the links
This is a behavioural change in effect since pipewire 0.3.68, where
pipewire's link-factory ignores the link.passive property and the
node.pasive = in/out/true is used instead.
2023-11-20 11:56:07 +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
b1f891e149 lua api: add support for PW_PERM_L 2023-11-13 17:18:40 +02:00
George Kiagiadakis
cf4fb87b35 lua api: allow nil to be passed on all constructors that take optional properties 2023-11-10 13:23:50 +02:00
George Kiagiadakis
a6bea40172 core: add wp_core_get_own_bound_id() method
This allows retrieving the bound-id of our own client
2023-11-10 11:27:13 +02:00
George Kiagiadakis
e88fa840f2 lua: json: add optional argument in the json parse() method to limit the number of recursions
This allows partially parsing a json object, allowing some parts to be
passed on as strings to another component that does its own parsing
(ex. a pipewire module)
2023-11-10 11:27:13 +02:00
George Kiagiadakis
0bc6ca6a2d lua: json: allow keys inside objects to be without quotes 2023-11-10 11:27:13 +02:00