From a92e1a64ec5118aa879939a483e727c2f3307043 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Wed, 12 Feb 2020 14:15:51 +0200 Subject: [PATCH] global & object-manager: use GType instead of the pipewire type --- lib/wp/core.c | 30 +++++++++++++-- lib/wp/object-manager.c | 15 +++----- lib/wp/object-manager.h | 3 +- lib/wp/private.h | 4 +- lib/wp/proxy.c | 38 ++----------------- modules/module-client-permissions.c | 4 +- modules/module-config-endpoint/context.c | 4 +- modules/module-config-static-nodes/context.c | 4 +- .../audio-softdsp-endpoint/stream.c | 2 +- tests/wp/endpoint.c | 5 +-- tests/wp/proxy.c | 5 +-- tests/wp/session.c | 5 +-- tools/wireplumber-cli.c | 13 +++---- 13 files changed, 54 insertions(+), 78 deletions(-) diff --git a/lib/wp/core.c b/lib/wp/core.c index a152c54f..b77f0ef1 100644 --- a/lib/wp/core.c +++ b/lib/wp/core.c @@ -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++) { diff --git a/lib/wp/object-manager.c b/lib/wp/object-manager.c index 2882101a..2bcea915 100644 --- a/lib/wp/object-manager.c +++ b/lib/wp/object-manager.c @@ -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))) { diff --git a/lib/wp/object-manager.h b/lib/wp/object-manager.h index f088788d..e7db5f2b 100644 --- a/lib/wp/object-manager.h +++ b/lib/wp/object-manager.h @@ -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, diff --git a/lib/wp/private.h b/lib/wp/private.h index 0d0da87f..cda33004 100644 --- a/lib/wp/private.h +++ b/lib/wp/private.h @@ -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); } diff --git a/lib/wp/proxy.c b/lib/wp/proxy.c index 82e6bc56..76323b58 100644 --- a/lib/wp/proxy.c +++ b/lib/wp/proxy.c @@ -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 #include #include @@ -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); diff --git a/modules/module-client-permissions.c b/modules/module-client-permissions.c index ff4e46db..b31a5322 100644 --- a/modules/module-client-permissions.c +++ b/modules/module-client-permissions.c @@ -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); diff --git a/modules/module-config-endpoint/context.c b/modules/module-config-endpoint/context.c index 734cb36c..fe138016 100644 --- a/modules/module-config-endpoint/context.c +++ b/modules/module-config-endpoint/context.c @@ -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", diff --git a/modules/module-config-static-nodes/context.c b/modules/module-config-static-nodes/context.c index 2fa77cbc..be5427da 100644 --- a/modules/module-config-static-nodes/context.c +++ b/modules/module-config-static-nodes/context.c @@ -6,8 +6,6 @@ * SPDX-License-Identifier: MIT */ -#include - #include #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); } diff --git a/modules/module-pipewire/audio-softdsp-endpoint/stream.c b/modules/module-pipewire/audio-softdsp-endpoint/stream.c index 08b7d92e..d6006ab7 100644 --- a/modules/module-pipewire/audio-softdsp-endpoint/stream.c +++ b/modules/module-pipewire/audio-softdsp-endpoint/stream.c @@ -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); diff --git a/tests/wp/endpoint.c b/tests/wp/endpoint.c index b3700f69..de79c0f9 100644 --- a/tests/wp/endpoint.c +++ b/tests/wp/endpoint.c @@ -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)); diff --git a/tests/wp/proxy.c b/tests/wp/proxy.c index 90a00de5..0ee030c7 100644 --- a/tests/wp/proxy.c +++ b/tests/wp/proxy.c @@ -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)); diff --git a/tests/wp/session.c b/tests/wp/session.c index 34e74356..fd63839c 100644 --- a/tests/wp/session.c +++ b/tests/wp/session.c @@ -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)); diff --git a/tools/wireplumber-cli.c b/tools/wireplumber-cli.c index c4a0d91e..bd5b9abf 100644 --- a/tools/wireplumber-cli.c +++ b/tools/wireplumber-cli.c @@ -8,7 +8,6 @@ #include #include -#include 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);