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

session-item: implement and use _get_associated_proxy() API

parent 1a45e650
No related branches found
No related tags found
No related merge requests found
...@@ -708,6 +708,7 @@ wp_impl_endpoint_stream_augment (WpProxy * proxy, WpProxyFeatures features) ...@@ -708,6 +708,7 @@ wp_impl_endpoint_stream_augment (WpProxy * proxy, WpProxyFeatures features)
if (features & WP_PROXY_FEATURE_INFO) { if (features & WP_PROXY_FEATURE_INFO) {
const gchar *key, *value; const gchar *key, *value;
g_autoptr (WpProxy) endpoint = NULL;
/* initialize info struct */ /* initialize info struct */
priv->info = &self->info; priv->info = &self->info;
...@@ -718,6 +719,11 @@ wp_impl_endpoint_stream_augment (WpProxy * proxy, WpProxyFeatures features) ...@@ -718,6 +719,11 @@ wp_impl_endpoint_stream_augment (WpProxy * proxy, WpProxyFeatures features)
&self->info.name, &self->info.name,
&immutable_props); &immutable_props);
endpoint = wp_session_item_get_associated_proxy (
WP_SESSION_ITEM (self->item), WP_TYPE_ENDPOINT);
self->info.endpoint_id =
endpoint ? wp_proxy_get_bound_id (endpoint) : SPA_ID_INVALID;
populate_endpoint_stream_info (self, PW_ENDPOINT_STREAM_CHANGE_MASK_ALL); populate_endpoint_stream_info (self, PW_ENDPOINT_STREAM_CHANGE_MASK_ALL);
/* subscribe to changes */ /* subscribe to changes */
...@@ -729,6 +735,10 @@ wp_impl_endpoint_stream_augment (WpProxy * proxy, WpProxyFeatures features) ...@@ -729,6 +735,10 @@ wp_impl_endpoint_stream_augment (WpProxy * proxy, WpProxyFeatures features)
props = wp_properties_new ( props = wp_properties_new (
PW_KEY_ENDPOINT_STREAM_NAME, self->info.name, PW_KEY_ENDPOINT_STREAM_NAME, self->info.name,
NULL); NULL);
if (self->info.endpoint_id != SPA_ID_INVALID) {
wp_properties_setf (props, PW_KEY_ENDPOINT_ID, "%u",
self->info.endpoint_id);
}
while (g_variant_iter_next (immutable_props, "{&s&s}", &key, &value)) { while (g_variant_iter_next (immutable_props, "{&s&s}", &key, &value)) {
wp_properties_set (props, key, value); wp_properties_set (props, key, value);
} }
......
...@@ -647,10 +647,10 @@ populate_endpoint_info (WpImplEndpoint * self, guint32 change_mask) ...@@ -647,10 +647,10 @@ populate_endpoint_info (WpImplEndpoint * self, guint32 change_mask)
} }
if (change_mask & PW_ENDPOINT_CHANGE_MASK_SESSION) { if (change_mask & PW_ENDPOINT_CHANGE_MASK_SESSION) {
g_autoptr (WpSession) session = g_autoptr (WpProxy) session = wp_session_item_get_associated_proxy (
wp_session_item_get_session (WP_SESSION_ITEM (self->item)); WP_SESSION_ITEM (self->item), WP_TYPE_SESSION);
self->info.session_id = self->info.session_id =
session ? wp_proxy_get_bound_id (WP_PROXY (session)) : SPA_ID_INVALID; session ? wp_proxy_get_bound_id (session) : SPA_ID_INVALID;
} }
if (change_mask & PW_ENDPOINT_CHANGE_MASK_PROPS) { if (change_mask & PW_ENDPOINT_CHANGE_MASK_PROPS) {
......
...@@ -117,6 +117,34 @@ wp_session_item_finalize (GObject * object) ...@@ -117,6 +117,34 @@ wp_session_item_finalize (GObject * object)
G_OBJECT_CLASS (wp_session_item_parent_class)->finalize (object); G_OBJECT_CLASS (wp_session_item_parent_class)->finalize (object);
} }
static gpointer
wp_session_item_default_get_associated_proxy (WpSessionItem * self,
GType proxy_type)
{
WpSessionItemPrivate *priv;
if (WP_IS_SI_STREAM (self)) {
WpSiEndpoint *ep = wp_si_stream_get_parent_endpoint (WP_SI_STREAM (self));
priv = wp_session_item_get_instance_private (WP_SESSION_ITEM (ep));
} else {
priv = wp_session_item_get_instance_private (self);
}
if (proxy_type == WP_TYPE_SESSION) {
return g_weak_ref_get (&priv->session);
}
else if (proxy_type == WP_TYPE_ENDPOINT) {
return priv->impl_endpoint ? g_object_ref (priv->impl_endpoint) : NULL;
}
else if (proxy_type == WP_TYPE_ENDPOINT_STREAM) {
gpointer impl_stream = priv->impl_streams ?
g_hash_table_lookup (priv->impl_streams, self) : NULL;
return impl_stream ? g_object_ref (impl_stream) : NULL;
}
return NULL;
}
static guint static guint
wp_session_item_default_get_next_step (WpSessionItem * self, wp_session_item_default_get_next_step (WpSessionItem * self,
WpTransition * transition, guint step) WpTransition * transition, guint step)
...@@ -352,6 +380,7 @@ wp_session_item_class_init (WpSessionItemClass * klass) ...@@ -352,6 +380,7 @@ wp_session_item_class_init (WpSessionItemClass * klass)
object_class->dispose = wp_session_item_dispose; object_class->dispose = wp_session_item_dispose;
object_class->finalize = wp_session_item_finalize; object_class->finalize = wp_session_item_finalize;
klass->get_associated_proxy = wp_session_item_default_get_associated_proxy;
klass->get_next_step = wp_session_item_default_get_next_step; klass->get_next_step = wp_session_item_default_get_next_step;
klass->execute_step = wp_session_item_default_execute_step; klass->execute_step = wp_session_item_default_execute_step;
klass->reset = wp_session_item_default_reset; klass->reset = wp_session_item_default_reset;
...@@ -370,23 +399,6 @@ wp_session_item_class_init (WpSessionItemClass * klass) ...@@ -370,23 +399,6 @@ wp_session_item_class_init (WpSessionItemClass * klass)
G_TYPE_NONE, 1, WP_TYPE_SI_FLAGS); G_TYPE_NONE, 1, WP_TYPE_SI_FLAGS);
} }
/**
* wp_session_item_get_session:
* @self: the session item
*
* Returns: (nullable) (transfer full): the session that owns this item, or
* %NULL if this item is not part of a session
*/
WpSession *
wp_session_item_get_session (WpSessionItem * self)
{
g_return_val_if_fail (WP_IS_SESSION_ITEM (self), NULL);
WpSessionItemPrivate *priv =
wp_session_item_get_instance_private (self);
return g_weak_ref_get (&priv->session);
}
/** /**
* wp_session_item_get_flags: * wp_session_item_get_flags:
* @self: the session item * @self: the session item
...@@ -455,6 +467,37 @@ wp_session_item_clear_flag (WpSessionItem * self, WpSiFlags flag) ...@@ -455,6 +467,37 @@ wp_session_item_clear_flag (WpSessionItem * self, WpSiFlags flag)
} }
} }
/**
* wp_session_item_get_associated_proxy: (virtual get_associated_proxy)
* @self: the session item
* @proxy_type: a #WpProxy subclass #GType
*
* An associated proxy is a #WpProxy subclass instance that is somehow related
* to this item. For example:
* - An exported #WpSiEndpoint should have at least:
* - an associated #WpEndpoint
* - an associated #WpSession
* - An exported #WpSiStream should have at least:
* - an associated #WpEndpointStream
* - an associated #WpEndpoint
* - In cases where the item wraps a single PipeWire node, it should also
* have an associated #WpNode
*
* Returns: (nullable) (transfer full) (type WpProxy): the associated proxy
* of the specified @proxy_type, or %NULL if there is no association to
* such a proxy
*/
gpointer
wp_session_item_get_associated_proxy (WpSessionItem * self, GType proxy_type)
{
g_return_val_if_fail (WP_IS_SESSION_ITEM (self), NULL);
g_return_val_if_fail (WP_SESSION_ITEM_GET_CLASS (self)->get_associated_proxy,
NULL);
g_return_val_if_fail (g_type_is_a (proxy_type, WP_TYPE_PROXY), NULL);
return WP_SESSION_ITEM_GET_CLASS (self)->get_associated_proxy (self, proxy_type);
}
/** /**
* wp_session_item_configure: (virtual configure) * wp_session_item_configure: (virtual configure)
* @self: the session item * @self: the session item
......
...@@ -64,6 +64,7 @@ typedef enum { ...@@ -64,6 +64,7 @@ typedef enum {
/** /**
* WpSessionItemClass: * WpSessionItemClass:
* @get_associated_proxy: See wp_session_item_get_associated_proxy()
* @configure: See wp_session_item_configure() * @configure: See wp_session_item_configure()
* @get_configuration: See wp_session_item_get_configuration() * @get_configuration: See wp_session_item_get_configuration()
* @get_next_step: Implements #WpTransitionClass.get_next_step() for the * @get_next_step: Implements #WpTransitionClass.get_next_step() for the
...@@ -79,6 +80,8 @@ struct _WpSessionItemClass ...@@ -79,6 +80,8 @@ struct _WpSessionItemClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
gpointer (*get_associated_proxy) (WpSessionItem * self, GType proxy_type);
gboolean (*configure) (WpSessionItem * self, GVariant * args); gboolean (*configure) (WpSessionItem * self, GVariant * args);
GVariant * (*get_configuration) (WpSessionItem * self); GVariant * (*get_configuration) (WpSessionItem * self);
...@@ -97,10 +100,7 @@ struct _WpSessionItemClass ...@@ -97,10 +100,7 @@ struct _WpSessionItemClass
void (*unexport) (WpSessionItem * self); void (*unexport) (WpSessionItem * self);
}; };
/* properties */ /* flags */
WP_API
WpSession * wp_session_item_get_session (WpSessionItem * self);
WP_API WP_API
WpSiFlags wp_session_item_get_flags (WpSessionItem * self); WpSiFlags wp_session_item_get_flags (WpSessionItem * self);
...@@ -111,6 +111,12 @@ void wp_session_item_set_flag (WpSessionItem * self, WpSiFlags flag); ...@@ -111,6 +111,12 @@ void wp_session_item_set_flag (WpSessionItem * self, WpSiFlags flag);
WP_API WP_API
void wp_session_item_clear_flag (WpSessionItem * self, WpSiFlags flag); void wp_session_item_clear_flag (WpSessionItem * self, WpSiFlags flag);
/* associated proxies */
WP_API
gpointer wp_session_item_get_associated_proxy (WpSessionItem * self,
GType proxy_type);
/* configuration */ /* configuration */
WP_API WP_API
......
...@@ -79,6 +79,18 @@ si_adapter_reset (WpSessionItem * item) ...@@ -79,6 +79,18 @@ si_adapter_reset (WpSessionItem * item)
WP_SESSION_ITEM_CLASS (si_adapter_parent_class)->reset (item); WP_SESSION_ITEM_CLASS (si_adapter_parent_class)->reset (item);
} }
static gpointer
si_adapter_get_associated_proxy (WpSessionItem * item, GType proxy_type)
{
WpSiAdapter *self = WP_SI_ADAPTER (item);
if (proxy_type == WP_TYPE_NODE)
return self->node ? g_object_ref (self->node) : NULL;
return WP_SESSION_ITEM_CLASS (si_adapter_parent_class)->get_associated_proxy (
item, proxy_type);
}
static GVariant * static GVariant *
si_adapter_get_configuration (WpSessionItem * item) si_adapter_get_configuration (WpSessionItem * item)
{ {
...@@ -355,6 +367,7 @@ si_adapter_class_init (WpSiAdapterClass * klass) ...@@ -355,6 +367,7 @@ si_adapter_class_init (WpSiAdapterClass * klass)
object_class->finalize = si_adapter_finalize; object_class->finalize = si_adapter_finalize;
si_class->get_associated_proxy = si_adapter_get_associated_proxy;
si_class->configure = si_adapter_configure; si_class->configure = si_adapter_configure;
si_class->get_configuration = si_adapter_get_configuration; si_class->get_configuration = si_adapter_get_configuration;
si_class->get_next_step = si_adapter_get_next_step; si_class->get_next_step = si_adapter_get_next_step;
......
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