registry: hide again the WpCore struct, separate registry and core better
This commit is contained in:
@@ -372,7 +372,7 @@ wp_base_endpoint_register (WpBaseEndpoint * self)
|
||||
g_info ("WpBaseEndpoint:%p registering '%s' (%s)", self, priv->name,
|
||||
priv->media_class);
|
||||
|
||||
wp_core_register_object (core, g_object_ref (self));
|
||||
wp_registry_register_object (wp_core_get_registry (core), g_object_ref (self));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,7 +402,7 @@ wp_base_endpoint_unregister (WpBaseEndpoint * self)
|
||||
g_info ("WpBaseEndpoint:%p unregistering '%s' (%s)", self, priv->name,
|
||||
priv->media_class);
|
||||
|
||||
wp_core_remove_object (core, self);
|
||||
wp_registry_remove_object (wp_core_get_registry (core), self);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -87,10 +87,12 @@ wp_configuration_get_instance (WpCore *core)
|
||||
|
||||
g_return_val_if_fail (WP_IS_CORE (core), NULL);
|
||||
|
||||
self = wp_core_find_object (core, (GEqualFunc) WP_IS_CONFIGURATION, NULL);
|
||||
self = wp_registry_find_object (wp_core_get_registry (core),
|
||||
(GEqualFunc) WP_IS_CONFIGURATION, NULL);
|
||||
if (!self) {
|
||||
self = g_object_new (WP_TYPE_CONFIGURATION, NULL);
|
||||
wp_core_register_object (core, g_object_ref (self));
|
||||
wp_registry_register_object (wp_core_get_registry (core),
|
||||
g_object_ref (self));
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@@ -73,6 +73,28 @@ wp_loop_source_new (void)
|
||||
* WpCore
|
||||
*/
|
||||
|
||||
struct _WpCore
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
/* main loop integration */
|
||||
GMainContext *context;
|
||||
|
||||
/* extra properties */
|
||||
WpProperties *properties;
|
||||
|
||||
/* pipewire main objects */
|
||||
struct pw_context *pw_context;
|
||||
struct pw_core *pw_core;
|
||||
|
||||
/* pipewire main listeners */
|
||||
struct spa_hook core_listener;
|
||||
struct spa_hook proxy_core_listener;
|
||||
|
||||
WpRegistry registry;
|
||||
GHashTable *async_tasks; // <int seq, GTask*>
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CONTEXT,
|
||||
@@ -89,7 +111,6 @@ enum {
|
||||
|
||||
static guint32 signals[NUM_SIGNALS];
|
||||
|
||||
|
||||
G_DEFINE_TYPE (WpCore, wp_core, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
@@ -402,3 +423,15 @@ wp_core_sync_finish (WpCore * self, GAsyncResult * res, GError ** error)
|
||||
|
||||
return g_task_propagate_boolean (G_TASK (res), error);
|
||||
}
|
||||
|
||||
WpRegistry *
|
||||
wp_core_get_registry (WpCore * self)
|
||||
{
|
||||
return &self->registry;
|
||||
}
|
||||
|
||||
WpCore *
|
||||
wp_registry_get_core (WpRegistry * self)
|
||||
{
|
||||
return SPA_CONTAINER_OF (self, WpCore, registry);
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func)
|
||||
|
||||
g_info ("WpFactory:%p new factory: %s", f, name);
|
||||
|
||||
wp_core_register_object (core, f);
|
||||
wp_registry_register_object (wp_core_get_registry (core), f);
|
||||
|
||||
return f;
|
||||
}
|
||||
@@ -124,8 +124,8 @@ wp_factory_find (WpCore * core, const gchar * name)
|
||||
{
|
||||
GObject *f;
|
||||
GQuark q = g_quark_from_string (name);
|
||||
f = wp_core_find_object (core, (GEqualFunc) find_factory_func,
|
||||
GUINT_TO_POINTER (q));
|
||||
f = wp_registry_find_object (wp_core_get_registry (core),
|
||||
(GEqualFunc) find_factory_func, GUINT_TO_POINTER (q));
|
||||
return f ? WP_FACTORY (f) : NULL;
|
||||
}
|
||||
|
||||
|
@@ -139,7 +139,8 @@ wp_module_load (WpCore * core, const gchar * abi, const gchar * module_name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wp_core_register_object (core, g_object_ref (module));
|
||||
wp_registry_register_object (wp_core_get_registry (core),
|
||||
g_object_ref (module));
|
||||
|
||||
return module;
|
||||
}
|
||||
|
@@ -723,7 +723,7 @@ wp_registry_prepare_new_global (WpRegistry * self, guint32 id,
|
||||
WpProxy *proxy, const struct spa_dict *props)
|
||||
{
|
||||
g_autoptr (WpGlobal) global = NULL;
|
||||
WpCore *core = SPA_CONTAINER_OF (self, WpCore, registry);
|
||||
WpCore *core = wp_registry_get_core (self);
|
||||
|
||||
g_return_val_if_fail (flag != 0, NULL);
|
||||
g_return_val_if_fail (self->globals->len <= id ||
|
||||
@@ -782,8 +782,8 @@ wp_registry_prepare_new_global (WpRegistry * self, guint32 id,
|
||||
}
|
||||
|
||||
/*
|
||||
* wp_core_find_object:
|
||||
* @core: the core
|
||||
* wp_registry_find_object:
|
||||
* @reg: the registry
|
||||
* @func: (scope call): a function that takes the object being searched
|
||||
* as the first argument and @data as the second. it should return TRUE if
|
||||
* the object is found or FALSE otherwise
|
||||
@@ -795,16 +795,11 @@ wp_registry_prepare_new_global (WpRegistry * self, guint32 id,
|
||||
* or NULL if not found
|
||||
*/
|
||||
gpointer
|
||||
wp_core_find_object (WpCore * core, GEqualFunc func, gconstpointer data)
|
||||
wp_registry_find_object (WpRegistry *reg, GEqualFunc func, gconstpointer data)
|
||||
{
|
||||
WpRegistry *reg;
|
||||
GObject *object;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (WP_IS_CORE (core), NULL);
|
||||
|
||||
reg = &core->registry;
|
||||
|
||||
/* prevent bad things when called from within wp_registry_clear() */
|
||||
if (G_UNLIKELY (!reg->objects))
|
||||
return NULL;
|
||||
@@ -819,8 +814,8 @@ wp_core_find_object (WpCore * core, GEqualFunc func, gconstpointer data)
|
||||
}
|
||||
|
||||
/*
|
||||
* wp_core_register_object:
|
||||
* @core: the core
|
||||
* wp_registry_register_object:
|
||||
* @reg: the registry
|
||||
* @obj: (transfer full) (type GObject*): the object to register
|
||||
*
|
||||
* Registers @obj with the core, making it appear on #WpObjectManager
|
||||
@@ -828,15 +823,10 @@ wp_core_find_object (WpCore * core, GEqualFunc func, gconstpointer data)
|
||||
* until it is removed.
|
||||
*/
|
||||
void
|
||||
wp_core_register_object (WpCore * core, gpointer obj)
|
||||
wp_registry_register_object (WpRegistry *reg, gpointer obj)
|
||||
{
|
||||
WpRegistry *reg;
|
||||
|
||||
g_return_if_fail (WP_IS_CORE (core));
|
||||
g_return_if_fail (G_IS_OBJECT (obj));
|
||||
|
||||
reg = &core->registry;
|
||||
|
||||
/* prevent bad things when called from within wp_registry_clear() */
|
||||
if (G_UNLIKELY (!reg->objects)) {
|
||||
g_object_unref (obj);
|
||||
@@ -850,22 +840,17 @@ wp_core_register_object (WpCore * core, gpointer obj)
|
||||
}
|
||||
|
||||
/*
|
||||
* wp_core_remove_object:
|
||||
* @core: the core
|
||||
* wp_registry_remove_object:
|
||||
* @reg: the registry
|
||||
* @obj: (transfer none) (type GObject*): a pointer to the object to remove
|
||||
*
|
||||
* Detaches and unrefs the specified object from this core
|
||||
*/
|
||||
void
|
||||
wp_core_remove_object (WpCore * core, gpointer obj)
|
||||
wp_registry_remove_object (WpRegistry *reg, gpointer obj)
|
||||
{
|
||||
WpRegistry *reg;
|
||||
|
||||
g_return_if_fail (WP_IS_CORE (core));
|
||||
g_return_if_fail (G_IS_OBJECT (obj));
|
||||
|
||||
reg = &core->registry;
|
||||
|
||||
/* prevent bad things when called from within wp_registry_clear() */
|
||||
if (G_UNLIKELY (!reg->objects))
|
||||
return;
|
||||
@@ -894,7 +879,7 @@ wp_core_install_object_manager (WpCore * core, WpObjectManager * om)
|
||||
g_return_if_fail (WP_IS_CORE (core));
|
||||
g_return_if_fail (WP_IS_OBJECT_MANAGER (om));
|
||||
|
||||
reg = &core->registry;
|
||||
reg = wp_core_get_registry (core);
|
||||
|
||||
g_object_weak_ref (G_OBJECT (om), object_manager_destroyed, reg);
|
||||
g_ptr_array_add (reg->object_managers, om);
|
||||
|
@@ -107,8 +107,8 @@ wp_policy_manager_get_instance (WpCore *core)
|
||||
|
||||
g_return_val_if_fail (WP_IS_CORE (core), NULL);
|
||||
|
||||
mgr = wp_core_find_object (core, (GEqualFunc) WP_IS_POLICY_MANAGER,
|
||||
NULL);
|
||||
mgr = wp_registry_find_object (wp_core_get_registry (core),
|
||||
(GEqualFunc) WP_IS_POLICY_MANAGER, NULL);
|
||||
if (G_UNLIKELY (!mgr)) {
|
||||
mgr = g_object_new (WP_TYPE_POLICY_MANAGER, NULL);
|
||||
|
||||
@@ -127,7 +127,8 @@ wp_policy_manager_get_instance (WpCore *core)
|
||||
WP_PROXY_FEATURES_STANDARD | WP_SESSION_FEATURE_DEFAULT_ENDPOINT);
|
||||
wp_core_install_object_manager (core, mgr->sessions_om);
|
||||
|
||||
wp_core_register_object (core, g_object_ref (mgr));
|
||||
wp_registry_register_object (wp_core_get_registry (core),
|
||||
g_object_ref (mgr));
|
||||
}
|
||||
|
||||
return mgr;
|
||||
@@ -403,7 +404,8 @@ wp_policy_unregister (WpPolicy *self)
|
||||
|
||||
core = g_weak_ref_get (&priv->core);
|
||||
if (core) {
|
||||
mgr = wp_core_find_object (core, (GEqualFunc) WP_IS_POLICY_MANAGER, NULL);
|
||||
mgr = wp_registry_find_object (wp_core_get_registry (core),
|
||||
(GEqualFunc) WP_IS_POLICY_MANAGER, NULL);
|
||||
if (G_UNLIKELY (!mgr)) {
|
||||
g_critical ("WpPolicy:%p seems registered, but the policy manager "
|
||||
"is absent", self);
|
||||
@@ -429,7 +431,8 @@ wp_policy_notify_changed (WpPolicy *self)
|
||||
|
||||
core = g_weak_ref_get (&priv->core);
|
||||
if (core) {
|
||||
mgr = wp_core_find_object (core, (GEqualFunc) WP_IS_POLICY_MANAGER, NULL);
|
||||
mgr = wp_registry_find_object (wp_core_get_registry (core),
|
||||
(GEqualFunc) WP_IS_POLICY_MANAGER, NULL);
|
||||
if (G_UNLIKELY (!mgr)) {
|
||||
g_critical ("WpPolicy:%p seems registered, but the policy manager "
|
||||
"is absent", self);
|
||||
@@ -464,7 +467,7 @@ wp_policy_find_endpoint (WpCore *core, GVariant *props,
|
||||
g_return_val_if_fail (g_variant_is_of_type (props, G_VARIANT_TYPE_VARDICT), NULL);
|
||||
g_return_val_if_fail (stream_id != NULL, NULL);
|
||||
|
||||
mgr = wp_core_find_object (core,
|
||||
mgr = wp_registry_find_object (wp_core_get_registry (core),
|
||||
(GEqualFunc) WP_IS_POLICY_MANAGER, NULL);
|
||||
if (mgr) {
|
||||
for (l = g_list_first (mgr->policies); l; l = g_list_next (l)) {
|
||||
|
@@ -47,34 +47,16 @@ WpGlobal * wp_registry_prepare_new_global (WpRegistry * self, guint32 id,
|
||||
guint32 permissions, guint32 flag, GType type,
|
||||
WpProxy *proxy, const struct spa_dict *props);
|
||||
|
||||
gpointer wp_registry_find_object (WpRegistry *reg, GEqualFunc func,
|
||||
gconstpointer data);
|
||||
void wp_registry_register_object (WpRegistry *reg, gpointer obj);
|
||||
void wp_registry_remove_object (WpRegistry *reg, gpointer obj);
|
||||
|
||||
WpCore * wp_registry_get_core (WpRegistry * self);
|
||||
|
||||
/* core */
|
||||
|
||||
struct _WpCore
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
/* main loop integration */
|
||||
GMainContext *context;
|
||||
|
||||
/* extra properties */
|
||||
WpProperties *properties;
|
||||
|
||||
/* pipewire main objects */
|
||||
struct pw_context *pw_context;
|
||||
struct pw_core *pw_core;
|
||||
|
||||
/* pipewire main listeners */
|
||||
struct spa_hook core_listener;
|
||||
struct spa_hook proxy_core_listener;
|
||||
|
||||
WpRegistry registry;
|
||||
GHashTable *async_tasks; // <int seq, GTask*>
|
||||
};
|
||||
|
||||
gpointer wp_core_find_object (WpCore * self, GEqualFunc func,
|
||||
gconstpointer data);
|
||||
void wp_core_register_object (WpCore * self, gpointer obj);
|
||||
void wp_core_remove_object (WpCore * self, gpointer obj);
|
||||
WpRegistry * wp_core_get_registry (WpCore * self);
|
||||
|
||||
/* global */
|
||||
|
||||
|
@@ -120,7 +120,7 @@ proxy_event_bound (void *data, uint32_t global_id)
|
||||
if (!priv->global) {
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&priv->core);
|
||||
|
||||
priv->global = wp_registry_prepare_new_global (&core->registry,
|
||||
priv->global = wp_registry_prepare_new_global (wp_core_get_registry (core),
|
||||
global_id, PW_PERM_RWX, WP_GLOBAL_FLAG_OWNED_BY_PROXY,
|
||||
G_TYPE_FROM_INSTANCE (self), self, NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user