scripts: s/putils/lutils/g ("policy" utils -> "linking" utils)

This commit is contained in:
George Kiagiadakis 2024-01-03 11:10:56 +02:00
parent 994f1c1f4a
commit 5d41ef2311
13 changed files with 61 additions and 61 deletions

View file

@ -9,11 +9,11 @@
local cutils = require ("common-utils")
local putils = {
local lutils = {
si_flags = {},
}
function putils.get_flags (self, si_id)
function lutils.get_flags (self, si_id)
if not self.si_flags [si_id] then
self.si_flags [si_id] = {}
end
@ -21,11 +21,11 @@ function putils.get_flags (self, si_id)
return self.si_flags [si_id]
end
function putils.clear_flags (self, si_id)
function lutils.clear_flags (self, si_id)
self.si_flags [si_id] = nil
end
function putils.unwrap_select_target_event (self, event)
function lutils.unwrap_select_target_event (self, event)
local source = event:get_source ()
local si = event:get_subject ()
local target = event:get_data ("target")
@ -35,7 +35,7 @@ function putils.unwrap_select_target_event (self, event)
return source, om, si, si.properties, self:get_flags (si_id), target
end
function putils.canPassthrough (si, si_target)
function lutils.canPassthrough (si, si_target)
local props = si.properties
local tprops = si_target.properties
-- both nodes must support encoded formats
@ -60,7 +60,7 @@ function putils.canPassthrough (si, si_target)
return false
end
function putils.checkFollowDefault (si, si_target)
function lutils.checkFollowDefault (si, si_target)
-- If it got linked to the default target that is defined by node
-- props but not metadata, start ignoring the node prop from now on.
-- This is what Pulseaudio does.
@ -87,7 +87,7 @@ function putils.checkFollowDefault (si, si_target)
end
end
function putils.lookupLink (si_id, si_target_id)
function lutils.lookupLink (si_id, si_target_id)
local link = cutils.get_object_manager ("session-item"):lookup {
type = "SiLink",
Constraint { "out.item.id", "=", si_id },
@ -103,7 +103,7 @@ function putils.lookupLink (si_id, si_target_id)
return link
end
function putils.isLinked (si_target)
function lutils.isLinked (si_target)
local target_id = si_target.id
local linked = false
local exclusive = false
@ -123,7 +123,7 @@ function putils.isLinked (si_target)
return linked, exclusive
end
function putils.canLink (properties, si_target)
function lutils.canLink (properties, si_target)
local target_props = si_target.properties
-- nodes must have the same media type
@ -210,7 +210,7 @@ function putils.canLink (properties, si_target)
return true
end
function putils.findDefaultLinkable (si)
function lutils.findDefaultLinkable (si)
local si_props = si.properties
local target_direction = cutils.getTargetDirection (si_props)
local def_node_id = cutils.getDefaultNode (si_props, target_direction)
@ -221,12 +221,12 @@ function putils.findDefaultLinkable (si)
}
end
function putils.checkPassthroughCompatibility (si, si_target)
function lutils.checkPassthroughCompatibility (si, si_target)
local si_must_passthrough =
cutils.parseBool (si.properties ["item.node.encoded-only"])
local si_target_must_passthrough =
cutils.parseBool (si_target.properties ["item.node.encoded-only"])
local can_passthrough = putils.canPassthrough (si, si_target)
local can_passthrough = lutils.canPassthrough (si, si_target)
if (si_must_passthrough or si_target_must_passthrough)
and not can_passthrough then
return false, can_passthrough
@ -236,7 +236,7 @@ end
-- Does the target device have any active/available paths/routes to
-- the physical device(spkr/mic/cam)?
function putils.haveAvailableRoutes (si_props)
function lutils.haveAvailableRoutes (si_props)
local card_profile_device = si_props ["card.profile.device"]
local device_id = si_props ["device.id"]
local device = device_id and cutils.get_object_manager ("device"):lookup {
@ -300,7 +300,7 @@ function putils.haveAvailableRoutes (si_props)
return false
end
function putils.sendClientError (event, node, message)
function lutils.sendClientError (event, node, message)
local source = event:get_source ()
local client_id = node.properties ["client.id"]
if client_id then
@ -314,4 +314,4 @@ function putils.sendClientError (event, node, message)
end
end
return putils
return lutils

View file

@ -10,7 +10,7 @@
--
-- FIXME: this script can be further improved
putils = require ("linking-utils")
lutils = require ("linking-utils")
settings = require ("settings-linking")
log = Log.open_topic ("s-linking")
@ -96,7 +96,7 @@ SimpleEventHook {
if settings.filter_forward_format then
local si_props = si.properties
local link_group = si_props ["node.link-group"]
local si_flags = putils:get_flags (si.id)
local si_flags = lutils:get_flags (si.id)
-- only listen for ports state changed on audio filter streams
if si_flags.ports_state_signal ~= true and

View file

@ -6,7 +6,7 @@
--
-- Traverse through all the possible targets to pick up target node.
putils = require ("linking-utils")
lutils = require ("linking-utils")
cutils = require ("common-utils")
log = Log.open_topic ("s-linking")
@ -20,7 +20,7 @@ SimpleEventHook {
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
-- bypass the hook if the target is already picked up
if target then
@ -57,18 +57,18 @@ SimpleEventHook {
goto skip_linkable
end
if not putils.canLink (si_props, target) then
if not lutils.canLink (si_props, target) then
log:debug ("... cannot link, skip linkable")
goto skip_linkable
end
if not putils.haveAvailableRoutes (target_props) then
if not lutils.haveAvailableRoutes (target_props) then
log:debug ("... does not have routes, skip linkable")
goto skip_linkable
end
local passthrough_compatible, can_passthrough =
putils.checkPassthroughCompatibility (si, target)
lutils.checkPassthroughCompatibility (si, target)
if not passthrough_compatible then
log:debug ("... passthrough is not compatible, skip linkable")
goto skip_linkable

View file

@ -6,7 +6,7 @@
--
-- Check if default nodes can be picked up as target node.
putils = require ("linking-utils")
lutils = require ("linking-utils")
log = Log.open_topic ("s-linking")
SimpleEventHook {
@ -19,7 +19,7 @@ SimpleEventHook {
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
-- bypass the hook if the target is already picked up
if target then
@ -31,13 +31,13 @@ SimpleEventHook {
log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
target = putils.findDefaultLinkable (si)
target = lutils.findDefaultLinkable (si)
local can_passthrough, passthrough_compatible
if target then
passthrough_compatible, can_passthrough =
putils.checkPassthroughCompatibility (si, target)
if putils.canLink (si_props, target) and passthrough_compatible then
lutils.checkPassthroughCompatibility (si, target)
if lutils.canLink (si_props, target) and passthrough_compatible then
target_picked = true;
end
end

View file

@ -9,7 +9,7 @@
-- 1. "node.target"/"target.object" in the node properties
-- 2. "target.node"/"target.object" in the default metadata
putils = require ("linking-utils")
lutils = require ("linking-utils")
cutils = require ("common-utils")
settings = require ("settings-linking")
log = Log.open_topic ("s-linking")
@ -24,7 +24,7 @@ SimpleEventHook {
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
-- bypass the hook if the target is already picked up
if target then
@ -76,7 +76,7 @@ SimpleEventHook {
type = "SiLinkable",
Constraint { target_key, "=", target_value },
}
if target and putils.canLink (si_props, target) then
if target and lutils.canLink (si_props, target) then
target_picked = true
end
elseif target_value then
@ -85,7 +85,7 @@ SimpleEventHook {
if (target_props ["node.name"] == target_value or
target_props ["object.path"] == target_value) and
target_props ["item.node.direction"] == cutils.getTargetDirection (si_props) and
putils.canLink (si_props, lnkbl) then
lutils.canLink (si_props, lnkbl) then
target_picked = true
target = lnkbl
break
@ -96,7 +96,7 @@ SimpleEventHook {
local can_passthrough, passthrough_compatible
if target then
passthrough_compatible, can_passthrough =
putils.checkPassthroughCompatibility (si, target)
lutils.checkPassthroughCompatibility (si, target)
if not passthrough_compatible then
target = nil
end
@ -116,7 +116,7 @@ SimpleEventHook {
local linger = cutils.parseBool (si_props ["target.linger"])
if not linger then
local node = si:get_associated_proxy ("node")
putils.sendClientError (event, node, "defined target not found")
lutils.sendClientError (event, node, "defined target not found")
node:request_destroy ()
log:info(si, "... destroyed node as defined target was not found")
else

View file

@ -6,7 +6,7 @@
--
-- Check if the target node is a filter target.
putils = require ("linking-utils")
lutils = require ("linking-utils")
cutils = require ("common-utils")
futils = require ("filter-utils")
log = Log.open_topic ("s-linking")
@ -41,7 +41,7 @@ SimpleEventHook {
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
-- bypass the hook if the target is already picked up
if target then
@ -61,8 +61,8 @@ SimpleEventHook {
local can_passthrough, passthrough_compatible
if target then
passthrough_compatible, can_passthrough =
putils.checkPassthroughCompatibility (si, target)
if putils.canLink (si_props, target) and passthrough_compatible then
lutils.checkPassthroughCompatibility (si, target)
if lutils.canLink (si_props, target) and passthrough_compatible then
target_picked = true
end
end
@ -80,7 +80,7 @@ SimpleEventHook {
local linger = cutils.parseBool (si_props ["target.linger"])
if not linger then
local node = si:get_associated_proxy ("node")
putils.sendClientError (event, node, "smart filter defined target not found")
lutils.sendClientError (event, node, "smart filter defined target not found")
node:request_destroy ()
log:info(si, "... destroyed node as smart filter defined target was not found")
else

View file

@ -6,7 +6,7 @@
--
-- example of a user injectible hook to link a node to a custom target
putils = require ("linking-utils")
lutils = require ("linking-utils")
log = Log.open_topic ("s-linking")
SimpleEventHook {
@ -19,7 +19,7 @@ SimpleEventHook {
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
-- bypass the hook if the target is already picked up
if target then

View file

@ -6,7 +6,7 @@
--
-- Select the virtual target based on roles
putils = require ("linking-utils")
lutils = require ("linking-utils")
log = Log.open_topic ("s-linking")
defaults = {}
@ -56,7 +56,7 @@ SimpleEventHook {
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
local target_class_assoc = {
["Stream/Input/Audio"] = "Audio/Source",
["Stream/Output/Audio"] = "Audio/Sink",
@ -109,7 +109,7 @@ SimpleEventHook {
local can_passthrough, passthrough_compatible
if target then
passthrough_compatible, can_passthrough =
putils.checkPassthroughCompatibility (si, target)
lutils.checkPassthroughCompatibility (si, target)
if not passthrough_compatible then
target = nil

View file

@ -6,7 +6,7 @@
--
-- Check if the target node is a filter target.
putils = require ("linking-utils")
lutils = require ("linking-utils")
cutils = require ("common-utils")
futils = require ("filter-utils")
log = Log.open_topic ("s-linking")
@ -21,7 +21,7 @@ SimpleEventHook {
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
-- bypass the hook if the target was not found
if target == nil then
@ -45,8 +45,8 @@ SimpleEventHook {
local can_passthrough, passthrough_compatible
if target ~= nil then
passthrough_compatible, can_passthrough =
putils.checkPassthroughCompatibility (si, target)
if putils.canLink (si_props, target) and passthrough_compatible then
lutils.checkPassthroughCompatibility (si, target)
if lutils.canLink (si_props, target) and passthrough_compatible then
target_picked = true;
end
end

View file

@ -7,7 +7,7 @@
-- Links a session item to the target that has been previously selected.
-- This is meant to be the last hook in the select-target chain.
putils = require ("linking-utils")
lutils = require ("linking-utils")
cutils = require ("common-utils")
log = Log.open_topic ("s-linking")
@ -24,7 +24,7 @@ AsyncEventHook {
next = "none",
execute = function (event, transition)
local source, om, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
if not target then
-- bypass the hook, nothing to link to.

View file

@ -8,7 +8,7 @@
-- indicate it is not available for linking. If no target is available, send
-- down an error to the corresponding client.
putils = require ("linking-utils")
lutils = require ("linking-utils")
cutils = require ("common-utils")
settings = require ("settings-linking")
log = Log.open_topic ("s-linking")
@ -23,7 +23,7 @@ SimpleEventHook {
},
execute = function (event)
local source, _, si, si_props, si_flags, target =
putils:unwrap_select_target_event (event)
lutils:unwrap_select_target_event (event)
local si_id = si.id
local reconnect = not cutils.parseBool (si_props ["node.dont-reconnect"])
@ -40,14 +40,14 @@ SimpleEventHook {
-- Check this also here, in case in default targets changed
if settings.follow_default_target and si_flags.has_node_defined_target then
putils.checkFollowDefault (si, target)
lutils.checkFollowDefault (si, target)
end
target = nil
goto done
end
local link = putils.lookupLink (si_id, si_flags.peer_id)
local link = lutils.lookupLink (si_id, si_flags.peer_id)
if reconnect then
if link ~= nil then
-- remove old link
@ -78,7 +78,7 @@ SimpleEventHook {
-- check target's availability
if target then
local target_is_linked, target_is_exclusive = putils.isLinked (target)
local target_is_linked, target_is_exclusive = lutils.isLinked (target)
if target_is_exclusive then
log:info (si, "... target is linked exclusively")
target = nil
@ -104,7 +104,7 @@ SimpleEventHook {
return
end
putils.sendClientError (event, node,
lutils.sendClientError (event, node,
reconnect and "no target node available" or "target not found")
if not reconnect then

View file

@ -5,7 +5,7 @@
--
-- SPDX-License-Identifier: MIT
putils = require ("linking-utils")
lutils = require ("linking-utils")
log = Log.open_topic ("s-linking")
defaults = {}
@ -172,7 +172,7 @@ AsyncEventHook {
local function onVirtualLinkActivated (l, e)
local si_id = tonumber (l.properties ["main.item.id"])
local target_id = tonumber (l.properties ["target.item.id"])
local si_flags = putils:get_flags (si_id)
local si_flags = lutils:get_flags (si_id)
if e then
log:warning (l, "failed to activate virtual si-standard-link: " .. e)

View file

@ -10,7 +10,7 @@
-- Cleanup links when the linkables they are associated with are removed.
-- Also, cleanup flags attached to linkables.
putils = require ("linking-utils")
lutils = require ("linking-utils")
cutils = require ("common-utils")
futils = require ("filter-utils")
settings = require ("settings-linking")
@ -80,8 +80,8 @@ function unhandleLinkable (si, om)
local in_id = tonumber (silink.properties ["in.item.id"])
if out_id == si_id or in_id == si_id then
local in_flags = putils:get_flags (in_id)
local out_flags = putils:get_flags (out_id)
local in_flags = lutils:get_flags (in_id)
local out_flags = lutils:get_flags (out_id)
if out_id == si_id and in_flags.peer_id == out_id then
in_flags.peer_id = nil
@ -94,7 +94,7 @@ function unhandleLinkable (si, om)
end
end
putils:clear_flags (si_id)
lutils:clear_flags (si_id)
end
SimpleEventHook {