registry: hide again the WpCore struct, separate registry and core better

This commit is contained in:
George Kiagiadakis
2020-02-17 18:31:03 +02:00
parent 0b55729e06
commit c46a48d13f
9 changed files with 75 additions and 69 deletions

View File

@@ -372,7 +372,7 @@ wp_base_endpoint_register (WpBaseEndpoint * self)
g_info ("WpBaseEndpoint:%p registering '%s' (%s)", self, priv->name, g_info ("WpBaseEndpoint:%p registering '%s' (%s)", self, priv->name,
priv->media_class); 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, g_info ("WpBaseEndpoint:%p unregistering '%s' (%s)", self, priv->name,
priv->media_class); priv->media_class);
wp_core_remove_object (core, self); wp_registry_remove_object (wp_core_get_registry (core), self);
} }
} }

View File

@@ -87,10 +87,12 @@ wp_configuration_get_instance (WpCore *core)
g_return_val_if_fail (WP_IS_CORE (core), NULL); 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) { if (!self) {
self = g_object_new (WP_TYPE_CONFIGURATION, NULL); 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; return self;

View File

@@ -73,6 +73,28 @@ wp_loop_source_new (void)
* WpCore * 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 { enum {
PROP_0, PROP_0,
PROP_CONTEXT, PROP_CONTEXT,
@@ -89,7 +111,6 @@ enum {
static guint32 signals[NUM_SIGNALS]; static guint32 signals[NUM_SIGNALS];
G_DEFINE_TYPE (WpCore, wp_core, G_TYPE_OBJECT) G_DEFINE_TYPE (WpCore, wp_core, G_TYPE_OBJECT)
static void 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); 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);
}

View File

@@ -72,7 +72,7 @@ wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func)
g_info ("WpFactory:%p new factory: %s", f, name); 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; return f;
} }
@@ -124,8 +124,8 @@ wp_factory_find (WpCore * core, const gchar * name)
{ {
GObject *f; GObject *f;
GQuark q = g_quark_from_string (name); GQuark q = g_quark_from_string (name);
f = wp_core_find_object (core, (GEqualFunc) find_factory_func, f = wp_registry_find_object (wp_core_get_registry (core),
GUINT_TO_POINTER (q)); (GEqualFunc) find_factory_func, GUINT_TO_POINTER (q));
return f ? WP_FACTORY (f) : NULL; return f ? WP_FACTORY (f) : NULL;
} }

View File

@@ -139,7 +139,8 @@ wp_module_load (WpCore * core, const gchar * abi, const gchar * module_name,
return NULL; 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; return module;
} }

View File

@@ -723,7 +723,7 @@ wp_registry_prepare_new_global (WpRegistry * self, guint32 id,
WpProxy *proxy, const struct spa_dict *props) WpProxy *proxy, const struct spa_dict *props)
{ {
g_autoptr (WpGlobal) global = NULL; 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 (flag != 0, NULL);
g_return_val_if_fail (self->globals->len <= id || 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: * wp_registry_find_object:
* @core: the core * @reg: the registry
* @func: (scope call): a function that takes the object being searched * @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 * as the first argument and @data as the second. it should return TRUE if
* the object is found or FALSE otherwise * 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 * or NULL if not found
*/ */
gpointer 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; GObject *object;
guint i; 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() */ /* prevent bad things when called from within wp_registry_clear() */
if (G_UNLIKELY (!reg->objects)) if (G_UNLIKELY (!reg->objects))
return NULL; return NULL;
@@ -819,8 +814,8 @@ wp_core_find_object (WpCore * core, GEqualFunc func, gconstpointer data)
} }
/* /*
* wp_core_register_object: * wp_registry_register_object:
* @core: the core * @reg: the registry
* @obj: (transfer full) (type GObject*): the object to register * @obj: (transfer full) (type GObject*): the object to register
* *
* Registers @obj with the core, making it appear on #WpObjectManager * 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. * until it is removed.
*/ */
void 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)); g_return_if_fail (G_IS_OBJECT (obj));
reg = &core->registry;
/* prevent bad things when called from within wp_registry_clear() */ /* prevent bad things when called from within wp_registry_clear() */
if (G_UNLIKELY (!reg->objects)) { if (G_UNLIKELY (!reg->objects)) {
g_object_unref (obj); g_object_unref (obj);
@@ -850,22 +840,17 @@ wp_core_register_object (WpCore * core, gpointer obj)
} }
/* /*
* wp_core_remove_object: * wp_registry_remove_object:
* @core: the core * @reg: the registry
* @obj: (transfer none) (type GObject*): a pointer to the object to remove * @obj: (transfer none) (type GObject*): a pointer to the object to remove
* *
* Detaches and unrefs the specified object from this core * Detaches and unrefs the specified object from this core
*/ */
void 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)); g_return_if_fail (G_IS_OBJECT (obj));
reg = &core->registry;
/* prevent bad things when called from within wp_registry_clear() */ /* prevent bad things when called from within wp_registry_clear() */
if (G_UNLIKELY (!reg->objects)) if (G_UNLIKELY (!reg->objects))
return; 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_CORE (core));
g_return_if_fail (WP_IS_OBJECT_MANAGER (om)); 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_object_weak_ref (G_OBJECT (om), object_manager_destroyed, reg);
g_ptr_array_add (reg->object_managers, om); g_ptr_array_add (reg->object_managers, om);

View File

@@ -107,8 +107,8 @@ wp_policy_manager_get_instance (WpCore *core)
g_return_val_if_fail (WP_IS_CORE (core), NULL); g_return_val_if_fail (WP_IS_CORE (core), NULL);
mgr = wp_core_find_object (core, (GEqualFunc) WP_IS_POLICY_MANAGER, mgr = wp_registry_find_object (wp_core_get_registry (core),
NULL); (GEqualFunc) WP_IS_POLICY_MANAGER, NULL);
if (G_UNLIKELY (!mgr)) { if (G_UNLIKELY (!mgr)) {
mgr = g_object_new (WP_TYPE_POLICY_MANAGER, NULL); 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_PROXY_FEATURES_STANDARD | WP_SESSION_FEATURE_DEFAULT_ENDPOINT);
wp_core_install_object_manager (core, mgr->sessions_om); 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; return mgr;
@@ -403,7 +404,8 @@ wp_policy_unregister (WpPolicy *self)
core = g_weak_ref_get (&priv->core); core = g_weak_ref_get (&priv->core);
if (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)) { if (G_UNLIKELY (!mgr)) {
g_critical ("WpPolicy:%p seems registered, but the policy manager " g_critical ("WpPolicy:%p seems registered, but the policy manager "
"is absent", self); "is absent", self);
@@ -429,7 +431,8 @@ wp_policy_notify_changed (WpPolicy *self)
core = g_weak_ref_get (&priv->core); core = g_weak_ref_get (&priv->core);
if (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)) { if (G_UNLIKELY (!mgr)) {
g_critical ("WpPolicy:%p seems registered, but the policy manager " g_critical ("WpPolicy:%p seems registered, but the policy manager "
"is absent", self); "is absent", self);
@@ -464,8 +467,8 @@ 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 (g_variant_is_of_type (props, G_VARIANT_TYPE_VARDICT), NULL);
g_return_val_if_fail (stream_id != NULL, 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); (GEqualFunc) WP_IS_POLICY_MANAGER, NULL);
if (mgr) { if (mgr) {
for (l = g_list_first (mgr->policies); l; l = g_list_next (l)) { for (l = g_list_first (mgr->policies); l; l = g_list_next (l)) {
p = WP_POLICY (l->data); p = WP_POLICY (l->data);

View File

@@ -47,34 +47,16 @@ WpGlobal * wp_registry_prepare_new_global (WpRegistry * self, guint32 id,
guint32 permissions, guint32 flag, GType type, guint32 permissions, guint32 flag, GType type,
WpProxy *proxy, const struct spa_dict *props); 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 */ /* core */
struct _WpCore WpRegistry * wp_core_get_registry (WpCore * self);
{
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);
/* global */ /* global */

View File

@@ -120,7 +120,7 @@ proxy_event_bound (void *data, uint32_t global_id)
if (!priv->global) { if (!priv->global) {
g_autoptr (WpCore) core = g_weak_ref_get (&priv->core); 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, global_id, PW_PERM_RWX, WP_GLOBAL_FLAG_OWNED_BY_PROXY,
G_TYPE_FROM_INSTANCE (self), self, NULL); G_TYPE_FROM_INSTANCE (self), self, NULL);
} }