event-dispatcher: expose iterator to iterate over the registered hooks

This commit is contained in:
George Kiagiadakis
2022-11-25 21:26:34 +02:00
committed by Julian Bouzas
parent b100bdda4a
commit 5a435fae11
2 changed files with 18 additions and 0 deletions

View File

@@ -603,3 +603,18 @@ wp_event_dispatcher_unregister_hook (WpEventDispatcher * self,
wp_event_hook_set_dispatcher (hook, NULL);
g_ptr_array_remove_fast (self->hooks, hook);
}
/*!
* \brief Returns an iterator to iterate over all the registered hooks
* \ingroup wpeventdispatcher
*
* \param self the event dispatcher
* \return (transfer full): a new iterator
*/
WpIterator *
wp_event_dispatcher_new_hooks_iterator (WpEventDispatcher * self)
{
GPtrArray *items =
g_ptr_array_copy (self->hooks, (GCopyFunc) g_object_ref, NULL);
return wp_iterator_new_ptr_array (items, WP_TYPE_EVENT_HOOK);
}

View File

@@ -85,6 +85,9 @@ WP_API
void wp_event_dispatcher_unregister_hook (WpEventDispatcher * self,
WpEventHook * hook);
WP_API
WpIterator * wp_event_dispatcher_new_hooks_iterator (WpEventDispatcher * self);
G_END_DECLS
#endif