| 1 |
-- WirePlumber |
| 2 |
-- |
| 3 |
-- Copyright © 2022 Collabora Ltd. |
| 4 |
-- |
| 5 |
-- SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
-- apply the selected profile to the device |
| 8 |
|
| 9 |
cutils = require ("common-utils") |
| 10 |
log = Log.open_topic ("s-device") |
| 11 |
|
| 12 |
AsyncEventHook { |
| 13 |
name = "device/apply-profile", |
| 14 |
after = { "device/find-calling-profile", "device/find-stored-profile", "device/find-preferred-profile", "device/find-best-profile" }, |
| 15 |
interests = { |
| 16 |
EventInterest { |
| 17 |
Constraint { "event.type", "=", "select-profile" }, |
| 18 |
}, |
| 19 |
}, |
| 20 |
steps = { |
| 21 |
start = { |
| 22 |
next = "none", |
| 23 |
execute = function (event, transition) |
| 24 |
local device = event:get_subject () |
| 25 |
local profile = event:get_data ("selected-profile") |
| 26 |
local dev_name = device.properties ["device.name"] or "" |
| 27 |
|
| 28 |
if not profile then |
| 29 |
log:info (device, "No profile found to set on " .. dev_name) |
| 30 |
transition:advance () |
| 31 |
return |
| 32 |
end |
| 33 |
|
| 34 |
for p in device:iterate_params ("Profile") do |
| 35 |
local active_profile = cutils.parseParam (p, "Profile") |
| 36 |
if active_profile.index == tonumber(profile.index) then |
| 37 |
log:info (device, "Profile " .. profile.name .. " is already set on " .. dev_name) |
| 38 |
transition:advance () |
| 39 |
return |
| 40 |
end |
| 41 |
end |
| 42 |
|
| 43 |
local param = Pod.Object { |
| 44 |
"Spa:Pod:Object:Param:Profile", "Profile", |
| 45 |
index = tonumber(profile.index), |
| 46 |
} |
| 47 |
log:info (device, "Setting profile " .. profile.name .. " on " .. dev_name) |
| 48 |
device:set_param ("Profile", param) |
| 49 |
|
| 50 |
-- FIXME: add cancellability |
| 51 |
-- sync on the pipewire connection to ensure that the param |
| 52 |
-- has been configured on the remote device object |
| 53 |
Core.sync (function () |
| 54 |
transition:advance () |
| 55 |
end) |
| 56 |
end |
| 57 |
}, |
| 58 |
} |
| 59 |
}:register() |