diff mbox series

[BlueZ,v4,5/9] shared/shell: Add pre_run menu callback

Message ID 20250513093913.396876-6-hadess@hadess.net
State New
Headers show
Series Fix bluetoothctl --help hanging if daemon isn't running | expand

Commit Message

Bastien Nocera May 13, 2025, 9:38 a.m. UTC
This callback will be called every time the menu is called, and can be
used to make sure that, for example, a D-Bus connection, is setup for
the menu to use.

This means that it is now possible to install a menu without setting up
a D-Bus connexion, but still have access to that connexion when the menu
is activated.
---
 src/shared/shell.c | 9 +++++++++
 src/shared/shell.h | 2 ++
 2 files changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 4e42bd69b4d7..3e5959fc1868 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -1447,6 +1447,15 @@  static void env_destroy(void *data)
 int bt_shell_run(void)
 {
 	int status;
+	const struct queue_entry *submenu;
+
+	for (submenu = queue_get_entries(data.submenus); submenu;
+	     submenu = submenu->next) {
+		struct bt_shell_menu *menu = submenu->data;
+
+		if (menu->pre_run != NULL)
+			menu->pre_run(menu);
+	}
 
 	status = mainloop_run_with_signal(signal_callback, NULL);
 
diff --git a/src/shared/shell.h b/src/shared/shell.h
index eebbc71faffb..297fb69a6fb8 100644
--- a/src/shared/shell.h
+++ b/src/shared/shell.h
@@ -27,6 +27,7 @@  typedef void (*bt_shell_menu_disp_t) (char **matches, int num_matches,
 							int max_length);
 typedef void (*bt_shell_prompt_input_func) (const char *input, void *user_data);
 typedef bool (*bt_shell_menu_exists_t) (const struct bt_shell_menu *menu);
+typedef void (*bt_shell_menu_pre_run_t) (const struct bt_shell_menu *menu);
 
 struct bt_shell_menu_entry {
 	const char *cmd;
@@ -41,6 +42,7 @@  struct bt_shell_menu_entry {
 struct bt_shell_menu {
 	const char *name;
 	const char *desc;
+	bt_shell_menu_pre_run_t pre_run;
 	const struct bt_shell_menu_entry entries[];
 };