Files
wireplumber/tests/wplua/scripts/event-hooks.lua
George Kiagiadakis 3a23fb451a event-dispatcher: refactor to use before/after dependencies on hooks
* Remove entirely the hook priority numbers and use before/after dependencies
* Split the WpEvent code out of WpEventDispatcher
* Add methods on WpEvent to interface with it from the WpEventDispatcher.
  As a bonus, we can now also implement tooling to inspect which hooks would
  in theory run for an event and write tests around that
* Removed some internal debugging facilities and log calls, will redo it later.
* Using spa_list now for the list of hooks, to reduce the number of allocations
  happening in the "hook collection" algorithm
* Switched some internal data to use g_new0 instead of g_slice_new0
* Added g_free to free WpEvent structures... surprisingly, we were leaking them
  before
2023-04-17 07:48:18 -04:00

88 lines
1.9 KiB
Lua

Script.async_activation = true
local tags = {}
local function checkpoint(tag)
Log.info("at " .. tag)
table.insert(tags, tag)
end
local function check_results()
local i = 0
local function inc()
i = i+1
return i
end
assert(tags[inc()] == "simple-first")
assert(tags[inc()] == "simple-1")
assert(tags[inc()] == "async-start")
assert(tags[inc()] == "async-start-advance")
assert(tags[inc()] == "async-step2")
assert(tags[inc()] == "simple-last")
end
local common_interests = {
EventInterest {
Constraint { "event.type", "=", "test-event" },
},
}
AsyncEventHook {
name = "test-async-hook",
before = "test-last-hook" ,
after = { "test-first-hook", "test-simple-hook" },
interests = common_interests,
steps = {
start = {
next = "step2",
execute = function (event, transition)
checkpoint("async-start")
Core.idle_add(function ()
checkpoint("async-start-advance")
transition:advance()
return false
end)
end,
},
step2 = {
next = "none",
execute = function (event, transition)
checkpoint("async-step2")
transition:advance()
end,
},
},
}:register()
SimpleEventHook {
name = "test-first-hook",
before = { "test-simple-hook", "test-last-hook" },
interests = common_interests,
execute = function (event)
checkpoint("simple-first")
end
}:register()
SimpleEventHook {
name = "test-simple-hook",
after = { "test-first-hook" },
before = {},
interests = common_interests,
execute = function (event)
checkpoint("simple-1")
end
}:register()
SimpleEventHook {
name = "test-last-hook",
interests = common_interests,
execute = function (event)
checkpoint("simple-last")
check_results()
Script:finish_activation()
end
}:register()
EventDispatcher.push_event { type = "test-event", priority = 1 }