mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-09 05:08:04 +02:00
state-profile: Use state metadata to store saved profiles
This allows users to clear the stored profile for any device at runtime using the pw-metadata tool.
This commit is contained in:
parent
ac38b8fa33
commit
e51e4e574d
1 changed files with 35 additions and 12 deletions
|
|
@ -14,9 +14,8 @@
|
||||||
cutils = require ("common-utils")
|
cutils = require ("common-utils")
|
||||||
log = Log.open_topic ("s-device")
|
log = Log.open_topic ("s-device")
|
||||||
|
|
||||||
-- the state storage
|
-- the state meta storage
|
||||||
state = nil
|
state_meta = nil
|
||||||
state_table = nil
|
|
||||||
|
|
||||||
find_stored_profile_hook = SimpleEventHook {
|
find_stored_profile_hook = SimpleEventHook {
|
||||||
name = "device/find-stored-profile",
|
name = "device/find-stored-profile",
|
||||||
|
|
@ -43,7 +42,7 @@ find_stored_profile_hook = SimpleEventHook {
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local profile_name = state_table[dev_name]
|
local profile_name = state_meta:get (dev_name)
|
||||||
|
|
||||||
if profile_name then
|
if profile_name then
|
||||||
for p in device:iterate_params ("EnumProfile") do
|
for p in device:iterate_params ("EnumProfile") do
|
||||||
|
|
@ -100,7 +99,7 @@ function updateStoredProfile (device, profile)
|
||||||
profile.name, profile.index, dev_name))
|
profile.name, profile.index, dev_name))
|
||||||
|
|
||||||
-- check if the new profile is the same as the current one
|
-- check if the new profile is the same as the current one
|
||||||
if state_table[dev_name] == profile.name then
|
if state_meta:get (dev_name) == profile.name then
|
||||||
log:debug (device, " ... profile is already stored")
|
log:debug (device, " ... profile is already stored")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -121,25 +120,49 @@ function updateStoredProfile (device, profile)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
state_table[dev_name] = profile.name
|
reevaluate_on_state_changed_hook:remove ()
|
||||||
state:save_after_timeout (state_table)
|
state_meta:set (dev_name, profile.name)
|
||||||
|
reevaluate_on_state_changed_hook:register ()
|
||||||
|
|
||||||
log:info (device, string.format (
|
log:info (device, string.format (
|
||||||
"stored profile '%s' (%d) for device '%s'",
|
"stored profile '%s' (%d) for device '%s'",
|
||||||
profile.name, index, dev_name))
|
profile.name, index, dev_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
reevaluate_on_state_changed_hook = SimpleEventHook {
|
||||||
|
name = "device/reevaluate-on-state-changed",
|
||||||
|
interests = {
|
||||||
|
EventInterest {
|
||||||
|
Constraint { "event.type", "=", "metadata-changed" },
|
||||||
|
Constraint { "metadata.name", "=", "default-profile" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
execute = function (event)
|
||||||
|
local source = event:get_source ()
|
||||||
|
local device_om = source:call ("get-object-manager", "device")
|
||||||
|
for device in device_om:iterate () do
|
||||||
|
source:call ("push-event", "select-profile", device, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
function toggleState (enable)
|
function toggleState (enable)
|
||||||
if enable and not state then
|
if enable and not state_meta then
|
||||||
state = State ("default-profile")
|
state_meta = StateMetadata ("default-profile")
|
||||||
state_table = state:load ()
|
state_meta:activate (Features.ALL, function (_, e)
|
||||||
|
if e then
|
||||||
|
log:warning ("failed to activate state metadata: " .. e)
|
||||||
|
end
|
||||||
|
end)
|
||||||
find_stored_profile_hook:register ()
|
find_stored_profile_hook:register ()
|
||||||
store_user_selected_profile_hook:register ()
|
store_user_selected_profile_hook:register ()
|
||||||
|
reevaluate_on_state_changed_hook:register ()
|
||||||
elseif not enable and state then
|
elseif not enable and state then
|
||||||
state = nil
|
state_meta:deactivate (Features.ALL)
|
||||||
state_table = nil
|
state_meta = nil
|
||||||
find_stored_profile_hook:remove ()
|
find_stored_profile_hook:remove ()
|
||||||
store_user_selected_profile_hook:remove ()
|
store_user_selected_profile_hook:remove ()
|
||||||
|
reevaluate_on_state_changed_hook:remove ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue