From 68eaede3e4fd3d6de981af2d4f123483006c43fe Mon Sep 17 00:00:00 2001 From: Ashok Sidipotu Date: Fri, 16 Sep 2022 10:40:53 +0530 Subject: [PATCH] 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 # --- lib/wp/event-dispatcher.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/wp/event-dispatcher.c b/lib/wp/event-dispatcher.c index 8fb2b9f0..fccc7e2b 100644 --- a/lib/wp/event-dispatcher.c +++ b/lib/wp/event-dispatcher.c @@ -471,12 +471,23 @@ event_cmp_func (const WpEvent *a, const WpEvent *b) } static gint -hook_cmp_func (const WpEventHookData *a, const WpEventHookData *b) +hook_cmp_func (const WpEventHookData *new_hook, const WpEventHookData *listed_hook) { - return wp_event_hook_get_priority ((WpEventHook *) b->hook) - - wp_event_hook_get_priority ((WpEventHook *) a->hook); + return wp_event_hook_get_priority ((WpEventHook *) listed_hook->hook) - + wp_event_hook_get_priority ((WpEventHook *) new_hook->hook); } +static gint +after_events_hook_cmp_func (const WpEventHookData *new_hook, + const WpEventHookData *listed_hook) +{ + if (new_hook->event != listed_hook->event) + return G_MININT; + else + return hook_cmp_func (new_hook, listed_hook); +} + + static gint is_hook_present (const WpEventHookData *hook_data, const WpEventHook *hook) { @@ -527,7 +538,8 @@ wp_event_dispatcher_push_event (WpEventDispatcher * self, WpEvent * event) hook_data->event = wp_event_ref (event); self->rescan_event->hooks = g_list_insert_sorted ( - self->rescan_event->hooks, hook_data, (GCompareFunc) hook_cmp_func); + self->rescan_event->hooks, hook_data, + (GCompareFunc) after_events_hook_cmp_func); rescan_hooks_added = true; wp_debug_object (self, "added after-events-with-event rescan hook"