Skip to contentSkip to conversation

device: Fix probing service twice

PATCH Applied Luiz Augusto von Dentz 1 participant 3 messages Feb 19, 2018 – Feb 20, 2018 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 device: Fix probing service twice

From: Luiz Augusto von Dentz <[email protected]>

If there is already a service for a given profile there is no point in probing it again.

---
 src/device.c | 5 +++++
 1 file changed, 5 insertions(+)
src/device.c +5 -0
index 1acecce33..0da4184f6 100644
@@ -4202,6 +4202,7 @@ static struct btd_service *probe_service(struct btd_device *device,
 						struct btd_profile *profile,
 						GSList *uuids)
 {
+	GSList *l;
 	struct btd_service *service;
 
 	if (profile->device_probe == NULL)
@@ -4210,6 +4211,10 @@ static struct btd_service *probe_service(struct btd_device *device,
 	if (!device_match_profile(device, profile, uuids))
 		return NULL;
 
+	l = find_service_with_profile(device->services, profile);
+	if (l)
+		return l->data;
+
 	service = service_create(device, profile);
 
 	if (service_probe(service)) {
Signature · 1 line
2.14.3
author maintainer
#1 lore raw

PATCH 1/1 shared/shell: Add non-interactive mode

From: Luiz Augusto von Dentz <[email protected]>

This detects if any command was given as parameter, execute it and exit disabling all other outputs:

bluetoothctl list
Controller 00:1B:DC:07:31:88 Vudentz's T460s #1 [default] Controller B8:8A:60:D8:17:D7 BlueZ-1

---
 src/shared/shell.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
src/shared/shell.c +20 -1
index 12330ff53..01a62074f 100644
@@ -55,6 +55,9 @@
 			cmd, (int)(CMD_LENGTH - strlen(cmd)), "", desc)
 
 static GMainLoop *main_loop;
+static int exec_argc;
+static char **exec_argv;
+static bool interactive;
 
 struct bt_shell_env {
 	char *name;
@@ -373,6 +376,9 @@ void bt_shell_printf(const char *fmt, ...)
 	char *saved_line;
 	int saved_point;
 
+	if (!interactive)
+		return;
+
 	save_input = !RL_ISSTATE(RL_STATE_DONE);
 
 	if (save_input) {
@@ -784,6 +790,9 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 	} else
 		snprintf(optstr, sizeof(optstr), "+hv");
 
+	exec_argc = --argc;
+	exec_argv = &argv[1];
+
 	while ((c = getopt_long(argc, argv, optstr, options, &index)) != -1) {
 		switch (c) {
 		case 'v':
@@ -876,7 +885,7 @@ bool bt_shell_add_submenu(const struct bt_shell_menu *menu)
 
 void bt_shell_set_prompt(const char *string)
 {
-	if (!main_loop)
+	if (!main_loop || !interactive)
 		return;
 
 	rl_set_prompt(string);
@@ -899,6 +908,16 @@ bool bt_shell_attach(int fd)
 	if (data.input)
 		return false;
 
+	if (exec_argc > 0) {
+		interactive = true;
+		shell_exec(exec_argc, exec_argv);
+		interactive = false;
+
+		g_main_loop_quit(main_loop);
+
+		return false;
+	}
+
 	io = io_new(fd);
 
 	io_set_read_handler(io, input_read, NULL, NULL);
Signature · 1 line
2.14.3
author maintainer Applied
#2 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 32 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

If there is already a service for a given profile there is no point in probing it again.

---
 src/device.c | 5 +++++
 1 file changed, 5 insertions(+)
src/device.c +5 -1
index 1acecce33..0da4184f6 100644
@@ -4202,6 +4202,7 @@ static struct btd_service *probe_service(struct btd_device *device,
                                                struct btd_profile *profile,
                                                GSList *uuids)
 {
+       GSList *l;
        struct btd_service *service;
 
        if (profile->device_probe == NULL)
@@ -4210,6 +4211,10 @@ static struct btd_service *probe_service(struct btd_device *device,
        if (!device_match_profile(device, profile, uuids))
                return NULL;
 
+       l = find_service_with_profile(device->services, profile);
+       if (l)
+               return l->data;
+
        service = service_create(device, profile);
 
        if (service_probe(service)) {
--
Quoted 1 line

2.14.3

Applied, thanks.

Signature · 1 line
Luiz Augusto von Dentz