| 1 |
/* WirePlumber |
| 2 |
* |
| 3 |
* Copyright © 2023 Collabora Ltd. |
| 4 |
* Copyright © 2023 Pauli Virtanen <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <wp/wp.h> |
| 10 |
#include <errno.h> |
| 11 |
#include <pipewire/pipewire.h> |
| 12 |
#include <pipewire/keys.h> |
| 13 |
|
| 14 |
WP_DEFINE_LOCAL_LOG_TOPIC ("m-log-settings") |
| 15 |
|
| 16 |
struct _WpLogSettingsPlugin |
| 17 |
{ |
| 18 |
WpPlugin parent; |
| 19 |
WpObjectManager *metadata_om; |
| 20 |
}; |
| 21 |
|
| 22 |
G_DECLARE_FINAL_TYPE (WpLogSettingsPlugin, wp_log_settings_plugin, |
| 23 |
WP, LOG_SETTINGS_PLUGIN, WpPlugin) |
| 24 |
G_DEFINE_TYPE (WpLogSettingsPlugin, wp_log_settings_plugin, WP_TYPE_PLUGIN) |
| 25 |
|
| 26 |
static void |
| 27 |
wp_log_settings_plugin_init (WpLogSettingsPlugin * self) |
| 28 |
{ |
| 29 |
} |
| 30 |
|
| 31 |
static void |
| 32 |
on_metadata_changed (WpMetadata *m, guint32 subject, |
| 33 |
const gchar *key, const gchar *type, const gchar *value, gpointer d) |
| 34 |
{ |
| 35 |
WpLogSettingsPlugin * self = WP_LOG_SETTINGS_PLUGIN (d); |
| 36 |
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self)); |
| 37 |
g_return_if_fail (core); |
| 38 |
|
| 39 |
if (subject != wp_core_get_own_bound_id (core)) |
| 40 |
return; |
| 41 |
|
| 42 |
if (spa_streq(key, "log.level")) |
| 43 |
wp_log_set_level (value ? value : "2"); |
| 44 |
} |
| 45 |
|
| 46 |
static void |
| 47 |
on_metadata_added (WpObjectManager *om, WpMetadata *metadata, gpointer d) |
| 48 |
{ |
| 49 |
WpLogSettingsPlugin * self = WP_LOG_SETTINGS_PLUGIN (d); |
| 50 |
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self)); |
| 51 |
g_return_if_fail (core); |
| 52 |
|
| 53 |
/* Handle the changed signal */ |
| 54 |
g_signal_connect_object (metadata, "changed", |
| 55 |
G_CALLBACK (on_metadata_changed), self, 0); |
| 56 |
} |
| 57 |
|
| 58 |
static void |
| 59 |
wp_log_settings_plugin_enable (WpPlugin * plugin, WpTransition * transition) |
| 60 |
{ |
| 61 |
WpLogSettingsPlugin * self = WP_LOG_SETTINGS_PLUGIN (plugin); |
| 62 |
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (plugin)); |
| 63 |
g_return_if_fail (core); |
| 64 |
|
| 65 |
/* Create the metadata object manager */ |
| 66 |
self->metadata_om = wp_object_manager_new (); |
| 67 |
wp_object_manager_add_interest (self->metadata_om, WP_TYPE_METADATA, |
| 68 |
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "metadata.name", "=s", "settings", |
| 69 |
NULL); |
| 70 |
wp_object_manager_request_object_features (self->metadata_om, |
| 71 |
WP_TYPE_METADATA, WP_OBJECT_FEATURES_ALL); |
| 72 |
g_signal_connect_object (self->metadata_om, "object-added", |
| 73 |
G_CALLBACK (on_metadata_added), self, 0); |
| 74 |
wp_core_install_object_manager (core, self->metadata_om); |
| 75 |
|
| 76 |
wp_object_update_features (WP_OBJECT (self), WP_PLUGIN_FEATURE_ENABLED, 0); |
| 77 |
} |
| 78 |
|
| 79 |
static void |
| 80 |
wp_log_settings_plugin_disable (WpPlugin * plugin) |
| 81 |
{ |
| 82 |
WpLogSettingsPlugin * self = WP_LOG_SETTINGS_PLUGIN (plugin); |
| 83 |
|
| 84 |
g_clear_object (&self->metadata_om); |
| 85 |
} |
| 86 |
|
| 87 |
static void |
| 88 |
wp_log_settings_plugin_class_init (WpLogSettingsPluginClass * klass) |
| 89 |
{ |
| 90 |
WpPluginClass *plugin_class = (WpPluginClass *) klass; |
| 91 |
|
| 92 |
plugin_class->enable = wp_log_settings_plugin_enable; |
| 93 |
plugin_class->disable = wp_log_settings_plugin_disable; |
| 94 |
} |
| 95 |
|
| 96 |
WP_PLUGIN_EXPORT GObject * |
| 97 |
wireplumber__module_init (WpCore * core, GVariant * args, GError ** error) |
| 98 |
{ |
| 99 |
return G_OBJECT (g_object_new (wp_log_settings_plugin_get_type (), |
| 100 |
"name", "log-settings", |
| 101 |
"core", core, |
| 102 |
NULL)); |
| 103 |
} |