wpctl: show persistent settings and add sub-command to clear them
This commit is contained in:
@@ -80,6 +80,10 @@ static struct {
|
|||||||
guint64 id;
|
guint64 id;
|
||||||
} clear_default;
|
} clear_default;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
const gchar *key;
|
||||||
|
} clear_persistent;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
guint64 id;
|
guint64 id;
|
||||||
const char *level;
|
const char *level;
|
||||||
@@ -212,6 +216,7 @@ status_prepare (WpCtl * self, GError ** error)
|
|||||||
wp_object_manager_add_interest (self->om, WP_TYPE_LINK, NULL);
|
wp_object_manager_add_interest (self->om, WP_TYPE_LINK, NULL);
|
||||||
wp_object_manager_request_object_features (self->om, WP_TYPE_GLOBAL_PROXY,
|
wp_object_manager_request_object_features (self->om, WP_TYPE_GLOBAL_PROXY,
|
||||||
WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL);
|
WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL);
|
||||||
|
wp_object_manager_add_interest (self->om, WP_TYPE_METADATA, NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,6 +393,7 @@ status_run (WpCtl * self)
|
|||||||
g_autoptr (WpIterator) it = NULL;
|
g_autoptr (WpIterator) it = NULL;
|
||||||
g_auto (GValue) val = G_VALUE_INIT;
|
g_auto (GValue) val = G_VALUE_INIT;
|
||||||
g_autoptr (WpPlugin) def_nodes_api = NULL;
|
g_autoptr (WpPlugin) def_nodes_api = NULL;
|
||||||
|
g_autoptr (WpMetadata) persistent_settings = NULL;
|
||||||
struct print_context context = { .self = self };
|
struct print_context context = { .self = self };
|
||||||
|
|
||||||
def_nodes_api = wp_plugin_find (self->core, "default-nodes-api");
|
def_nodes_api = wp_plugin_find (self->core, "default-nodes-api");
|
||||||
@@ -509,8 +515,25 @@ status_run (WpCtl * self)
|
|||||||
/* Settings */
|
/* Settings */
|
||||||
printf ("Settings\n");
|
printf ("Settings\n");
|
||||||
|
|
||||||
|
persistent_settings = wp_object_manager_lookup (self->om, WP_TYPE_METADATA,
|
||||||
|
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY,
|
||||||
|
"metadata.name", "=s", "persistent-sm-settings",
|
||||||
|
NULL);
|
||||||
|
printf (TREE_INDENT_NODE "Persistent:\n");
|
||||||
|
if (persistent_settings) {
|
||||||
|
it = wp_metadata_new_iterator (persistent_settings, 0);
|
||||||
|
for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
|
||||||
|
const gchar *key, *value;
|
||||||
|
wp_metadata_iterator_item_extract (&val, NULL, &key, NULL, &value);
|
||||||
|
printf (TREE_INDENT_LINE " - %s: %s\n", key, value);
|
||||||
|
}
|
||||||
|
g_clear_pointer (&it, wp_iterator_unref);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf (TREE_INDENT_LINE "\n");
|
||||||
|
|
||||||
|
printf (TREE_INDENT_END "Default Configured Devices:\n");
|
||||||
if (def_nodes_api) {
|
if (def_nodes_api) {
|
||||||
printf (TREE_INDENT_END "Default Configured Node Names:\n");
|
|
||||||
for (guint i = 0; i < G_N_ELEMENTS (DEFAULT_NODE_MEDIA_CLASSES); i++) {
|
for (guint i = 0; i < G_N_ELEMENTS (DEFAULT_NODE_MEDIA_CLASSES); i++) {
|
||||||
const gchar *name = NULL;
|
const gchar *name = NULL;
|
||||||
g_signal_emit_by_name (def_nodes_api, "get-default-configured-node-name",
|
g_signal_emit_by_name (def_nodes_api, "get-default-configured-node-name",
|
||||||
@@ -1308,7 +1331,6 @@ static void
|
|||||||
clear_default_run (WpCtl * self)
|
clear_default_run (WpCtl * self)
|
||||||
{
|
{
|
||||||
g_autoptr (WpPlugin) def_nodes_api = NULL;
|
g_autoptr (WpPlugin) def_nodes_api = NULL;
|
||||||
g_autoptr (GError) error = NULL;
|
|
||||||
gboolean res = FALSE;
|
gboolean res = FALSE;
|
||||||
|
|
||||||
def_nodes_api = wp_plugin_find (self->core, "default-nodes-api");
|
def_nodes_api = wp_plugin_find (self->core, "default-nodes-api");
|
||||||
@@ -1346,6 +1368,57 @@ out:
|
|||||||
g_main_loop_quit (self->loop);
|
g_main_loop_quit (self->loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clear-persistent */
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
clear_persistent_parse_positional (gint argc, gchar ** argv, GError **error)
|
||||||
|
{
|
||||||
|
if (argc >= 3)
|
||||||
|
cmdline.clear_persistent.key = argv[2];
|
||||||
|
else
|
||||||
|
cmdline.clear_persistent.key = NULL;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
clear_persistent_prepare (WpCtl * self, GError ** error)
|
||||||
|
{
|
||||||
|
wp_object_manager_add_interest (self->om, WP_TYPE_METADATA, NULL);
|
||||||
|
wp_object_manager_request_object_features (self->om, WP_TYPE_METADATA,
|
||||||
|
WP_OBJECT_FEATURES_ALL);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clear_persistent_run (WpCtl * self)
|
||||||
|
{
|
||||||
|
g_autoptr (WpMetadata) persistent_settings = NULL;
|
||||||
|
|
||||||
|
persistent_settings = wp_object_manager_lookup (self->om, WP_TYPE_METADATA,
|
||||||
|
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY,
|
||||||
|
"metadata.name", "=s", "persistent-sm-settings",
|
||||||
|
NULL);
|
||||||
|
if (!persistent_settings) {
|
||||||
|
fprintf (stderr, "Persistent settings metadata not found\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmdline.clear_persistent.key)
|
||||||
|
wp_metadata_set (persistent_settings, 0, cmdline.clear_persistent.key, NULL,
|
||||||
|
NULL);
|
||||||
|
else
|
||||||
|
wp_metadata_clear (persistent_settings);
|
||||||
|
|
||||||
|
|
||||||
|
wp_core_sync (self->core, NULL, (GAsyncReadyCallback) async_quit, self);
|
||||||
|
return;
|
||||||
|
|
||||||
|
out:
|
||||||
|
self->exit_code = 3;
|
||||||
|
g_main_loop_quit (self->loop);
|
||||||
|
}
|
||||||
|
|
||||||
/* set-log-level */
|
/* set-log-level */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -1573,6 +1646,16 @@ static const struct subcommand {
|
|||||||
.prepare = clear_default_prepare,
|
.prepare = clear_default_prepare,
|
||||||
.run = clear_default_run,
|
.run = clear_default_run,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "clear-persistent",
|
||||||
|
.positional_args = "[KEY]",
|
||||||
|
.summary = "Clears the persistent setting (no KEY means 'all')",
|
||||||
|
.description = NULL,
|
||||||
|
.entries = { { NULL } },
|
||||||
|
.parse_positional = clear_persistent_parse_positional,
|
||||||
|
.prepare = clear_persistent_prepare,
|
||||||
|
.run = clear_persistent_run,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = "set-log-level",
|
.name = "set-log-level",
|
||||||
.positional_args = "[ID] LEVEL",
|
.positional_args = "[ID] LEVEL",
|
||||||
|
Reference in New Issue
Block a user