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.
This commit is contained in:
Ashok Sidipotu
2022-08-05 07:32:48 +05:30
committed by Julian Bouzas
parent 72226e3934
commit 3ff9f240c8
4 changed files with 143 additions and 23 deletions

View File

@@ -21,6 +21,8 @@ struct _WpEventHookPrivate
WpEventHookExecType exec_type;
GWeakRef dispatcher;
gchar *name;
/* event triggering the hook, useful for after-events. */
WpEvent *event_trigger;
};
enum {
@@ -47,6 +49,7 @@ wp_event_hook_finalize (GObject * object)
WpEventHookPrivate *priv = wp_event_hook_get_instance_private (self);
g_weak_ref_clear (&priv->dispatcher);
g_clear_pointer (&priv->event_trigger, wp_event_unref);
g_free (priv->name);
G_OBJECT_CLASS (wp_event_hook_parent_class)->finalize (object);
@@ -130,6 +133,38 @@ wp_event_hook_class_init (WpEventHookClass * klass)
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
/*!
* \brief Returns the event triggering the hook, this data is useful for
* after-events.
*
* \ingroup wpeventhook
* \param self the event hook
* \returns (transfer none) (nullable): the event
*/
WpEvent *
wp_event_hook_get_event (WpEventHook *self)
{
g_return_val_if_fail (WP_IS_EVENT_HOOK (self), 0);
WpEventHookPrivate *priv = wp_event_hook_get_instance_private (self);
return priv->event_trigger;
}
/*!
* \brief Sets the event triggering the hook
*
* \ingroup wpeventhook
* \param self the event hook
* \param event (transfer none) (nullable):the event associated with the hook
*/
void
wp_event_hook_set_event (WpEventHook *self, WpEvent *event)
{
WpEventHookPrivate *priv = wp_event_hook_get_instance_private (self);
g_clear_pointer (&priv->event_trigger, wp_event_unref);
if (event)
priv->event_trigger = wp_event_ref (event);
}
/*!
* \brief Returns the priority of the hook
*
@@ -191,6 +226,14 @@ wp_event_hook_get_dispatcher (WpEventHook * self)
return g_weak_ref_get (&priv->dispatcher);
}
/*!
* \brief Sets the dispatcher to the hook
*
* \ingroup wpeventhook
* \param self the event hook
* \param dispatcher (transfer none) (nullable) dispatcher to which the hook is
* to be registered.
*/
void
wp_event_hook_set_dispatcher (WpEventHook * self, WpEventDispatcher * dispatcher)
{