mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2025-12-20 15:50:03 +01:00
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
137 lines
3.5 KiB
C
137 lines
3.5 KiB
C
/* 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;
|
|
|
|
/*! \defgroup wpeventhook WpEventHook */
|
|
/*!
|
|
* \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.
|
|
*/
|
|
#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);
|
|
|
|
GPtrArray * (*get_matching_event_types) (WpEventHook *self);
|
|
|
|
/*< private >*/
|
|
WP_PADDING(4)
|
|
};
|
|
|
|
WP_API
|
|
const gchar * wp_event_hook_get_name (WpEventHook * self);
|
|
|
|
WP_API
|
|
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);
|
|
|
|
WP_PRIVATE_API
|
|
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);
|
|
|
|
WP_API
|
|
GPtrArray * wp_event_hook_get_matching_event_types (WpEventHook * self);
|
|
|
|
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
|
|
WpEventHook * wp_simple_event_hook_new (const gchar *name,
|
|
const gchar * before[], const gchar * after[],
|
|
GClosure * closure);
|
|
|
|
|
|
/*!
|
|
* \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
|
|
WpEventHook * wp_async_event_hook_new (const gchar *name,
|
|
const gchar * before[], const gchar * after[],
|
|
GClosure * get_next_step, GClosure * execute_step);
|
|
|
|
G_END_DECLS
|
|
|
|
#endif
|