This is still WIP, but I'm pushing it here early so that you can follow progress.
The key points that these changes bring are:
- Work towards reducing the amount of object managers that we use. For the policy, we should only ever use 1 object manager, the one that lives inside the standard-event-source. With a property to get access to it, we can use this object manager to iterate over objects (nodes, devices, session items, etc...), eliminating the need for dedicated object managers in every script.
- Pass the standard-event-source as the "source" object of all events and use this to expose additional functionality to hooks:
- The "object-manager" property
- An action signal "push-event", to wrap the EventDispatcher function, so that event priorities are only ever set in standard-event-source
- An action signal "schedule-rescan" to push the rescan event (see below)
- Additional functionality could be provided in the future
- Work towards removing the "after-events" and "after-events-with-event" hook types. Instead, use the "schedule-rescan" action from the event source to push a "rescan-session" event. This event has a very low priority and will normally be handled after everything else. Then, if one of its hooks needs to push more events (policy normally pushes the "find-target-si-and-link" event), then these events shall have the highest priority, so that they are executed immediately without interruptions.
Rewrite the hook priorities to make some sense... It is important that: 1. When we look at a few hooks in the codebase, we should be able to immediately understand which hook runs first and which runs second. With the previous hook priorities enumeration, this was not possible. We instead had to look at the event-hook.h header and try to parse the huge list of priorities with bare eyes... 2. Users should be able to use custom hook priorities to inject custom hooks in-between others. It is now possible to write ex
priority = HookPriority.NORMAL + 10. Previously it wasn't possible (
priority = "find-best-target-si" + 10???!)
- Drop hook priorities in favor of a before/after dependencies model, just like it works on systemd units.
- Add support for attaching arbitrary data on events. I want to use this to set the
si_targetvariable in the policy hooks without having to use the
si_flagsfor that. For 2 reasons:
- flags are meant to be booleans, not objects
- someone needs to clear
si_target, because it keeps a reference to the session item GObject and that is no good. By attaching it to the event, it will automatically be unref'ed when the event is done.
- move each of the hooks from policy-hooks.lua into its own file, with clear and documented code
- remove all unnecessary object managers
- use the rescan-session event and drop the "after-events..." types