Skip to content
Snippets Groups Projects
Commit 7608ae37 authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

lib: implement WpProxyClient

parent 789194b5
No related branches found
No related tags found
No related merge requests found
...@@ -7,9 +7,10 @@ wp_lib_sources = [ ...@@ -7,9 +7,10 @@ wp_lib_sources = [
'policy.c', 'policy.c',
'properties.c', 'properties.c',
'proxy.c', 'proxy.c',
'proxy-client.c',
'proxy-link.c',
'proxy-node.c', 'proxy-node.c',
'proxy-port.c', 'proxy-port.c',
'proxy-link.c',
'remote.c', 'remote.c',
'remote-pipewire.c', 'remote-pipewire.c',
] ]
...@@ -23,6 +24,7 @@ wp_lib_headers = [ ...@@ -23,6 +24,7 @@ wp_lib_headers = [
'policy.h', 'policy.h',
'properties.h', 'properties.h',
'proxy.h', 'proxy.h',
'proxy-client.h',
'proxy-node.h', 'proxy-node.h',
'proxy-port.h', 'proxy-port.h',
'proxy-link.h', 'proxy-link.h',
......
/* WirePlumber
*
* Copyright © 2019 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#include "proxy-client.h"
#include <pipewire/pipewire.h>
struct _WpProxyClient
{
WpProxy parent;
struct pw_client_info *info;
/* The client proxy listener */
struct spa_hook listener;
};
enum {
PROP_0,
PROP_INFO,
PROP_PROPERTIES,
};
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 void
wp_proxy_client_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{
WpProxyClient *self = WP_PROXY_CLIENT (object);
switch (property_id) {
case PROP_INFO:
g_value_set_pointer (value, self->info);
break;
case PROP_PROPERTIES:
g_value_take_boxed (value, wp_proxy_client_get_properties (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
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_proxy_events client_events = {
PW_VERSION_CLIENT_PROXY_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_proxy_add_listener ((struct pw_client_proxy *) 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;
object_class->get_property = wp_proxy_client_get_property;
proxy_class->pw_proxy_created = wp_proxy_client_pw_proxy_created;
g_object_class_install_property (object_class, PROP_INFO,
g_param_spec_pointer ("info", "info", "The struct pw_client_info *",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the proxy", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
const struct pw_client_info *
wp_proxy_client_get_info (WpProxyClient * self)
{
return self->info;
}
WpProperties *
wp_proxy_client_get_properties (WpProxyClient * self)
{
return wp_properties_new_wrap_dict (self->info->props);
}
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_proxy *pwp;
int client_update_permissions_result;
g_return_if_fail (WP_IS_PROXY_CLIENT (self));
pwp = (struct pw_client_proxy *) wp_proxy_get_pw_proxy (WP_PROXY (self));
g_return_if_fail (pwp != NULL);
client_update_permissions_result = pw_client_proxy_update_permissions (
pwp, n_perm, permissions);
g_warn_if_fail (client_update_permissions_result >= 0);
}
/* WirePlumber
*
* Copyright © 2019 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#ifndef __WIREPLUMBER_PROXY_CLIENT_H__
#define __WIREPLUMBER_PROXY_CLIENT_H__
#include "proxy.h"
G_BEGIN_DECLS
struct pw_client_info;
struct pw_permission;
#define WP_TYPE_PROXY_CLIENT (wp_proxy_client_get_type ())
G_DECLARE_FINAL_TYPE (WpProxyClient, wp_proxy_client, WP, PROXY_CLIENT, WpProxy)
const struct pw_client_info * wp_proxy_client_get_info (WpProxyClient * self);
WpProperties * wp_proxy_client_get_properties (WpProxyClient * self);
void wp_proxy_client_update_permissions (WpProxyClient * self,
guint n_perm, ...);
void wp_proxy_client_update_permissions_array (WpProxyClient * self,
guint n_perm, const struct pw_permission *permissions);
G_END_DECLS
#endif
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "remote-pipewire.h" #include "remote-pipewire.h"
#include "wpenums.h" #include "wpenums.h"
#include "proxy-client.h"
#include "proxy-link.h" #include "proxy-link.h"
#include "proxy-node.h" #include "proxy-node.h"
#include "proxy-port.h" #include "proxy-port.h"
...@@ -97,7 +98,7 @@ static struct { ...@@ -97,7 +98,7 @@ static struct {
{ PW_TYPE_INTERFACE_Port, 0, wp_proxy_port_get_type, wp_proxy_port_quark }, { PW_TYPE_INTERFACE_Port, 0, wp_proxy_port_get_type, wp_proxy_port_quark },
{ PW_TYPE_INTERFACE_Factory, 0, wp_proxy_get_type, wp_proxy_factory_quark }, { PW_TYPE_INTERFACE_Factory, 0, wp_proxy_get_type, wp_proxy_factory_quark },
{ PW_TYPE_INTERFACE_Link, 0, wp_proxy_link_get_type, wp_proxy_link_quark }, { PW_TYPE_INTERFACE_Link, 0, wp_proxy_link_get_type, wp_proxy_link_quark },
{ PW_TYPE_INTERFACE_Client, 0, wp_proxy_get_type, wp_proxy_client_quark }, { PW_TYPE_INTERFACE_Client, 0, wp_proxy_client_get_type, wp_proxy_client_quark },
{ PW_TYPE_INTERFACE_Module, 0, wp_proxy_get_type, wp_proxy_module_quark }, { PW_TYPE_INTERFACE_Module, 0, wp_proxy_get_type, wp_proxy_module_quark },
{ PW_TYPE_INTERFACE_Device, 0, wp_proxy_get_type, wp_proxy_device_quark }, { PW_TYPE_INTERFACE_Device, 0, wp_proxy_get_type, wp_proxy_device_quark },
{ PW_TYPE_INTERFACE_ClientNode, 0, wp_proxy_get_type, wp_proxy_client_node_quark }, { PW_TYPE_INTERFACE_ClientNode, 0, wp_proxy_get_type, wp_proxy_client_node_quark },
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "policy.h" #include "policy.h"
#include "properties.h" #include "properties.h"
#include "proxy.h" #include "proxy.h"
#include "proxy-client.h"
#include "proxy-link.h" #include "proxy-link.h"
#include "proxy-node.h" #include "proxy-node.h"
#include "proxy-port.h" #include "proxy-port.h"
......
...@@ -134,6 +134,7 @@ test_proxy_basic_global_added (WpRemote *remote, WpProxy *proxy, ...@@ -134,6 +134,7 @@ test_proxy_basic_global_added (WpRemote *remote, WpProxy *proxy,
g_assert_cmpstr (wp_proxy_get_interface_name (proxy), ==, g_assert_cmpstr (wp_proxy_get_interface_name (proxy), ==,
"PipeWire:Interface:Client"); "PipeWire:Interface:Client");
g_assert_cmphex (wp_proxy_get_global_permissions (proxy), ==, PW_PERM_RWX); g_assert_cmphex (wp_proxy_get_global_permissions (proxy), ==, PW_PERM_RWX);
g_assert_true (WP_IS_PROXY_CLIENT (proxy));
g_assert_cmphex (wp_proxy_get_features (proxy), ==, 0); g_assert_cmphex (wp_proxy_get_features (proxy), ==, 0);
g_assert_null (wp_proxy_get_pw_proxy (proxy)); g_assert_null (wp_proxy_get_pw_proxy (proxy));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment