lib: proxy: make the pipewire property getter an interface on WpObject

We are going to use this in other object types as well
This commit is contained in:
George Kiagiadakis 2019-04-22 12:44:42 +03:00
parent eeb99f908a
commit 55365e97c1
4 changed files with 68 additions and 26 deletions

View file

@ -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);
}

View file

@ -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

View file

@ -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;
}

View file

@ -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