From 55365e97c119ace58533adfd12999a0ee0f9aa63 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Mon, 22 Apr 2019 12:44:42 +0300 Subject: [PATCH] lib: proxy: make the pipewire property getter an interface on WpObject We are going to use this in other object types as well --- lib/wp/object.c | 29 +++++++++++++++++++++++++++++ lib/wp/object.h | 16 ++++++++++++++++ lib/wp/proxy.c | 46 +++++++++++++++++++++++----------------------- lib/wp/proxy.h | 3 --- 4 files changed, 68 insertions(+), 26 deletions(-) diff --git a/lib/wp/object.c b/lib/wp/object.c index 3bbf8ca7..d887c906 100644 --- a/lib/wp/object.c +++ b/lib/wp/object.c @@ -176,3 +176,32 @@ wp_object_attach_interface_impl (WpObject * self, gpointer impl, wp_interface_impl_set_object (WP_INTERFACE_IMPL (impl), self); return TRUE; } + +/* WpPipewireProperties */ + +G_DEFINE_INTERFACE (WpPipewireProperties, wp_pipewire_properties, G_TYPE_OBJECT) + +static void +wp_pipewire_properties_default_init (WpPipewirePropertiesInterface * iface) +{ +} + +/** + * wp_pipewire_properties_get: (virtual get) + * @self: the interface + * @key: the name of the property to lookup + * + * Return: (transfer none): The value of the underlying PipeWire object's + * property with this @key, or %NULL. + */ +const gchar * +wp_pipewire_properties_get (WpPipewireProperties * self, const gchar * key) +{ + WpPipewirePropertiesInterface *iface = WP_PIPEWIRE_PROPERTIES_GET_IFACE (self); + + g_return_val_if_fail (WP_IS_PIPEWIRE_PROPERTIES (self), NULL); + g_return_val_if_fail (key != NULL, NULL); + g_return_val_if_fail (iface->get, NULL); + + return iface->get (self, key); +} diff --git a/lib/wp/object.h b/lib/wp/object.h index 138c4bb7..63c6d351 100644 --- a/lib/wp/object.h +++ b/lib/wp/object.h @@ -28,6 +28,22 @@ GType * wp_object_list_interfaces (WpObject * self, guint * n_interfaces); gboolean wp_object_attach_interface_impl (WpObject * self, gpointer impl, GError ** error); +/* WpPipewireProperties */ + +#define WP_TYPE_PIPEWIRE_PROPERTIES (wp_pipewire_properties_get_type ()) +G_DECLARE_INTERFACE (WpPipewireProperties, wp_pipewire_properties, + WP, PIPEWIRE_PROPERTIES, GObject) + +struct _WpPipewirePropertiesInterface +{ + GTypeInterface parent; + + const gchar * (*get) (WpPipewireProperties * self, const gchar * key); +}; + +const gchar * wp_pipewire_properties_get (WpPipewireProperties * self, + const gchar * key); + G_END_DECLS #endif diff --git a/lib/wp/proxy.c b/lib/wp/proxy.c index 2740edc5..19d5781b 100644 --- a/lib/wp/proxy.c +++ b/lib/wp/proxy.c @@ -50,7 +50,11 @@ enum { static guint signals[N_SIGNALS]; -G_DEFINE_TYPE (WpProxy, wp_proxy, wp_object_get_type ()); +static void wp_proxy_pw_properties_init (WpPipewirePropertiesInterface * iface); + +G_DEFINE_TYPE_WITH_CODE (WpProxy, wp_proxy, WP_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (WP_TYPE_PIPEWIRE_PROPERTIES, wp_proxy_pw_properties_init); +) static void spa_dict_to_hashtable (const struct spa_dict * dict, GHashTable * htable) @@ -67,7 +71,7 @@ spa_dict_to_hashtable (const struct spa_dict * dict, GHashTable * htable) { \ static GQuark _quark = 0; \ if (!_quark) \ - g_quark_from_static_string (name); \ + _quark = g_quark_from_static_string (name); \ g_hash_table_insert (self->properties, GUINT_TO_POINTER (_quark), lvalue); \ } @@ -75,7 +79,7 @@ spa_dict_to_hashtable (const struct spa_dict * dict, GHashTable * htable) { \ static GQuark _quark = 0; \ if (!_quark) \ - g_quark_from_static_string (name); \ + _quark = g_quark_from_static_string (name); \ if (!g_hash_table_contains (self->properties, GUINT_TO_POINTER (_quark))) { \ g_hash_table_insert (self->properties, GUINT_TO_POINTER (_quark), lvalue); \ } \ @@ -422,6 +426,22 @@ wp_proxy_class_init (WpProxyClass * klass) G_TYPE_NONE, 0); } +const gchar * +wp_proxy_pw_properties_get (WpPipewireProperties * p, const gchar * property) +{ + WpProxy * self = WP_PROXY (p); + GQuark quark = g_quark_try_string (property); + + return quark ? + g_hash_table_lookup (self->properties, GUINT_TO_POINTER (quark)) : NULL; +} + +static void +wp_proxy_pw_properties_init (WpPipewirePropertiesInterface * iface) +{ + iface->get = wp_proxy_pw_properties_get; +} + /** * wp_proxy_get_id: (method) * @self: the proxy @@ -513,23 +533,3 @@ wp_proxy_get_pw_proxy (WpProxy * self) g_return_val_if_fail (WP_IS_PROXY (self), NULL); return self->proxy; } - -/** - * wp_proxy_get_pw_property: (method) - * @self: the proxy - * @property: (transfer none): the name of the property to lookup - * - * Returns: (transfer none): the value or %NULL - */ -const gchar * -wp_proxy_get_pw_property (WpProxy * self, const gchar * property) -{ - GQuark quark = 0; - - g_return_val_if_fail (WP_IS_PROXY (self), NULL); - g_return_val_if_fail (property != NULL, NULL); - - quark = g_quark_try_string (property); - return quark ? - g_hash_table_lookup (self->properties, GUINT_TO_POINTER (quark)) : NULL; -} diff --git a/lib/wp/proxy.h b/lib/wp/proxy.h index 3a4d9b7c..12971cf5 100644 --- a/lib/wp/proxy.h +++ b/lib/wp/proxy.h @@ -29,9 +29,6 @@ WpProxyRegistry * wp_proxy_get_registry (WpProxy *self); gboolean wp_proxy_is_destroyed (WpProxy * self); struct pw_proxy * wp_proxy_get_pw_proxy (WpProxy * self); -const gchar * wp_proxy_get_pw_property (WpProxy * self, const gchar * property); - - G_END_DECLS #endif