mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-05 07:48:01 +02:00
wp-factory: enumerate pw_factory objects
pw_factory objects allow permissions to be set on its clients, wp-factory exposes this funtionality to wireplumber clients.
This commit is contained in:
parent
ea229779a8
commit
e2e3c5a69c
7 changed files with 221 additions and 0 deletions
116
lib/wp/factory.c
Normal file
116
lib/wp/factory.c
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2021 Collabora Ltd.
|
||||
* @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "wp-factory"
|
||||
|
||||
#include "factory.h"
|
||||
#include "private/pipewire-object-mixin.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
/*! \defgroup wpfactory WpFactory */
|
||||
/*!
|
||||
* \struct WpFactory
|
||||
*
|
||||
* The WpFactory class allows accessing the properties and methods of
|
||||
* PipeWire Factory objects (`struct pw_factory`).
|
||||
*
|
||||
* A WpFactory is constructed internally by wireplumber, when the pipewire
|
||||
* constructed factory objects are reported in by PipeWire registry
|
||||
* and it is made available for wireplumber clients through the
|
||||
* WpObjectManager API.
|
||||
*/
|
||||
|
||||
struct _WpFactory
|
||||
{
|
||||
WpGlobalProxy parent;
|
||||
};
|
||||
|
||||
static void wp_factory_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface);
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (WpFactory, wp_factory, WP_TYPE_GLOBAL_PROXY,
|
||||
G_IMPLEMENT_INTERFACE (WP_TYPE_PIPEWIRE_OBJECT,
|
||||
wp_pw_object_mixin_object_interface_init)
|
||||
G_IMPLEMENT_INTERFACE (WP_TYPE_PW_OBJECT_MIXIN_PRIV,
|
||||
wp_factory_pw_object_mixin_priv_interface_init))
|
||||
|
||||
static void wp_factory_init (WpFactory * self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
wp_factory_activate_execute_step (WpObject * object,
|
||||
WpFeatureActivationTransition * transition, guint step,
|
||||
WpObjectFeatures missing)
|
||||
{
|
||||
switch (step) {
|
||||
case WP_PW_OBJECT_MIXIN_STEP_BIND:
|
||||
case WP_TRANSITION_STEP_ERROR:
|
||||
/* base class can handle BIND and ERROR */
|
||||
WP_OBJECT_CLASS (wp_factory_parent_class)->
|
||||
activate_execute_step (object, transition, step, missing);
|
||||
break;
|
||||
case WP_PW_OBJECT_MIXIN_STEP_WAIT_INFO:
|
||||
/* just wait, info will be emitted anyway after binding */
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static const struct pw_factory_events factory_events = {
|
||||
PW_VERSION_FACTORY_EVENTS,
|
||||
.info = (HandleEventInfoFunc(factory)) wp_pw_object_mixin_handle_event_info,
|
||||
};
|
||||
|
||||
static void
|
||||
wp_factory_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
|
||||
{
|
||||
wp_pw_object_mixin_handle_pw_proxy_created (proxy, pw_proxy,
|
||||
factory, &factory_events);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_factory_pw_proxy_destroyed (WpProxy * proxy)
|
||||
{
|
||||
wp_pw_object_mixin_handle_pw_proxy_destroyed (proxy);
|
||||
|
||||
WP_PROXY_CLASS (wp_factory_parent_class)->pw_proxy_destroyed (proxy);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_factory_class_init (WpFactoryClass * klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpObjectClass *wpobject_class = (WpObjectClass *) klass;
|
||||
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||
|
||||
object_class->get_property = wp_pw_object_mixin_get_property;
|
||||
|
||||
wpobject_class->get_supported_features =
|
||||
wp_pw_object_mixin_get_supported_features;
|
||||
wpobject_class->activate_get_next_step =
|
||||
wp_pw_object_mixin_activate_get_next_step;
|
||||
wpobject_class->activate_execute_step = wp_factory_activate_execute_step;
|
||||
|
||||
proxy_class->pw_iface_type = PW_TYPE_INTERFACE_Factory;
|
||||
proxy_class->pw_iface_version = PW_VERSION_FACTORY;
|
||||
proxy_class->pw_proxy_created = wp_factory_pw_proxy_created;
|
||||
proxy_class->pw_proxy_destroyed = wp_factory_pw_proxy_destroyed;
|
||||
|
||||
wp_pw_object_mixin_class_override_properties (object_class);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_factory_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface)
|
||||
{
|
||||
wp_pw_object_mixin_priv_interface_info_init_no_params (iface, factory, FACTORY);
|
||||
}
|
||||
29
lib/wp/factory.h
Normal file
29
lib/wp/factory.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2021 Collabora Ltd.
|
||||
* @author Ashok Sidipotu <ashok.sidipotuc@ollabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __WIREPLUMBER_FACTORY_H__
|
||||
#define __WIREPLUMBER_FACTORY_H__
|
||||
|
||||
#include "global-proxy.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct pw_factory;
|
||||
|
||||
/*!
|
||||
* \brief The WpFactory GType
|
||||
* \ingroup wpfactory
|
||||
*/
|
||||
#define WP_TYPE_FACTORY (wp_factory_get_type ())
|
||||
|
||||
WP_API
|
||||
G_DECLARE_FINAL_TYPE (WpFactory, wp_factory, WP, FACTORY, WpGlobalProxy)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
@ -5,6 +5,7 @@ wp_lib_sources = files(
|
|||
'device.c',
|
||||
'endpoint.c',
|
||||
'error.c',
|
||||
'factory.c',
|
||||
'global-proxy.c',
|
||||
'iterator.c',
|
||||
'link.c',
|
||||
|
|
@ -65,6 +66,7 @@ wp_lib_headers = files(
|
|||
'state.h',
|
||||
'transition.h',
|
||||
'wp.h',
|
||||
'factory.h',
|
||||
)
|
||||
|
||||
install_headers(wp_lib_headers,
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ wp_init (WpInitFlags flags)
|
|||
g_type_ensure (WP_TYPE_METADATA);
|
||||
g_type_ensure (WP_TYPE_NODE);
|
||||
g_type_ensure (WP_TYPE_PORT);
|
||||
g_type_ensure (WP_TYPE_FACTORY);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
#include "transition.h"
|
||||
#include "wpenums.h"
|
||||
#include "wpversion.h"
|
||||
#include "factory.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
65
tests/wp/factory.c
Normal file
65
tests/wp/factory.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2021 Collabora Ltd.
|
||||
* @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "../common/base-test-fixture.h"
|
||||
|
||||
typedef struct {
|
||||
WpBaseTestFixture base;
|
||||
WpObjectManager *om;
|
||||
} TestFixture;
|
||||
|
||||
static void
|
||||
test_factory_setup (TestFixture *self, gconstpointer user_data)
|
||||
{
|
||||
wp_base_test_fixture_setup (&self->base, 0);
|
||||
self->om = wp_object_manager_new ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_factory_teardown (TestFixture *self, gconstpointer user_data)
|
||||
{
|
||||
g_clear_object (&self->om);
|
||||
wp_base_test_fixture_teardown (&self->base);
|
||||
}
|
||||
|
||||
static void
|
||||
test_factory_enumeration_object_added (WpObjectManager *om,
|
||||
WpFactory *factory, TestFixture *fixture)
|
||||
{
|
||||
g_autoptr (WpProperties) properties =
|
||||
wp_global_proxy_get_global_properties(WP_GLOBAL_PROXY(factory));
|
||||
const gchar* name = wp_properties_get (properties, PW_KEY_FACTORY_NAME);
|
||||
g_assert_nonnull(name);
|
||||
g_debug("factory name=%s", name);
|
||||
|
||||
/* among all the pw factory objects look for client-node-factory object */
|
||||
if (!g_strcmp0(name, "client-node"))
|
||||
g_main_loop_quit(fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_factory_enumeration (TestFixture *self, gconstpointer user_data)
|
||||
{
|
||||
g_signal_connect (self->om, "object_added",
|
||||
(GCallback) test_factory_enumeration_object_added, self);
|
||||
|
||||
wp_object_manager_add_interest(self->om, WP_TYPE_FACTORY, NULL);
|
||||
wp_core_install_object_manager(self->base.core, self->om);
|
||||
g_main_loop_run(self->base.loop);
|
||||
}
|
||||
|
||||
gint
|
||||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/wp/factory/enumeration", TestFixture, NULL,
|
||||
test_factory_setup, test_factory_enumeration, test_factory_teardown);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
@ -89,3 +89,10 @@ test(
|
|||
dependencies: common_deps, c_args: common_args),
|
||||
env: common_env,
|
||||
)
|
||||
|
||||
test(
|
||||
'test-factory',
|
||||
executable('test-factory', 'factory.c',
|
||||
dependencies: common_deps, c_args: common_args),
|
||||
env: common_env,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue