2022-01-19 13:48:59 +02:00
|
|
|
/* WirePlumber
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2022 Collabora Ltd.
|
|
|
|
|
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __WIREPLUMBER_EVENT_HOOK_H__
|
|
|
|
|
#define __WIREPLUMBER_EVENT_HOOK_H__
|
|
|
|
|
|
|
|
|
|
#include "properties.h"
|
|
|
|
|
#include "object-interest.h"
|
|
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
|
|
typedef struct _WpEvent WpEvent;
|
|
|
|
|
typedef struct _WpEventDispatcher WpEventDispatcher;
|
|
|
|
|
|
2022-06-30 10:03:18 +05:30
|
|
|
/*! \defgroup wpeventhook WpEventHook */
|
2022-01-19 13:48:59 +02:00
|
|
|
/*!
|
2022-06-30 10:03:18 +05:30
|
|
|
* \struct WpEventHook
|
|
|
|
|
*
|
|
|
|
|
* The event hook is a structure that describes some executable action
|
|
|
|
|
* that an event dispatcher will run when a matching event has been received.
|
2022-01-19 13:48:59 +02:00
|
|
|
*/
|
|
|
|
|
#define WP_TYPE_EVENT_HOOK (wp_event_hook_get_type ())
|
|
|
|
|
WP_API
|
|
|
|
|
G_DECLARE_DERIVABLE_TYPE (WpEventHook, wp_event_hook, WP, EVENT_HOOK, GObject)
|
|
|
|
|
|
|
|
|
|
struct _WpEventHookClass
|
|
|
|
|
{
|
|
|
|
|
GObjectClass parent_class;
|
|
|
|
|
|
|
|
|
|
gboolean (*runs_for_event) (WpEventHook * self, WpEvent * event);
|
|
|
|
|
|
|
|
|
|
void (*run) (WpEventHook * self, WpEvent * event, GCancellable * cancellable,
|
|
|
|
|
GAsyncReadyCallback callback, gpointer callback_data);
|
|
|
|
|
|
|
|
|
|
gboolean (*finish) (WpEventHook * self, GAsyncResult * res, GError ** error);
|
|
|
|
|
|
event-dispatcher: Register hooks for defined events in a hash table
Since all the current hooks are defined specifically for a particular event
type, we can register the hooks in a hash table using the event type as key
for faster event hook collection.
Also, hooks that are not specific to a particular event type, like constraints
such as 'event.type=*', will be registered in both the undefined hook list,
and also in all the hash table defined hook lists so they are always evaluated.
Even though 'wp_event_dispatcher_new_hooks_iterator()' can still be used, it is
now marked as deprecated because it is slower. The event hook collection uses
'wp_event_dispatcher_new_hooks_for_event_type_iterator()' now because it is
much faster.
Previously, the more hooks we were registering, the slower WirePlumber would
process events as all hooks needed to be evaluated for all events constantly.
This is not the case anymore with this patch. We can register thousands of
hooks, and if only 1 of those runs for a particular event, only 1 will be
evaluated instead of all of them.
See #824
2025-11-20 16:36:37 -05:00
|
|
|
GPtrArray * (*get_matching_event_types) (WpEventHook *self);
|
|
|
|
|
|
2022-01-19 13:48:59 +02:00
|
|
|
/*< private >*/
|
event-dispatcher: Register hooks for defined events in a hash table
Since all the current hooks are defined specifically for a particular event
type, we can register the hooks in a hash table using the event type as key
for faster event hook collection.
Also, hooks that are not specific to a particular event type, like constraints
such as 'event.type=*', will be registered in both the undefined hook list,
and also in all the hash table defined hook lists so they are always evaluated.
Even though 'wp_event_dispatcher_new_hooks_iterator()' can still be used, it is
now marked as deprecated because it is slower. The event hook collection uses
'wp_event_dispatcher_new_hooks_for_event_type_iterator()' now because it is
much faster.
Previously, the more hooks we were registering, the slower WirePlumber would
process events as all hooks needed to be evaluated for all events constantly.
This is not the case anymore with this patch. We can register thousands of
hooks, and if only 1 of those runs for a particular event, only 1 will be
evaluated instead of all of them.
See #824
2025-11-20 16:36:37 -05:00
|
|
|
WP_PADDING(4)
|
2022-01-19 13:48:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WP_API
|
2022-11-29 20:08:13 +02:00
|
|
|
const gchar * wp_event_hook_get_name (WpEventHook * self);
|
2022-01-19 13:48:59 +02:00
|
|
|
|
2022-06-30 10:03:18 +05:30
|
|
|
WP_API
|
2022-11-29 20:08:13 +02:00
|
|
|
const gchar * const * wp_event_hook_get_runs_before_hooks (WpEventHook * self);
|
|
|
|
|
|
|
|
|
|
WP_API
|
|
|
|
|
const gchar * const * wp_event_hook_get_runs_after_hooks (WpEventHook * self);
|
2022-06-30 10:03:18 +05:30
|
|
|
|
2022-03-24 09:38:24 +02:00
|
|
|
WP_PRIVATE_API
|
2022-01-19 13:48:59 +02:00
|
|
|
WpEventDispatcher * wp_event_hook_get_dispatcher (WpEventHook * self);
|
|
|
|
|
|
|
|
|
|
WP_PRIVATE_API
|
|
|
|
|
void wp_event_hook_set_dispatcher (WpEventHook * self,
|
|
|
|
|
WpEventDispatcher * dispatcher);
|
|
|
|
|
|
|
|
|
|
WP_API
|
|
|
|
|
gboolean wp_event_hook_runs_for_event (WpEventHook * self, WpEvent * event);
|
|
|
|
|
|
|
|
|
|
WP_API
|
|
|
|
|
void wp_event_hook_run (WpEventHook * self,
|
|
|
|
|
WpEvent * event, GCancellable * cancellable,
|
|
|
|
|
GAsyncReadyCallback callback, gpointer callback_data);
|
|
|
|
|
|
event-dispatcher: Register hooks for defined events in a hash table
Since all the current hooks are defined specifically for a particular event
type, we can register the hooks in a hash table using the event type as key
for faster event hook collection.
Also, hooks that are not specific to a particular event type, like constraints
such as 'event.type=*', will be registered in both the undefined hook list,
and also in all the hash table defined hook lists so they are always evaluated.
Even though 'wp_event_dispatcher_new_hooks_iterator()' can still be used, it is
now marked as deprecated because it is slower. The event hook collection uses
'wp_event_dispatcher_new_hooks_for_event_type_iterator()' now because it is
much faster.
Previously, the more hooks we were registering, the slower WirePlumber would
process events as all hooks needed to be evaluated for all events constantly.
This is not the case anymore with this patch. We can register thousands of
hooks, and if only 1 of those runs for a particular event, only 1 will be
evaluated instead of all of them.
See #824
2025-11-20 16:36:37 -05:00
|
|
|
WP_API
|
|
|
|
|
GPtrArray * wp_event_hook_get_matching_event_types (WpEventHook * self);
|
|
|
|
|
|
2022-01-19 13:48:59 +02:00
|
|
|
WP_API
|
|
|
|
|
gboolean wp_event_hook_finish (WpEventHook * self, GAsyncResult * res,
|
|
|
|
|
GError ** error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief The WpInterestEventHook GType
|
|
|
|
|
* \ingroup wpeventhook
|
|
|
|
|
*/
|
|
|
|
|
#define WP_TYPE_INTEREST_EVENT_HOOK (wp_interest_event_hook_get_type ())
|
|
|
|
|
WP_API
|
|
|
|
|
G_DECLARE_DERIVABLE_TYPE (WpInterestEventHook, wp_interest_event_hook,
|
|
|
|
|
WP, INTEREST_EVENT_HOOK, WpEventHook)
|
|
|
|
|
|
|
|
|
|
struct _WpInterestEventHookClass
|
|
|
|
|
{
|
|
|
|
|
WpEventHookClass parent_class;
|
|
|
|
|
|
|
|
|
|
/*< private >*/
|
|
|
|
|
WP_PADDING(4)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WP_API
|
|
|
|
|
void wp_interest_event_hook_add_interest (WpInterestEventHook * self,
|
|
|
|
|
...) G_GNUC_NULL_TERMINATED;
|
|
|
|
|
|
|
|
|
|
WP_API
|
|
|
|
|
void wp_interest_event_hook_add_interest_full (WpInterestEventHook * self,
|
|
|
|
|
WpObjectInterest * interest);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief The WpSimpleEventHook GType
|
|
|
|
|
* \ingroup wpeventhook
|
|
|
|
|
*/
|
|
|
|
|
#define WP_TYPE_SIMPLE_EVENT_HOOK (wp_simple_event_hook_get_type ())
|
|
|
|
|
WP_API
|
|
|
|
|
G_DECLARE_FINAL_TYPE (WpSimpleEventHook, wp_simple_event_hook,
|
|
|
|
|
WP, SIMPLE_EVENT_HOOK, WpInterestEventHook)
|
|
|
|
|
|
|
|
|
|
WP_API
|
2022-11-29 20:08:13 +02:00
|
|
|
WpEventHook * wp_simple_event_hook_new (const gchar *name,
|
|
|
|
|
const gchar * before[], const gchar * after[],
|
2022-11-24 17:39:21 +02:00
|
|
|
GClosure * closure);
|
2022-01-19 13:48:59 +02:00
|
|
|
|
2022-02-21 18:36:32 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief The WpAsyncEventHook GType
|
|
|
|
|
* \ingroup wpeventhook
|
|
|
|
|
*/
|
|
|
|
|
#define WP_TYPE_ASYNC_EVENT_HOOK (wp_async_event_hook_get_type ())
|
|
|
|
|
WP_API
|
|
|
|
|
G_DECLARE_FINAL_TYPE (WpAsyncEventHook, wp_async_event_hook,
|
|
|
|
|
WP, ASYNC_EVENT_HOOK, WpInterestEventHook)
|
|
|
|
|
|
|
|
|
|
WP_API
|
2022-11-29 20:08:13 +02:00
|
|
|
WpEventHook * wp_async_event_hook_new (const gchar *name,
|
|
|
|
|
const gchar * before[], const gchar * after[],
|
2022-11-24 17:39:21 +02:00
|
|
|
GClosure * get_next_step, GClosure * execute_step);
|
2022-02-21 18:36:32 +02:00
|
|
|
|
2022-01-19 13:48:59 +02:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
|
|
#endif
|