[BlueZ v4 8/9] client: Port "mgmt" menu to pre_run

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 client/main.c  |  1 -
 client/mgmt.c  | 14 +++++++++++---
 client/mgmt.h  |  1 -
 tools/btmgmt.c |  5 -----
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/client/main.c b/client/main.c
index ce753c1ac4c4..06ae25c9d8e9 100644
--- a/client/main.c
+++ b/client/main.c
@@ -3426,7 +3426,6 @@ int main(int argc, char *argv[])
 		bt_shell_set_env("AUTO_REGISTER_ENDPOINT",
 					(void *)endpoint_option);
 
-	mgmt_enable_submenu();
 	assistant_enable_submenu();
 
 	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
diff --git a/client/mgmt.c b/client/mgmt.c
index 6c6d62f4bba1..eda68b25a3e9 100644
--- a/client/mgmt.c
+++ b/client/mgmt.c
@@ -71,6 +71,8 @@ static int pending_index = 0;
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 #endif
 
+static void mgmt_menu_pre_run(const struct bt_shell_menu *menu);
+
 #define PROMPT_ON	COLOR_BLUE "[mgmt]" COLOR_OFF "> "
 
 static void update_prompt(uint16_t index)
@@ -5998,6 +6000,7 @@ static const struct bt_shell_menu monitor_menu = {
 static const struct bt_shell_menu mgmt_menu = {
 	.name = "mgmt",
 	.desc = "Management Submenu",
+	.pre_run = mgmt_menu_pre_run,
 	.entries = {
 	{ "select",		"<index>",
 		cmd_select,		"Select a different index"	},
@@ -6175,12 +6178,17 @@ void mgmt_add_submenu(void)
 	bt_shell_add_submenu(&monitor_menu);
 }
 
-bool mgmt_enable_submenu(void)
+static bool pre_run_done = false;
+
+static void mgmt_menu_pre_run(const struct bt_shell_menu *menu)
 {
+	if (pre_run_done)
+		return;
+
 	mgmt = mgmt_new_default();
 	if (!mgmt) {
 		fprintf(stderr, "Unable to open mgmt_socket\n");
-		return false;
+		return;
 	}
 
 	if (getenv("MGMT_DEBUG"))
@@ -6188,7 +6196,7 @@ bool mgmt_enable_submenu(void)
 
 	register_mgmt_callbacks(mgmt, mgmt_index);
 
-	return true;
+	pre_run_done = true;
 }
 
 void mgmt_remove_submenu(void)
diff --git a/client/mgmt.h b/client/mgmt.h
index b0f3cafd0777..6d235fbb1388 100644
--- a/client/mgmt.h
+++ b/client/mgmt.h
@@ -9,6 +9,5 @@
  */
 
 void mgmt_add_submenu(void);
-bool mgmt_enable_submenu(void);
 void mgmt_remove_submenu(void);
 void mgmt_set_index(const char *arg);
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 0f6051d5befe..0f3de2880014 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -47,11 +47,6 @@ int main(int argc, char *argv[])
 	bt_shell_init(argc, argv, &opt);
 
 	mgmt_add_submenu();
-	if (!mgmt_enable_submenu()) {
-		fprintf(stderr, "Unable to open mgmt_socket\n");
-		return EXIT_FAILURE;
-	}
-
 	mgmt_set_index(index_option);
 	bt_shell_attach(fileno(stdin));
 	status = bt_shell_run();
-- 
2.49.0





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux