mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-08 10:28:03 +02:00
global & object-manager: use GType instead of the pipewire type
This commit is contained in:
parent
467d745082
commit
a92e1a64ec
13 changed files with 54 additions and 78 deletions
|
|
@ -119,6 +119,30 @@ static guint32 signals[NUM_SIGNALS];
|
|||
|
||||
G_DEFINE_TYPE (WpCore, wp_core, G_TYPE_OBJECT)
|
||||
|
||||
/* find the subclass of WpProxy that can handle
|
||||
the given pipewire interface type of the given version */
|
||||
static inline GType
|
||||
find_proxy_instance_type (const char * type, guint32 version)
|
||||
{
|
||||
g_autofree GType *children;
|
||||
guint n_children;
|
||||
|
||||
children = g_type_children (WP_TYPE_PROXY, &n_children);
|
||||
|
||||
for (gint i = 0; i < n_children; i++) {
|
||||
WpProxyClass *klass = (WpProxyClass *) g_type_class_ref (children[i]);
|
||||
if (g_strcmp0 (klass->pw_iface_type, type) == 0 &&
|
||||
klass->pw_iface_version == version) {
|
||||
g_type_class_unref (klass);
|
||||
return children[i];
|
||||
}
|
||||
|
||||
g_type_class_unref (klass);
|
||||
}
|
||||
|
||||
return WP_TYPE_PROXY;
|
||||
}
|
||||
|
||||
static void
|
||||
registry_global (void *data, uint32_t id, uint32_t permissions,
|
||||
const char *type, uint32_t version, const struct spa_dict *props)
|
||||
|
|
@ -136,8 +160,7 @@ registry_global (void *data, uint32_t id, uint32_t permissions,
|
|||
/* construct & store the global */
|
||||
global = wp_global_new ();
|
||||
global->id = id;
|
||||
global->type = g_strdup (type);
|
||||
global->version = version;
|
||||
global->type = find_proxy_instance_type (type, version);
|
||||
global->permissions = permissions;
|
||||
global->properties = wp_properties_new_copy_dict (props);
|
||||
|
||||
|
|
@ -162,8 +185,7 @@ registry_global_remove (void *data, uint32_t id)
|
|||
|
||||
global = g_steal_pointer (&g_ptr_array_index (self->globals, id));
|
||||
|
||||
g_debug ("registry global removed:%u type:%s/%u", id,
|
||||
global->type, global->version);
|
||||
g_debug ("registry global removed:%u type:%s", id, g_type_name (global->type));
|
||||
|
||||
/* notify object managers */
|
||||
for (i = 0; i < self->object_managers->len; i++) {
|
||||
|
|
|
|||
|
|
@ -12,10 +12,7 @@
|
|||
|
||||
struct interest
|
||||
{
|
||||
union {
|
||||
char * proxy_type;
|
||||
GType g_type;
|
||||
};
|
||||
GType g_type;
|
||||
gboolean for_proxy;
|
||||
WpProxyFeatures wanted_features;
|
||||
GVariant *constraints; // aa{sv}
|
||||
|
|
@ -71,8 +68,6 @@ wp_object_manager_finalize (GObject * object)
|
|||
g_clear_pointer (&self->objects, g_ptr_array_unref);
|
||||
|
||||
pw_array_for_each (i, &self->interests) {
|
||||
if (i->for_proxy)
|
||||
g_clear_pointer (&i->proxy_type, g_free);
|
||||
g_clear_pointer (&i->constraints, g_variant_unref);
|
||||
}
|
||||
pw_array_clear (&self->interests);
|
||||
|
|
@ -150,19 +145,19 @@ wp_object_manager_new (void)
|
|||
|
||||
void
|
||||
wp_object_manager_add_proxy_interest (WpObjectManager *self,
|
||||
const gchar * iface_type, GVariant * constraints,
|
||||
GType gtype, GVariant * constraints,
|
||||
WpProxyFeatures wanted_features)
|
||||
{
|
||||
struct interest *i;
|
||||
|
||||
g_return_if_fail (WP_IS_OBJECT_MANAGER (self));
|
||||
g_return_if_fail (iface_type != 0);
|
||||
g_return_if_fail (g_type_is_a (gtype, WP_TYPE_PROXY));
|
||||
g_return_if_fail (constraints == NULL ||
|
||||
g_variant_is_of_type (constraints, G_VARIANT_TYPE ("aa{sv}")));
|
||||
|
||||
/* grow the array by 1 struct interest and fill it in */
|
||||
i = pw_array_add (&self->interests, sizeof (struct interest));
|
||||
i->proxy_type = g_strdup (iface_type);
|
||||
i->g_type = gtype;
|
||||
i->for_proxy = TRUE;
|
||||
i->wanted_features = wanted_features;
|
||||
i->constraints = constraints ? g_variant_ref_sink (constraints) : NULL;
|
||||
|
|
@ -354,7 +349,7 @@ wp_object_manager_is_interested_in_global (WpObjectManager * self,
|
|||
|
||||
pw_array_for_each (i, &self->interests) {
|
||||
if (i->for_proxy
|
||||
&& g_strcmp0 (i->proxy_type, global->type) == 0
|
||||
&& g_type_is_a (global->type, i->g_type)
|
||||
&& (!i->constraints ||
|
||||
check_constraints (i->constraints, global->properties, NULL)))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ WpObjectManager * wp_object_manager_new (void);
|
|||
|
||||
WP_API
|
||||
void wp_object_manager_add_proxy_interest (WpObjectManager *self,
|
||||
const gchar * iface_type, GVariant * constraints,
|
||||
WpProxyFeatures wanted_features);
|
||||
GType gtype, GVariant * constraints, WpProxyFeatures wanted_features);
|
||||
|
||||
WP_API
|
||||
void wp_object_manager_add_object_interest (WpObjectManager *self,
|
||||
|
|
|
|||
|
|
@ -34,8 +34,7 @@ typedef struct _WpGlobal WpGlobal;
|
|||
struct _WpGlobal
|
||||
{
|
||||
guint32 id;
|
||||
char *type;
|
||||
guint32 version;
|
||||
GType type;
|
||||
guint32 permissions;
|
||||
WpProperties *properties;
|
||||
GWeakRef proxy;
|
||||
|
|
@ -52,7 +51,6 @@ wp_global_new (void)
|
|||
static inline void
|
||||
wp_global_clear (WpGlobal * self)
|
||||
{
|
||||
g_clear_pointer (&self->type, g_free);
|
||||
g_clear_pointer (&self->properties, wp_properties_unref);
|
||||
g_weak_ref_clear (&self->proxy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,14 +13,6 @@
|
|||
#include "wpenums.h"
|
||||
#include "private.h"
|
||||
|
||||
#include "endpoint.h"
|
||||
#include "client.h"
|
||||
#include "device.h"
|
||||
#include "link.h"
|
||||
#include "node.h"
|
||||
#include "port.h"
|
||||
#include "session.h"
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
#include <pipewire/impl.h>
|
||||
#include <pipewire/extensions/metadata.h>
|
||||
|
|
@ -75,30 +67,6 @@ static guint wp_proxy_signals[LAST_SIGNAL] = { 0 };
|
|||
G_DEFINE_BOXED_TYPE (WpGlobal, wp_global, wp_global_ref, wp_global_unref)
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (WpProxy, wp_proxy, G_TYPE_OBJECT)
|
||||
|
||||
/* find the subclass of WpProxy that can handle
|
||||
the given pipewire interface type of the given version */
|
||||
static inline GType
|
||||
wp_proxy_find_instance_type (const char * type, guint32 version)
|
||||
{
|
||||
g_autofree GType *children;
|
||||
guint n_children;
|
||||
|
||||
children = g_type_children (WP_TYPE_PROXY, &n_children);
|
||||
|
||||
for (gint i = 0; i < n_children; i++) {
|
||||
WpProxyClass *klass = (WpProxyClass *) g_type_class_ref (children[i]);
|
||||
if (g_strcmp0 (klass->pw_iface_type, type) == 0 &&
|
||||
klass->pw_iface_version == version) {
|
||||
g_type_class_unref (klass);
|
||||
return children[i];
|
||||
}
|
||||
|
||||
g_type_class_unref (klass);
|
||||
}
|
||||
|
||||
return WP_TYPE_PROXY;
|
||||
}
|
||||
|
||||
static void
|
||||
proxy_event_destroy (void *data)
|
||||
{
|
||||
|
|
@ -285,6 +253,7 @@ static void
|
|||
wp_proxy_default_augment (WpProxy * self, WpProxyFeatures features)
|
||||
{
|
||||
WpProxyPrivate *priv = wp_proxy_get_instance_private (self);
|
||||
WpProxyClass *klass = WP_PROXY_GET_CLASS (self);
|
||||
g_autoptr (WpCore) core = NULL;
|
||||
|
||||
/* ensure we have a pw_proxy, as we can't have
|
||||
|
|
@ -309,7 +278,7 @@ wp_proxy_default_augment (WpProxy * self, WpProxyFeatures features)
|
|||
/* bind */
|
||||
wp_proxy_set_pw_proxy (self, pw_registry_bind (
|
||||
wp_core_get_pw_registry (core), priv->global->id,
|
||||
priv->global->type, priv->global->version, 0));
|
||||
klass->pw_iface_type, klass->pw_iface_version, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -389,8 +358,7 @@ wp_proxy_class_init (WpProxyClass * klass)
|
|||
WpProxy *
|
||||
wp_proxy_new_global (WpCore * core, WpGlobal * global)
|
||||
{
|
||||
GType gtype = wp_proxy_find_instance_type (global->type, global->version);
|
||||
return g_object_new (gtype,
|
||||
return g_object_new (global->type,
|
||||
"core", core,
|
||||
"global", global,
|
||||
NULL);
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ wireplumber__module_init (WpModule * module, WpCore * core, GVariant * args)
|
|||
WpObjectManager *om;
|
||||
|
||||
om = wp_object_manager_new ();
|
||||
wp_object_manager_add_proxy_interest (om, PW_TYPE_INTERFACE_Client, NULL,
|
||||
WP_PROXY_FEATURE_PW_PROXY | WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND);
|
||||
wp_object_manager_add_proxy_interest (om, WP_TYPE_CLIENT, NULL,
|
||||
WP_PROXY_FEATURES_STANDARD);
|
||||
|
||||
g_signal_connect (om, "object-added", (GCallback) client_added, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -256,8 +256,8 @@ wp_config_endpoint_context_init (WpConfigEndpointContext *self)
|
|||
g_direct_equal, NULL, (GDestroyNotify) g_object_unref);
|
||||
|
||||
/* Only handle augmented nodes with info set */
|
||||
wp_object_manager_add_proxy_interest (self->om, PW_TYPE_INTERFACE_Node, NULL,
|
||||
WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND);
|
||||
wp_object_manager_add_proxy_interest (self->om, WP_TYPE_NODE, NULL,
|
||||
WP_PROXY_FEATURES_STANDARD);
|
||||
|
||||
/* Register the global added/removed callbacks */
|
||||
g_signal_connect(self->om, "object-added",
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@
|
|||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
#include "parser-node.h"
|
||||
|
|
@ -208,7 +206,7 @@ wp_config_static_nodes_context_init (WpConfigStaticNodesContext *self)
|
|||
|
||||
/* Only handle devices */
|
||||
wp_object_manager_add_proxy_interest (self->devices_om,
|
||||
PW_TYPE_INTERFACE_Device, NULL, WP_PROXY_FEATURE_INFO);
|
||||
WP_TYPE_DEVICE, NULL, WP_PROXY_FEATURE_INFO);
|
||||
g_signal_connect (self->devices_om, "object-added",
|
||||
(GCallback) on_device_added, self);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ on_node_proxy_augmented (WpProxy * proxy, GAsyncResult * res,
|
|||
g_variant_builder_close (&b);
|
||||
|
||||
/* declare interest on ports with this constraint */
|
||||
wp_object_manager_add_proxy_interest (priv->ports_om, PW_TYPE_INTERFACE_Port,
|
||||
wp_object_manager_add_proxy_interest (priv->ports_om, WP_TYPE_PORT,
|
||||
g_variant_builder_end (&b),
|
||||
WP_PROXY_FEATURE_PW_PROXY | WP_PROXY_FEATURE_INFO);
|
||||
|
||||
|
|
|
|||
|
|
@ -234,9 +234,8 @@ test_endpoint_basic (TestEndpointFixture *fixture, gconstpointer data)
|
|||
g_signal_connect (fixture->proxy_om, "object-removed",
|
||||
(GCallback) test_endpoint_basic_proxy_object_removed, fixture);
|
||||
wp_object_manager_add_proxy_interest (fixture->proxy_om,
|
||||
PW_TYPE_INTERFACE_Endpoint, NULL,
|
||||
WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND |
|
||||
WP_ENDPOINT_FEATURE_CONTROLS);
|
||||
WP_TYPE_ENDPOINT, NULL,
|
||||
WP_PROXY_FEATURES_STANDARD | WP_ENDPOINT_FEATURE_CONTROLS);
|
||||
wp_core_install_object_manager (fixture->proxy_core, fixture->proxy_om);
|
||||
|
||||
g_assert_true (wp_core_connect (fixture->proxy_core));
|
||||
|
|
|
|||
|
|
@ -138,8 +138,7 @@ test_proxy_basic (TestProxyFixture *fixture, gconstpointer data)
|
|||
g_signal_connect (fixture->om, "object-added",
|
||||
(GCallback) test_proxy_basic_object_added, fixture);
|
||||
|
||||
wp_object_manager_add_proxy_interest (fixture->om,
|
||||
PW_TYPE_INTERFACE_Client, NULL, 0);
|
||||
wp_object_manager_add_proxy_interest (fixture->om, WP_TYPE_CLIENT, NULL, 0);
|
||||
wp_core_install_object_manager (fixture->core, fixture->om);
|
||||
|
||||
g_assert_true (wp_core_connect (fixture->core));
|
||||
|
|
@ -241,7 +240,7 @@ test_node (TestProxyFixture *fixture, gconstpointer data)
|
|||
/* declare interest and set default features to be ready
|
||||
when the signal is fired */
|
||||
wp_object_manager_add_proxy_interest (fixture->om,
|
||||
PW_TYPE_INTERFACE_Node, NULL, WP_PROXY_FEATURES_STANDARD);
|
||||
WP_TYPE_NODE, NULL, WP_PROXY_FEATURES_STANDARD);
|
||||
wp_core_install_object_manager (fixture->core, fixture->om);
|
||||
|
||||
g_assert_true (wp_core_connect (fixture->core));
|
||||
|
|
|
|||
|
|
@ -232,9 +232,8 @@ test_session_basic (TestSessionFixture *fixture, gconstpointer data)
|
|||
g_signal_connect (fixture->proxy_om, "object-removed",
|
||||
(GCallback) test_session_basic_proxy_object_removed, fixture);
|
||||
wp_object_manager_add_proxy_interest (fixture->proxy_om,
|
||||
PW_TYPE_INTERFACE_Session, NULL,
|
||||
WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND |
|
||||
WP_SESSION_FEATURE_DEFAULT_ENDPOINT);
|
||||
WP_TYPE_SESSION, NULL,
|
||||
WP_PROXY_FEATURES_STANDARD | WP_SESSION_FEATURE_DEFAULT_ENDPOINT);
|
||||
wp_core_install_object_manager (fixture->proxy_core, fixture->proxy_om);
|
||||
|
||||
g_assert_true (wp_core_connect (fixture->proxy_core));
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include <wp/wp.h>
|
||||
#include <pipewire/pipewire.h>
|
||||
#include <pipewire/extensions/session-manager/interfaces.h>
|
||||
|
||||
static GOptionEntry entries[] =
|
||||
{
|
||||
|
|
@ -259,10 +258,10 @@ main (gint argc, gchar **argv)
|
|||
om = wp_object_manager_new ();
|
||||
|
||||
if (argc == 2 && !g_strcmp0 (argv[1], "ls-endpoints")) {
|
||||
wp_object_manager_add_proxy_interest (om, PW_TYPE_INTERFACE_Endpoint,
|
||||
wp_object_manager_add_proxy_interest (om, WP_TYPE_ENDPOINT,
|
||||
NULL, WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND |
|
||||
WP_ENDPOINT_FEATURE_CONTROLS);
|
||||
wp_object_manager_add_proxy_interest (om, PW_TYPE_INTERFACE_Session,
|
||||
wp_object_manager_add_proxy_interest (om, WP_TYPE_SESSION,
|
||||
NULL, WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND |
|
||||
WP_SESSION_FEATURE_DEFAULT_ENDPOINT);
|
||||
g_signal_connect (om, "objects-changed", (GCallback) list_endpoints, &data);
|
||||
|
|
@ -275,9 +274,9 @@ main (gint argc, gchar **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
wp_object_manager_add_proxy_interest (om, PW_TYPE_INTERFACE_Endpoint,
|
||||
wp_object_manager_add_proxy_interest (om, WP_TYPE_ENDPOINT,
|
||||
NULL, WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND);
|
||||
wp_object_manager_add_proxy_interest (om, PW_TYPE_INTERFACE_Session,
|
||||
wp_object_manager_add_proxy_interest (om, WP_TYPE_SESSION,
|
||||
NULL, WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND |
|
||||
WP_SESSION_FEATURE_DEFAULT_ENDPOINT);
|
||||
|
||||
|
|
@ -293,7 +292,7 @@ main (gint argc, gchar **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
wp_object_manager_add_proxy_interest (om, PW_TYPE_INTERFACE_Endpoint,
|
||||
wp_object_manager_add_proxy_interest (om, WP_TYPE_ENDPOINT,
|
||||
NULL, WP_PROXY_FEATURE_INFO | WP_PROXY_FEATURE_BOUND |
|
||||
WP_ENDPOINT_FEATURE_CONTROLS);
|
||||
|
||||
|
|
@ -303,7 +302,7 @@ main (gint argc, gchar **argv)
|
|||
}
|
||||
|
||||
else if (argc == 2 && !g_strcmp0 (argv[1], "device-node-props")) {
|
||||
wp_object_manager_add_proxy_interest (om, PW_TYPE_INTERFACE_Node, NULL,
|
||||
wp_object_manager_add_proxy_interest (om, WP_TYPE_NODE, NULL,
|
||||
WP_PROXY_FEATURE_INFO);
|
||||
g_signal_connect (om, "objects-changed", (GCallback) device_node_props,
|
||||
&data);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue