From b100bdda4a00c39fa2143a191c38d7ca25cf16a3 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Thu, 24 Nov 2022 17:39:21 +0200 Subject: [PATCH] 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. --- lib/wp/event-dispatcher.c | 96 ++----------------- lib/wp/event-hook.c | 38 +------- lib/wp/event-hook.h | 14 +-- modules/module-default-nodes-api.c | 4 +- modules/module-default-nodes.c | 6 +- modules/module-default-profile.c | 4 +- modules/module-lua-scripting/api/api.c | 20 +--- modules/module-standard-event-source.c | 3 +- src/scripts/create-item.lua | 2 - src/scripts/node/suspend-node.lua | 1 - src/scripts/policy-bluetooth.lua | 4 - .../policy-desktop/filter-forward-format.lua | 1 - .../policy-desktop/find-best-target.lua | 1 - .../policy-desktop/find-default-target.lua | 1 - .../policy-desktop/find-defined-target.lua | 1 - .../find-user-target.lua.example | 1 - src/scripts/policy-desktop/link-target.lua | 1 - src/scripts/policy-desktop/move-follow.lua | 2 - src/scripts/policy-desktop/prepare-link.lua | 1 - src/scripts/policy-desktop/rescan.lua | 3 - src/scripts/policy-device-profile.lua | 2 - src/scripts/policy-device-routes.lua | 2 - src/scripts/restore-stream.lua | 4 - tests/wp/events.c | 72 +++++--------- tests/wplua/scripts/event-hooks.lua | 7 +- 25 files changed, 49 insertions(+), 242 deletions(-) diff --git a/lib/wp/event-dispatcher.c b/lib/wp/event-dispatcher.c index 708b09a6..438bcef5 100644 --- a/lib/wp/event-dispatcher.c +++ b/lib/wp/event-dispatcher.c @@ -284,7 +284,6 @@ struct _WpEventDispatcher GSource *source; /* the event loop source */ GList *events; /* the events stack */ gchar *events_chain; /* chain of events for an event run */ - WpEvent *rescan_event; struct spa_system *system; int eventfd; }; @@ -375,7 +374,6 @@ wp_event_source_dispatch (GSource * s, GSourceFunc callback, gpointer user_data) WpEventHook *hook = hook_data->hook; const gchar *name = wp_event_hook_get_name (hook); gint priority = wp_event_hook_get_priority (hook); - WpEventHookExecType type = wp_event_hook_get_exec_type (hook); event->current_hook_in_async = hook_data; event->hooks = g_list_delete_link (event->hooks, @@ -384,31 +382,14 @@ wp_event_source_dispatch (GSource * s, GSourceFunc callback, gpointer user_data) event->hooks_chain = build_chain (name, priority, event->hooks_chain); wp_trace_object (d, "running hook <%p>(%s)", hook, name); - if ((event == d->rescan_event) && - (type == WP_EVENT_HOOK_EXEC_TYPE_AFTER_EVENTS_WITH_EVENT)) { - WpEvent *hook_event = hook_data->event; - wp_trace_object (d, "after-events-with-event with event %s", hook_event->name); - - if (g_cancellable_is_cancelled (hook_event->cancellable)) { - wp_debug_object (d, "skip running hook(%s) as its trigger event(%s)" - " is cancelled", name, hook_event->name); - event->current_hook_in_async = NULL; - } - else - wp_event_hook_run (hook, hook_event, event->cancellable, - (GAsyncReadyCallback) on_event_hook_done, event); - } - else - /* execute the hook, possibly async */ - wp_event_hook_run (hook, event, event->cancellable, - (GAsyncReadyCallback) on_event_hook_done, event); + /* execute the hook, possibly async */ + wp_event_hook_run (hook, event, event->cancellable, + (GAsyncReadyCallback) on_event_hook_done, event); } /* clear the event after all hooks are done */ if (!event->hooks && !event->current_hook_in_async) { d->events = g_list_delete_link (d->events, g_steal_pointer (&levent)); - if (event == d->rescan_event) - d->rescan_event = NULL; g_clear_pointer (&event, wp_event_unref); } @@ -533,23 +514,6 @@ hook_cmp_func (const WpEventHookData *new_hook, const WpEventHookData *listed_ho 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) -{ - return !(hook == hook_data->hook); -} - /*! * \brief Pushes a new event onto the event stack for dispatching only if there * are any hooks are available for it. @@ -564,10 +528,6 @@ wp_event_dispatcher_push_event (WpEventDispatcher * self, WpEvent * event) g_return_if_fail (WP_IS_EVENT_DISPATCHER (self)); g_return_if_fail (event != NULL); gboolean hooks_added = FALSE; - gboolean rescan_hooks_added = FALSE; - - if (!self->rescan_event) - self->rescan_event = wp_event_new ("rescan", G_MININT16, NULL, NULL, NULL); /* attach hooks that run for this event */ for (guint i = 0; i < self->hooks->len; i++) { @@ -575,65 +535,29 @@ wp_event_dispatcher_push_event (WpEventDispatcher * self, WpEvent * event) if (wp_event_hook_runs_for_event (hook, event)) { WpEventHookData *hook_data = g_slice_new0 (WpEventHookData); - WpEventHookExecType hook_type = wp_event_hook_get_exec_type (hook); const gchar *name = wp_event_hook_get_name (hook); gint priority = wp_event_hook_get_priority (hook); hook_data->hook = g_object_ref (hook); - /* ON_EVENT hooks run at the dispatching of the event */ - if (hook_type == WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT) { - event->hooks = g_list_insert_sorted (event->hooks, hook_data, - (GCompareFunc) hook_cmp_func); - hooks_added = true; + event->hooks = g_list_insert_sorted (event->hooks, hook_data, + (GCompareFunc) hook_cmp_func); + hooks_added = true; - wp_debug_object (self, "added hook <%p>(%s(%d))", hook, name, priority); - } - /* AFTER_EVENTS hooks run after all other events have been dispatched */ - else if (hook_type == WP_EVENT_HOOK_EXEC_TYPE_AFTER_EVENTS_WITH_EVENT) { - /* this event will be sent to hook when it is being dispatched */ - hook_data->event = wp_event_ref (event); - - self->rescan_event->hooks = g_list_insert_sorted ( - 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" - " <%p>(%s(%d)) for event %s", hook, name, priority, event->name); - } - /* for after-events retain only one instance per hook */ - else if (!g_list_find_custom (self->rescan_event->hooks, hook, - (GCompareFunc) is_hook_present)) { - self->rescan_event->hooks = g_list_insert_sorted ( - self->rescan_event->hooks, hook_data, (GCompareFunc) hook_cmp_func); - rescan_hooks_added = true; - - wp_debug_object (self, "added rescan hook <%p>(%s(%d))", hook, name, priority); - } + wp_debug_object (self, "added hook <%p>(%s(%d))", hook, name, priority); } } - if (rescan_hooks_added) { - if (!g_list_find (self->events, self->rescan_event)) - self->events = g_list_insert_sorted (self->events, self->rescan_event, - (GCompareFunc) event_cmp_func); - - wp_debug_object (self, "pushed rescan event %p for event(%s)", - self->rescan_event, event->name); - } - if (hooks_added) { self->events = g_list_insert_sorted (self->events, event, (GCompareFunc) event_cmp_func); wp_debug_object (self, "pushed event (%s)" WP_OBJECT_FORMAT " priority(%d)", event->name, WP_OBJECT_ARGS (event->subject), event->priority); + + /* wakeup the GSource */ + spa_system_eventfd_write (self->system, self->eventfd, 1); } else g_clear_pointer (&event, wp_event_unref); - - if (hooks_added || rescan_hooks_added) - /* wakeup the GSource */ - spa_system_eventfd_write (self->system, self->eventfd, 1); } /*! diff --git a/lib/wp/event-hook.c b/lib/wp/event-hook.c index 43741c8a..e34d3399 100644 --- a/lib/wp/event-hook.c +++ b/lib/wp/event-hook.c @@ -18,7 +18,6 @@ typedef struct _WpEventHookPrivate WpEventHookPrivate; struct _WpEventHookPrivate { gint priority; - WpEventHookExecType exec_type; GWeakRef dispatcher; gchar *name; }; @@ -27,7 +26,6 @@ enum { PROP_0, PROP_NAME, PROP_PRIORITY, - PROP_EXEC_TYPE, PROP_DISPATCHER, }; @@ -66,9 +64,6 @@ wp_event_hook_set_property (GObject * object, guint property_id, case PROP_PRIORITY: priv->priority = g_value_get_int (value); break; - case PROP_EXEC_TYPE: - priv->exec_type = g_value_get_enum (value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -89,9 +84,6 @@ wp_event_hook_get_property (GObject * object, guint property_id, GValue * value, case PROP_PRIORITY: g_value_set_int (value, priv->priority); break; - case PROP_EXEC_TYPE: - g_value_set_enum (value, priv->exec_type); - break; case PROP_DISPATCHER: g_value_take_object (value, wp_event_hook_get_dispatcher (self)); break; @@ -119,11 +111,6 @@ wp_event_hook_class_init (WpEventHookClass * klass) "The priority of the hook", -G_MAXINT, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, PROP_EXEC_TYPE, - g_param_spec_enum ("exec-type", "exec-type", "The exec type of the hook", - WP_TYPE_EVENT_HOOK_EXEC_TYPE, WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, PROP_DISPATCHER, g_param_spec_object ("dispatcher", "dispatcher", "The associated event dispatcher", WP_TYPE_EVENT_DISPATCHER, @@ -160,21 +147,6 @@ wp_event_hook_get_name (WpEventHook * self) return priv->name; } -/*! - * \brief Returns the execution type of the hook - * - * \ingroup wpeventhook - * \param self the event hook - * \return the event hook execution type - */ -WpEventHookExecType -wp_event_hook_get_exec_type (WpEventHook * self) -{ - g_return_val_if_fail (WP_IS_EVENT_HOOK (self), 0); - WpEventHookPrivate *priv = wp_event_hook_get_instance_private (self); - return priv->exec_type; -} - /*! * \brief Returns the associated event dispatcher * @@ -500,22 +472,19 @@ wp_simple_event_hook_class_init (WpSimpleEventHookClass * klass) * * \param name the name of the hook * \param priority the priority of the hook - * \param type the execution type of the hook * \param closure the closure to invoke when the hook is executed; the closure * should accept two parameters: the event dispatcher and the event, returning * nothing * \return a new simple event hook */ WpEventHook * -wp_simple_event_hook_new (const gchar *name, gint priority, - WpEventHookExecType type, GClosure * closure) +wp_simple_event_hook_new (const gchar *name, gint priority, GClosure * closure) { g_return_val_if_fail (closure != NULL, NULL); return g_object_new (WP_TYPE_SIMPLE_EVENT_HOOK, "name", name, "priority", priority, - "exec-type", type, "closure", closure, NULL); } @@ -643,15 +612,13 @@ wp_async_event_hook_class_init (WpAsyncEventHookClass * klass) * * \param name the name of the hook * \param priority the priority of the hook - * \param type the execution type of the hook * \param get_next_step the closure to invoke to get the next step * \param execute_step the closure to invoke to execute the step * \return a new async event hook */ WpEventHook * wp_async_event_hook_new (const gchar *name, gint priority, - WpEventHookExecType type, GClosure * get_next_step, - GClosure * execute_step) + GClosure * get_next_step, GClosure * execute_step) { g_return_val_if_fail (get_next_step != NULL, NULL); g_return_val_if_fail (execute_step != NULL, NULL); @@ -659,7 +626,6 @@ wp_async_event_hook_new (const gchar *name, gint priority, return g_object_new (WP_TYPE_ASYNC_EVENT_HOOK, "name", name, "priority", priority, - "exec-type", type, "get-next-step", get_next_step, "execute-step", execute_step, NULL); diff --git a/lib/wp/event-hook.h b/lib/wp/event-hook.h index 71e41c30..ba0a7ba2 100644 --- a/lib/wp/event-hook.h +++ b/lib/wp/event-hook.h @@ -17,12 +17,6 @@ G_BEGIN_DECLS typedef struct _WpEvent WpEvent; typedef struct _WpEventDispatcher WpEventDispatcher; -typedef enum { - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, - WP_EVENT_HOOK_EXEC_TYPE_AFTER_EVENTS, - WP_EVENT_HOOK_EXEC_TYPE_AFTER_EVENTS_WITH_EVENT, -} WpEventHookExecType; - typedef enum { WP_EVENT_HOOK_PRIORITY_LOWEST = -500, WP_EVENT_HOOK_PRIORITY_ULTRA_LOW = -300, @@ -67,9 +61,6 @@ gint wp_event_hook_get_priority (WpEventHook * self); WP_API const gchar * wp_event_hook_get_name (WpEventHook * self); -WP_API -WpEventHookExecType wp_event_hook_get_exec_type (WpEventHook * self); - WP_PRIVATE_API WpEventDispatcher * wp_event_hook_get_dispatcher (WpEventHook * self); @@ -127,7 +118,7 @@ G_DECLARE_FINAL_TYPE (WpSimpleEventHook, wp_simple_event_hook, WP_API WpEventHook * wp_simple_event_hook_new (const gchar *name, gint priority, - WpEventHookExecType type, GClosure * closure); + GClosure * closure); /*! @@ -141,8 +132,7 @@ G_DECLARE_FINAL_TYPE (WpAsyncEventHook, wp_async_event_hook, WP_API WpEventHook * wp_async_event_hook_new (const gchar *name, gint priority, - WpEventHookExecType type, GClosure * get_next_step, - GClosure * execute_step); + GClosure * get_next_step, GClosure * execute_step); G_END_DECLS diff --git a/modules/module-default-nodes-api.c b/modules/module-default-nodes-api.c index 04f4675e..fba6d002 100644 --- a/modules/module-default-nodes-api.c +++ b/modules/module-default-nodes-api.c @@ -151,7 +151,7 @@ wp_default_nodes_api_enable (WpPlugin * plugin, WpTransition * transition) /* default metadata added */ hook = wp_simple_event_hook_new ("metadata-added@default-nodes-api", - WP_EVENT_HOOK_PRIORITY_NORMAL, WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, + WP_EVENT_HOOK_PRIORITY_NORMAL, g_cclosure_new ((GCallback) on_metadata_added, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "metadata-added", @@ -162,7 +162,7 @@ wp_default_nodes_api_enable (WpPlugin * plugin, WpTransition * transition) /* default metadata changed */ hook = wp_simple_event_hook_new ("metadata-changed@default-nodes-api", - WP_EVENT_HOOK_PRIORITY_NORMAL, WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, + WP_EVENT_HOOK_PRIORITY_NORMAL, g_cclosure_new ((GCallback) on_metadata_changed_hook, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), diff --git a/modules/module-default-nodes.c b/modules/module-default-nodes.c index 0fb55cd8..7d8a2dd0 100644 --- a/modules/module-default-nodes.c +++ b/modules/module-default-nodes.c @@ -592,7 +592,7 @@ wp_default_nodes_enable (WpPlugin * plugin, WpTransition * transition) /* default metadata added */ hook = wp_simple_event_hook_new ("metadata-added@default-nodes", - WP_EVENT_HOOK_PRIORITY_NORMAL, WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, + WP_EVENT_HOOK_PRIORITY_NORMAL, g_cclosure_new ((GCallback) on_metadata_added, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "metadata-added", @@ -603,7 +603,7 @@ wp_default_nodes_enable (WpPlugin * plugin, WpTransition * transition) /* default metadata changed */ hook = wp_simple_event_hook_new ("metadata-changed@default-nodes", - WP_EVENT_HOOK_PRIORITY_NORMAL, WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, + WP_EVENT_HOOK_PRIORITY_NORMAL, g_cclosure_new ((GCallback) on_metadata_changed, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), @@ -632,7 +632,7 @@ wp_default_nodes_enable (WpPlugin * plugin, WpTransition * transition) /* register rescan hook as an after event */ hook = wp_simple_event_hook_new("rescan@default-nodes", - WP_EVENT_HOOK_PRIORITY_NORMAL, WP_EVENT_HOOK_EXEC_TYPE_AFTER_EVENTS, + WP_EVENT_HOOK_PRIORITY_NORMAL, g_cclosure_new ((GCallback) rescan, self, NULL)); /* default.configured.audio.sink changed */ diff --git a/modules/module-default-profile.c b/modules/module-default-profile.c index 9c610245..27cf3fcc 100644 --- a/modules/module-default-profile.c +++ b/modules/module-default-profile.c @@ -269,7 +269,7 @@ wp_default_profile_enable (WpPlugin * plugin, WpTransition * transition) /* device added */ hook = wp_simple_event_hook_new ("device-added@m-default-profile", - WP_EVENT_HOOK_PRIORITY_NORMAL, WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, + WP_EVENT_HOOK_PRIORITY_NORMAL, g_cclosure_new ((GCallback) on_device_added, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "device-added", @@ -279,7 +279,7 @@ wp_default_profile_enable (WpPlugin * plugin, WpTransition * transition) /* device params changed */ hook = wp_simple_event_hook_new ("device-parms-changed@m-default-profile", - WP_EVENT_HOOK_PRIORITY_NORMAL, WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, + WP_EVENT_HOOK_PRIORITY_NORMAL, g_cclosure_new ((GCallback) on_device_params_changed_hook, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "device-params-changed", diff --git a/modules/module-lua-scripting/api/api.c b/modules/module-lua-scripting/api/api.c index 4d094c37..fda8562b 100644 --- a/modules/module-lua-scripting/api/api.c +++ b/modules/module-lua-scripting/api/api.c @@ -1919,7 +1919,6 @@ simple_event_hook_new (lua_State *L) gint priority = 0; gint priority_type = 0; const gchar *name; - WpEventHookExecType type = 0; GClosure *closure = NULL; /* validate arguments */ @@ -1939,13 +1938,6 @@ simple_event_hook_new (lua_State *L) luaL_error (L, "SimpleEventHook: expected 'priority' as number"); lua_pop (L, 1); - lua_pushliteral (L, "type"); - if (lua_gettable (L, 1) == LUA_TSTRING) - type = wplua_lua_to_enum (L, -1, WP_TYPE_EVENT_HOOK_EXEC_TYPE); - else - luaL_error (L, "SimpleEventHook: expected 'type' as string"); - lua_pop (L, 1); - lua_pushliteral (L, "execute"); if (lua_gettable (L, 1) == LUA_TFUNCTION) closure = wplua_function_to_closure (L, -1); @@ -1953,7 +1945,7 @@ simple_event_hook_new (lua_State *L) luaL_error (L, "SimpleEventHook: expected 'execute' as function"); lua_pop (L, 1); - hook = wp_simple_event_hook_new (name, priority, type, closure); + hook = wp_simple_event_hook_new (name, priority, closure); wplua_pushobject (L, hook); lua_pushliteral (L, "interests"); @@ -2101,7 +2093,6 @@ async_event_hook_new (lua_State *L) const gchar *name; gint priority = 0; gint priority_type = 0; - WpEventHookExecType type = 0; GClosure *get_next_step = NULL; GClosure *execute_step = NULL; @@ -2122,12 +2113,6 @@ async_event_hook_new (lua_State *L) luaL_error(L, "AsyncEventHook: expected 'priority' as number"); lua_pop (L, 1); - lua_pushliteral (L, "type"); - if (lua_gettable (L, 1) != LUA_TSTRING) - luaL_error (L, "AsyncEventHook: expected 'type' as string"); - type = wplua_lua_to_enum (L, -1, WP_TYPE_EVENT_HOOK_EXEC_TYPE); - lua_pop (L, 1); - lua_pushliteral (L, "steps"); if (lua_gettable (L, 1) != LUA_TTABLE) luaL_error (L, "AsyncEventHook: expected 'steps' as table"); @@ -2143,8 +2128,7 @@ async_event_hook_new (lua_State *L) execute_step = wplua_function_to_closure (L, -1); lua_pop (L, 1); - hook = wp_async_event_hook_new (name, priority, type, get_next_step, - execute_step); + hook = wp_async_event_hook_new (name, priority, get_next_step, execute_step); wplua_pushobject (L, hook); lua_pushliteral (L, "interests"); diff --git a/modules/module-standard-event-source.c b/modules/module-standard-event-source.c index 6302358f..bb4ef113 100644 --- a/modules/module-standard-event-source.c +++ b/modules/module-standard-event-source.c @@ -322,8 +322,7 @@ wp_standard_event_source_enable (WpPlugin * plugin, WpTransition * transition) /* install hook to restore the rescan_scheduled state after rescanning */ self->rescan_done_hook = wp_simple_event_hook_new ( - "rescan-done@std-event-source", - WP_EVENT_HOOK_PRIORITY_LOWEST, WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, + "rescan-done@std-event-source", WP_EVENT_HOOK_PRIORITY_LOWEST, g_cclosure_new_object ((GCallback) on_rescan_done, G_OBJECT (self))); wp_interest_event_hook_add_interest ( WP_INTEREST_EVENT_HOOK (self->rescan_done_hook), diff --git a/src/scripts/create-item.lua b/src/scripts/create-item.lua index b1ed27ff..91cd5f9e 100644 --- a/src/scripts/create-item.lua +++ b/src/scripts/create-item.lua @@ -67,7 +67,6 @@ end AsyncEventHook { name = "node-added@create-item", - type = "on-event", priority = HookPriority.LOW, interests = { EventInterest { @@ -139,7 +138,6 @@ AsyncEventHook { SimpleEventHook { name = "node-removed@create-item", - type = "on-event", priority = HookPriority.LOW, interests = { EventInterest { diff --git a/src/scripts/node/suspend-node.lua b/src/scripts/node/suspend-node.lua index 303972b4..56c9149f 100644 --- a/src/scripts/node/suspend-node.lua +++ b/src/scripts/node/suspend-node.lua @@ -9,7 +9,6 @@ sources = {} SimpleEventHook { name = "suspend-node", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { diff --git a/src/scripts/policy-bluetooth.lua b/src/scripts/policy-bluetooth.lua index b70c5f88..63a27ffd 100644 --- a/src/scripts/policy-bluetooth.lua +++ b/src/scripts/policy-bluetooth.lua @@ -387,7 +387,6 @@ end SimpleEventHook { name = "input-stream-removed@policy-bluetooth", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { @@ -405,7 +404,6 @@ SimpleEventHook { SimpleEventHook { name = "input-stream-changed@policy-bluetooth", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { @@ -428,7 +426,6 @@ SimpleEventHook { SimpleEventHook { name = "bluez-device-added@policy-bluetooth", - type = "on-event", priority = HookPriority.VERY_LOW, interests = { EventInterest { @@ -448,7 +445,6 @@ SimpleEventHook { SimpleEventHook { name = "metadata-changed@policy-bluetooth", - type = "on-event", priority = HookPriority.VERY_LOW, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/filter-forward-format.lua b/src/scripts/policy-desktop/filter-forward-format.lua index d90bc01a..b00665e6 100644 --- a/src/scripts/policy-desktop/filter-forward-format.lua +++ b/src/scripts/policy-desktop/filter-forward-format.lua @@ -80,7 +80,6 @@ end SimpleEventHook { name = "filter-forward-format@policy-node", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/find-best-target.lua b/src/scripts/policy-desktop/find-best-target.lua index be83f031..eff40797 100644 --- a/src/scripts/policy-desktop/find-best-target.lua +++ b/src/scripts/policy-desktop/find-best-target.lua @@ -11,7 +11,6 @@ local cutils = require ("common-utils") SimpleEventHook { name = "find-best-target@policy-desktop", - type = "on-event", priority = HookPriority.LOW, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/find-default-target.lua b/src/scripts/policy-desktop/find-default-target.lua index 497bb38f..5fbca04a 100644 --- a/src/scripts/policy-desktop/find-default-target.lua +++ b/src/scripts/policy-desktop/find-default-target.lua @@ -10,7 +10,6 @@ local putils = require ("policy-utils") SimpleEventHook { name = "find-default-target@policy-desktop", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/find-defined-target.lua b/src/scripts/policy-desktop/find-defined-target.lua index 9845dd82..5e564f82 100644 --- a/src/scripts/policy-desktop/find-defined-target.lua +++ b/src/scripts/policy-desktop/find-defined-target.lua @@ -15,7 +15,6 @@ local config = require ("policy-config") SimpleEventHook { name = "find-defined-target@policy-desktop", - type = "on-event", priority = HookPriority.HIGH, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/find-user-target.lua.example b/src/scripts/policy-desktop/find-user-target.lua.example index 3b1b500c..2b7db1df 100644 --- a/src/scripts/policy-desktop/find-user-target.lua.example +++ b/src/scripts/policy-desktop/find-user-target.lua.example @@ -10,7 +10,6 @@ local putils = require ("policy-utils") SimpleEventHook { name = "sample-find-user-target@policy-desktop", - type = "on-event", priority = HookPriority.VERY_HIGH, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/link-target.lua b/src/scripts/policy-desktop/link-target.lua index 4ab20c85..a95adb92 100644 --- a/src/scripts/policy-desktop/link-target.lua +++ b/src/scripts/policy-desktop/link-target.lua @@ -12,7 +12,6 @@ local cutils = require ("common-utils") SimpleEventHook { name = "link-target@policy-desktop", - type = "on-event", priority = HookPriority.ULTRA_LOW, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/move-follow.lua b/src/scripts/policy-desktop/move-follow.lua index 4c1f7399..c10e19e1 100644 --- a/src/scripts/policy-desktop/move-follow.lua +++ b/src/scripts/policy-desktop/move-follow.lua @@ -14,7 +14,6 @@ function handleFollowSetting (enable) if (not handles.follow_hook) and (enable == true) then handles.follow_hook = SimpleEventHook { name = "follow@policy-desktop", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { @@ -40,7 +39,6 @@ function handleMoveSetting (enable) if (not handles.move_hook) and (enable == true) then handles.move_hook = SimpleEventHook { name = "move@policy-desktop", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/prepare-link.lua b/src/scripts/policy-desktop/prepare-link.lua index b1af0b30..be3d21e4 100644 --- a/src/scripts/policy-desktop/prepare-link.lua +++ b/src/scripts/policy-desktop/prepare-link.lua @@ -13,7 +13,6 @@ local cutils = require ("common-utils") SimpleEventHook { name = "prepare-link@policy-desktop", - type = "on-event", priority = HookPriority.VERY_LOW, interests = { EventInterest { diff --git a/src/scripts/policy-desktop/rescan.lua b/src/scripts/policy-desktop/rescan.lua index b393b7b8..0ceca743 100644 --- a/src/scripts/policy-desktop/rescan.lua +++ b/src/scripts/policy-desktop/rescan.lua @@ -32,7 +32,6 @@ end SimpleEventHook { name = "linkable-removed@policy-node", - type = "on-event", priority = HookPriority.VERY_LOW, interests = { EventInterest { @@ -80,7 +79,6 @@ SimpleEventHook { SimpleEventHook { name = "rescan-session@policy-desktop", - type = "on-event", -- let higher priority hooks deal with preparing the graph first -- (things like finding the default nodes, etc...) priority = HookPriority.VERY_LOW, @@ -121,7 +119,6 @@ SimpleEventHook { -- go with a low priority to allow NORMAL handlers -- to stop the event and prevent the rescan priority = HookPriority.VERY_LOW, - type = "on-event", interests = { -- on linkable added or removed, where linkable is adapter or plain node EventInterest { diff --git a/src/scripts/policy-device-profile.lua b/src/scripts/policy-device-profile.lua index 48746efd..d9e8c14a 100644 --- a/src/scripts/policy-device-profile.lua +++ b/src/scripts/policy-device-profile.lua @@ -103,7 +103,6 @@ end SimpleEventHook { name = "handle-profiles@policy-device-profile", - type = "on-event", priority = HookPriority.LOW, interests = { EventInterest { @@ -166,7 +165,6 @@ SimpleEventHook { SimpleEventHook { name = "device-removed@policy-device-profile", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { diff --git a/src/scripts/policy-device-routes.lua b/src/scripts/policy-device-routes.lua index a1c81672..d5b37c15 100644 --- a/src/scripts/policy-device-routes.lua +++ b/src/scripts/policy-device-routes.lua @@ -469,7 +469,6 @@ end SimpleEventHook { name = "handle-device@device-routes", - type = "on-event", priority = HookPriority.ULTRA_LOW, interests = { EventInterest { @@ -511,7 +510,6 @@ SimpleEventHook { SimpleEventHook { name = "handle-device@device-routes", - type = "on-event", priority = HookPriority.ULTRA_LOW, interests = { EventInterest { diff --git a/src/scripts/restore-stream.lua b/src/scripts/restore-stream.lua index 8f15026d..52051d9e 100644 --- a/src/scripts/restore-stream.lua +++ b/src/scripts/restore-stream.lua @@ -345,7 +345,6 @@ local function handleRestoreTargetSetting (enable) -- save "targe.node" if it is present in default metadata restore_target_hook_handles [1] = SimpleEventHook { name = "metadata-added@restore-stream-save-target", - type = "on-event", priority = HookPriority.ULTRA_LOW, interests = { EventInterest { @@ -366,7 +365,6 @@ local function handleRestoreTargetSetting (enable) -- save "target.node" on metadata changes restore_target_hook_handles [2] = SimpleEventHook { name = "metadata-changed@restore-stream-save-target", - type = "on-event", priority = HookPriority.ULTRA_LOW, interests = { EventInterest { @@ -468,7 +466,6 @@ local function handleRestoreStreamSetting (enable) -- restore-stream properties restore_stream_hook_handles [1] = SimpleEventHook { name = "node-added@restore-stream", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { @@ -495,7 +492,6 @@ local function handleRestoreStreamSetting (enable) -- save-stream if any of the stream parms changes restore_stream_hook_handles [2] = SimpleEventHook { name = "node-parms-changed@restore-stream-save-stream", - type = "on-event", priority = HookPriority.NORMAL, interests = { EventInterest { diff --git a/tests/wp/events.c b/tests/wp/events.c index 982ed3b2..a8e320b0 100644 --- a/tests/wp/events.c +++ b/tests/wp/events.c @@ -10,7 +10,6 @@ typedef struct { WpBaseTestFixture base; - WpObjectManager *om; GPtrArray *hooks_executed; GPtrArray *events; WpTransition *transition; @@ -28,6 +27,7 @@ static void test_events_teardown (TestFixture *self, gconstpointer user_data) { g_clear_pointer (&self->hooks_executed, g_ptr_array_unref); + g_clear_pointer (&self->events, g_ptr_array_unref); wp_base_test_fixture_teardown (&self->base); } @@ -54,28 +54,17 @@ hook_quit (WpEvent *event, TestFixture *self) g_main_loop_quit (self->base.loop); } -static void -hook_after_events_with_event (WpEvent *event, TestFixture *self) -{ - g_debug ("in hook_after_events_with_event %p", event); - g_ptr_array_add (self->hooks_executed, hook_after_events_with_event); - g_ptr_array_add (self->events, event); - g_main_loop_quit (self->base.loop); -} - - static void test_events_basic (TestFixture *self, gconstpointer user_data) { g_autoptr (WpEventDispatcher) dispatcher = NULL; g_autoptr (WpEventHook) hook = NULL; - WpEvent *event1 = NULL, *event2 = NULL; + WpEvent *event1 = NULL, *event2 = NULL, *event3 = NULL; dispatcher = wp_event_dispatcher_get_instance (self->base.core); g_assert_nonnull (dispatcher); hook = wp_simple_event_hook_new ("hook-a", 10, - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, g_cclosure_new ((GCallback) hook_a, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); @@ -83,7 +72,6 @@ test_events_basic (TestFixture *self, gconstpointer user_data) g_clear_object (&hook); hook = wp_simple_event_hook_new ("hook-b", -200, - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, g_cclosure_new ((GCallback) hook_b, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); @@ -91,7 +79,6 @@ test_events_basic (TestFixture *self, gconstpointer user_data) g_clear_object (&hook); hook = wp_simple_event_hook_new ("hook-c", 100, - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, g_cclosure_new ((GCallback) hook_c, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); @@ -99,30 +86,18 @@ test_events_basic (TestFixture *self, gconstpointer user_data) g_clear_object (&hook); hook = wp_simple_event_hook_new ("hook-d", 0, - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, g_cclosure_new ((GCallback) hook_d, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type2", NULL); wp_event_dispatcher_register_hook (dispatcher, hook); g_clear_object (&hook); - hook = wp_simple_event_hook_new ("hook_after_events_with_event", 2000, - WP_EVENT_HOOK_EXEC_TYPE_AFTER_EVENTS_WITH_EVENT, - g_cclosure_new ((GCallback) hook_after_events_with_event, self, NULL)); - wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), - WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); - wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), - WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type2", NULL); - wp_event_dispatcher_register_hook (dispatcher, hook); - g_clear_object (&hook); - - hook = wp_simple_event_hook_new ("hook-quit-async", 1000, - WP_EVENT_HOOK_EXEC_TYPE_AFTER_EVENTS, + hook = wp_simple_event_hook_new ("hook-quit", -1000, g_cclosure_new ((GCallback) hook_quit, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), - WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type2", NULL); + WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type3", NULL); wp_event_dispatcher_register_hook (dispatcher, hook); g_clear_object (&hook); @@ -131,17 +106,18 @@ test_events_basic (TestFixture *self, gconstpointer user_data) wp_event_dispatcher_push_event (dispatcher, event1); g_assert_cmpint (self->hooks_executed->len, == , 0); + g_assert_cmpint (self->events->len, == , 0); g_main_loop_run (self->base.loop); - g_assert_cmpint (self->hooks_executed->len, == , 5); + g_assert_cmpint (self->hooks_executed->len, == , 4); + g_assert_cmpint (self->events->len, == , 4); g_assert (hook_c == self->hooks_executed->pdata [0]); g_assert (event1 == self->events->pdata [0]); g_assert (hook_a == self->hooks_executed->pdata [1]); g_assert (event1 == self->events->pdata [1]); g_assert (hook_b == self->hooks_executed->pdata [2]); g_assert (event1 == self->events->pdata [2]); - g_assert (hook_after_events_with_event == self->hooks_executed->pdata [3]); + g_assert (hook_quit == self->hooks_executed->pdata [3]); g_assert (event1 == self->events->pdata [3]); - g_assert (hook_quit == self->hooks_executed->pdata [4]); g_ptr_array_remove_range (self->hooks_executed, 0, self->hooks_executed->len); g_assert_cmpint (self->hooks_executed->len, == , 0); @@ -158,8 +134,10 @@ test_events_basic (TestFixture *self, gconstpointer user_data) wp_event_dispatcher_push_event (dispatcher, event2); g_assert_cmpint (self->hooks_executed->len, == , 0); + g_assert_cmpint (self->events->len, == , 0); g_main_loop_run (self->base.loop); - g_assert_cmpint (self->hooks_executed->len, == , 7); + g_assert_cmpint (self->hooks_executed->len, == , 5); + g_assert_cmpint (self->events->len, == , 5); g_assert (hook_d == self->hooks_executed->pdata [0]); g_assert (event2 == self->events->pdata [0]); g_assert (hook_c == self->hooks_executed->pdata [1]); @@ -168,11 +146,8 @@ test_events_basic (TestFixture *self, gconstpointer user_data) g_assert (event1 == self->events->pdata [2]); g_assert (hook_b == self->hooks_executed->pdata [3]); g_assert (event1 == self->events->pdata [3]); - g_assert (hook_after_events_with_event == self->hooks_executed->pdata [4]); - g_assert (event2 == self->events->pdata [4]); - g_assert (hook_after_events_with_event == self->hooks_executed->pdata [5]); - g_assert (event1 == self->events->pdata [5]); - g_assert (hook_quit == self->hooks_executed->pdata [6]); + g_assert (hook_quit == self->hooks_executed->pdata [4]); + g_assert (event1 == self->events->pdata [4]); g_ptr_array_remove_range (self->hooks_executed, 0, self->hooks_executed->len); g_assert_cmpint (self->hooks_executed->len, == , 0); @@ -184,19 +159,23 @@ test_events_basic (TestFixture *self, gconstpointer user_data) wp_properties_new ("test.prop", "some-val", NULL), NULL, NULL); event2 = wp_event_new ("type2", 100, wp_properties_new ("test.prop", "some-val", NULL), NULL, NULL); + event3 = wp_event_new ("type3", 50, + wp_properties_new ("test.prop", "some-val", NULL), NULL, NULL); + wp_event_dispatcher_push_event (dispatcher, event3); wp_event_dispatcher_push_event (dispatcher, event2); wp_event_dispatcher_push_event (dispatcher, event1); wp_event_stop_processing (event1); g_assert_cmpint (self->hooks_executed->len, == , 0); + g_assert_cmpint (self->events->len, == , 0); g_main_loop_run (self->base.loop); - g_assert_cmpint (self->hooks_executed->len, == , 3); + g_assert_cmpint (self->hooks_executed->len, == , 2); + g_assert_cmpint (self->events->len, == , 2); g_assert (hook_d == self->hooks_executed->pdata [0]); g_assert (event2 == self->events->pdata [0]); - g_assert (hook_after_events_with_event == self->hooks_executed->pdata [1]); - g_assert (event2 == self->events->pdata [1]); - g_assert (hook_quit == self->hooks_executed->pdata [2]); + g_assert (hook_quit == self->hooks_executed->pdata [1]); + g_assert (event3 == self->events->pdata [1]); } enum { @@ -245,7 +224,6 @@ test_events_async_hook (TestFixture *self, gconstpointer user_data) g_assert_nonnull (dispatcher); hook = wp_simple_event_hook_new ("hook-a", 10, - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, g_cclosure_new ((GCallback) hook_a, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); @@ -253,7 +231,6 @@ test_events_async_hook (TestFixture *self, gconstpointer user_data) g_clear_object (&hook); hook = wp_simple_event_hook_new ("hook-b", -200, - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, g_cclosure_new ((GCallback) hook_b, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); @@ -261,25 +238,22 @@ test_events_async_hook (TestFixture *self, gconstpointer user_data) g_clear_object (&hook); hook = wp_simple_event_hook_new ("hook-c", 100, - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, g_cclosure_new ((GCallback) hook_c, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); wp_event_dispatcher_register_hook (dispatcher, hook); g_clear_object (&hook); - hook = wp_simple_event_hook_new ("hook-quit", 1000, - WP_EVENT_HOOK_EXEC_TYPE_AFTER_EVENTS, + hook = wp_simple_event_hook_new ("hook-quit", -1000, g_cclosure_new ((GCallback) hook_quit, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type1", NULL); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), - WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type2", NULL); + WP_CONSTRAINT_TYPE_PW_PROPERTY, "event.type", "=s", "type3", NULL); wp_event_dispatcher_register_hook (dispatcher, hook); g_clear_object (&hook); hook = wp_async_event_hook_new ("async-test-hook", 50, - WP_EVENT_HOOK_EXEC_TYPE_ON_EVENT, g_cclosure_new ((GCallback) async_hook_get_next_step, self, NULL), g_cclosure_new ((GCallback) async_hook_execute_step, self, NULL)); wp_interest_event_hook_add_interest (WP_INTEREST_EVENT_HOOK (hook), diff --git a/tests/wplua/scripts/event-hooks.lua b/tests/wplua/scripts/event-hooks.lua index b227f841..3a05bc1d 100644 --- a/tests/wplua/scripts/event-hooks.lua +++ b/tests/wplua/scripts/event-hooks.lua @@ -30,7 +30,6 @@ local common_interests = { AsyncEventHook { name = "test-async-hook", priority = 10, - type = "on-event", interests = common_interests, steps = { start = { @@ -57,7 +56,6 @@ AsyncEventHook { SimpleEventHook { name = "test-simple-hook", priority = 15, - type = "on-event", interests = common_interests, execute = function (event) checkpoint("simple-1") @@ -65,9 +63,8 @@ SimpleEventHook { }:register() SimpleEventHook { - name = "test-afterevent-hook", - priority = 1, - type = "after-events", + name = "test-last-hook", + priority = -1000, interests = common_interests, execute = function (event) checkpoint("simple-2")