127 lines
3.1 KiB
C
127 lines
3.1 KiB
C
/* WirePlumber
|
|
*
|
|
* Copyright © 2019 Collabora Ltd.
|
|
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include "proxy-client.h"
|
|
#include "private.h"
|
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
struct _WpProxyClient
|
|
{
|
|
WpProxy parent;
|
|
struct pw_client_info *info;
|
|
|
|
/* The client proxy listener */
|
|
struct spa_hook listener;
|
|
};
|
|
|
|
G_DEFINE_TYPE (WpProxyClient, wp_proxy_client, WP_TYPE_PROXY)
|
|
|
|
static void
|
|
wp_proxy_client_init (WpProxyClient * self)
|
|
{
|
|
}
|
|
|
|
static void
|
|
wp_proxy_client_finalize (GObject * object)
|
|
{
|
|
WpProxyClient *self = WP_PROXY_CLIENT (object);
|
|
|
|
g_clear_pointer (&self->info, pw_client_info_free);
|
|
|
|
G_OBJECT_CLASS (wp_proxy_client_parent_class)->finalize (object);
|
|
}
|
|
|
|
static gconstpointer
|
|
wp_proxy_client_get_info (WpProxy * self)
|
|
{
|
|
return WP_PROXY_CLIENT (self)->info;
|
|
}
|
|
|
|
WpProperties *
|
|
wp_proxy_client_get_properties (WpProxy * self)
|
|
{
|
|
return wp_properties_new_wrap_dict (WP_PROXY_CLIENT (self)->info->props);
|
|
}
|
|
|
|
static void
|
|
client_event_info(void *data, const struct pw_client_info *info)
|
|
{
|
|
WpProxyClient *self = WP_PROXY_CLIENT (data);
|
|
|
|
self->info = pw_client_info_update (self->info, info);
|
|
g_object_notify (G_OBJECT (self), "info");
|
|
|
|
if (info->change_mask & PW_CLIENT_CHANGE_MASK_PROPS)
|
|
g_object_notify (G_OBJECT (self), "properties");
|
|
|
|
wp_proxy_set_feature_ready (WP_PROXY (self), WP_PROXY_FEATURE_INFO);
|
|
}
|
|
|
|
static const struct pw_client_events client_events = {
|
|
PW_VERSION_CLIENT_EVENTS,
|
|
.info = client_event_info,
|
|
};
|
|
|
|
static void
|
|
wp_proxy_client_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
|
|
{
|
|
WpProxyClient *self = WP_PROXY_CLIENT (proxy);
|
|
pw_client_add_listener ((struct pw_client *) pw_proxy,
|
|
&self->listener, &client_events, self);
|
|
}
|
|
|
|
static void
|
|
wp_proxy_client_class_init (WpProxyClientClass * klass)
|
|
{
|
|
GObjectClass *object_class = (GObjectClass *) klass;
|
|
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
|
|
|
object_class->finalize = wp_proxy_client_finalize;
|
|
|
|
proxy_class->get_info = wp_proxy_client_get_info;
|
|
proxy_class->get_properties = wp_proxy_client_get_properties;
|
|
|
|
proxy_class->pw_proxy_created = wp_proxy_client_pw_proxy_created;
|
|
}
|
|
|
|
void
|
|
wp_proxy_client_update_permissions (WpProxyClient * self,
|
|
guint n_perm, ...)
|
|
{
|
|
va_list args;
|
|
struct pw_permission *perm =
|
|
g_alloca (n_perm * sizeof (struct pw_permission));
|
|
|
|
va_start (args, n_perm);
|
|
for (gint i = 0; i < n_perm; i++) {
|
|
perm[i].id = va_arg (args, guint32);
|
|
perm[i].permissions = va_arg (args, guint32);
|
|
}
|
|
va_end (args);
|
|
|
|
wp_proxy_client_update_permissions_array (self, n_perm, perm);
|
|
}
|
|
|
|
void
|
|
wp_proxy_client_update_permissions_array (WpProxyClient * self,
|
|
guint n_perm, const struct pw_permission *permissions)
|
|
{
|
|
struct pw_client *pwp;
|
|
int client_update_permissions_result;
|
|
|
|
g_return_if_fail (WP_IS_PROXY_CLIENT (self));
|
|
|
|
pwp = (struct pw_client *) wp_proxy_get_pw_proxy (WP_PROXY (self));
|
|
g_return_if_fail (pwp != NULL);
|
|
|
|
client_update_permissions_result = pw_client_update_permissions (
|
|
pwp, n_perm, permissions);
|
|
g_warn_if_fail (client_update_permissions_result >= 0);
|
|
}
|