27 Commits

Author SHA1 Message Date
George Kiagiadakis
4a3557d8e4 event: add some trace logs to debug sorting hook dependencies 2024-01-08 12:28:21 +02:00
Julian Bouzas
4ac7dc831e event-dispatcher: fix ingroup documentation 2024-01-05 09:34:35 -05:00
Duncan Overbruck
bebee99fc8 event-dispatcher: sort same priority events by the order they have been received 2023-09-03 17:30:03 +03:00
Ashok Sidipotu
27c1ea869b event*.c: add a few more log msgs 2023-08-15 07:14:59 +00:00
George Kiagiadakis
8a8cd97ca8 core: make the object registration functions public
This allows registering arbitrary objects on the core's registry and
finding them later, without having to add API for each and every object.

I think this is useful enough to have it public, even though it's
probably not going to be used that much... The rationale here is to
allow registering custom component loaders without having to make them
subclass WpPlugin or to create custom API for registering component
loaders specifically.

Also, remove the wp_plugin_register() and wp_si_factory_register()
functions, since they are not going to be used much in the future.
The idea is to let the component loader do the registration under the
scenes, as the component is getting loaded.
2023-06-20 12:39:29 +03:00
George Kiagiadakis
4f27d18bd3 log: rename "message" level to "notice" and print criticals with "E"
Syslog calls this level "notice" and I prefer it because we use it
to display significant messages that are not warnings, but they
are not really "standard", as GLib wants them to be. There is nothing
"standard" about log messages in general.

Also, make these notice messages be enabled at debug level 2, together
with warnings. The default log.level is 2 and it is a good idea to show
notices by default too.

Finally, show them in the log with "N" and also change criticals to be
shown with "E", meaning "error"... Then promote G_LOG_LEVEL_ERROR
messages to be shown with "F", meaning "fatal", because in fact these
messages are always fatal and always call abort(). Still, keep the term
"critical" in the functions to make sure that whoever uses them is aware
that this level is only for critical conditions and not suitable to
display any kind of error.
2023-05-18 16:19:49 +03:00
George Kiagiadakis
4736d56557 log: implement a log topics system, like pipewire
The intention is to make checks for enabled log topics faster.

Every topic has its own structure that is statically defined in the file
where the logs are printed from. The structure is initialized transparently
when it is first used and it contains all the log level flags for the levels
that this topic should print messages. It is then checked on the wp_log()
macro before printing the message.

Topics from SPA/PipeWire are also handled natively, so messages are printed
directly without checking if the topic is enabled, since the PipeWire and SPA
macros do the checking themselves.

Messages coming from GLib are checked inside the handler.

An internal WpLogFields object is used to manage the state of each log
message, populating all the fields appropriately from the place they
are coming from (wp_log, spa_log, glib log), formatting the message and
then printing it. For printing to the journald, we still use the glib
message handler, converting all the needed fields to GLogField on demand.
That message handler does not do any checks for the topic or the level, so
we can just call it to send the message.
2023-05-16 20:42:28 +03:00
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
George Kiagiadakis
5a435fae11 event-dispatcher: expose iterator to iterate over the registered hooks 2023-04-17 07:48:18 -04:00
George Kiagiadakis
b100bdda4a event-hook: remove the exec type property & enumeration
With the latest changes, we can implement the "after-events" type
with external code that pushes a very low priority event that is
the "rescan" event.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
6c3bd9e27d event: add datalist to store arbitrary data on the event 2023-04-17 07:48:18 -04:00
George Kiagiadakis
497f30453d lib: event-hook/dispatcher: constness and staticness fixes 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
119b99dc23 event-dispatcher: Add a trace log msg to indicate the events created 2023-04-17 07:48:18 -04:00
Ashok Sidipotu
68eaede3e4 event-dispatcher: Group after-events-with-event hooks of a session item
after-events-with-event hooks are rendered based on the priority, this means
when a rescan event happens, all the findDefinedTarget hooks(of different
session items) are run first and then all the findDefinedTarget hooks, so on.

This kind of scheduling of hooks was removing the established link between zoom
voice engine and digial mic. Also It is slightly difficult to follow the flow in
the logs.

Instead of arranging the hooks flately based on priority, better scheme to
prioritize them in two layers. First all the hooks for an event or session items
are grouped and with in that group, priority of the hook is honored.

src/scripts/policy-hooks.lua #	modified:   src/scripts/policy-node.lua #
2023-04-17 07:48:18 -04:00
Ashok Sidipotu
a060c6a130 m-default-nodes{-api}: optimize for event-stack
- Sharpen the hooks, so that they are called only when needed.
- Make settings live, apply them when they are changed.
- Remove the state saver after events hook, call it directly.
- Remove the settings bookkeeping as the gobject properties.
- Remove the scheduling of default-nodes-changed signal via core.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
3b211d9082 event-dispatcher: Introduce after-events-with-event hook type
after-events hooks are instantiated with rescan event, not with the event which
actually triggered it. after-events-with-event fills this gap.

policy-node clean needed this kind of hooks.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
33ee9984ed Revert "event-dispatcher: after-events hooks to get the trigger event info"
This reverts commit f97e60a331e72e1c1b79075a9498517628e2a349.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
3ff9f240c8 event-dispatcher: after-events hooks to get the trigger event info
after-events hooks will get the original event triggering it, instead of the
rescan event.

after-events hook can register with any event, but it is called with rescan event
info. This is so because, after-events hook run after all the on-events hooks
are done with and as a part of the rescan event. so it is triggered with rescan
event data, which doesnt carry much info, instead of rescan event, it makes more
sense to call the after-events hook with the original event which triggered it.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
da2ac1b7a1 lib: event-dispatcher: Dont push empty events
Empty events are the events without any hooks, refine log msgs further.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
6bdc6fb697 event-dispatcher: Donot cancel the object-removed event
The event is not reaching the object-removal hooks due to this.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
6e31b47c28 event-dispatcher: Add an enumeration of default event hook priorities
This scheme provides for an orderly execution of hooks as the priorities
are controlled from one single place. Enumeration is defined in such a
way that new items can be added easily.

All the event hooks are changed to get the priorities from this
enumeration.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
ff833b138d event-dispatcher: log event and hook names and chains
- Add a new variable "name" in WpEventHook and use it to log all the
  hooks(by name) picked up in _push_event(). This gives a clear picture
  if hook is registered for a given event.
- Form a name for an event and a chain of events for an event run, log
  both of them. This gives a clear picture of the events executed and
  order in which they are dispatched.
- Similarly build hooks chain and print it in _source_dispatch(), this
  gives a clear picture of the hooks picked and the order in which they
  are dispatched.
- Log only the dispatchable(with hooks) events, this de-clutters
  the log messages.
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
d61be3c397 doc: event-dispatcher: Update the annotations 2023-04-17 07:47:09 -04:00
Ashok Sidipotu
869a1068a4 event-dispatcher: Merge global properties
Global properties are needed for event stack to deal with global
objects.

Refine debug messages
2023-04-17 07:47:09 -04:00
Ashok Sidipotu
655e052f59 lib: Refine trace messages 2023-04-17 07:47:09 -04:00
George Kiagiadakis
01a56496e2 event-dispatcher: use an eventfd to make the source ready
- the source shouldn't become ready if there is nothing to do,
  otherwise idle sources do not run (since they have lower priority)
- when the source becomes ready, we need a fd to wake up GLib's event
  dispatching mechanism to continue processing, otherwise nothing happens
2023-04-17 07:47:09 -04:00
George Kiagiadakis
9afd588d79 lib: initial version of WpEventDispatcher / WpEvent / WpEventHook 2023-04-17 07:47:09 -04:00