mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2025-12-25 14:50:04 +01:00
modules: port config-static-nodes to use WpPlugin
This commit is contained in:
parent
faa9719f53
commit
27ff8d5ef2
5 changed files with 36 additions and 97 deletions
|
|
@ -13,6 +13,6 @@
|
|||
WP_PLUGIN_EXPORT void
|
||||
wireplumber__module_init (WpModule * module, WpCore * core, GVariant * args)
|
||||
{
|
||||
WpConfigStaticNodesContext *ctx = wp_config_static_nodes_context_new (core);
|
||||
wp_module_set_destroy_callback (module, g_object_unref, ctx);
|
||||
WpConfigStaticNodesContext *ctx = wp_config_static_nodes_context_new (module);
|
||||
wp_plugin_register (WP_PLUGIN (ctx));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,18 +15,10 @@ struct _WpConfigStaticNodesContext
|
|||
{
|
||||
GObject parent;
|
||||
|
||||
/* Props */
|
||||
GWeakRef core;
|
||||
|
||||
WpObjectManager *devices_om;
|
||||
GPtrArray *static_nodes;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CORE,
|
||||
};
|
||||
|
||||
enum {
|
||||
SIGNAL_NODE_CREATED,
|
||||
N_SIGNALS
|
||||
|
|
@ -35,7 +27,7 @@ enum {
|
|||
static guint signals[N_SIGNALS];
|
||||
|
||||
G_DEFINE_TYPE (WpConfigStaticNodesContext, wp_config_static_nodes_context,
|
||||
G_TYPE_OBJECT)
|
||||
WP_TYPE_PLUGIN)
|
||||
|
||||
static void
|
||||
on_node_created (GObject * proxy, GAsyncResult * res, gpointer user_data)
|
||||
|
|
@ -60,7 +52,7 @@ wp_config_static_nodes_context_create_node (WpConfigStaticNodesContext *self,
|
|||
const struct WpParserNodeData *node_data)
|
||||
{
|
||||
g_autoptr (WpProxy) node = NULL;
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
|
||||
g_autoptr (WpCore) core = wp_plugin_get_core (WP_PLUGIN (self));
|
||||
g_return_if_fail (core);
|
||||
|
||||
/* Create the node */
|
||||
|
|
@ -83,7 +75,7 @@ on_device_added (WpObjectManager *om, WpProxy *proxy, gpointer p)
|
|||
{
|
||||
WpConfigStaticNodesContext *self = p;
|
||||
g_autoptr (WpProperties) dev_props = NULL;
|
||||
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 WpParserNodeData *node_data = NULL;
|
||||
|
|
@ -124,7 +116,7 @@ parser_node_foreach_func (const struct WpParserNodeData *node_data,
|
|||
static void
|
||||
start_static_nodes (WpConfigStaticNodesContext *self)
|
||||
{
|
||||
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 =
|
||||
wp_configuration_get_parser (config, WP_PARSER_NODE_EXTENSION);
|
||||
|
|
@ -135,10 +127,10 @@ start_static_nodes (WpConfigStaticNodesContext *self)
|
|||
}
|
||||
|
||||
static void
|
||||
wp_config_static_nodes_context_constructed (GObject * object)
|
||||
wp_config_static_nodes_context_activate (WpPlugin * plugin)
|
||||
{
|
||||
WpConfigStaticNodesContext *self = WP_CONFIG_STATIC_NODES_CONTEXT (object);
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
|
||||
WpConfigStaticNodesContext *self = WP_CONFIG_STATIC_NODES_CONTEXT (plugin);
|
||||
g_autoptr (WpCore) core = wp_plugin_get_core (plugin);
|
||||
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
|
||||
|
||||
/* Add the node parser and parse the node files */
|
||||
|
|
@ -152,58 +144,21 @@ wp_config_static_nodes_context_constructed (GObject * object)
|
|||
/* Start creating static nodes when the connected callback is triggered */
|
||||
g_signal_connect_object (core, "connected", (GCallback) start_static_nodes,
|
||||
self, G_CONNECT_SWAPPED);
|
||||
|
||||
G_OBJECT_CLASS (wp_config_static_nodes_context_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_static_nodes_context_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
wp_config_static_nodes_context_deactivate (WpPlugin *plugin)
|
||||
{
|
||||
WpConfigStaticNodesContext *self = WP_CONFIG_STATIC_NODES_CONTEXT (object);
|
||||
|
||||
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_static_nodes_context_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpConfigStaticNodesContext *self = WP_CONFIG_STATIC_NODES_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_static_nodes_context_finalize (GObject *object)
|
||||
{
|
||||
WpConfigStaticNodesContext *self = WP_CONFIG_STATIC_NODES_CONTEXT (object);
|
||||
WpConfigStaticNodesContext *self = WP_CONFIG_STATIC_NODES_CONTEXT (plugin);
|
||||
|
||||
g_clear_object (&self->devices_om);
|
||||
g_clear_pointer (&self->static_nodes, g_ptr_array_unref);
|
||||
|
||||
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_NODE_EXTENSION);
|
||||
}
|
||||
g_weak_ref_clear (&self->core);
|
||||
|
||||
G_OBJECT_CLASS (wp_config_static_nodes_context_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -223,18 +178,10 @@ wp_config_static_nodes_context_init (WpConfigStaticNodesContext *self)
|
|||
static void
|
||||
wp_config_static_nodes_context_class_init (WpConfigStaticNodesContextClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpPluginClass *plugin_class = (WpPluginClass *) klass;
|
||||
|
||||
object_class->constructed = wp_config_static_nodes_context_constructed;
|
||||
object_class->finalize = wp_config_static_nodes_context_finalize;
|
||||
object_class->set_property = wp_config_static_nodes_context_set_property;
|
||||
object_class->get_property = wp_config_static_nodes_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_static_nodes_context_activate;
|
||||
plugin_class->deactivate = wp_config_static_nodes_context_deactivate;
|
||||
|
||||
/* Signals */
|
||||
signals[SIGNAL_NODE_CREATED] = g_signal_new ("node-created",
|
||||
|
|
@ -243,16 +190,9 @@ wp_config_static_nodes_context_class_init (WpConfigStaticNodesContextClass *klas
|
|||
}
|
||||
|
||||
WpConfigStaticNodesContext *
|
||||
wp_config_static_nodes_context_new (WpCore *core)
|
||||
wp_config_static_nodes_context_new (WpModule * module)
|
||||
{
|
||||
return g_object_new (wp_config_static_nodes_context_get_type (),
|
||||
"core", core,
|
||||
NULL);
|
||||
}
|
||||
|
||||
guint
|
||||
wp_config_static_nodes_context_get_length (WpConfigStaticNodesContext *self)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_CONFIG_STATIC_NODES_CONTEXT (self), 0);
|
||||
return self->static_nodes->len;
|
||||
"module", module,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,12 +15,9 @@ G_BEGIN_DECLS
|
|||
|
||||
#define WP_TYPE_CONFIG_STATIC_NODES_CONTEXT (wp_config_static_nodes_context_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (WpConfigStaticNodesContext, wp_config_static_nodes_context,
|
||||
WP, CONFIG_STATIC_NODES_CONTEXT, GObject);
|
||||
WP, CONFIG_STATIC_NODES_CONTEXT, WpPlugin);
|
||||
|
||||
WpConfigStaticNodesContext * wp_config_static_nodes_context_new (WpCore *core);
|
||||
|
||||
guint wp_config_static_nodes_context_get_length (
|
||||
WpConfigStaticNodesContext *self);
|
||||
WpConfigStaticNodesContext * wp_config_static_nodes_context_new (WpModule * module);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
#include "../common/base-test-fixture.h"
|
||||
#include "../../modules/module-config-static-nodes/context.h"
|
||||
|
||||
typedef struct {
|
||||
WpBaseTestFixture base;
|
||||
|
|
@ -26,6 +25,13 @@ config_static_nodes_setup (TestConfigStaticNodesFixture *self,
|
|||
pw_context_load_module (self->base.server.context,
|
||||
"libpipewire-module-spa-node-factory", NULL, NULL);
|
||||
pw_thread_loop_unlock (self->base.server.thread_loop);
|
||||
|
||||
/* load wireplumber module */
|
||||
g_autoptr (GError) error = NULL;
|
||||
WpModule *module = wp_module_load (self->base.core, "C",
|
||||
"libwireplumber-module-config-static-nodes", NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_nonnull (module);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -36,8 +42,7 @@ config_static_nodes_teardown (TestConfigStaticNodesFixture *self,
|
|||
}
|
||||
|
||||
static void
|
||||
on_node_created (WpConfigStaticNodesContext *ctx, WpProxy *proxy,
|
||||
TestConfigStaticNodesFixture *f)
|
||||
on_node_created (WpPlugin *ctx, WpProxy *proxy, TestConfigStaticNodesFixture *f)
|
||||
{
|
||||
g_assert_nonnull (proxy);
|
||||
g_main_loop_quit (f->base.loop);
|
||||
|
|
@ -51,23 +56,22 @@ basic (TestConfigStaticNodesFixture *f, gconstpointer data)
|
|||
g_assert_nonnull (config);
|
||||
wp_configuration_add_path (config, "config-static-nodes/basic");
|
||||
|
||||
/* Create the context */
|
||||
g_autoptr (WpConfigStaticNodesContext) ctx =
|
||||
wp_config_static_nodes_context_new (f->base.core);
|
||||
/* Find the plugin context and handle the node-created 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_assert_cmpint (wp_config_static_nodes_context_get_length (ctx), ==, 0);
|
||||
|
||||
/* Add a handler to stop the main loop when a node is created */
|
||||
g_signal_connect (ctx, "node-created", (GCallback) on_node_created, f);
|
||||
|
||||
/* Activate */
|
||||
wp_plugin_activate (ctx);
|
||||
|
||||
/* Connect */
|
||||
g_assert_true (wp_core_connect (f->base.core));
|
||||
|
||||
/* Run the main loop */
|
||||
g_main_loop_run (f->base.loop);
|
||||
|
||||
/* Check if the node was created */
|
||||
g_assert_cmpint (wp_config_static_nodes_context_get_length (ctx), ==, 1);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ test(
|
|||
executable('test-config-static-nodes',
|
||||
[
|
||||
'config-static-nodes.c',
|
||||
'../../modules/module-config-static-nodes/parser-node.c',
|
||||
'../../modules/module-config-static-nodes/context.c',
|
||||
],
|
||||
dependencies: common_deps + [wptoml_dep], c_args: common_args),
|
||||
env: common_env,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue