mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-04-14 17:10:38 +02:00
modules: port config-policy to use WpPlugin
This commit is contained in:
parent
1aefda4128
commit
faa9719f53
5 changed files with 32 additions and 79 deletions
|
|
@ -13,6 +13,6 @@
|
|||
WP_PLUGIN_EXPORT void
|
||||
wireplumber__module_init (WpModule * module, WpCore * core, GVariant * args)
|
||||
{
|
||||
WpConfigPolicyContext *ctx = wp_config_policy_context_new (core);
|
||||
wp_module_set_destroy_callback (module, g_object_unref, ctx);
|
||||
WpConfigPolicyContext *ctx = wp_config_policy_context_new (module);
|
||||
wp_plugin_register (WP_PLUGIN (ctx));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,17 +32,9 @@ struct _WpConfigPolicyContext
|
|||
{
|
||||
GObject parent;
|
||||
|
||||
/* Props */
|
||||
GWeakRef core;
|
||||
|
||||
WpObjectManager *sessions_om;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CORE,
|
||||
};
|
||||
|
||||
enum {
|
||||
SIGNAL_LINK_ACTIVATED,
|
||||
N_SIGNALS
|
||||
|
|
@ -51,7 +43,7 @@ enum {
|
|||
static guint signals[N_SIGNALS];
|
||||
|
||||
G_DEFINE_TYPE (WpConfigPolicyContext, wp_config_policy_context,
|
||||
G_TYPE_OBJECT)
|
||||
WP_TYPE_PLUGIN)
|
||||
|
||||
static WpEndpoint *
|
||||
wp_config_policy_context_get_data_target (WpConfigPolicyContext *self,
|
||||
|
|
@ -140,7 +132,7 @@ static void
|
|||
wp_config_policy_context_add_link_info (WpConfigPolicyContext *self,
|
||||
GHashTable *table, WpSession *session, WpEndpoint *ep)
|
||||
{
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
|
||||
g_autoptr (WpCore) core = wp_plugin_get_core (WP_PLUGIN (self));
|
||||
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
|
||||
g_autoptr (WpConfigParser) parser = NULL;
|
||||
const struct WpParserEndpointLinkData *data = NULL;
|
||||
|
|
@ -315,10 +307,10 @@ on_session_added (WpObjectManager *om, WpProxy *proxy,
|
|||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_constructed (GObject * object)
|
||||
wp_config_policy_context_activate (WpPlugin * plugin)
|
||||
{
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (object);
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (plugin);
|
||||
g_autoptr (WpCore) core = wp_plugin_get_core (plugin);
|
||||
g_return_if_fail (core);
|
||||
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
|
||||
g_return_if_fail (config);
|
||||
|
|
@ -331,86 +323,41 @@ wp_config_policy_context_constructed (GObject * object)
|
|||
wp_configuration_reload (config, WP_PARSER_ENDPOINT_LINK_EXTENSION);
|
||||
|
||||
/* Install the session object manager */
|
||||
self->sessions_om = wp_object_manager_new ();
|
||||
wp_object_manager_add_interest_1 (self->sessions_om, WP_TYPE_SESSION, NULL);
|
||||
wp_object_manager_request_proxy_features (self->sessions_om, WP_TYPE_SESSION,
|
||||
WP_SESSION_FEATURES_STANDARD);
|
||||
g_signal_connect_object (self->sessions_om, "object-added",
|
||||
G_CALLBACK (on_session_added), self, 0);
|
||||
wp_core_install_object_manager (core, self->sessions_om);
|
||||
|
||||
G_OBJECT_CLASS (wp_config_policy_context_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
wp_config_policy_context_deactivate (WpPlugin *plugin)
|
||||
{
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (object);
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (plugin);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_CORE:
|
||||
g_weak_ref_set (&self->core, g_value_get_object (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_CORE:
|
||||
g_value_take_object (value, g_weak_ref_get (&self->core));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_finalize (GObject *object)
|
||||
{
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (object);
|
||||
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
|
||||
g_autoptr (WpCore) core = wp_plugin_get_core (plugin);
|
||||
if (core) {
|
||||
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
|
||||
wp_configuration_remove_extension (config, WP_PARSER_ENDPOINT_LINK_EXTENSION);
|
||||
}
|
||||
g_weak_ref_clear (&self->core);
|
||||
|
||||
g_clear_object (&self->sessions_om);
|
||||
|
||||
G_OBJECT_CLASS (wp_config_policy_context_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_init (WpConfigPolicyContext *self)
|
||||
{
|
||||
self->sessions_om = wp_object_manager_new ();
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_class_init (WpConfigPolicyContextClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpPluginClass *plugin_class = (WpPluginClass *) klass;
|
||||
|
||||
object_class->constructed = wp_config_policy_context_constructed;
|
||||
object_class->finalize = wp_config_policy_context_finalize;
|
||||
object_class->set_property = wp_config_policy_context_set_property;
|
||||
object_class->get_property = wp_config_policy_context_get_property;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property (object_class, PROP_CORE,
|
||||
g_param_spec_object ("core", "core", "The wireplumber core",
|
||||
WP_TYPE_CORE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
plugin_class->activate = wp_config_policy_context_activate;
|
||||
plugin_class->deactivate = wp_config_policy_context_deactivate;
|
||||
|
||||
/* Signals */
|
||||
signals[SIGNAL_LINK_ACTIVATED] = g_signal_new ("link-activated",
|
||||
|
|
@ -419,9 +366,9 @@ wp_config_policy_context_class_init (WpConfigPolicyContextClass *klass)
|
|||
}
|
||||
|
||||
WpConfigPolicyContext *
|
||||
wp_config_policy_context_new (WpCore *core)
|
||||
wp_config_policy_context_new (WpModule * module)
|
||||
{
|
||||
return g_object_new (wp_config_policy_context_get_type (),
|
||||
"core", core,
|
||||
NULL);
|
||||
"module", module,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ G_BEGIN_DECLS
|
|||
|
||||
#define WP_TYPE_CONFIG_POLICY_CONTEXT (wp_config_policy_context_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (WpConfigPolicyContext, wp_config_policy_context,
|
||||
WP, CONFIG_POLICY_CONTEXT, GObject);
|
||||
WP, CONFIG_POLICY_CONTEXT, WpPlugin);
|
||||
|
||||
WpConfigPolicyContext * wp_config_policy_context_new (WpCore *core);
|
||||
WpConfigPolicyContext * wp_config_policy_context_new (WpModule *module);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
#include "../common/base-test-fixture.h"
|
||||
#include "../../modules/module-config-policy/context.h"
|
||||
|
||||
typedef struct {
|
||||
WpBaseTestFixture base;
|
||||
|
|
@ -193,6 +192,10 @@ config_policy_setup (TestFixture *f, gconstpointer user_data)
|
|||
"libwireplumber-module-si-standard-link", NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_nonnull (module);
|
||||
module = wp_module_load (f->base.core, "C",
|
||||
"libwireplumber-module-config-policy", NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_nonnull (module);
|
||||
}
|
||||
|
||||
g_assert_nonnull (
|
||||
|
|
@ -212,7 +215,7 @@ config_policy_teardown (TestFixture *f, gconstpointer user_data)
|
|||
}
|
||||
|
||||
static void
|
||||
on_link_activated (WpConfigPolicyContext *ctx, WpEndpointLink *ep_link,
|
||||
on_link_activated (WpPlugin *ctx, WpEndpointLink *ep_link,
|
||||
TestFixture *f)
|
||||
{
|
||||
g_assert_nonnull (ep_link);
|
||||
|
|
@ -227,12 +230,17 @@ playback (TestFixture *f, gconstpointer data)
|
|||
g_assert_nonnull (config);
|
||||
wp_configuration_add_path (config, "config-policy/playback");
|
||||
|
||||
/* Create the policy context and handle the done callback */
|
||||
g_autoptr (WpConfigPolicyContext) ctx =
|
||||
wp_config_policy_context_new (f->base.core);
|
||||
/* Find the plugin context and handle the link-activated callback */
|
||||
g_autoptr (WpObjectManager) om = wp_object_manager_new ();
|
||||
wp_object_manager_add_interest_1 (om, WP_TYPE_PLUGIN, NULL);
|
||||
wp_core_install_object_manager (f->base.core, om);
|
||||
g_autoptr (WpPlugin) ctx = wp_object_manager_lookup (om, WP_TYPE_PLUGIN, NULL);
|
||||
g_assert_nonnull (ctx);
|
||||
g_signal_connect (ctx, "link-activated", (GCallback) on_link_activated, f);
|
||||
|
||||
/* Activate */
|
||||
wp_plugin_activate (ctx);
|
||||
|
||||
/* Create the items and make sure a link is created */
|
||||
g_autoptr (WpSessionItem) sink = load_item (f, "fakesink", "Audio/Sink");
|
||||
g_assert_nonnull (sink);
|
||||
|
|
|
|||
|
|
@ -46,8 +46,6 @@ test(
|
|||
executable('test-config-policy',
|
||||
[
|
||||
'config-policy.c',
|
||||
'../../modules/module-config-policy/parser-endpoint-link.c',
|
||||
'../../modules/module-config-policy/context.c',
|
||||
],
|
||||
dependencies: common_deps + [wptoml_dep], c_args: common_args),
|
||||
env: common_env,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue