mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-08 15:08:04 +02:00
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.
This commit is contained in:
parent
3fbf1286e6
commit
655a24acf0
13 changed files with 50 additions and 43 deletions
|
|
@ -1788,8 +1788,8 @@ json_utils_match_rules_update_properties (lua_State *L)
|
|||
|
||||
count = wp_json_utils_match_rules_update_properties (json, properties);
|
||||
|
||||
lua_pushinteger (L, count);
|
||||
wplua_properties_to_table (L, properties);
|
||||
lua_pushinteger (L, count);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ end
|
|||
function getPermissions (properties)
|
||||
local section = Conf.get_section_as_json ("access.rules")
|
||||
if section then
|
||||
local matched, mprops = JsonUtils.match_rules_update_properties (
|
||||
local mprops, matched = JsonUtils.match_rules_update_properties (
|
||||
section, properties)
|
||||
if (matched > 0 and mprops["default_permissions"]) then
|
||||
return mprops["default_permissions"], mprops["access"]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
cutils = require ("common-utils")
|
||||
log = Log.open_topic ("s-device")
|
||||
|
||||
config = {}
|
||||
config.rules = Conf.get_section_as_json ("device.profile.priority.rules", Json.Array {})
|
||||
|
||||
SimpleEventHook {
|
||||
name = "device/find-preferred-profile",
|
||||
after = "device/find-stored-profile",
|
||||
|
|
@ -28,11 +31,8 @@ SimpleEventHook {
|
|||
end
|
||||
|
||||
local device = event:get_subject ()
|
||||
local device_name = device.properties["device.name"]
|
||||
local props = {
|
||||
["device.name"] = device_name,
|
||||
}
|
||||
cutils.evaluateRulesApplyProperties(props, "device.profile.priority.rules")
|
||||
local props = JsonUtils.match_rules_update_properties (
|
||||
config.rules, device.properties)
|
||||
local p_array = props["priorities"]
|
||||
|
||||
-- skip hook if the profile priorities are NOT defined for this device.
|
||||
|
|
|
|||
|
|
@ -83,22 +83,6 @@ function cutils.get_default_metadata_object ()
|
|||
}
|
||||
end
|
||||
|
||||
function cutils.evaluateRulesApplyProperties (properties, name)
|
||||
local section = Conf.get_section_as_json (name)
|
||||
if not section then
|
||||
return
|
||||
end
|
||||
|
||||
local matched, mprops = JsonUtils.match_rules_update_properties (
|
||||
section, properties)
|
||||
|
||||
if (matched > 0 and mprops) then
|
||||
for k, v in pairs (mprops) do
|
||||
properties [k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function cutils.arrayContains (a, value)
|
||||
for _, v in ipairs (a) do
|
||||
if v == value then
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ log = Log.open_topic ("s-monitors")
|
|||
config = {}
|
||||
config.reserve_device = Core.test_feature ("monitor.alsa.reserve-device")
|
||||
config.properties = Conf.get_section_as_properties ("monitor.alsa.properties")
|
||||
config.rules = Conf.get_section_as_json ("monitor.alsa.rules", Json.Array {})
|
||||
|
||||
-- unique device/node name tables
|
||||
device_names_table = nil
|
||||
|
|
@ -150,7 +151,8 @@ function createNode(parent, id, obj_type, factory, properties)
|
|||
end
|
||||
|
||||
-- apply properties from rules defined in JSON .conf file
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.alsa.rules")
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
if properties["node.disabled"] then
|
||||
node_names_table [properties ["node.name"]] = nil
|
||||
return
|
||||
|
|
@ -253,7 +255,7 @@ function prepareDevice(parent, id, obj_type, factory, properties)
|
|||
|
||||
-- apply properties from rules defined in JSON .conf file
|
||||
applyDefaultDeviceProperties (properties)
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.alsa.rules")
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
if properties ["device.disabled"] then
|
||||
device_names_table [properties ["device.name"]] = nil
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ config = {}
|
|||
config.seat_monitoring = Core.test_feature ("monitor.bluez.seat-monitoring")
|
||||
config.properties = Conf.get_section_as_properties ("monitor.bluez-midi.properties")
|
||||
config.servers = Conf.get_section_as_array ("monitor.bluez-midi.servers", defaults.servers)
|
||||
config.rules = Conf.get_section_as_json ("monitor.bluez-midi.rules", Json.Array {})
|
||||
|
||||
-- unique device/node name tables
|
||||
node_names_table = nil
|
||||
|
|
@ -58,8 +59,8 @@ function createNode(parent, id, type, factory, properties)
|
|||
|
||||
properties["api.glib.mainloop"] = "true"
|
||||
|
||||
-- apply properties from bluetooth.conf
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.bluez-midi.rules")
|
||||
-- apply properties from the rules in the configuration file
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
local latency_offset = properties["node.latency-offset-msec"]
|
||||
properties["node.latency-offset-msec"] = nil
|
||||
|
|
@ -115,7 +116,7 @@ function createServers()
|
|||
["factory.name"] = "api.bluez5.midi.node",
|
||||
["api.glib.mainloop"] = "true",
|
||||
}
|
||||
cutils.evaluateRulesApplyProperties (node_props, "monitor.bluez-midi.rules")
|
||||
node_props = JsonUtils.match_rules_update_properties (config.rules, node_props)
|
||||
|
||||
local latency_offset = node_props["node.latency-offset-msec"]
|
||||
node_props["node.latency-offset-msec"] = nil
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ log = Log.open_topic ("s-monitors")
|
|||
config = {}
|
||||
config.seat_monitoring = Core.test_feature ("monitor.bluez.seat-monitoring")
|
||||
config.properties = Conf.get_section_as_properties ("monitor.bluez.properties")
|
||||
config.rules = Conf.get_section_as_json ("monitor.bluez.rules", Json.Array {})
|
||||
|
||||
-- This is not a setting, it must always be enabled
|
||||
config.properties["api.bluez5.connection-info"] = true
|
||||
|
|
@ -284,8 +285,8 @@ function createNode(parent, id, type, factory, properties)
|
|||
properties["api.bluez5.internal"] = true
|
||||
end
|
||||
|
||||
-- apply properties from bluetooth.conf
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.bluez.rules")
|
||||
-- apply properties from the rules in the configuration file
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
-- create the node; bluez requires "local" nodes, i.e. ones that run in
|
||||
-- the same process as the spa device, for several reasons
|
||||
|
|
@ -347,8 +348,8 @@ function createDevice(parent, id, type, factory, properties)
|
|||
properties["bluez5.profile"] = "off"
|
||||
properties["api.bluez5.id"] = id
|
||||
|
||||
-- apply properties from bluetooth.conf
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.bluez.rules")
|
||||
-- apply properties from the rules in the configuration file
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
-- create the device
|
||||
device = SpaDevice(factory, properties)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ mutils = require ("monitor-utils")
|
|||
|
||||
log = Log.open_topic ("s-monitors-libcamera")
|
||||
|
||||
config = {}
|
||||
config.rules = Conf.get_section_as_json ("monitor.libcamera.rules", Json.Array {})
|
||||
|
||||
function createLibcamNode (parent, id, type, factory, properties)
|
||||
local registered = mutils:register_cam_node (parent, id, factory, properties)
|
||||
if not registered then
|
||||
|
|
@ -39,7 +42,8 @@ SimpleEventHook {
|
|||
local id = event:get_data ("device-sub-id")
|
||||
|
||||
-- apply properties from rules defined in JSON .conf file
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.libcamera.rules")
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
if properties["device.disabled"] then
|
||||
log:notice ("lib cam device " .. properties["device.name"] .. " disabled")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ mutils = require ("monitor-utils")
|
|||
|
||||
log = Log.open_topic ("s-monitors-libcamera")
|
||||
|
||||
config = {}
|
||||
config.rules = Conf.get_section_as_json ("monitor.libcamera.rules", Json.Array {})
|
||||
|
||||
SimpleEventHook {
|
||||
name = "monitor/libcamera/create-node",
|
||||
after = "monitor/libcamera/name-node",
|
||||
|
|
@ -24,7 +27,8 @@ SimpleEventHook {
|
|||
local id = event:get_data ("node-sub-id")
|
||||
|
||||
-- apply properties from rules defined in JSON .conf file
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.libcamera.rules")
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
if properties["node.disabled"] then
|
||||
log:warning ("lib cam device node" .. properties["device.name"] .. " disabled")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ mutils = require ("monitor-utils")
|
|||
|
||||
log = Log.open_topic ("s-monitors-v4l2")
|
||||
|
||||
config = {}
|
||||
config.rules = Conf.get_section_as_json ("monitor.v4l2.rules", Json.Array {})
|
||||
|
||||
function createV4l2camNode (parent, id, type, factory, properties)
|
||||
local registered = mutils:register_cam_node (parent, id, factory, properties)
|
||||
if not registered then
|
||||
|
|
@ -39,7 +42,8 @@ SimpleEventHook {
|
|||
local id = event:get_data ("device-sub-id")
|
||||
|
||||
-- apply properties from rules defined in JSON .conf file
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.v4l2.rules")
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
if properties["device.disabled"] then
|
||||
log:warning ("v4l2 device " .. properties["device.name"] .. " disabled")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ mutils = require ("monitor-utils")
|
|||
|
||||
log = Log.open_topic ("s-monitors-v4l2")
|
||||
|
||||
config = {}
|
||||
config.rules = Conf.get_section_as_json ("monitor.v4l2.rules", Json.Array {})
|
||||
|
||||
SimpleEventHook {
|
||||
name = "monitor/v4l2/create-node",
|
||||
after = "monitor/v4l2/name-node",
|
||||
|
|
@ -25,7 +28,8 @@ SimpleEventHook {
|
|||
local factory = event:get_data ("factory")
|
||||
|
||||
-- apply properties from rules defined in JSON .conf file
|
||||
cutils.evaluateRulesApplyProperties (properties, "monitor.v4l2.rules")
|
||||
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
|
||||
|
||||
if properties["node.disabled"] then
|
||||
log:warning ("v4l2 device node" .. properties["device.name"] .. " disabled")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
cutils = require ("common-utils")
|
||||
log = Log.open_topic ("s-node")
|
||||
|
||||
config = {}
|
||||
config.rules = Conf.get_section_as_json ("stream.rules", Json.Array {})
|
||||
|
||||
-- the state storage
|
||||
state = nil
|
||||
state_table = nil
|
||||
|
|
@ -42,7 +45,7 @@ restore_stream_hook = SimpleEventHook {
|
|||
execute = function (event)
|
||||
local node = event:get_subject ()
|
||||
local stream_props = node.properties
|
||||
cutils.evaluateRulesApplyProperties (stream_props, "stream.rules")
|
||||
stream_props = JsonUtils.match_rules_update_properties (config.rules, stream_props)
|
||||
|
||||
local key = formKey (stream_props)
|
||||
if not key then
|
||||
|
|
@ -149,7 +152,7 @@ store_stream_props_hook = SimpleEventHook {
|
|||
execute = function (event)
|
||||
local node = event:get_subject ()
|
||||
local stream_props = node.properties
|
||||
cutils.evaluateRulesApplyProperties (stream_props, "stream.rules")
|
||||
stream_props = JsonUtils.match_rules_update_properties (config.rules, stream_props)
|
||||
|
||||
if Settings.get_boolean ("node.stream.restore-props") and stream_props ["state.restore-props"] ~= "false"
|
||||
then
|
||||
|
|
@ -223,7 +226,7 @@ store_stream_target_hook = SimpleEventHook {
|
|||
end
|
||||
|
||||
local stream_props = node.properties
|
||||
cutils.evaluateRulesApplyProperties (stream_props, "stream.rules")
|
||||
stream_props = JsonUtils.match_rules_update_properties (config.rules, stream_props)
|
||||
|
||||
if stream_props ["state.restore-target"] == "false" then
|
||||
return
|
||||
|
|
|
|||
|
|
@ -31,19 +31,19 @@ rules_json_str = [[
|
|||
]]
|
||||
|
||||
match_props = { ["device.name"] = "unmatched-device-name" }
|
||||
ret, ret_props = JsonUtils.match_rules_update_properties (Json.Raw (rules_json_str), match_props)
|
||||
ret_props, ret = JsonUtils.match_rules_update_properties (Json.Raw (rules_json_str), match_props)
|
||||
assert (ret == 0)
|
||||
assert (ret_props["device.name"] == match_props["device.name"])
|
||||
|
||||
match_props = { ["device.name"] = "alsa_card_0.my-alsa-device" }
|
||||
ret, ret_props = JsonUtils.match_rules_update_properties (Json.Raw (rules_json_str), match_props)
|
||||
ret_props, ret = JsonUtils.match_rules_update_properties (Json.Raw (rules_json_str), match_props)
|
||||
assert (ret == 2)
|
||||
assert (ret_props["device.name"] == "alsa_card_0.my-alsa-device")
|
||||
assert (ret_props["api.alsa.use-acp"] == "true")
|
||||
assert (ret_props["api.acp.auto-port"] == "false")
|
||||
|
||||
match_props = { ["node.name"] = "alsa_output.0.my-alsa-device" }
|
||||
ret, ret_props = JsonUtils.match_rules_update_properties (Json.Raw (rules_json_str), match_props)
|
||||
ret_props, ret = JsonUtils.match_rules_update_properties (Json.Raw (rules_json_str), match_props)
|
||||
assert (ret == 2)
|
||||
assert (ret_props["node.name"] == "alsa_output.0.my-alsa-device")
|
||||
assert (ret_props["audio.rate"] == "96000")
|
||||
|
|
@ -56,7 +56,7 @@ match_props = {
|
|||
["audio.rate"] = "48000",
|
||||
["node.description"] = "Test",
|
||||
}
|
||||
ret, ret_props = JsonUtils.match_rules_update_properties (Json.Raw (rules_json_str), match_props)
|
||||
ret_props, ret = JsonUtils.match_rules_update_properties (Json.Raw (rules_json_str), match_props)
|
||||
assert (ret == 3)
|
||||
assert (ret_props["node.name"] == "alsa_output.0.my-alsa-device")
|
||||
assert (ret_props["audio.rate"] == "96000")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue