All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 1/5] client/display: Add initial code for handling interactive mode
@ 2015-02-12 17:52 Szymon Janc
  2015-02-12 17:52 ` [RFC 2/5] client/display: Prefix remaining functions with interactive_ Szymon Janc
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Szymon Janc @ 2015-02-12 17:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This will allow to have interactive mode code in single place.
This code will allow to register commands, handle input, history,
completion etc.

Another benefit is abstracting readline which will allow to have
different backend on platforms that don't support it (ie Android).
---
 Makefile.tools   |   5 +-
 client/agent.c   |   1 +
 client/display.c | 273 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 client/display.h |  20 +++-
 tools/btmgmt.c   |   4 +-
 5 files changed, 298 insertions(+), 5 deletions(-)

diff --git a/Makefile.tools b/Makefile.tools
index e28f3cb..d721b4a 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -8,6 +8,7 @@ client_bluetoothctl_SOURCES = client/main.c \
 					client/gatt.h client/gatt.c \
 					monitor/uuid.h monitor/uuid.c
 client_bluetoothctl_LDADD = gdbus/libgdbus-internal.la @GLIB_LIBS@ @DBUS_LIBS@ \
+				src/libshared-mainloop.la \
 				-lreadline
 endif
 
@@ -300,6 +301,7 @@ attrib_gatttool_SOURCES = attrib/gatttool.c attrib/att.c attrib/gatt.c \
 				attrib/utils.c src/log.c client/display.c \
 				client/display.h
 attrib_gatttool_LDADD = lib/libbluetooth-internal.la \
+			src/libshared-mainloop.la \
 			src/libshared-glib.la @GLIB_LIBS@ -lreadline
 
 tools_obex_client_tool_SOURCES = $(gobex_sources) $(btio_sources) \
@@ -314,11 +316,12 @@ tools_obex_server_tool_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
 tools_bluetooth_player_SOURCES = tools/bluetooth-player.c \
 				client/display.h client/display.c
 tools_bluetooth_player_LDADD = gdbus/libgdbus-internal.la \
+				src/libshared-mainloop.la \
 				@GLIB_LIBS@ @DBUS_LIBS@ -lreadline
 
 tools_obexctl_SOURCES = tools/obexctl.c \
 				client/display.h client/display.c
-tools_obexctl_LDADD = gdbus/libgdbus-internal.la \
+tools_obexctl_LDADD = gdbus/libgdbus-internal.la src/libshared-mainloop.la \
 				@GLIB_LIBS@ @DBUS_LIBS@ -lreadline
 endif
 
diff --git a/client/agent.c b/client/agent.c
index eeabd5b..1034cad 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -27,6 +27,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <readline/readline.h>
 #include <gdbus.h>
 
diff --git a/client/display.c b/client/display.c
index 619973c..f016853 100644
--- a/client/display.c
+++ b/client/display.c
@@ -2,7 +2,7 @@
  *
  *  BlueZ - Bluetooth protocol stack for Linux
  *
- *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012-2015  Intel Corporation. All rights reserved.
  *
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -29,10 +29,22 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdbool.h>
+#include <unistd.h>
+#include <wordexp.h>
 #include <readline/readline.h>
+#include <readline/history.h>
+
+#include "src/shared/mainloop.h"
+#include "src/shared/io.h"
 
 #include "display.h"
 
+static char *saved_prompt = NULL;
+static int saved_point = 0;
+static struct io *input = NULL;
+static const struct interactive_command *commands = NULL;
+static interactive_prompt_func_t prompt_cb = NULL;
+
 void rl_printf(const char *fmt, ...)
 {
 	va_list args;
@@ -103,3 +115,262 @@ void rl_hexdump(const unsigned char *buf, size_t len)
 		rl_printf("%s\n", str);
 	}
 }
+
+void interactive_release_prompt(void)
+{
+	if (!saved_prompt)
+		return;
+
+	/* This will cause rl_expand_prompt to re-run over the last prompt,
+	 * but our prompt doesn't expand anyway.
+	 */
+	rl_set_prompt(saved_prompt);
+	rl_replace_line("", 0);
+	rl_point = saved_point;
+	rl_redisplay();
+
+	free(saved_prompt);
+	saved_prompt = NULL;
+}
+
+void interactive_update_prompt(const char *prompt)
+{
+	if (saved_prompt) {
+		free(saved_prompt);
+		saved_prompt = strdup(prompt);
+		return;
+	}
+
+	rl_set_prompt(prompt);
+}
+
+void interactive_prompt(const char *msg)
+{
+	if (saved_prompt)
+		return;
+
+	saved_prompt = strdup(rl_prompt);
+	if (!saved_prompt)
+		return;
+
+	saved_point = rl_point;
+
+	rl_set_prompt("");
+	rl_redisplay();
+
+	rl_set_prompt(msg);
+
+	rl_replace_line("", 0);
+	rl_redisplay();
+}
+
+static void cmd_quit(int argc, char **argv)
+{
+	mainloop_exit_success();
+}
+
+static struct interactive_command interactive_cmd[] = {
+	{ "quit",	cmd_quit,	"Exit program"			},
+	{ "exit",	cmd_quit,	"Exit program"			},
+	{ "help",	NULL,		"List supported commands"	},
+	{ }
+};
+
+static char *cmd_generator(const char *text, int state)
+{
+	static int i, j, len;
+	const char *cmd;
+
+	if (!state) {
+		i = 0;
+		j = 0;
+		len = strlen(text);
+	}
+
+	while ((cmd = commands[i].cmd)) {
+		i++;
+
+		if (!strncmp(cmd, text, len))
+			return strdup(cmd);
+	}
+
+	while ((cmd = interactive_cmd[j].cmd)) {
+		j++;
+
+		if (!strncmp(cmd, text, len))
+			return strdup(cmd);
+	}
+
+	return NULL;
+}
+
+static char **cmd_completion(const char *text, int start, int end)
+{
+	char **matches = NULL;
+
+	if (start > 0) {
+		int i;
+
+		for (i = 0; commands[i].cmd; i++) {
+			if (strncmp(commands[i].cmd,
+					rl_line_buffer, start - 1))
+				continue;
+
+			if (!commands[i].gen)
+				continue;
+
+			rl_completion_display_matches_hook = commands[i].disp;
+			matches = rl_completion_matches(text, commands[i].gen);
+			break;
+		}
+	} else {
+		rl_completion_display_matches_hook = NULL;
+		matches = rl_completion_matches(text, cmd_generator);
+	}
+
+	if (!matches)
+		rl_attempted_completion_over = 1;
+
+	return matches;
+}
+
+static void rl_handler(char *input)
+{
+	wordexp_t w;
+	char *cmd, **argv;
+	size_t argc;
+	int i;
+
+	if (!input) {
+		rl_insert_text("quit");
+		rl_redisplay();
+		rl_crlf();
+		mainloop_quit();
+		return;
+	}
+
+	if (!strlen(input))
+		goto done;
+
+	if (prompt_cb(input))
+		goto done;
+
+	add_history(input);
+
+	if (wordexp(input, &w, WRDE_NOCMD))
+		goto done;
+
+	if (w.we_wordc == 0)
+		goto free_we;
+
+	cmd = w.we_wordv[0];
+	argv = w.we_wordv;
+	argc = w.we_wordc;
+
+	if (!strcmp(cmd, "quit") || !strcmp(cmd, "exit")) {
+		mainloop_quit();
+		goto free_we;
+	}
+
+	for (i = 0; commands[i].cmd; i++) {
+		if (strcmp(cmd, commands[i].cmd))
+			continue;
+
+		if (commands[i].func) {
+			commands[i].func(argc, argv);
+			goto free_we;
+		}
+	}
+
+	for (i = 0; interactive_cmd[i].cmd; i++) {
+		if (strcmp(cmd, interactive_cmd[i].cmd))
+			continue;
+
+		if (interactive_cmd[i].func) {
+			interactive_cmd[i].func(argc, argv);
+			goto free_we;
+		}
+	}
+
+	if (strcmp(cmd, "help")) {
+		rl_printf("Invalid command\n");
+		goto free_we;
+	}
+
+	rl_printf("Available commands:\n");
+
+	for (i = 0; commands[i].cmd; i++) {
+		if (commands[i].doc)
+			rl_printf("  %s %-*s %s\n", commands[i].cmd,
+					(int)(25 - strlen(commands[i].cmd)),
+					"", commands[i].doc ? : "");
+	}
+
+	for (i = 0; interactive_cmd[i].cmd; i++) {
+		if (!interactive_cmd[i].doc)
+			continue;
+
+		rl_printf("  %s %-*s %s\n", interactive_cmd[i].cmd,
+				(int)(25 - strlen(interactive_cmd[i].cmd)),
+				"", interactive_cmd[i].doc ? : "");
+	}
+
+free_we:
+	wordfree(&w);
+done:
+	free(input);
+}
+
+static bool prompt_read(struct io *io, void *user_data)
+{
+	rl_callback_read_char();
+	return true;
+}
+
+static struct io *setup_stdin(void)
+{
+	struct io *io;
+
+	io = io_new(STDIN_FILENO);
+	if (!io)
+		return io;
+
+	io_set_read_handler(io, prompt_read, NULL, NULL);
+
+	return io;
+}
+
+bool interactive_init(const char *prompt, interactive_prompt_func_t cb,
+					const struct interactive_command *cmd)
+{
+	if (!prompt || !cb || !cmd)
+		return false;
+
+	input = setup_stdin();
+	if (!input)
+		return false;
+
+	commands = cmd;
+	prompt_cb = cb;
+
+	rl_attempted_completion_function = cmd_completion;
+
+	rl_erase_empty_line = 1;
+	rl_callback_handler_install(NULL, rl_handler);
+
+	rl_set_prompt(prompt);
+	rl_redisplay();
+
+	return true;
+}
+
+void interactive_cleanup(void)
+{
+	if (!input)
+		return;
+
+	io_destroy(input);
+
+	rl_message("");
+	rl_callback_handler_remove();
+}
diff --git a/client/display.h b/client/display.h
index 88dbbd0..c858639 100644
--- a/client/display.h
+++ b/client/display.h
@@ -2,7 +2,7 @@
  *
  *  BlueZ - Bluetooth protocol stack for Linux
  *
- *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012-2015  Intel Corporation. All rights reserved.
  *
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -29,5 +29,23 @@
 #define COLOR_BOLDGRAY	"\x1B[1;30m"
 #define COLOR_BOLDWHITE	"\x1B[1;37m"
 
+struct interactive_command {
+	char *cmd;
+	void (*func)(int argc, char **argv);
+	char *doc;
+	char * (*gen)(const char *text, int state);
+	void (*disp)(char **matches, int num_matches, int max_length);
+};
+
+typedef bool (*interactive_prompt_func_t)(const char *prompt);
+
+bool interactive_init(const char *prompt, interactive_prompt_func_t cb,
+					const struct interactive_command *cmd);
+void interactive_cleanup(void);
+
+void interactive_update_prompt(const char *prompt);
+void interactive_prompt(const char *msg);
+void interactive_release_prompt(void);
+
 void rl_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
 void rl_hexdump(const unsigned char *buf, size_t len);
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index c8fc9f6..e3bd5ce 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -801,7 +801,7 @@ static bool prompt_input(const char *input)
 	return true;
 }
 
-static void interactive_prompt(const char *msg)
+static void btmgmt_interactive_prompt(const char *msg)
 {
 	if (saved_prompt)
 		return;
@@ -856,7 +856,7 @@ static void ask(uint16_t index, uint16_t req, const struct mgmt_addr_info *addr,
 					COLOR_BOLDGRAY ">>" COLOR_OFF);
 
 	if (interactive) {
-		interactive_prompt(msg);
+		btmgmt_interactive_prompt(msg);
 		va_end(ap);
 		return;
 	}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC 2/5] client/display: Prefix remaining functions with interactive_
  2015-02-12 17:52 [RFC 1/5] client/display: Add initial code for handling interactive mode Szymon Janc
@ 2015-02-12 17:52 ` Szymon Janc
  2015-02-12 17:52 ` [RFC 3/5] tools/btmgmt: Rewrite interactive mode on top of client code Szymon Janc
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Szymon Janc @ 2015-02-12 17:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This is to not confuse those with readline API.
---
 attrib/interactive.c     |  44 +++----
 client/agent.c           |  48 ++++----
 client/display.c         |  16 +--
 client/display.h         |   4 +-
 client/gatt.c            |  40 +++----
 client/main.c            | 130 ++++++++++----------
 tools/bluetooth-player.c | 192 +++++++++++++++---------------
 tools/btmgmt.c           |   4 +-
 tools/obexctl.c          | 302 +++++++++++++++++++++++------------------------
 9 files changed, 390 insertions(+), 390 deletions(-)

diff --git a/attrib/interactive.c b/attrib/interactive.c
index 7911ba5..da8bcb9 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -70,10 +70,10 @@ static enum state {
 } conn_state;
 
 #define error(fmt, arg...) \
-	rl_printf(COLOR_RED "Error: " COLOR_OFF fmt, ## arg)
+	interactive_printf(COLOR_RED "Error: " COLOR_OFF fmt, ## arg)
 
 #define failed(fmt, arg...) \
-	rl_printf(COLOR_RED "Command Failed: " COLOR_OFF fmt, ## arg)
+	interactive_printf(COLOR_RED "Command Failed: " COLOR_OFF fmt, ## arg)
 
 static char *get_prompt(void)
 {
@@ -135,7 +135,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
 	for (i = 3; i < len; i++)
 		g_string_append_printf(s, "%02x ", pdu[i]);
 
-	rl_printf("%s\n", s->str);
+	interactive_printf("%s\n", s->str);
 	g_string_free(s, TRUE);
 
 	if (pdu[0] == ATT_OP_HANDLE_NOTIFY)
@@ -177,7 +177,7 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
 	g_attrib_register(attrib, ATT_OP_HANDLE_IND, GATTRIB_ALL_HANDLES,
 						events_handler, attrib, NULL);
 	set_state(STATE_CONNECTED);
-	rl_printf("Connection successful\n");
+	interactive_printf("Connection successful\n");
 }
 
 static void disconnect_io()
@@ -213,7 +213,7 @@ static void primary_all_cb(uint8_t status, GSList *services, void *user_data)
 
 	for (l = services; l; l = l->next) {
 		struct gatt_primary *prim = l->data;
-		rl_printf("attr handle: 0x%04x, end grp handle: 0x%04x uuid: %s\n",
+		interactive_printf("attr handle: 0x%04x, end grp handle: 0x%04x uuid: %s\n",
 				prim->range.start, prim->range.end, prim->uuid);
 	}
 }
@@ -235,7 +235,7 @@ static void primary_by_uuid_cb(uint8_t status, GSList *ranges, void *user_data)
 
 	for (l = ranges; l; l = l->next) {
 		struct att_range *range = l->data;
-		rl_printf("Starting handle: 0x%04x Ending handle: 0x%04x\n",
+		interactive_printf("Starting handle: 0x%04x Ending handle: 0x%04x\n",
 						range->start, range->end);
 	}
 }
@@ -251,13 +251,13 @@ static void included_cb(uint8_t status, GSList *includes, void *user_data)
 	}
 
 	if (includes == NULL) {
-		rl_printf("No included services found for this range\n");
+		interactive_printf("No included services found for this range\n");
 		return;
 	}
 
 	for (l = includes; l; l = l->next) {
 		struct gatt_included *incl = l->data;
-		rl_printf("handle: 0x%04x, start handle: 0x%04x, "
+		interactive_printf("handle: 0x%04x, start handle: 0x%04x, "
 					"end handle: 0x%04x uuid: %s\n",
 					incl->handle, incl->range.start,
 					incl->range.end, incl->uuid);
@@ -277,7 +277,7 @@ static void char_cb(uint8_t status, GSList *characteristics, void *user_data)
 	for (l = characteristics; l; l = l->next) {
 		struct gatt_char *chars = l->data;
 
-		rl_printf("handle: 0x%04x, char properties: 0x%02x, char value "
+		interactive_printf("handle: 0x%04x, char properties: 0x%02x, char value "
 				"handle: 0x%04x, uuid: %s\n", chars->handle,
 				chars->properties, chars->value_handle,
 				chars->uuid);
@@ -297,7 +297,7 @@ static void char_desc_cb(uint8_t status, GSList *descriptors, void *user_data)
 	for (l = descriptors; l; l = l->next) {
 		struct gatt_desc *desc = l->data;
 
-		rl_printf("handle: 0x%04x, uuid: %s\n", desc->handle,
+		interactive_printf("handle: 0x%04x, uuid: %s\n", desc->handle,
 								desc->uuid);
 	}
 }
@@ -326,7 +326,7 @@ static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
 	for (i = 0; i < vlen; i++)
 		g_string_append_printf(s, "%02x ", value[i]);
 
-	rl_printf("%s\n", s->str);
+	interactive_printf("%s\n", s->str);
 	g_string_free(s, TRUE);
 }
 
@@ -358,7 +358,7 @@ static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
 		for (j = 0; j < list->len - 2; j++, value++)
 			g_string_append_printf(s, "%02x ", *value);
 
-		rl_printf("%s\n", s->str);
+		interactive_printf("%s\n", s->str);
 	}
 
 	att_data_list_free(list);
@@ -402,7 +402,7 @@ static void cmd_connect(int argcp, char **argvp)
 		return;
 	}
 
-	rl_printf("Attempting to connect to %s\n", opt_dst);
+	interactive_printf("Attempting to connect to %s\n", opt_dst);
 	set_state(STATE_CONNECTING);
 	iochannel = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level,
 					opt_psm, opt_mtu, connect_cb, &gerr);
@@ -631,7 +631,7 @@ static void char_write_req_cb(guint8 status, const guint8 *pdu, guint16 plen,
 		return;
 	}
 
-	rl_printf("Characteristic value was written successfully\n");
+	interactive_printf("Characteristic value was written successfully\n");
 }
 
 static void cmd_char_write(int argcp, char **argvp)
@@ -646,7 +646,7 @@ static void cmd_char_write(int argcp, char **argvp)
 	}
 
 	if (argcp < 3) {
-		rl_printf("Usage: %s <handle> <new value>\n", argvp[0]);
+		interactive_printf("Usage: %s <handle> <new value>\n", argvp[0]);
 		return;
 	}
 
@@ -677,7 +677,7 @@ static void cmd_sec_level(int argcp, char **argvp)
 	BtIOSecLevel sec_level;
 
 	if (argcp < 2) {
-		rl_printf("sec-level: %s\n", opt_sec_level);
+		interactive_printf("sec-level: %s\n", opt_sec_level);
 		return;
 	}
 
@@ -688,7 +688,7 @@ static void cmd_sec_level(int argcp, char **argvp)
 	else if (strcasecmp(argvp[1], "low") == 0)
 		sec_level = BT_IO_SEC_LOW;
 	else {
-		rl_printf("Allowed values: low | medium | high\n");
+		interactive_printf("Allowed values: low | medium | high\n");
 		return;
 	}
 
@@ -699,7 +699,7 @@ static void cmd_sec_level(int argcp, char **argvp)
 		return;
 
 	if (opt_psm) {
-		rl_printf("Change will take effect on reconnection\n");
+		interactive_printf("Change will take effect on reconnection\n");
 		return;
 	}
 
@@ -731,7 +731,7 @@ static void exchange_mtu_cb(guint8 status, const guint8 *pdu, guint16 plen,
 	mtu = MIN(mtu, opt_mtu);
 	/* Set new value for MTU in client */
 	if (g_attrib_set_mtu(attrib, mtu))
-		rl_printf("MTU was exchanged successfully: %d\n", mtu);
+		interactive_printf("MTU was exchanged successfully: %d\n", mtu);
 	else
 		error("Error exchanging MTU\n");
 }
@@ -749,7 +749,7 @@ static void cmd_mtu(int argcp, char **argvp)
 	}
 
 	if (argcp < 2) {
-		rl_printf("Usage: mtu <value>\n");
+		interactive_printf("Usage: mtu <value>\n");
 		return;
 	}
 
@@ -813,7 +813,7 @@ static void cmd_help(int argcp, char **argvp)
 	int i;
 
 	for (i = 0; commands[i].cmd; i++)
-		rl_printf("%-15s %-30s %s\n", commands[i].cmd,
+		interactive_printf("%-15s %-30s %s\n", commands[i].cmd,
 				commands[i].params, commands[i].desc);
 }
 
@@ -824,7 +824,7 @@ static void parse_line(char *line_read)
 	int i;
 
 	if (line_read == NULL) {
-		rl_printf("\n");
+		interactive_printf("\n");
 		cmd_exit(0, NULL);
 		return;
 	}
diff --git a/client/agent.c b/client/agent.c
index 1034cad..4691afe 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -173,7 +173,7 @@ static void agent_release(DBusConnection *conn)
 static DBusMessage *release_agent(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	rl_printf("Agent released\n");
+	interactive_printf("Agent released\n");
 
 	agent_release(conn);
 
@@ -185,7 +185,7 @@ static DBusMessage *request_pincode(DBusConnection *conn,
 {
 	const char *device;
 
-	rl_printf("Request PIN code\n");
+	interactive_printf("Request PIN code\n");
 
 	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
 							DBUS_TYPE_INVALID);
@@ -206,7 +206,7 @@ static DBusMessage *display_pincode(DBusConnection *conn,
 	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
 				DBUS_TYPE_STRING, &pincode, DBUS_TYPE_INVALID);
 
-	rl_printf(AGENT_PROMPT "PIN code: %s\n", pincode);
+	interactive_printf(AGENT_PROMPT "PIN code: %s\n", pincode);
 
 	return dbus_message_new_method_return(msg);
 }
@@ -216,7 +216,7 @@ static DBusMessage *request_passkey(DBusConnection *conn,
 {
 	const char *device;
 
-	rl_printf("Request passkey\n");
+	interactive_printf("Request passkey\n");
 
 	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
 							DBUS_TYPE_INVALID);
@@ -246,7 +246,7 @@ static DBusMessage *display_passkey(DBusConnection *conn,
 	if (entered > strlen(passkey_full))
 		entered = strlen(passkey_full);
 
-	rl_printf(AGENT_PROMPT "Passkey: "
+	interactive_printf(AGENT_PROMPT "Passkey: "
 			COLOR_BOLDGRAY "%.*s" COLOR_BOLDWHITE "%s\n" COLOR_OFF,
 				entered, passkey_full, passkey_full + entered);
 
@@ -260,7 +260,7 @@ static DBusMessage *request_confirmation(DBusConnection *conn,
 	dbus_uint32_t passkey;
 	char *str;
 
-	rl_printf("Request confirmation\n");
+	interactive_printf("Request confirmation\n");
 
 	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
 				DBUS_TYPE_UINT32, &passkey, DBUS_TYPE_INVALID);
@@ -279,7 +279,7 @@ static DBusMessage *request_authorization(DBusConnection *conn,
 {
 	const char *device;
 
-	rl_printf("Request authorization\n");
+	interactive_printf("Request authorization\n");
 
 	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
 							DBUS_TYPE_INVALID);
@@ -297,7 +297,7 @@ static DBusMessage *authorize_service(DBusConnection *conn,
 	const char *device, *uuid;
 	char *str;
 
-	rl_printf("Authorize service\n");
+	interactive_printf("Authorize service\n");
 
 	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
 				DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID);
@@ -314,7 +314,7 @@ static DBusMessage *authorize_service(DBusConnection *conn,
 static DBusMessage *cancel_request(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	rl_printf("Request canceled\n");
+	interactive_printf("Request canceled\n");
 
 	agent_release_prompt();
 	dbus_message_unref(pending_message);
@@ -369,14 +369,14 @@ static void register_agent_reply(DBusMessage *message, void *user_data)
 
 	if (dbus_set_error_from_message(&error, message) == FALSE) {
 		agent_registered = TRUE;
-		rl_printf("Agent registered\n");
+		interactive_printf("Agent registered\n");
 	} else {
-		rl_printf("Failed to register agent: %s\n", error.name);
+		interactive_printf("Failed to register agent: %s\n", error.name);
 		dbus_error_free(&error);
 
 		if (g_dbus_unregister_interface(conn, AGENT_PATH,
 						AGENT_INTERFACE) == FALSE)
-			rl_printf("Failed to unregister agent object\n");
+			interactive_printf("Failed to unregister agent object\n");
 	}
 }
 
@@ -385,7 +385,7 @@ void agent_register(DBusConnection *conn, GDBusProxy *manager,
 
 {
 	if (agent_registered == TRUE) {
-		rl_printf("Agent is already registered\n");
+		interactive_printf("Agent is already registered\n");
 		return;
 	}
 
@@ -394,7 +394,7 @@ void agent_register(DBusConnection *conn, GDBusProxy *manager,
 	if (g_dbus_register_interface(conn, AGENT_PATH,
 					AGENT_INTERFACE, methods,
 					NULL, NULL, NULL, NULL) == FALSE) {
-		rl_printf("Failed to register agent object\n");
+		interactive_printf("Failed to register agent object\n");
 		return;
 	}
 
@@ -402,7 +402,7 @@ void agent_register(DBusConnection *conn, GDBusProxy *manager,
 						register_agent_setup,
 						register_agent_reply,
 						conn, NULL) == FALSE) {
-		rl_printf("Failed to call register agent method\n");
+		interactive_printf("Failed to call register agent method\n");
 		return;
 	}
 
@@ -424,10 +424,10 @@ static void unregister_agent_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == FALSE) {
-		rl_printf("Agent unregistered\n");
+		interactive_printf("Agent unregistered\n");
 		agent_release(conn);
 	} else {
-		rl_printf("Failed to unregister agent: %s\n", error.name);
+		interactive_printf("Failed to unregister agent: %s\n", error.name);
 		dbus_error_free(&error);
 	}
 }
@@ -435,12 +435,12 @@ static void unregister_agent_reply(DBusMessage *message, void *user_data)
 void agent_unregister(DBusConnection *conn, GDBusProxy *manager)
 {
 	if (agent_registered == FALSE) {
-		rl_printf("No agent is registered\n");
+		interactive_printf("No agent is registered\n");
 		return;
 	}
 
 	if (!manager) {
-		rl_printf("Agent unregistered\n");
+		interactive_printf("Agent unregistered\n");
 		agent_release(conn);
 		return;
 	}
@@ -449,7 +449,7 @@ void agent_unregister(DBusConnection *conn, GDBusProxy *manager)
 						unregister_agent_setup,
 						unregister_agent_reply,
 						conn, NULL) == FALSE) {
-		rl_printf("Failed to call unregister agent method\n");
+		interactive_printf("Failed to call unregister agent method\n");
 		return;
 	}
 }
@@ -468,18 +468,18 @@ static void request_default_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to request default agent: %s\n", error.name);
+		interactive_printf("Failed to request default agent: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Default agent request successful\n");
+	interactive_printf("Default agent request successful\n");
 }
 
 void agent_default(DBusConnection *conn, GDBusProxy *manager)
 {
 	if (agent_registered == FALSE) {
-		rl_printf("No agent is registered\n");
+		interactive_printf("No agent is registered\n");
 		return;
 	}
 
@@ -487,7 +487,7 @@ void agent_default(DBusConnection *conn, GDBusProxy *manager)
 						request_default_setup,
 						request_default_reply,
 						NULL, NULL) == FALSE) {
-		rl_printf("Failed to call request default agent method\n");
+		interactive_printf("Failed to call request default agent method\n");
 		return;
 	}
 }
diff --git a/client/display.c b/client/display.c
index f016853..25eafe3 100644
--- a/client/display.c
+++ b/client/display.c
@@ -45,7 +45,7 @@ static struct io *input = NULL;
 static const struct interactive_command *commands = NULL;
 static interactive_prompt_func_t prompt_cb = NULL;
 
-void rl_printf(const char *fmt, ...)
+void interactive_printf(const char *fmt, ...)
 {
 	va_list args;
 	bool save_input;
@@ -75,7 +75,7 @@ void rl_printf(const char *fmt, ...)
 	}
 }
 
-void rl_hexdump(const unsigned char *buf, size_t len)
+void interactive_hexdump(const unsigned char *buf, size_t len)
 {
 	static const char hexdigits[] = "0123456789abcdef";
 	char str[68];
@@ -96,7 +96,7 @@ void rl_hexdump(const unsigned char *buf, size_t len)
 			str[49] = ' ';
 			str[50] = ' ';
 			str[67] = '\0';
-			rl_printf("%s\n", str);
+			interactive_printf("%s\n", str);
 			str[0] = ' ';
 		}
 	}
@@ -112,7 +112,7 @@ void rl_hexdump(const unsigned char *buf, size_t len)
 		str[49] = ' ';
 		str[50] = ' ';
 		str[67] = '\0';
-		rl_printf("%s\n", str);
+		interactive_printf("%s\n", str);
 	}
 }
 
@@ -293,15 +293,15 @@ static void rl_handler(char *input)
 	}
 
 	if (strcmp(cmd, "help")) {
-		rl_printf("Invalid command\n");
+		interactive_printf("Invalid command\n");
 		goto free_we;
 	}
 
-	rl_printf("Available commands:\n");
+	interactive_printf("Available commands:\n");
 
 	for (i = 0; commands[i].cmd; i++) {
 		if (commands[i].doc)
-			rl_printf("  %s %-*s %s\n", commands[i].cmd,
+			interactive_printf("  %s %-*s %s\n", commands[i].cmd,
 					(int)(25 - strlen(commands[i].cmd)),
 					"", commands[i].doc ? : "");
 	}
@@ -310,7 +310,7 @@ static void rl_handler(char *input)
 		if (!interactive_cmd[i].doc)
 			continue;
 
-		rl_printf("  %s %-*s %s\n", interactive_cmd[i].cmd,
+		interactive_printf("  %s %-*s %s\n", interactive_cmd[i].cmd,
 				(int)(25 - strlen(interactive_cmd[i].cmd)),
 				"", interactive_cmd[i].doc ? : "");
 	}
diff --git a/client/display.h b/client/display.h
index c858639..e223670 100644
--- a/client/display.h
+++ b/client/display.h
@@ -47,5 +47,5 @@ void interactive_update_prompt(const char *prompt);
 void interactive_prompt(const char *msg);
 void interactive_release_prompt(void);
 
-void rl_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
-void rl_hexdump(const unsigned char *buf, size_t len);
+void interactive_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
+void interactive_hexdump(const unsigned char *buf, size_t len);
diff --git a/client/gatt.c b/client/gatt.c
index 3785452..4bdbaba 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -70,7 +70,7 @@ static void print_service(GDBusProxy *proxy, const char *description)
 	if (!text)
 		text = uuid;
 
-	rl_printf("%s%s%sService %s %s %s\n",
+	interactive_printf("%s%s%sService %s %s %s\n",
 				description ? "[" : "",
 				description ? : "",
 				description ? "] " : "",
@@ -106,7 +106,7 @@ static void print_characteristic(GDBusProxy *proxy, const char *description)
 	if (!text)
 		text = uuid;
 
-	rl_printf("%s%s%sCharacteristic %s %s\n",
+	interactive_printf("%s%s%sCharacteristic %s %s\n",
 				description ? "[" : "",
 				description ? : "",
 				description ? "] " : "",
@@ -171,7 +171,7 @@ static void print_descriptor(GDBusProxy *proxy, const char *description)
 	if (!text)
 		text = uuid;
 
-	rl_printf("%s%s%sDescriptor %s %s\n",
+	interactive_printf("%s%s%sDescriptor %s %s\n",
 				description ? "[" : "",
 				description ? : "",
 				description ? "] " : "",
@@ -338,7 +338,7 @@ static void read_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to read: %s\n", error.name);
+		interactive_printf("Failed to read: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -346,7 +346,7 @@ static void read_reply(DBusMessage *message, void *user_data)
 	dbus_message_iter_init(message, &iter);
 
 	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
-		rl_printf("Invalid response to read\n");
+		interactive_printf("Invalid response to read\n");
 		return;
 	}
 
@@ -354,22 +354,22 @@ static void read_reply(DBusMessage *message, void *user_data)
 	dbus_message_iter_get_fixed_array(&array, &value, &len);
 
 	if (len < 0) {
-		rl_printf("Unable to parse value\n");
+		interactive_printf("Unable to parse value\n");
 		return;
 	}
 
-	rl_hexdump(value, len);
+	interactive_hexdump(value, len);
 }
 
 static void read_attribute(GDBusProxy *proxy)
 {
 	if (g_dbus_proxy_method_call(proxy, "ReadValue", NULL, read_reply,
 							NULL, NULL) == FALSE) {
-		rl_printf("Failed to read\n");
+		interactive_printf("Failed to read\n");
 		return;
 	}
 
-	rl_printf("Attempting to read %s\n", g_dbus_proxy_get_path(proxy));
+	interactive_printf("Attempting to read %s\n", g_dbus_proxy_get_path(proxy));
 }
 
 void gatt_read_attribute(GDBusProxy *proxy)
@@ -383,7 +383,7 @@ void gatt_read_attribute(GDBusProxy *proxy)
 		return;
 	}
 
-	rl_printf("Unable to read attribute %s\n",
+	interactive_printf("Unable to read attribute %s\n",
 						g_dbus_proxy_get_path(proxy));
 }
 
@@ -394,7 +394,7 @@ static void write_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to write: %s\n", error.name);
+		interactive_printf("Failed to write: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -426,13 +426,13 @@ static void write_attribute(GDBusProxy *proxy, char *arg)
 			continue;
 
 		if (i > 512) {
-			rl_printf("Too much data\n");
+			interactive_printf("Too much data\n");
 			return;
 		}
 
 		val = strtol(entry, &endptr, 0);
 		if (!endptr || *endptr != '\0' || val > UINT8_MAX) {
-			rl_printf("Invalid value at index %d\n", i);
+			interactive_printf("Invalid value at index %d\n", i);
 			return;
 		}
 
@@ -444,11 +444,11 @@ static void write_attribute(GDBusProxy *proxy, char *arg)
 
 	if (g_dbus_proxy_method_call(proxy, "WriteValue", write_setup,
 					write_reply, &iov, NULL) == FALSE) {
-		rl_printf("Failed to write\n");
+		interactive_printf("Failed to write\n");
 		return;
 	}
 
-	rl_printf("Attempting to write %s\n", g_dbus_proxy_get_path(proxy));
+	interactive_printf("Attempting to write %s\n", g_dbus_proxy_get_path(proxy));
 }
 
 void gatt_write_attribute(GDBusProxy *proxy, const char *arg)
@@ -462,7 +462,7 @@ void gatt_write_attribute(GDBusProxy *proxy, const char *arg)
 		return;
 	}
 
-	rl_printf("Unable to write attribute %s\n",
+	interactive_printf("Unable to write attribute %s\n",
 						g_dbus_proxy_get_path(proxy));
 }
 
@@ -474,13 +474,13 @@ static void notify_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to %s notify: %s\n",
+		interactive_printf("Failed to %s notify: %s\n",
 				enable ? "start" : "stop", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Notify %s\n", enable == TRUE ? "started" : "stopped");
+	interactive_printf("Notify %s\n", enable == TRUE ? "started" : "stopped");
 }
 
 static void notify_attribute(GDBusProxy *proxy, bool enable)
@@ -494,7 +494,7 @@ static void notify_attribute(GDBusProxy *proxy, bool enable)
 
 	if (g_dbus_proxy_method_call(proxy, method, NULL, notify_reply,
 				GUINT_TO_POINTER(enable), NULL) == FALSE) {
-		rl_printf("Failed to %s notify\n", enable ? "start" : "stop");
+		interactive_printf("Failed to %s notify\n", enable ? "start" : "stop");
 		return;
 	}
 }
@@ -509,6 +509,6 @@ void gatt_notify_attribute(GDBusProxy *proxy, bool enable)
 		return;
 	}
 
-	rl_printf("Unable to notify attribute %s\n",
+	interactive_printf("Unable to notify attribute %s\n",
 						g_dbus_proxy_get_path(proxy));
 }
diff --git a/client/main.c b/client/main.c
index 809c372..96781b2 100644
--- a/client/main.c
+++ b/client/main.c
@@ -120,7 +120,7 @@ static void print_adapter(GDBusProxy *proxy, const char *description)
 	else
 		name = "<unknown>";
 
-	rl_printf("%s%s%sController %s %s %s\n",
+	interactive_printf("%s%s%sController %s %s %s\n",
 				description ? "[" : "",
 				description ? : "",
 				description ? "] " : "",
@@ -144,7 +144,7 @@ static void print_device(GDBusProxy *proxy, const char *description)
 	else
 		name = "<unknown>";
 
-	rl_printf("%s%s%sDevice %s %s\n",
+	interactive_printf("%s%s%sDevice %s %s\n",
 				description ? "[" : "",
 				description ? : "",
 				description ? "] " : "",
@@ -163,39 +163,39 @@ static void print_iter(const char *label, const char *name,
 	DBusMessageIter subiter;
 
 	if (iter == NULL) {
-		rl_printf("%s%s is nil\n", label, name);
+		interactive_printf("%s%s is nil\n", label, name);
 		return;
 	}
 
 	switch (dbus_message_iter_get_arg_type(iter)) {
 	case DBUS_TYPE_INVALID:
-		rl_printf("%s%s is invalid\n", label, name);
+		interactive_printf("%s%s is invalid\n", label, name);
 		break;
 	case DBUS_TYPE_STRING:
 	case DBUS_TYPE_OBJECT_PATH:
 		dbus_message_iter_get_basic(iter, &valstr);
-		rl_printf("%s%s: %s\n", label, name, valstr);
+		interactive_printf("%s%s: %s\n", label, name, valstr);
 		break;
 	case DBUS_TYPE_BOOLEAN:
 		dbus_message_iter_get_basic(iter, &valbool);
-		rl_printf("%s%s: %s\n", label, name,
+		interactive_printf("%s%s: %s\n", label, name,
 					valbool == TRUE ? "yes" : "no");
 		break;
 	case DBUS_TYPE_UINT32:
 		dbus_message_iter_get_basic(iter, &valu32);
-		rl_printf("%s%s: 0x%06x\n", label, name, valu32);
+		interactive_printf("%s%s: 0x%06x\n", label, name, valu32);
 		break;
 	case DBUS_TYPE_UINT16:
 		dbus_message_iter_get_basic(iter, &valu16);
-		rl_printf("%s%s: 0x%04x\n", label, name, valu16);
+		interactive_printf("%s%s: 0x%04x\n", label, name, valu16);
 		break;
 	case DBUS_TYPE_INT16:
 		dbus_message_iter_get_basic(iter, &vals16);
-		rl_printf("%s%s: %d\n", label, name, vals16);
+		interactive_printf("%s%s: %d\n", label, name, vals16);
 		break;
 	case DBUS_TYPE_BYTE:
 		dbus_message_iter_get_basic(iter, &byte);
-		rl_printf("%s%s: 0x%02x\n", label, name, byte);
+		interactive_printf("%s%s: 0x%02x\n", label, name, byte);
 		break;
 	case DBUS_TYPE_VARIANT:
 		dbus_message_iter_recurse(iter, &subiter);
@@ -216,7 +216,7 @@ static void print_iter(const char *label, const char *name,
 		print_iter(label, valstr, &subiter);
 		break;
 	default:
-		rl_printf("%s%s has unsupported type\n", label, name);
+		interactive_printf("%s%s has unsupported type\n", label, name);
 		break;
 	}
 }
@@ -262,10 +262,10 @@ static void print_uuids(GDBusProxy *proxy)
 				n = sizeof(str) - 1;
 			}
 
-			rl_printf("\tUUID: %s%*c(%s)\n",
+			interactive_printf("\tUUID: %s%*c(%s)\n",
 						str, 26 - n, ' ', uuid);
 		} else
-			rl_printf("\tUUID: %*c(%s)\n", 26, ' ', uuid);
+			interactive_printf("\tUUID: %*c(%s)\n", 26, ' ', uuid);
 
 		dbus_message_iter_next(&value);
 	}
@@ -513,7 +513,7 @@ static void property_changed(GDBusProxy *proxy, const char *name,
 static void message_handler(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
-	rl_printf("[SIGNAL] %s.%s\n", dbus_message_get_interface(message),
+	interactive_printf("[SIGNAL] %s.%s\n", dbus_message_get_interface(message),
 					dbus_message_get_member(message));
 }
 
@@ -541,7 +541,7 @@ static GDBusProxy *find_proxy_by_address(GList *source, const char *address)
 static gboolean check_default_ctrl(void)
 {
 	if (!default_ctrl) {
-		rl_printf("No default controller available\n");
+		interactive_printf("No default controller available\n");
 		return FALSE;
 	}
 
@@ -551,7 +551,7 @@ static gboolean check_default_ctrl(void)
 static gboolean parse_argument_on_off(const char *arg, dbus_bool_t *value)
 {
 	if (!arg || !strlen(arg)) {
-		rl_printf("Missing on/off argument\n");
+		interactive_printf("Missing on/off argument\n");
 		return FALSE;
 	}
 
@@ -565,7 +565,7 @@ static gboolean parse_argument_on_off(const char *arg, dbus_bool_t *value)
 		return TRUE;
 	}
 
-	rl_printf("Invalid argument %s\n", arg);
+	interactive_printf("Invalid argument %s\n", arg);
 	return FALSE;
 }
 
@@ -575,7 +575,7 @@ static gboolean parse_argument_agent(const char *arg, dbus_bool_t *value,
 	const char * const *opt;
 
 	if (arg == NULL || strlen(arg) == 0) {
-		rl_printf("Missing on/off/capability argument\n");
+		interactive_printf("Missing on/off/capability argument\n");
 		return FALSE;
 	}
 
@@ -598,7 +598,7 @@ static gboolean parse_argument_agent(const char *arg, dbus_bool_t *value,
 		}
 	}
 
-	rl_printf("Invalid argument %s\n", arg);
+	interactive_printf("Invalid argument %s\n", arg);
 	return FALSE;
 }
 
@@ -626,7 +626,7 @@ static void cmd_show(const char *arg)
 	} else {
 		proxy = find_proxy_by_address(ctrl_list, arg);
 		if (!proxy) {
-			rl_printf("Controller %s not available\n", arg);
+			interactive_printf("Controller %s not available\n", arg);
 			return;
 		}
 	}
@@ -635,7 +635,7 @@ static void cmd_show(const char *arg)
 		return;
 
 	dbus_message_iter_get_basic(&iter, &address);
-	rl_printf("Controller %s\n", address);
+	interactive_printf("Controller %s\n", address);
 
 	print_property(proxy, "Name");
 	print_property(proxy, "Alias");
@@ -653,13 +653,13 @@ static void cmd_select(const char *arg)
 	GDBusProxy *proxy;
 
 	if (!arg || !strlen(arg)) {
-		rl_printf("Missing controller address argument\n");
+		interactive_printf("Missing controller address argument\n");
 		return;
 	}
 
 	proxy = find_proxy_by_address(ctrl_list, arg);
 	if (!proxy) {
-		rl_printf("Controller %s not available\n", arg);
+		interactive_printf("Controller %s not available\n", arg);
 		return;
 	}
 
@@ -708,9 +708,9 @@ static void generic_callback(const DBusError *error, void *user_data)
 	char *str = user_data;
 
 	if (dbus_error_is_set(error))
-		rl_printf("Failed to set %s: %s\n", str, error->name);
+		interactive_printf("Failed to set %s: %s\n", str, error->name);
 	else
-		rl_printf("Changing %s succeeded\n", str);
+		interactive_printf("Changing %s succeeded\n", str);
 }
 
 static void cmd_system_alias(const char *arg)
@@ -718,7 +718,7 @@ static void cmd_system_alias(const char *arg)
 	char *name;
 
 	if (!arg || !strlen(arg)) {
-		rl_printf("Missing name argument\n");
+		interactive_printf("Missing name argument\n");
 		return;
 	}
 
@@ -832,7 +832,7 @@ static void cmd_agent(const char *arg)
 			agent_register(dbus_conn, agent_manager,
 						auto_register_agent);
 		else
-			rl_printf("Agent registration enabled\n");
+			interactive_printf("Agent registration enabled\n");
 	} else {
 		g_free(auto_register_agent);
 		auto_register_agent = NULL;
@@ -840,7 +840,7 @@ static void cmd_agent(const char *arg)
 		if (agent_manager)
 			agent_unregister(dbus_conn, agent_manager);
 		else
-			rl_printf("Agent registration disabled\n");
+			interactive_printf("Agent registration disabled\n");
 	}
 }
 
@@ -857,13 +857,13 @@ static void start_discovery_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to %s discovery: %s\n",
+		interactive_printf("Failed to %s discovery: %s\n",
 				enable == TRUE ? "start" : "stop", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Discovery %s\n", enable == TRUE ? "started" : "stopped");
+	interactive_printf("Discovery %s\n", enable == TRUE ? "started" : "stopped");
 }
 
 static void cmd_scan(const char *arg)
@@ -885,7 +885,7 @@ static void cmd_scan(const char *arg)
 	if (g_dbus_proxy_method_call(default_ctrl, method,
 				NULL, start_discovery_reply,
 				GUINT_TO_POINTER(enable), NULL) == FALSE) {
-		rl_printf("Failed to %s discovery\n",
+		interactive_printf("Failed to %s discovery\n",
 					enable == TRUE ? "start" : "stop");
 		return;
 	}
@@ -898,13 +898,13 @@ static struct GDBusProxy *find_device(const char *arg)
 	if (!arg || !strlen(arg)) {
 		if (default_dev)
 			return default_dev;
-		rl_printf("Missing device address argument\n");
+		interactive_printf("Missing device address argument\n");
 		return NULL;
 	}
 
 	proxy = find_proxy_by_address(dev_list, arg);
 	if (!proxy) {
-		rl_printf("Device %s not available\n", arg);
+		interactive_printf("Device %s not available\n", arg);
 		return NULL;
 	}
 
@@ -925,7 +925,7 @@ static void cmd_info(const char *arg)
 		return;
 
 	dbus_message_iter_get_basic(&iter, &address);
-	rl_printf("Device %s\n", address);
+	interactive_printf("Device %s\n", address);
 
 	print_property(proxy, "Name");
 	print_property(proxy, "Alias");
@@ -948,12 +948,12 @@ static void pair_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to pair: %s\n", error.name);
+		interactive_printf("Failed to pair: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Pairing successful\n");
+	interactive_printf("Pairing successful\n");
 }
 
 static void cmd_pair(const char *arg)
@@ -966,11 +966,11 @@ static void cmd_pair(const char *arg)
 
 	if (g_dbus_proxy_method_call(proxy, "Pair", NULL, pair_reply,
 							NULL, NULL) == FALSE) {
-		rl_printf("Failed to pair\n");
+		interactive_printf("Failed to pair\n");
 		return;
 	}
 
-	rl_printf("Attempting to pair with %s\n", arg);
+	interactive_printf("Attempting to pair with %s\n", arg);
 }
 
 static void cmd_trust(const char *arg)
@@ -1068,12 +1068,12 @@ static void remove_device_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to remove device: %s\n", error.name);
+		interactive_printf("Failed to remove device: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Device has been removed\n");
+	interactive_printf("Device has been removed\n");
 }
 
 static void remove_device_setup(DBusMessageIter *iter, void *user_data)
@@ -1089,7 +1089,7 @@ static void cmd_remove(const char *arg)
 	char *path;
 
 	if (!arg || !strlen(arg)) {
-		rl_printf("Missing device address argument\n");
+		interactive_printf("Missing device address argument\n");
 		return;
 	}
 
@@ -1098,7 +1098,7 @@ static void cmd_remove(const char *arg)
 
 	proxy = find_proxy_by_address(dev_list, arg);
 	if (!proxy) {
-		rl_printf("Device %s not available\n", arg);
+		interactive_printf("Device %s not available\n", arg);
 		return;
 	}
 
@@ -1108,7 +1108,7 @@ static void cmd_remove(const char *arg)
 						remove_device_setup,
 						remove_device_reply,
 						path, g_free) == FALSE) {
-		rl_printf("Failed to remove device\n");
+		interactive_printf("Failed to remove device\n");
 		g_free(path);
 		return;
 	}
@@ -1122,12 +1122,12 @@ static void connect_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to connect: %s\n", error.name);
+		interactive_printf("Failed to connect: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Connection successful\n");
+	interactive_printf("Connection successful\n");
 
 	set_default_device(proxy, NULL);
 }
@@ -1137,23 +1137,23 @@ static void cmd_connect(const char *arg)
 	GDBusProxy *proxy;
 
 	if (!arg || !strlen(arg)) {
-		rl_printf("Missing device address argument\n");
+		interactive_printf("Missing device address argument\n");
 		return;
 	}
 
 	proxy = find_proxy_by_address(dev_list, arg);
 	if (!proxy) {
-		rl_printf("Device %s not available\n", arg);
+		interactive_printf("Device %s not available\n", arg);
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "Connect", NULL, connect_reply,
 							proxy, NULL) == FALSE) {
-		rl_printf("Failed to connect\n");
+		interactive_printf("Failed to connect\n");
 		return;
 	}
 
-	rl_printf("Attempting to connect to %s\n", arg);
+	interactive_printf("Attempting to connect to %s\n", arg);
 }
 
 static void disconn_reply(DBusMessage *message, void *user_data)
@@ -1164,12 +1164,12 @@ static void disconn_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to disconnect: %s\n", error.name);
+		interactive_printf("Failed to disconnect: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Successful disconnected\n");
+	interactive_printf("Successful disconnected\n");
 
 	if (proxy != default_dev)
 		return;
@@ -1187,11 +1187,11 @@ static void cmd_disconn(const char *arg)
 
 	if (g_dbus_proxy_method_call(proxy, "Disconnect", NULL, disconn_reply,
 							proxy, NULL) == FALSE) {
-		rl_printf("Failed to disconnect\n");
+		interactive_printf("Failed to disconnect\n");
 		return;
 	}
 
-	rl_printf("Attempting to disconnect from %s\n", arg);
+	interactive_printf("Attempting to disconnect from %s\n", arg);
 }
 
 static void cmd_list_attributes(const char *arg)
@@ -1210,12 +1210,12 @@ static void cmd_select_attribute(const char *arg)
 	GDBusProxy *proxy;
 
 	if (!arg || !strlen(arg)) {
-		rl_printf("Missing attribute argument\n");
+		interactive_printf("Missing attribute argument\n");
 		return;
 	}
 
 	if (!default_dev) {
-		rl_printf("No device connected\n");
+		interactive_printf("No device connected\n");
 		return;
 	}
 
@@ -1231,13 +1231,13 @@ static struct GDBusProxy *find_attribute(const char *arg)
 	if (!arg || !strlen(arg)) {
 		if (default_attr)
 			return default_attr;
-		rl_printf("Missing attribute argument\n");
+		interactive_printf("Missing attribute argument\n");
 		return NULL;
 	}
 
 	proxy = gatt_select_attribute(arg);
 	if (!proxy) {
-		rl_printf("Attribute %s not available\n", arg);
+		interactive_printf("Attribute %s not available\n", arg);
 		return NULL;
 	}
 
@@ -1265,14 +1265,14 @@ static void cmd_attribute_info(const char *arg)
 
 	iface = g_dbus_proxy_get_interface(proxy);
 	if (!strcmp(iface, "org.bluez.GattService1")) {
-		rl_printf("Service - %s\n", text);
+		interactive_printf("Service - %s\n", text);
 
 		print_property(proxy, "UUID");
 		print_property(proxy, "Primary");
 		print_property(proxy, "Characteristics");
 		print_property(proxy, "Includes");
 	} else if (!strcmp(iface, "org.bluez.GattCharacteristic1")) {
-		rl_printf("Characteristic - %s\n", text);
+		interactive_printf("Characteristic - %s\n", text);
 
 		print_property(proxy, "UUID");
 		print_property(proxy, "Service");
@@ -1281,7 +1281,7 @@ static void cmd_attribute_info(const char *arg)
 		print_property(proxy, "Flags");
 		print_property(proxy, "Descriptors");
 	} else if (!strcmp(iface, "org.bluez.GattDescriptor1")) {
-		rl_printf("Descriptor - %s\n", text);
+		interactive_printf("Descriptor - %s\n", text);
 
 		print_property(proxy, "UUID");
 		print_property(proxy, "Characteristic");
@@ -1292,7 +1292,7 @@ static void cmd_attribute_info(const char *arg)
 static void cmd_read(const char *arg)
 {
 	if (!default_attr) {
-		rl_printf("No attribute selected\n");
+		interactive_printf("No attribute selected\n");
 		return;
 	}
 
@@ -1302,12 +1302,12 @@ static void cmd_read(const char *arg)
 static void cmd_write(const char *arg)
 {
 	if (!arg || !strlen(arg)) {
-		rl_printf("Missing data argument\n");
+		interactive_printf("Missing data argument\n");
 		return;
 	}
 
 	if (!default_attr) {
-		rl_printf("No attribute selected\n");
+		interactive_printf("No attribute selected\n");
 		return;
 	}
 
@@ -1322,7 +1322,7 @@ static void cmd_notify(const char *arg)
 		return;
 
 	if (!default_attr) {
-		rl_printf("No attribute selected\n");
+		interactive_printf("No attribute selected\n");
 		return;
 	}
 
@@ -1331,7 +1331,7 @@ static void cmd_notify(const char *arg)
 
 static void cmd_version(const char *arg)
 {
-	rl_printf("Version %s\n", VERSION);
+	interactive_printf("Version %s\n", VERSION);
 }
 
 static void cmd_quit(const char *arg)
diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
index f10d9be..22e0557 100644
--- a/tools/bluetooth-player.c
+++ b/tools/bluetooth-player.c
@@ -83,7 +83,7 @@ static void cmd_quit(int argc, char *argv[])
 static bool check_default_player(void)
 {
 	if (!default_player) {
-		rl_printf("No default player available\n");
+		interactive_printf("No default player available\n");
 		return FALSE;
 	}
 
@@ -97,12 +97,12 @@ static void play_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to play: %s\n", error.name);
+		interactive_printf("Failed to play: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Play successful\n");
+	interactive_printf("Play successful\n");
 }
 
 static GDBusProxy *find_item(const char *path)
@@ -125,17 +125,17 @@ static void cmd_play_item(int argc, char *argv[])
 
 	proxy = find_item(argv[1]);
 	if (proxy == NULL) {
-		rl_printf("Item %s not available\n", argv[1]);
+		interactive_printf("Item %s not available\n", argv[1]);
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "Play", NULL, play_reply,
 							NULL, NULL) == FALSE) {
-		rl_printf("Failed to play\n");
+		interactive_printf("Failed to play\n");
 		return;
 	}
 
-	rl_printf("Attempting to play %s\n", argv[1]);
+	interactive_printf("Attempting to play %s\n", argv[1]);
 }
 
 static void cmd_play(int argc, char *argv[])
@@ -148,11 +148,11 @@ static void cmd_play(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(default_player, "Play", NULL, play_reply,
 							NULL, NULL) == FALSE) {
-		rl_printf("Failed to play\n");
+		interactive_printf("Failed to play\n");
 		return;
 	}
 
-	rl_printf("Attempting to play\n");
+	interactive_printf("Attempting to play\n");
 }
 
 static void pause_reply(DBusMessage *message, void *user_data)
@@ -162,12 +162,12 @@ static void pause_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to pause: %s\n", error.name);
+		interactive_printf("Failed to pause: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Pause successful\n");
+	interactive_printf("Pause successful\n");
 }
 
 static void cmd_pause(int argc, char *argv[])
@@ -177,11 +177,11 @@ static void cmd_pause(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(default_player, "Pause", NULL,
 					pause_reply, NULL, NULL) == FALSE) {
-		rl_printf("Failed to play\n");
+		interactive_printf("Failed to play\n");
 		return;
 	}
 
-	rl_printf("Attempting to pause\n");
+	interactive_printf("Attempting to pause\n");
 }
 
 static void stop_reply(DBusMessage *message, void *user_data)
@@ -191,12 +191,12 @@ static void stop_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to stop: %s\n", error.name);
+		interactive_printf("Failed to stop: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Stop successful\n");
+	interactive_printf("Stop successful\n");
 }
 
 static void cmd_stop(int argc, char *argv[])
@@ -206,11 +206,11 @@ static void cmd_stop(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(default_player, "Stop", NULL, stop_reply,
 							NULL, NULL) == FALSE) {
-		rl_printf("Failed to stop\n");
+		interactive_printf("Failed to stop\n");
 		return;
 	}
 
-	rl_printf("Attempting to stop\n");
+	interactive_printf("Attempting to stop\n");
 }
 
 static void next_reply(DBusMessage *message, void *user_data)
@@ -220,12 +220,12 @@ static void next_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to jump to next: %s\n", error.name);
+		interactive_printf("Failed to jump to next: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Next successful\n");
+	interactive_printf("Next successful\n");
 }
 
 static void cmd_next(int argc, char *argv[])
@@ -235,11 +235,11 @@ static void cmd_next(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(default_player, "Next", NULL, next_reply,
 							NULL, NULL) == FALSE) {
-		rl_printf("Failed to jump to next\n");
+		interactive_printf("Failed to jump to next\n");
 		return;
 	}
 
-	rl_printf("Attempting to jump to next\n");
+	interactive_printf("Attempting to jump to next\n");
 }
 
 static void previous_reply(DBusMessage *message, void *user_data)
@@ -249,12 +249,12 @@ static void previous_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to jump to previous: %s\n", error.name);
+		interactive_printf("Failed to jump to previous: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Previous successful\n");
+	interactive_printf("Previous successful\n");
 }
 
 static void cmd_previous(int argc, char *argv[])
@@ -264,11 +264,11 @@ static void cmd_previous(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(default_player, "Previous", NULL,
 					previous_reply, NULL, NULL) == FALSE) {
-		rl_printf("Failed to jump to previous\n");
+		interactive_printf("Failed to jump to previous\n");
 		return;
 	}
 
-	rl_printf("Attempting to jump to previous\n");
+	interactive_printf("Attempting to jump to previous\n");
 }
 
 static void fast_forward_reply(DBusMessage *message, void *user_data)
@@ -278,12 +278,12 @@ static void fast_forward_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to fast forward: %s\n", error.name);
+		interactive_printf("Failed to fast forward: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("FastForward successful\n");
+	interactive_printf("FastForward successful\n");
 }
 
 static void cmd_fast_forward(int argc, char *argv[])
@@ -293,11 +293,11 @@ static void cmd_fast_forward(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(default_player, "FastForward", NULL,
 				fast_forward_reply, NULL, NULL) == FALSE) {
-		rl_printf("Failed to jump to previous\n");
+		interactive_printf("Failed to jump to previous\n");
 		return;
 	}
 
-	rl_printf("Fast forward playback\n");
+	interactive_printf("Fast forward playback\n");
 }
 
 static void rewind_reply(DBusMessage *message, void *user_data)
@@ -307,12 +307,12 @@ static void rewind_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to rewind: %s\n", error.name);
+		interactive_printf("Failed to rewind: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Rewind successful\n");
+	interactive_printf("Rewind successful\n");
 }
 
 static void cmd_rewind(int argc, char *argv[])
@@ -322,11 +322,11 @@ static void cmd_rewind(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(default_player, "Rewind", NULL,
 					rewind_reply, NULL, NULL) == FALSE) {
-		rl_printf("Failed to rewind\n");
+		interactive_printf("Failed to rewind\n");
 		return;
 	}
 
-	rl_printf("Rewind playback\n");
+	interactive_printf("Rewind playback\n");
 }
 
 static void generic_callback(const DBusError *error, void *user_data)
@@ -334,9 +334,9 @@ static void generic_callback(const DBusError *error, void *user_data)
 	char *str = user_data;
 
 	if (dbus_error_is_set(error))
-		rl_printf("Failed to set %s: %s\n", str, error->name);
+		interactive_printf("Failed to set %s: %s\n", str, error->name);
 	else
-		rl_printf("Changing %s succeeded\n", str);
+		interactive_printf("Changing %s succeeded\n", str);
 }
 
 static void cmd_equalizer(int argc, char *argv[])
@@ -348,12 +348,12 @@ static void cmd_equalizer(int argc, char *argv[])
 		return;
 
 	if (argc < 2) {
-		rl_printf("Missing on/off argument\n");
+		interactive_printf("Missing on/off argument\n");
 		return;
 	}
 
 	if (!g_dbus_proxy_get_property(default_player, "Equalizer", &iter)) {
-		rl_printf("Operation not supported\n");
+		interactive_printf("Operation not supported\n");
 		return;
 	}
 
@@ -363,12 +363,12 @@ static void cmd_equalizer(int argc, char *argv[])
 						DBUS_TYPE_STRING, &value,
 						generic_callback, value,
 						g_free) == FALSE) {
-		rl_printf("Failed to setting equalizer\n");
+		interactive_printf("Failed to setting equalizer\n");
 		g_free(value);
 		return;
 	}
 
-	rl_printf("Attempting to set equalizer\n");
+	interactive_printf("Attempting to set equalizer\n");
 }
 
 static void cmd_repeat(int argc, char *argv[])
@@ -380,12 +380,12 @@ static void cmd_repeat(int argc, char *argv[])
 		return;
 
 	if (argc < 2) {
-		rl_printf("Missing mode argument\n");
+		interactive_printf("Missing mode argument\n");
 		return;
 	}
 
 	if (!g_dbus_proxy_get_property(default_player, "Repeat", &iter)) {
-		rl_printf("Operation not supported\n");
+		interactive_printf("Operation not supported\n");
 		return;
 	}
 
@@ -395,12 +395,12 @@ static void cmd_repeat(int argc, char *argv[])
 						DBUS_TYPE_STRING, &value,
 						generic_callback, value,
 						g_free) == FALSE) {
-		rl_printf("Failed to set repeat\n");
+		interactive_printf("Failed to set repeat\n");
 		g_free(value);
 		return;
 	}
 
-	rl_printf("Attempting to set repeat\n");
+	interactive_printf("Attempting to set repeat\n");
 }
 
 static void cmd_shuffle(int argc, char *argv[])
@@ -412,12 +412,12 @@ static void cmd_shuffle(int argc, char *argv[])
 		return;
 
 	if (argc < 2) {
-		rl_printf("Missing mode argument\n");
+		interactive_printf("Missing mode argument\n");
 		return;
 	}
 
 	if (!g_dbus_proxy_get_property(default_player, "Shuffle", &iter)) {
-		rl_printf("Operation not supported\n");
+		interactive_printf("Operation not supported\n");
 		return;
 	}
 
@@ -427,12 +427,12 @@ static void cmd_shuffle(int argc, char *argv[])
 						DBUS_TYPE_STRING, &value,
 						generic_callback, value,
 						g_free) == FALSE) {
-		rl_printf("Failed to set shuffle\n");
+		interactive_printf("Failed to set shuffle\n");
 		g_free(value);
 		return;
 	}
 
-	rl_printf("Attempting to set shuffle\n");
+	interactive_printf("Attempting to set shuffle\n");
 }
 
 static void cmd_scan(int argc, char *argv[])
@@ -444,12 +444,12 @@ static void cmd_scan(int argc, char *argv[])
 		return;
 
 	if (argc < 2) {
-		rl_printf("Missing mode argument\n");
+		interactive_printf("Missing mode argument\n");
 		return;
 	}
 
 	if (!g_dbus_proxy_get_property(default_player, "Shuffle", &iter)) {
-		rl_printf("Operation not supported\n");
+		interactive_printf("Operation not supported\n");
 		return;
 	}
 
@@ -459,12 +459,12 @@ static void cmd_scan(int argc, char *argv[])
 						DBUS_TYPE_STRING, &value,
 						generic_callback, value,
 						g_free) == FALSE) {
-		rl_printf("Failed to set scan\n");
+		interactive_printf("Failed to set scan\n");
 		g_free(value);
 		return;
 	}
 
-	rl_printf("Attempting to set scan\n");
+	interactive_printf("Attempting to set scan\n");
 }
 
 static char *proxy_description(GDBusProxy *proxy, const char *title,
@@ -487,7 +487,7 @@ static void print_player(GDBusProxy *proxy, const char *description)
 
 	str = proxy_description(proxy, "Player", description);
 
-	rl_printf("%s%s\n", str, default_player == proxy ? "[default]" : "");
+	interactive_printf("%s%s\n", str, default_player == proxy ? "[default]" : "");
 
 	g_free(str);
 }
@@ -527,35 +527,35 @@ static void print_iter(const char *label, const char *name,
 	DBusMessageIter subiter;
 
 	if (iter == NULL) {
-		rl_printf("%s%s is nil\n", label, name);
+		interactive_printf("%s%s is nil\n", label, name);
 		return;
 	}
 
 	switch (dbus_message_iter_get_arg_type(iter)) {
 	case DBUS_TYPE_INVALID:
-		rl_printf("%s%s is invalid\n", label, name);
+		interactive_printf("%s%s is invalid\n", label, name);
 		break;
 	case DBUS_TYPE_STRING:
 	case DBUS_TYPE_OBJECT_PATH:
 		dbus_message_iter_get_basic(iter, &valstr);
-		rl_printf("%s%s: %s\n", label, name, valstr);
+		interactive_printf("%s%s: %s\n", label, name, valstr);
 		break;
 	case DBUS_TYPE_BOOLEAN:
 		dbus_message_iter_get_basic(iter, &valbool);
-		rl_printf("%s%s: %s\n", label, name,
+		interactive_printf("%s%s: %s\n", label, name,
 					valbool == TRUE ? "yes" : "no");
 		break;
 	case DBUS_TYPE_UINT32:
 		dbus_message_iter_get_basic(iter, &valu32);
-		rl_printf("%s%s: 0x%06x\n", label, name, valu32);
+		interactive_printf("%s%s: 0x%06x\n", label, name, valu32);
 		break;
 	case DBUS_TYPE_UINT16:
 		dbus_message_iter_get_basic(iter, &valu16);
-		rl_printf("%s%s: 0x%04x\n", label, name, valu16);
+		interactive_printf("%s%s: 0x%04x\n", label, name, valu16);
 		break;
 	case DBUS_TYPE_INT16:
 		dbus_message_iter_get_basic(iter, &vals16);
-		rl_printf("%s%s: %d\n", label, name, vals16);
+		interactive_printf("%s%s: %d\n", label, name, vals16);
 		break;
 	case DBUS_TYPE_VARIANT:
 		dbus_message_iter_recurse(iter, &subiter);
@@ -576,7 +576,7 @@ static void print_iter(const char *label, const char *name,
 		print_iter(label, valstr, &subiter);
 		break;
 	default:
-		rl_printf("%s%s has unsupported type\n", label, name);
+		interactive_printf("%s%s has unsupported type\n", label, name);
 		break;
 	}
 }
@@ -610,17 +610,17 @@ static void cmd_show_item(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing item address argument\n");
+		interactive_printf("Missing item address argument\n");
 		return;
 	}
 
 	proxy = find_item(argv[1]);
 	if (!proxy) {
-		rl_printf("Item %s not available\n", argv[1]);
+		interactive_printf("Item %s not available\n", argv[1]);
 		return;
 	}
 
-	rl_printf("Item %s\n", g_dbus_proxy_get_path(proxy));
+	interactive_printf("Item %s\n", g_dbus_proxy_get_path(proxy));
 
 	print_property(proxy, "Player");
 	print_property(proxy, "Name");
@@ -646,12 +646,12 @@ static void cmd_show(int argc, char *argv[])
 	} else {
 		proxy = find_player(argv[1]);
 		if (!proxy) {
-			rl_printf("Player %s not available\n", argv[1]);
+			interactive_printf("Player %s not available\n", argv[1]);
 			return;
 		}
 	}
 
-	rl_printf("Player %s\n", g_dbus_proxy_get_path(proxy));
+	interactive_printf("Player %s\n", g_dbus_proxy_get_path(proxy));
 
 	print_property(proxy, "Name");
 	print_property(proxy, "Repeat");
@@ -666,7 +666,7 @@ static void cmd_show(int argc, char *argv[])
 	if (folder == NULL)
 		return;
 
-	rl_printf("Folder %s\n", g_dbus_proxy_get_path(proxy));
+	interactive_printf("Folder %s\n", g_dbus_proxy_get_path(proxy));
 
 	print_property(folder, "Name");
 	print_property(folder, "NumberOfItems");
@@ -680,7 +680,7 @@ static void cmd_show(int argc, char *argv[])
 	if (item == NULL)
 		return;
 
-	rl_printf("Playlist %s\n", path);
+	interactive_printf("Playlist %s\n", path);
 
 	print_property(item, "Name");
 }
@@ -690,13 +690,13 @@ static void cmd_select(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing player address argument\n");
+		interactive_printf("Missing player address argument\n");
 		return;
 	}
 
 	proxy = find_player(argv[1]);
 	if (proxy == NULL) {
-		rl_printf("Player %s not available\n", argv[1]);
+		interactive_printf("Player %s not available\n", argv[1]);
 		return;
 	}
 
@@ -714,12 +714,12 @@ static void change_folder_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to change folder: %s\n", error.name);
+		interactive_printf("Failed to change folder: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("ChangeFolder successful\n");
+	interactive_printf("ChangeFolder successful\n");
 }
 
 static void change_folder_setup(DBusMessageIter *iter, void *user_data)
@@ -734,12 +734,12 @@ static void cmd_change_folder(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing item argument\n");
+		interactive_printf("Missing item argument\n");
 		return;
 	}
 
 	if (dbus_validate_path(argv[1], NULL) == FALSE) {
-		rl_printf("Not a valid path\n");
+		interactive_printf("Not a valid path\n");
 		return;
 	}
 
@@ -748,17 +748,17 @@ static void cmd_change_folder(int argc, char *argv[])
 
 	proxy = find_folder(g_dbus_proxy_get_path(default_player));
 	if (proxy == NULL) {
-		rl_printf("Operation not supported\n");
+		interactive_printf("Operation not supported\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "ChangeFolder", change_folder_setup,
 				change_folder_reply, argv[1], NULL) == FALSE) {
-		rl_printf("Failed to change current folder\n");
+		interactive_printf("Failed to change current folder\n");
 		return;
 	}
 
-	rl_printf("Attempting to change folder\n");
+	interactive_printf("Attempting to change folder\n");
 }
 
 static void append_variant(DBusMessageIter *iter, int type, void *val)
@@ -832,12 +832,12 @@ static void list_items_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to list items: %s\n", error.name);
+		interactive_printf("Failed to list items: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("ListItems successful\n");
+	interactive_printf("ListItems successful\n");
 }
 
 static void cmd_list_items(int argc, char *argv[])
@@ -850,7 +850,7 @@ static void cmd_list_items(int argc, char *argv[])
 
 	proxy = find_folder(g_dbus_proxy_get_path(default_player));
 	if (proxy == NULL) {
-		rl_printf("Operation not supported\n");
+		interactive_printf("Operation not supported\n");
 		return;
 	}
 
@@ -864,7 +864,7 @@ static void cmd_list_items(int argc, char *argv[])
 	errno = 0;
 	args->start = strtol(argv[1], NULL, 10);
 	if (errno != 0) {
-		rl_printf("%s(%d)\n", strerror(errno), errno);
+		interactive_printf("%s(%d)\n", strerror(errno), errno);
 		g_free(args);
 		return;
 	}
@@ -875,7 +875,7 @@ static void cmd_list_items(int argc, char *argv[])
 	errno = 0;
 	args->end = strtol(argv[2], NULL, 10);
 	if (errno != 0) {
-		rl_printf("%s(%d)\n", strerror(errno), errno);
+		interactive_printf("%s(%d)\n", strerror(errno), errno);
 		g_free(args);
 		return;
 	}
@@ -883,12 +883,12 @@ static void cmd_list_items(int argc, char *argv[])
 done:
 	if (g_dbus_proxy_method_call(proxy, "ListItems", list_items_setup,
 				list_items_reply, args, g_free) == FALSE) {
-		rl_printf("Failed to change current folder\n");
+		interactive_printf("Failed to change current folder\n");
 		g_free(args);
 		return;
 	}
 
-	rl_printf("Attempting to list items\n");
+	interactive_printf("Attempting to list items\n");
 }
 
 static void search_setup(DBusMessageIter *iter, void *user_data)
@@ -915,12 +915,12 @@ static void search_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to search: %s\n", error.name);
+		interactive_printf("Failed to search: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Search successful\n");
+	interactive_printf("Search successful\n");
 }
 
 static void cmd_search(int argc, char *argv[])
@@ -929,7 +929,7 @@ static void cmd_search(int argc, char *argv[])
 	char *string;
 
 	if (argc < 2) {
-		rl_printf("Missing string argument\n");
+		interactive_printf("Missing string argument\n");
 		return;
 	}
 
@@ -938,7 +938,7 @@ static void cmd_search(int argc, char *argv[])
 
 	proxy = find_folder(g_dbus_proxy_get_path(default_player));
 	if (proxy == NULL) {
-		rl_printf("Operation not supported\n");
+		interactive_printf("Operation not supported\n");
 		return;
 	}
 
@@ -946,12 +946,12 @@ static void cmd_search(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(proxy, "Search", search_setup,
 				search_reply, string, g_free) == FALSE) {
-		rl_printf("Failed to search\n");
+		interactive_printf("Failed to search\n");
 		g_free(string);
 		return;
 	}
 
-	rl_printf("Attempting to search\n");
+	interactive_printf("Attempting to search\n");
 }
 
 static void add_to_nowplaying_reply(DBusMessage *message, void *user_data)
@@ -961,12 +961,12 @@ static void add_to_nowplaying_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to queue: %s\n", error.name);
+		interactive_printf("Failed to queue: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("AddToNowPlaying successful\n");
+	interactive_printf("AddToNowPlaying successful\n");
 }
 
 static void cmd_queue(int argc, char *argv[])
@@ -974,24 +974,24 @@ static void cmd_queue(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing item address argument\n");
+		interactive_printf("Missing item address argument\n");
 		return;
 	}
 
 	proxy = find_item(argv[1]);
 	if (proxy == NULL) {
-		rl_printf("Item %s not available\n", argv[1]);
+		interactive_printf("Item %s not available\n", argv[1]);
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "AddtoNowPlaying", NULL,
 					add_to_nowplaying_reply, NULL,
 					NULL) == FALSE) {
-		rl_printf("Failed to play\n");
+		interactive_printf("Failed to play\n");
 		return;
 	}
 
-	rl_printf("Attempting to queue %s\n", argv[1]);
+	interactive_printf("Attempting to queue %s\n", argv[1]);
 }
 
 static const struct {
@@ -1256,7 +1256,7 @@ static void print_folder(GDBusProxy *proxy, const char *description)
 
 	path = g_dbus_proxy_get_path(proxy);
 
-	rl_printf("%s%s%sFolder %s\n", description ? "[" : "",
+	interactive_printf("%s%s%sFolder %s\n", description ? "[" : "",
 					description ? : "",
 					description ? "] " : "",
 					path);
@@ -1281,7 +1281,7 @@ static void print_item(GDBusProxy *proxy, const char *description)
 	else
 		name = "<unknown>";
 
-	rl_printf("%s%s%sItem %s %s\n", description ? "[" : "",
+	interactive_printf("%s%s%sItem %s %s\n", description ? "[" : "",
 					description ? : "",
 					description ? "] " : "",
 					path, name);
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index e3bd5ce..abc2fd0 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -116,14 +116,14 @@ static void noninteractive_quit(int status)
 
 #define print(fmt, arg...) do { \
 	if (interactive) \
-		rl_printf(fmt "\n", ## arg); \
+		interactive_printf(fmt "\n", ## arg); \
 	else \
 		printf(fmt "\n", ## arg); \
 } while (0)
 
 #define error(fmt, arg...) do { \
 	if (interactive) \
-		rl_printf(COLOR_RED fmt "\n" COLOR_OFF, ## arg); \
+		interactive_printf(COLOR_RED fmt "\n" COLOR_OFF, ## arg); \
 	else \
 		fprintf(stderr, fmt "\n", ## arg); \
 } while (0)
diff --git a/tools/obexctl.c b/tools/obexctl.c
index b4fdc1c..c105b2f 100644
--- a/tools/obexctl.c
+++ b/tools/obexctl.c
@@ -104,12 +104,12 @@ static void connect_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to connect: %s\n", error.name);
+		interactive_printf("Failed to connect: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Connection successful\n");
+	interactive_printf("Connection successful\n");
 }
 
 static void append_variant(DBusMessageIter *iter, int type, void *val)
@@ -188,12 +188,12 @@ static void cmd_connect(int argc, char *argv[])
 	const char *target = "opp";
 
 	if (argc < 2) {
-		rl_printf("Missing device address argument\n");
+		interactive_printf("Missing device address argument\n");
 		return;
 	}
 
 	if (!client) {
-		rl_printf("Client proxy not available\n");
+		interactive_printf("Client proxy not available\n");
 		return;
 	}
 
@@ -206,11 +206,11 @@ static void cmd_connect(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(client, "CreateSession", connect_setup,
 			connect_reply, args, connect_args_free) == FALSE) {
-		rl_printf("Failed to connect\n");
+		interactive_printf("Failed to connect\n");
 		return;
 	}
 
-	rl_printf("Attempting to connect to %s\n", argv[1]);
+	interactive_printf("Attempting to connect to %s\n", argv[1]);
 }
 
 static void disconnect_reply(DBusMessage *message, void *user_data)
@@ -220,12 +220,12 @@ static void disconnect_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to disconnect: %s\n", error.name);
+		interactive_printf("Failed to disconnect: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Disconnection successful\n");
+	interactive_printf("Disconnection successful\n");
 }
 
 static void disconnect_setup(DBusMessageIter *iter, void *user_data)
@@ -262,17 +262,17 @@ static void cmd_disconnect(int argc, char *argv[])
 		proxy = default_session;
 
 	if (proxy == NULL) {
-		rl_printf("Session not available\n");
+		interactive_printf("Session not available\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(client, "RemoveSession", disconnect_setup,
 				disconnect_reply, proxy, NULL) == FALSE) {
-		rl_printf("Failed to disconnect\n");
+		interactive_printf("Failed to disconnect\n");
 		return;
 	}
 
-	rl_printf("Attempting to disconnect to %s\n",
+	interactive_printf("Attempting to disconnect to %s\n",
 						g_dbus_proxy_get_path(proxy));
 }
 
@@ -297,7 +297,7 @@ static void print_proxy(GDBusProxy *proxy, const char *title,
 
 	str = proxy_description(proxy, title, description);
 
-	rl_printf("%s%s\n", str, default_session == proxy ? "[default]" : "");
+	interactive_printf("%s%s\n", str, default_session == proxy ? "[default]" : "");
 
 	g_free(str);
 }
@@ -315,7 +315,7 @@ static void cmd_list(int argc, char *arg[])
 static bool check_default_session(void)
 {
 	if (!default_session) {
-		rl_printf("No default session available\n");
+		interactive_printf("No default session available\n");
 		return FALSE;
 	}
 
@@ -334,39 +334,39 @@ static void print_iter(const char *label, const char *name,
 	DBusMessageIter subiter;
 
 	if (iter == NULL) {
-		rl_printf("%s%s is nil\n", label, name);
+		interactive_printf("%s%s is nil\n", label, name);
 		return;
 	}
 
 	switch (dbus_message_iter_get_arg_type(iter)) {
 	case DBUS_TYPE_INVALID:
-		rl_printf("%s%s is invalid\n", label, name);
+		interactive_printf("%s%s is invalid\n", label, name);
 		break;
 	case DBUS_TYPE_STRING:
 	case DBUS_TYPE_OBJECT_PATH:
 		dbus_message_iter_get_basic(iter, &valstr);
-		rl_printf("%s%s: %s\n", label, name, valstr);
+		interactive_printf("%s%s: %s\n", label, name, valstr);
 		break;
 	case DBUS_TYPE_BOOLEAN:
 		dbus_message_iter_get_basic(iter, &valbool);
-		rl_printf("%s%s: %s\n", label, name,
+		interactive_printf("%s%s: %s\n", label, name,
 					valbool == TRUE ? "yes" : "no");
 		break;
 	case DBUS_TYPE_UINT64:
 		dbus_message_iter_get_basic(iter, &valu64);
-		rl_printf("%s%s: %" PRIu64 "\n", label, name, valu64);
+		interactive_printf("%s%s: %" PRIu64 "\n", label, name, valu64);
 		break;
 	case DBUS_TYPE_UINT32:
 		dbus_message_iter_get_basic(iter, &valu32);
-		rl_printf("%s%s: 0x%08x\n", label, name, valu32);
+		interactive_printf("%s%s: 0x%08x\n", label, name, valu32);
 		break;
 	case DBUS_TYPE_UINT16:
 		dbus_message_iter_get_basic(iter, &valu16);
-		rl_printf("%s%s: 0x%04x\n", label, name, valu16);
+		interactive_printf("%s%s: 0x%04x\n", label, name, valu16);
 		break;
 	case DBUS_TYPE_INT16:
 		dbus_message_iter_get_basic(iter, &vals16);
-		rl_printf("%s%s: %d\n", label, name, vals16);
+		interactive_printf("%s%s: %d\n", label, name, vals16);
 		break;
 	case DBUS_TYPE_VARIANT:
 		dbus_message_iter_recurse(iter, &subiter);
@@ -387,7 +387,7 @@ static void print_iter(const char *label, const char *name,
 		print_iter(label, valstr, &subiter);
 		break;
 	default:
-		rl_printf("%s%s has unsupported type\n", label, name);
+		interactive_printf("%s%s has unsupported type\n", label, name);
 		break;
 	}
 }
@@ -414,12 +414,12 @@ static void cmd_show(int argc, char *argv[])
 	} else {
 		proxy = find_session(argv[1]);
 		if (!proxy) {
-			rl_printf("Session %s not available\n", argv[1]);
+			interactive_printf("Session %s not available\n", argv[1]);
 			return;
 		}
 	}
 
-	rl_printf("Session %s\n", g_dbus_proxy_get_path(proxy));
+	interactive_printf("Session %s\n", g_dbus_proxy_get_path(proxy));
 
 	print_property(proxy, "Destination");
 	print_property(proxy, "Target");
@@ -451,13 +451,13 @@ static void cmd_select(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing session address argument\n");
+		interactive_printf("Missing session address argument\n");
 		return;
 	}
 
 	proxy = find_session(argv[1]);
 	if (proxy == NULL) {
-		rl_printf("Session %s not available\n", argv[1]);
+		interactive_printf("Session %s not available\n", argv[1]);
 		return;
 	}
 
@@ -499,7 +499,7 @@ static GDBusProxy *find_message(const char *path)
 
 static void transfer_info(GDBusProxy *proxy, int argc, char *argv[])
 {
-	rl_printf("Transfer %s\n", g_dbus_proxy_get_path(proxy));
+	interactive_printf("Transfer %s\n", g_dbus_proxy_get_path(proxy));
 
 	print_property(proxy, "Session");
 	print_property(proxy, "Name");
@@ -513,7 +513,7 @@ static void transfer_info(GDBusProxy *proxy, int argc, char *argv[])
 
 static void message_info(GDBusProxy *proxy, int argc, char *argv[])
 {
-	rl_printf("Message %s\n", g_dbus_proxy_get_path(proxy));
+	interactive_printf("Message %s\n", g_dbus_proxy_get_path(proxy));
 
 	print_property(proxy, "Folder");
 	print_property(proxy, "Subject");
@@ -538,7 +538,7 @@ static void cmd_info(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing object path argument\n");
+		interactive_printf("Missing object path argument\n");
 		return;
 	}
 
@@ -554,7 +554,7 @@ static void cmd_info(int argc, char *argv[])
 		return;
 	}
 
-	rl_printf("Object %s not available\n", argv[1]);
+	interactive_printf("Object %s not available\n", argv[1]);
 }
 
 static void cancel_reply(DBusMessage *message, void *user_data)
@@ -564,12 +564,12 @@ static void cancel_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to cancel: %s\n", error.name);
+		interactive_printf("Failed to cancel: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Cancel successful\n");
+	interactive_printf("Cancel successful\n");
 }
 
 static void cmd_cancel(int argc, char *argv[])
@@ -577,23 +577,23 @@ static void cmd_cancel(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing transfer address argument\n");
+		interactive_printf("Missing transfer address argument\n");
 		return;
 	}
 
 	proxy = find_transfer(argv[1]);
 	if (!proxy) {
-		rl_printf("Transfer %s not available\n", argv[1]);
+		interactive_printf("Transfer %s not available\n", argv[1]);
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "Cancel", NULL, cancel_reply, NULL,
 							NULL) == FALSE) {
-		rl_printf("Failed to cancel transfer\n");
+		interactive_printf("Failed to cancel transfer\n");
 		return;
 	}
 
-	rl_printf("Attempting to cancel transfer %s\n",
+	interactive_printf("Attempting to cancel transfer %s\n",
 						g_dbus_proxy_get_path(proxy));
 }
 
@@ -604,12 +604,12 @@ static void suspend_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to suspend: %s\n", error.name);
+		interactive_printf("Failed to suspend: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Suspend successful\n");
+	interactive_printf("Suspend successful\n");
 }
 
 static void cmd_suspend(int argc, char *argv[])
@@ -617,23 +617,23 @@ static void cmd_suspend(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing transfer address argument\n");
+		interactive_printf("Missing transfer address argument\n");
 		return;
 	}
 
 	proxy = find_transfer(argv[1]);
 	if (!proxy) {
-		rl_printf("Transfer %s not available\n", argv[1]);
+		interactive_printf("Transfer %s not available\n", argv[1]);
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "Suspend", NULL, suspend_reply,
 						NULL, NULL) == FALSE) {
-		rl_printf("Failed to suspend transfer\n");
+		interactive_printf("Failed to suspend transfer\n");
 		return;
 	}
 
-	rl_printf("Attempting to suspend transfer %s\n",
+	interactive_printf("Attempting to suspend transfer %s\n",
 						g_dbus_proxy_get_path(proxy));
 }
 
@@ -644,12 +644,12 @@ static void resume_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to resume: %s\n", error.name);
+		interactive_printf("Failed to resume: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Resume successful\n");
+	interactive_printf("Resume successful\n");
 }
 
 static void cmd_resume(int argc, char *argv[])
@@ -657,23 +657,23 @@ static void cmd_resume(int argc, char *argv[])
 	GDBusProxy *proxy;
 
 	if (argc < 2) {
-		rl_printf("Missing transfer address argument\n");
+		interactive_printf("Missing transfer address argument\n");
 		return;
 	}
 
 	proxy = find_transfer(argv[1]);
 	if (!proxy) {
-		rl_printf("Transfer %s not available\n", argv[1]);
+		interactive_printf("Transfer %s not available\n", argv[1]);
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "Resume", NULL, resume_reply,
 						NULL, NULL) == FALSE) {
-		rl_printf("Failed to resume transfer\n");
+		interactive_printf("Failed to resume transfer\n");
 		return;
 	}
 
-	rl_printf("Attempting to resume transfer %s\n",
+	interactive_printf("Attempting to resume transfer %s\n",
 						g_dbus_proxy_get_path(proxy));
 }
 
@@ -743,7 +743,7 @@ static void print_transfer_iter(DBusMessageIter *iter)
 
 	dbus_message_iter_get_basic(iter, &path);
 
-	rl_printf("Transfer %s\n", path);
+	interactive_printf("Transfer %s\n", path);
 
 	dbus_message_iter_next(iter);
 
@@ -758,7 +758,7 @@ static void send_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to send: %s\n", error.name);
+		interactive_printf("Failed to send: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -778,17 +778,17 @@ static void send_setup(DBusMessageIter *iter, void *user_data)
 static void opp_send(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (argc < 2) {
-		rl_printf("Missing file argument\n");
+		interactive_printf("Missing file argument\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "SendFile", send_setup, send_reply,
 					g_strdup(argv[1]), g_free) == FALSE) {
-		rl_printf("Failed to send\n");
+		interactive_printf("Failed to send\n");
 		return;
 	}
 
-	rl_printf("Attempting to send %s to %s\n", argv[1],
+	interactive_printf("Attempting to send %s to %s\n", argv[1],
 						g_dbus_proxy_get_path(proxy));
 }
 
@@ -800,7 +800,7 @@ static void push_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to PushMessage: %s\n", error.name);
+		interactive_printf("Failed to PushMessage: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -832,18 +832,18 @@ static void push_setup(DBusMessageIter *iter, void *user_data)
 static void map_send(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (argc < 2) {
-		rl_printf("Missing file argument\n");
+		interactive_printf("Missing file argument\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "PushMessage", push_setup,
 					push_reply, g_strdup(argv[1]),
 					g_free) == FALSE) {
-		rl_printf("Failed to send\n");
+		interactive_printf("Failed to send\n");
 		return;
 	}
 
-	rl_printf("Attempting to send %s to %s\n", argv[1],
+	interactive_printf("Attempting to send %s to %s\n", argv[1],
 						g_dbus_proxy_get_path(proxy));
 }
 
@@ -866,7 +866,7 @@ static void cmd_send(int argc, char *argv[])
 		return;
 	}
 
-	rl_printf("Command not supported\n");
+	interactive_printf("Command not supported\n");
 }
 
 static void change_folder_reply(DBusMessage *message, void *user_data)
@@ -876,12 +876,12 @@ static void change_folder_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to ChangeFolder: %s\n", error.name);
+		interactive_printf("Failed to ChangeFolder: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("ChangeFolder successful\n");
+	interactive_printf("ChangeFolder successful\n");
 }
 
 static void change_folder_setup(DBusMessageIter *iter, void *user_data)
@@ -899,14 +899,14 @@ static void select_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to Select: %s\n", error.name);
+		interactive_printf("Failed to Select: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
 	dbus_message_iter_init(message, &iter);
 
-	rl_printf("Select successful\n");
+	interactive_printf("Select successful\n");
 }
 
 static void select_setup(DBusMessageIter *iter, void *user_data)
@@ -925,12 +925,12 @@ static void setfolder_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to SetFolder: %s\n", error.name);
+		interactive_printf("Failed to SetFolder: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("SetFolder successful\n");
+	interactive_printf("SetFolder successful\n");
 }
 
 static void setfolder_setup(DBusMessageIter *iter, void *user_data)
@@ -971,52 +971,52 @@ static GDBusProxy *find_pbap(const char *path)
 static void ftp_cd(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (argc < 2) {
-		rl_printf("Missing path argument\n");
+		interactive_printf("Missing path argument\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "ChangeFolder", change_folder_setup,
 					change_folder_reply, g_strdup(argv[1]),
 					g_free) == FALSE) {
-		rl_printf("Failed to ChangeFolder\n");
+		interactive_printf("Failed to ChangeFolder\n");
 		return;
 	}
 
-	rl_printf("Attempting to ChangeFolder to %s\n", argv[1]);
+	interactive_printf("Attempting to ChangeFolder to %s\n", argv[1]);
 }
 
 static void pbap_cd(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (argc < 2) {
-		rl_printf("Missing path argument\n");
+		interactive_printf("Missing path argument\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "Select", select_setup,
 					select_reply, g_strdup(argv[1]),
 					g_free) == FALSE) {
-		rl_printf("Failed to Select\n");
+		interactive_printf("Failed to Select\n");
 		return;
 	}
 
-	rl_printf("Attempting to Select to %s\n", argv[1]);
+	interactive_printf("Attempting to Select to %s\n", argv[1]);
 }
 
 static void map_cd(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (argc < 2) {
-		rl_printf("Missing path argument\n");
+		interactive_printf("Missing path argument\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "SetFolder", setfolder_setup,
 					setfolder_reply, g_strdup(argv[1]),
 					g_free) == FALSE) {
-		rl_printf("Failed to SetFolder\n");
+		interactive_printf("Failed to SetFolder\n");
 		return;
 	}
 
-	rl_printf("Attempting to SetFolder to %s\n", argv[1]);
+	interactive_printf("Attempting to SetFolder to %s\n", argv[1]);
 }
 
 static void cmd_cd(int argc, char *argv[])
@@ -1044,7 +1044,7 @@ static void cmd_cd(int argc, char *argv[])
 		return;
 	}
 
-	rl_printf("Command not supported\n");
+	interactive_printf("Command not supported\n");
 }
 
 static void list_folder_reply(DBusMessage *message, void *user_data)
@@ -1055,7 +1055,7 @@ static void list_folder_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to ListFolder: %s\n", error.name);
+		interactive_printf("Failed to ListFolder: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1078,11 +1078,11 @@ static void ftp_ls(GDBusProxy *proxy, int argc, char *argv[])
 	if (g_dbus_proxy_method_call(proxy, "ListFolder", NULL,
 						list_folder_reply, NULL,
 						NULL) == FALSE) {
-		rl_printf("Failed to ls\n");
+		interactive_printf("Failed to ls\n");
 		return;
 	}
 
-	rl_printf("Attempting to ListFolder\n");
+	interactive_printf("Attempting to ListFolder\n");
 }
 
 static void parse_list_reply(DBusMessage *message)
@@ -1119,7 +1119,7 @@ static void list_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to List: %s\n", error.name);
+		interactive_printf("Failed to List: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1148,7 +1148,7 @@ static void search_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to Search: %s\n", error.name);
+		interactive_printf("Failed to Search: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1182,11 +1182,11 @@ static void pbap_search(GDBusProxy *proxy, int argc, char *argv[])
 	if (g_dbus_proxy_method_call(proxy, "Search", search_setup,
 					search_reply, g_strdup(argv[1]),
 					g_free) == FALSE) {
-		rl_printf("Failed to Search\n");
+		interactive_printf("Failed to Search\n");
 		return;
 	}
 
-	rl_printf("Attempting to Search\n");
+	interactive_printf("Attempting to Search\n");
 }
 
 static void list_folders_reply(DBusMessage *message, void *user_data)
@@ -1197,7 +1197,7 @@ static void list_folders_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to ListFolders: %s\n", error.name);
+		interactive_printf("Failed to ListFolders: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1238,7 +1238,7 @@ static void list_messages_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to ListFolders: %s\n", error.name);
+		interactive_printf("Failed to ListFolders: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1257,7 +1257,7 @@ static void list_messages_reply(DBusMessage *message, void *user_data)
 
 		dbus_message_iter_recurse(&array, &entry);
 		dbus_message_iter_get_basic(&entry, &obj);
-		rl_printf("\t%s\n", obj);
+		interactive_printf("\t%s\n", obj);
 		dbus_message_iter_next(&array);
 	}
 }
@@ -1286,11 +1286,11 @@ static void pbap_list(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (g_dbus_proxy_method_call(proxy, "List", list_setup, list_reply,
 						NULL, NULL) == FALSE) {
-		rl_printf("Failed to List\n");
+		interactive_printf("Failed to List\n");
 		return;
 	}
 
-	rl_printf("Attempting to List\n");
+	interactive_printf("Attempting to List\n");
 }
 
 static void get_size_reply(DBusMessage *message, void *user_data)
@@ -1302,7 +1302,7 @@ static void get_size_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to GetSize: %s\n", error.name);
+		interactive_printf("Failed to GetSize: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1318,11 +1318,11 @@ static void pbap_get_size(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (g_dbus_proxy_method_call(proxy, "GetSize", NULL, get_size_reply,
 						proxy, NULL) == FALSE) {
-		rl_printf("Failed to GetSize\n");
+		interactive_printf("Failed to GetSize\n");
 		return;
 	}
 
-	rl_printf("Attempting to GetSize\n");
+	interactive_printf("Attempting to GetSize\n");
 }
 
 static void pbap_ls(GDBusProxy *proxy, int argc, char *argv[])
@@ -1343,11 +1343,11 @@ static void map_ls_messages(GDBusProxy *proxy, int argc, char *argv[])
 	if (g_dbus_proxy_method_call(proxy, "ListMessages", list_messages_setup,
 					list_messages_reply, g_strdup(argv[1]),
 					g_free) == FALSE) {
-		rl_printf("Failed to ListMessages\n");
+		interactive_printf("Failed to ListMessages\n");
 		return;
 	}
 
-	rl_printf("Attempting to ListMessages\n");
+	interactive_printf("Attempting to ListMessages\n");
 }
 
 static void map_ls(GDBusProxy *proxy, int argc, char *argv[])
@@ -1360,11 +1360,11 @@ static void map_ls(GDBusProxy *proxy, int argc, char *argv[])
 	if (g_dbus_proxy_method_call(proxy, "ListFolders", list_folders_setup,
 						list_folders_reply, NULL,
 						NULL) == FALSE) {
-		rl_printf("Failed to ListFolders\n");
+		interactive_printf("Failed to ListFolders\n");
 		return;
 	}
 
-	rl_printf("Attempting to ListFolders\n");
+	interactive_printf("Attempting to ListFolders\n");
 }
 
 static void cmd_ls(int argc, char *argv[])
@@ -1392,7 +1392,7 @@ static void cmd_ls(int argc, char *argv[])
 		return;
 	}
 
-	rl_printf("Command not supported\n");
+	interactive_printf("Command not supported\n");
 }
 
 struct cp_args {
@@ -1449,12 +1449,12 @@ static void copy_file_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to CopyFile: %s\n", error.name);
+		interactive_printf("Failed to CopyFile: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("CopyFile successful\n");
+	interactive_printf("CopyFile successful\n");
 }
 
 static void ftp_copy(GDBusProxy *proxy, int argc, char *argv[])
@@ -1465,11 +1465,11 @@ static void ftp_copy(GDBusProxy *proxy, int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(proxy, "CopyFile", cp_setup,
 				copy_file_reply, args, cp_free) == FALSE) {
-		rl_printf("Failed to CopyFile\n");
+		interactive_printf("Failed to CopyFile\n");
 		return;
 	}
 
-	rl_printf("Attempting to CopyFile\n");
+	interactive_printf("Attempting to CopyFile\n");
 }
 
 static void get_file_reply(DBusMessage *message, void *user_data)
@@ -1480,7 +1480,7 @@ static void get_file_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to GetFile: %s\n", error.name);
+		interactive_printf("Failed to GetFile: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1509,11 +1509,11 @@ static void ftp_get(GDBusProxy *proxy, int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(proxy, "GetFile", get_file_setup,
 				get_file_reply, args, cp_free) == FALSE) {
-		rl_printf("Failed to GetFile\n");
+		interactive_printf("Failed to GetFile\n");
 		return;
 	}
 
-	rl_printf("Attempting to GetFile\n");
+	interactive_printf("Attempting to GetFile\n");
 }
 
 static void put_file_reply(DBusMessage *message, void *user_data)
@@ -1524,7 +1524,7 @@ static void put_file_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to PutFile: %s\n", error.name);
+		interactive_printf("Failed to PutFile: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1539,7 +1539,7 @@ static void ftp_put(GDBusProxy *proxy, int argc, char *argv[])
 	struct cp_args *args;
 
 	if (rindex(argv[2], ':') != NULL) {
-		rl_printf("Invalid target file argument\n");
+		interactive_printf("Invalid target file argument\n");
 		return;
 	}
 
@@ -1547,22 +1547,22 @@ static void ftp_put(GDBusProxy *proxy, int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(proxy, "PutFile", cp_setup, put_file_reply,
 						args, cp_free) == FALSE) {
-		rl_printf("Failed to PutFile\n");
+		interactive_printf("Failed to PutFile\n");
 		return;
 	}
 
-	rl_printf("Attempting to PutFile\n");
+	interactive_printf("Attempting to PutFile\n");
 }
 
 static void ftp_cp(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (argc < 2) {
-		rl_printf("Missing source file argument\n");
+		interactive_printf("Missing source file argument\n");
 		return;
 	}
 
 	if (argc < 3) {
-		rl_printf("Missing target file argument\n");
+		interactive_printf("Missing target file argument\n");
 		return;
 	}
 
@@ -1579,13 +1579,13 @@ static void pull_all_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to PullAll: %s\n", error.name);
+		interactive_printf("Failed to PullAll: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
 
-	rl_printf("PullAll successful\n");
+	interactive_printf("PullAll successful\n");
 }
 
 static void pull_all_setup(DBusMessageIter *iter, void *user_data)
@@ -1610,11 +1610,11 @@ static void pbap_pull_all(GDBusProxy *proxy, int argc, char *argv[])
 	if (g_dbus_proxy_method_call(proxy, "PullAll", pull_all_setup,
 					pull_all_reply, g_strdup(argv[2]),
 					g_free) == FALSE) {
-		rl_printf("Failed to PullAll\n");
+		interactive_printf("Failed to PullAll\n");
 		return;
 	}
 
-	rl_printf("Attempting to PullAll\n");
+	interactive_printf("Attempting to PullAll\n");
 }
 
 static void pull_reply(DBusMessage *message, void *user_data)
@@ -1624,13 +1624,13 @@ static void pull_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to Pull: %s\n", error.name);
+		interactive_printf("Failed to Pull: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
 
-	rl_printf("Pull successful\n");
+	interactive_printf("Pull successful\n");
 }
 
 static void pull_setup(DBusMessageIter *iter, void *user_data)
@@ -1659,22 +1659,22 @@ static void pbap_pull(GDBusProxy *proxy, int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(proxy, "Pull", pull_setup, pull_reply,
 						args, cp_free) == FALSE) {
-		rl_printf("Failed to Pull\n");
+		interactive_printf("Failed to Pull\n");
 		return;
 	}
 
-	rl_printf("Attempting to Pull\n");
+	interactive_printf("Attempting to Pull\n");
 }
 
 static void pbap_cp(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (argc < 2) {
-		rl_printf("Missing source file argument\n");
+		interactive_printf("Missing source file argument\n");
 		return;
 	}
 
 	if (argc < 3) {
-		rl_printf("Missing target file argument\n");
+		interactive_printf("Missing target file argument\n");
 		return;
 	}
 
@@ -1692,7 +1692,7 @@ static void get_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to Get: %s\n", error.name);
+		interactive_printf("Failed to Get: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
@@ -1716,28 +1716,28 @@ static void map_cp(GDBusProxy *proxy, int argc, char *argv[])
 	GDBusProxy *obj;
 
 	if (argc < 2) {
-		rl_printf("Missing message argument\n");
+		interactive_printf("Missing message argument\n");
 		return;
 	}
 
 	obj = find_message(argv[1]);
 	if (obj == NULL) {
-		rl_printf("Invalid message argument\n");
+		interactive_printf("Invalid message argument\n");
 		return;
 	}
 
 	if (argc < 3) {
-		rl_printf("Missing target file argument\n");
+		interactive_printf("Missing target file argument\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(obj, "Get", get_setup, get_reply,
 					g_strdup(argv[2]), g_free) == FALSE) {
-		rl_printf("Failed to Get\n");
+		interactive_printf("Failed to Get\n");
 		return;
 	}
 
-	rl_printf("Attempting to Get\n");
+	interactive_printf("Attempting to Get\n");
 }
 
 static void cmd_cp(int argc, char *argv[])
@@ -1766,7 +1766,7 @@ static void cmd_cp(int argc, char *argv[])
 		return;
 	}
 
-	rl_printf("Command not supported\n");
+	interactive_printf("Command not supported\n");
 }
 
 static void move_file_reply(DBusMessage *message, void *user_data)
@@ -1776,12 +1776,12 @@ static void move_file_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to MoveFile: %s\n", error.name);
+		interactive_printf("Failed to MoveFile: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("MoveFile successful\n");
+	interactive_printf("MoveFile successful\n");
 }
 
 static void cmd_mv(int argc, char *argv[])
@@ -1793,18 +1793,18 @@ static void cmd_mv(int argc, char *argv[])
 		return;
 
 	if (argc < 2) {
-		rl_printf("Missing source file argument\n");
+		interactive_printf("Missing source file argument\n");
 		return;
 	}
 
 	if (argc < 3) {
-		rl_printf("Missing target file argument\n");
+		interactive_printf("Missing target file argument\n");
 		return;
 	}
 
 	proxy = find_ftp(g_dbus_proxy_get_path(default_session));
 	if (proxy == NULL) {
-		rl_printf("Command not supported\n");
+		interactive_printf("Command not supported\n");
 		return;
 	}
 
@@ -1812,11 +1812,11 @@ static void cmd_mv(int argc, char *argv[])
 
 	if (g_dbus_proxy_method_call(proxy, "MoveFile", cp_setup,
 				move_file_reply, args, cp_free) == FALSE) {
-		rl_printf("Failed to MoveFile\n");
+		interactive_printf("Failed to MoveFile\n");
 		return;
 	}
 
-	rl_printf("Attempting to MoveFile\n");
+	interactive_printf("Attempting to MoveFile\n");
 }
 
 static void delete_reply(DBusMessage *message, void *user_data)
@@ -1826,12 +1826,12 @@ static void delete_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to Delete: %s\n", error.name);
+		interactive_printf("Failed to Delete: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("Delete successful\n");
+	interactive_printf("Delete successful\n");
 }
 
 static void delete_setup(DBusMessageIter *iter, void *user_data)
@@ -1844,26 +1844,26 @@ static void delete_setup(DBusMessageIter *iter, void *user_data)
 static void ftp_rm(GDBusProxy *proxy, int argc, char *argv[])
 {
 	if (argc < 2) {
-		rl_printf("Missing file argument\n");
+		interactive_printf("Missing file argument\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "Delete", delete_setup,
 					delete_reply, g_strdup(argv[1]),
 					g_free) == FALSE) {
-		rl_printf("Failed to Delete\n");
+		interactive_printf("Failed to Delete\n");
 		return;
 	}
 
-	rl_printf("Attempting to Delete\n");
+	interactive_printf("Attempting to Delete\n");
 }
 
 static void set_delete_reply(const DBusError *error, void *user_data)
 {
 	if (dbus_error_is_set(error))
-		rl_printf("Failed to set Deleted: %s\n", error->name);
+		interactive_printf("Failed to set Deleted: %s\n", error->name);
 	else
-		rl_printf("Set Deleted successful\n");
+		interactive_printf("Set Deleted successful\n");
 }
 
 static void map_rm(GDBusProxy *proxy, int argc, char *argv[])
@@ -1872,24 +1872,24 @@ static void map_rm(GDBusProxy *proxy, int argc, char *argv[])
 	dbus_bool_t value = TRUE;
 
 	if (argc < 2) {
-		rl_printf("Missing message argument\n");
+		interactive_printf("Missing message argument\n");
 		return;
 	}
 
 	msg = find_message(argv[1]);
 	if (msg == NULL) {
-		rl_printf("Invalid message argument\n");
+		interactive_printf("Invalid message argument\n");
 		return;
 	}
 
 	if (g_dbus_proxy_set_property_basic(msg, "Deleted", DBUS_TYPE_BOOLEAN,
 						&value, set_delete_reply,
 						NULL, NULL) == FALSE) {
-		rl_printf("Failed to set Deleted\n");
+		interactive_printf("Failed to set Deleted\n");
 		return;
 	}
 
-	rl_printf("Attempting to set Deleted\n");
+	interactive_printf("Attempting to set Deleted\n");
 }
 
 static void cmd_rm(int argc, char *argv[])
@@ -1911,7 +1911,7 @@ static void cmd_rm(int argc, char *argv[])
 		return;
 	}
 
-	rl_printf("Command not supported\n");
+	interactive_printf("Command not supported\n");
 }
 
 static void create_folder_reply(DBusMessage *message, void *user_data)
@@ -1921,12 +1921,12 @@ static void create_folder_reply(DBusMessage *message, void *user_data)
 	dbus_error_init(&error);
 
 	if (dbus_set_error_from_message(&error, message) == TRUE) {
-		rl_printf("Failed to CreateFolder: %s\n", error.name);
+		interactive_printf("Failed to CreateFolder: %s\n", error.name);
 		dbus_error_free(&error);
 		return;
 	}
 
-	rl_printf("CreateFolder successful\n");
+	interactive_printf("CreateFolder successful\n");
 }
 
 static void create_folder_setup(DBusMessageIter *iter, void *user_data)
@@ -1944,24 +1944,24 @@ static void cmd_mkdir(int argc, char *argv[])
 		return;
 
 	if (argc < 2) {
-		rl_printf("Missing folder argument\n");
+		interactive_printf("Missing folder argument\n");
 		return;
 	}
 
 	proxy = find_ftp(g_dbus_proxy_get_path(default_session));
 	if (proxy == NULL) {
-		rl_printf("Command not supported\n");
+		interactive_printf("Command not supported\n");
 		return;
 	}
 
 	if (g_dbus_proxy_method_call(proxy, "CreateFolder", create_folder_setup,
 					create_folder_reply, g_strdup(argv[1]),
 					g_free) == FALSE) {
-		rl_printf("Failed to CreateFolder\n");
+		interactive_printf("Failed to CreateFolder\n");
 		return;
 	}
 
-	rl_printf("Attempting to CreateFolder\n");
+	interactive_printf("Attempting to CreateFolder\n");
 }
 
 static const struct {
@@ -2232,7 +2232,7 @@ static void print_transferred(struct transfer_data *data, const char *str,
 	data->transferred = valu64;
 
 	if (data->size == 0) {
-		rl_printf("%sTransferred: %" PRIu64 " (@%" PRIu64 "KB/s)\n",
+		interactive_printf("%sTransferred: %" PRIu64 " (@%" PRIu64 "KB/s)\n",
 						str, valu64, speed / 1000);
 		return;
 	}
@@ -2240,7 +2240,7 @@ static void print_transferred(struct transfer_data *data, const char *str,
 	seconds = (data->size - data->transferred) / speed;
 	minutes = seconds / 60;
 	seconds %= 60;
-	rl_printf("%sTransferred: %" PRIu64 " (@%" PRIu64 "KB/s %02u:%02u)\n",
+	interactive_printf("%sTransferred: %" PRIu64 " (@%" PRIu64 "KB/s %02u:%02u)\n",
 				str, valu64, speed / 1000, minutes, seconds);
 }
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC 3/5] tools/btmgmt: Rewrite interactive mode on top of client code
  2015-02-12 17:52 [RFC 1/5] client/display: Add initial code for handling interactive mode Szymon Janc
  2015-02-12 17:52 ` [RFC 2/5] client/display: Prefix remaining functions with interactive_ Szymon Janc
@ 2015-02-12 17:52 ` Szymon Janc
  2015-02-12 17:52 ` [RFC 4/5] client/display: Rename to client/interactive Szymon Janc
  2015-02-12 17:52 ` [RFC 5/5] android: Fix btmgmt build Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Szymon Janc @ 2015-02-12 17:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Move direct readline dependency out of btmgmt and use common
interactive code.
---
 tools/btmgmt.c | 739 ++++++++++++++++-----------------------------------------
 1 file changed, 198 insertions(+), 541 deletions(-)

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index abc2fd0..b02af35 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -37,10 +37,7 @@
 #include <poll.h>
 #include <getopt.h>
 #include <stdbool.h>
-#include <wordexp.h>
-
-#include <readline/readline.h>
-#include <readline/history.h>
+#include <ctype.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
@@ -64,9 +61,6 @@ static bool discovery = false;
 static bool resolve_names = true;
 static bool interactive = false;
 
-static char *saved_prompt = NULL;
-static int saved_point = 0;
-
 static struct {
 	uint16_t index;
 	uint16_t req;
@@ -83,6 +77,14 @@ static int pending_index = 0;
 
 #define PROMPT_ON	COLOR_BLUE "[mgmt]" COLOR_OFF "# "
 
+static int get_index(void)
+{
+	if (mgmt_index == MGMT_INDEX_NONE)
+		return 0;
+
+	return mgmt_index;
+}
+
 static void update_prompt(uint16_t index)
 {
 	char str[32];
@@ -94,13 +96,7 @@ static void update_prompt(uint16_t index)
 		snprintf(str, sizeof(str),
 				COLOR_BLUE "[hci%u]" COLOR_OFF "# ", index);
 
-	if (saved_prompt) {
-		free(saved_prompt);
-		saved_prompt = strdup(str);
-		return;
-	}
-
-	rl_set_prompt(str);
+	interactive_update_prompt(str);
 }
 
 static void noninteractive_quit(int status)
@@ -383,19 +379,7 @@ static void release_prompt(void)
 	memset(&prompt, 0, sizeof(prompt));
 	prompt.index = MGMT_INDEX_NONE;
 
-	if (!saved_prompt)
-		return;
-
-	/* This will cause rl_expand_prompt to re-run over the last prompt,
-	 * but our prompt doesn't expand anyway.
-	 */
-	rl_set_prompt(saved_prompt);
-	rl_replace_line("", 0);
-	rl_point = saved_point;
-	rl_redisplay();
-
-	free(saved_prompt);
-	saved_prompt = NULL;
+	interactive_release_prompt();
 }
 
 static void disconnected(uint16_t index, uint16_t len, const void *param,
@@ -801,26 +785,6 @@ static bool prompt_input(const char *input)
 	return true;
 }
 
-static void btmgmt_interactive_prompt(const char *msg)
-{
-	if (saved_prompt)
-		return;
-
-	saved_prompt = strdup(rl_prompt);
-	if (!saved_prompt)
-		return;
-
-	saved_point = rl_point;
-
-	rl_set_prompt("");
-	rl_redisplay();
-
-	rl_set_prompt(msg);
-
-	rl_replace_line("", 0);
-	rl_redisplay();
-}
-
 static size_t get_input(char *buf, size_t buf_len)
 {
 	size_t len;
@@ -856,7 +820,7 @@ static void ask(uint16_t index, uint16_t req, const struct mgmt_addr_info *addr,
 					COLOR_BOLDGRAY ">>" COLOR_OFF);
 
 	if (interactive) {
-		btmgmt_interactive_prompt(msg);
+		interactive_prompt(msg);
 		va_end(ap);
 		return;
 	}
@@ -972,8 +936,7 @@ done:
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_version(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_version(int argc, char **argv)
 {
 	if (mgmt_send(mgmt, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE,
 				0, NULL, version_rsp, NULL, NULL) == 0) {
@@ -1032,8 +995,7 @@ done:
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_commands(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_commands(int argc, char **argv)
 {
 	if (mgmt_send(mgmt, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE,
 				0, NULL, commands_rsp, NULL, NULL) == 0) {
@@ -1112,11 +1074,11 @@ done:
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_config(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_config(int argc, char **argv)
 {
 	void *data;
 
-	if (index == MGMT_INDEX_NONE) {
+	if (mgmt_index == MGMT_INDEX_NONE) {
 		if (mgmt_send(mgmt, MGMT_OP_READ_UNCONF_INDEX_LIST,
 					MGMT_INDEX_NONE, 0, NULL,
 					unconf_index_rsp, mgmt, NULL) == 0) {
@@ -1127,9 +1089,9 @@ static void cmd_config(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 		return;
 	}
 
-	data = UINT_TO_PTR(index);
+	data = UINT_TO_PTR(mgmt_index);
 
-	if (mgmt_send(mgmt, MGMT_OP_READ_CONFIG_INFO, index, 0, NULL,
+	if (mgmt_send(mgmt, MGMT_OP_READ_CONFIG_INFO, mgmt_index, 0, NULL,
 					config_info_rsp, data, NULL) == 0) {
 		error("Unable to send read_config_info cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -1228,11 +1190,11 @@ static void index_rsp(uint8_t status, uint16_t len, const void *param,
 		noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_info(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_info(int argc, char **argv)
 {
 	void *data;
 
-	if (index == MGMT_INDEX_NONE) {
+	if (mgmt_index == MGMT_INDEX_NONE) {
 		if (mgmt_send(mgmt, MGMT_OP_READ_INDEX_LIST,
 					MGMT_INDEX_NONE, 0, NULL,
 					index_rsp, mgmt, NULL) == 0) {
@@ -1243,9 +1205,9 @@ static void cmd_info(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 		return;
 	}
 
-	data = UINT_TO_PTR(index);
+	data = UINT_TO_PTR(mgmt_index);
 
-	if (mgmt_send(mgmt, MGMT_OP_READ_INFO, index, 0, NULL, info_rsp,
+	if (mgmt_send(mgmt, MGMT_OP_READ_INFO, mgmt_index, 0, NULL, info_rsp,
 							data, NULL) == 0) {
 		error("Unable to send read_info cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -1333,24 +1295,21 @@ static void cmd_setting(struct mgmt *mgmt, uint16_t index, uint16_t op,
 	else
 		val = atoi(argv[1]);
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	if (send_cmd(mgmt, op, index, sizeof(val), &val, setting_rsp) == 0) {
 		error("Unable to send %s cmd", mgmt_opstr(op));
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 }
 
-static void cmd_power(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_power(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_POWERED, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_POWERED, argc, argv);
 }
 
-static void cmd_discov(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_discov(int argc, char **argv)
 {
 	struct mgmt_cp_set_discoverable cp;
+	int index;
 
 	if (argc < 2) {
 		print("Usage: btmgmt %s <yes/no/limited> [timeout]", argv[0]);
@@ -1371,8 +1330,7 @@ static void cmd_discov(struct mgmt *mgmt, uint16_t index, int argc,
 	if (argc > 2)
 		cp.timeout = htobs(atoi(argv[2]));
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
+	index = get_index();
 
 	if (send_cmd(mgmt, MGMT_OP_SET_DISCOVERABLE, index, sizeof(cp), &cp,
 							setting_rsp) == 0) {
@@ -1381,36 +1339,33 @@ static void cmd_discov(struct mgmt *mgmt, uint16_t index, int argc,
 	}
 }
 
-static void cmd_connectable(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_connectable(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_CONNECTABLE, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_CONNECTABLE, argc, argv);
 }
 
-static void cmd_fast_conn(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_fast_conn(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_FAST_CONNECTABLE, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_FAST_CONNECTABLE, argc,
+									argv);
 }
 
-static void cmd_bondable(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_bondable(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_BONDABLE, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_BONDABLE, argc, argv);
 }
 
-static void cmd_linksec(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_linksec(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_LINK_SECURITY, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_LINK_SECURITY, argc, argv);
 }
 
-static void cmd_ssp(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_ssp(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_SSP, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_SSP, argc, argv);
 }
 
-static void cmd_sc(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_sc(int argc, char **argv)
 {
 	uint8_t val;
 
@@ -1428,39 +1383,35 @@ static void cmd_sc(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 	else
 		val = atoi(argv[1]);
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
-	if (send_cmd(mgmt, MGMT_OP_SET_SECURE_CONN, index,
+	if (send_cmd(mgmt, MGMT_OP_SET_SECURE_CONN, get_index(),
 					sizeof(val), &val, setting_rsp) == 0) {
 		error("Unable to send set_secure_conn cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 }
 
-static void cmd_hs(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_hs(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_HS, argc, argv);
+
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_HS, argc, argv);
 }
 
-static void cmd_le(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_le(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_LE, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_LE, argc, argv);
 }
 
-static void cmd_advertising(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_advertising(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_ADVERTISING, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_ADVERTISING, argc, argv);
 }
 
-static void cmd_bredr(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_bredr(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_BREDR, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_BREDR, argc, argv);
 }
 
-static void cmd_privacy(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_privacy(int argc, char **argv)
 {
 	struct mgmt_cp_set_privacy cp;
 
@@ -1476,9 +1427,6 @@ static void cmd_privacy(struct mgmt *mgmt, uint16_t index, int argc,
 	else
 		cp.privacy = atoi(argv[1]);
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	if (argc > 2) {
 		if (convert_hexstr(argv[2], cp.irk,
 					sizeof(cp.irk)) != sizeof(cp.irk)) {
@@ -1503,7 +1451,7 @@ static void cmd_privacy(struct mgmt *mgmt, uint16_t index, int argc,
 		close(fd);
 	}
 
-	if (send_cmd(mgmt, MGMT_OP_SET_PRIVACY, index, sizeof(cp), &cp,
+	if (send_cmd(mgmt, MGMT_OP_SET_PRIVACY, get_index(), sizeof(cp), &cp,
 							setting_rsp) == 0) {
 		error("Unable to send Set Privacy command");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -1532,7 +1480,7 @@ static void class_rsp(uint16_t op, uint16_t id, uint8_t status, uint16_t len,
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_class(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_class(int argc, char **argv)
 {
 	uint8_t class[2];
 
@@ -1544,11 +1492,8 @@ static void cmd_class(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 	class[0] = atoi(argv[1]);
 	class[1] = atoi(argv[2]);
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
-	if (send_cmd(mgmt, MGMT_OP_SET_DEV_CLASS, index, sizeof(class), class,
-							class_rsp) == 0) {
+	if (send_cmd(mgmt, MGMT_OP_SET_DEV_CLASS, get_index(),
+				sizeof(class), class, class_rsp) == 0) {
 		error("Unable to send set_dev_class cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -1593,8 +1538,7 @@ static struct option disconnect_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_disconnect(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_disconnect(int argc, char **argv)
 {
 	struct mgmt_cp_disconnect cp;
 	uint8_t type = BDADDR_BREDR;
@@ -1624,14 +1568,11 @@ static void cmd_disconnect(struct mgmt *mgmt, uint16_t index, int argc,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.addr.bdaddr);
 	cp.addr.type = type;
 
-	if (mgmt_send(mgmt, MGMT_OP_DISCONNECT, index, sizeof(cp), &cp,
+	if (mgmt_send(mgmt, MGMT_OP_DISCONNECT, get_index(), sizeof(cp), &cp,
 					disconnect_rsp, NULL, NULL) == 0) {
 		error("Unable to send disconnect cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -1667,12 +1608,9 @@ static void con_rsp(uint8_t status, uint16_t len, const void *param,
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_con(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_con(int argc, char **argv)
 {
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
-	if (mgmt_send(mgmt, MGMT_OP_GET_CONNECTIONS, index, 0, NULL,
+	if (mgmt_send(mgmt, MGMT_OP_GET_CONNECTIONS, get_index(), 0, NULL,
 						con_rsp, NULL, NULL) == 0) {
 		error("Unable to send get_connections cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -1718,8 +1656,7 @@ static void uuid_to_uuid128(uuid_t *uuid128, const uuid_t *uuid)
 
 #define MAX_UUIDS 4
 
-static void cmd_find_service(struct mgmt *mgmt, uint16_t index, int argc,
-			     char **argv)
+static void cmd_find_service(int argc, char **argv)
 {
 	struct mgmt_cp_start_service_discovery *cp;
 	uint8_t buf[sizeof(*cp) + 16 * MAX_UUIDS];
@@ -1731,9 +1668,6 @@ static void cmd_find_service(struct mgmt *mgmt, uint16_t index, int argc,
 	uint16_t count;
 	int opt;
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	type = 0;
 	type |= (1 << BDADDR_BREDR);
 	type |= (1 << BDADDR_LE_PUBLIC);
@@ -1801,7 +1735,7 @@ static void cmd_find_service(struct mgmt *mgmt, uint16_t index, int argc,
 	cp->rssi = rssi;
 	cp->uuid_count = cpu_to_le16(count);
 
-	if (mgmt_send(mgmt, MGMT_OP_START_SERVICE_DISCOVERY, index,
+	if (mgmt_send(mgmt, MGMT_OP_START_SERVICE_DISCOVERY, get_index(),
 				sizeof(*cp) + count * 16, cp,
 				find_service_rsp, NULL, NULL) == 0) {
 		error("Unable to send start_service_discovery cmd");
@@ -1834,15 +1768,12 @@ static struct option find_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_find(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_find(int argc, char **argv)
 {
 	struct mgmt_cp_start_discovery cp;
 	uint8_t type;
 	int opt;
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	type = 0;
 	type |= (1 << BDADDR_BREDR);
 	type |= (1 << BDADDR_LE_PUBLIC);
@@ -1877,8 +1808,8 @@ static void cmd_find(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 	memset(&cp, 0, sizeof(cp));
 	cp.type = type;
 
-	if (mgmt_send(mgmt, MGMT_OP_START_DISCOVERY, index, sizeof(cp), &cp,
-						find_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_START_DISCOVERY, get_index(),
+				sizeof(cp), &cp, find_rsp, NULL, NULL) == 0) {
 		error("Unable to send start_discovery cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -1894,7 +1825,7 @@ static void name_rsp(uint8_t status, uint16_t len, const void *param,
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_name(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_name(int argc, char **argv)
 {
 	struct mgmt_cp_set_local_name cp;
 
@@ -1903,17 +1834,14 @@ static void cmd_name(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	strncpy((char *) cp.name, argv[1], HCI_MAX_NAME_LENGTH);
 	if (argc > 2)
 		strncpy((char *) cp.short_name, argv[2],
 					MGMT_MAX_SHORT_NAME_LENGTH);
 
-	if (mgmt_send(mgmt, MGMT_OP_SET_LOCAL_NAME, index, sizeof(cp), &cp,
-						name_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_SET_LOCAL_NAME, get_index(),
+				sizeof(cp), &cp, name_rsp, NULL, NULL) == 0) {
 		error("Unable to send set_name cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -1963,7 +1891,7 @@ static struct option pair_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_pair(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_pair(int argc, char **argv)
 {
 	struct mgmt_cp_pair_device cp;
 	uint8_t cap = 0x01;
@@ -1998,9 +1926,6 @@ static void cmd_pair(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.addr.bdaddr);
 	cp.addr.type = type;
@@ -2009,7 +1934,7 @@ static void cmd_pair(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 	ba2str(&cp.addr.bdaddr, addr);
 	print("Pairing with %s (%s)", addr, typestr(cp.addr.type));
 
-	if (mgmt_send(mgmt, MGMT_OP_PAIR_DEVICE, index, sizeof(cp), &cp,
+	if (mgmt_send(mgmt, MGMT_OP_PAIR_DEVICE, get_index(), sizeof(cp), &cp,
 						pair_rsp, NULL, NULL) == 0) {
 		error("Unable to send pair_device cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -2056,8 +1981,7 @@ static struct option cancel_pair_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_cancel_pair(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_cancel_pair(int argc, char **argv)
 {
 	struct mgmt_addr_info cp;
 	uint8_t type = BDADDR_BREDR;
@@ -2087,15 +2011,12 @@ static void cmd_cancel_pair(struct mgmt *mgmt, uint16_t index, int argc,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.bdaddr);
 	cp.type = type;
 
-	if (mgmt_send(mgmt, MGMT_OP_CANCEL_PAIR_DEVICE, index, sizeof(cp), &cp,
-					cancel_pair_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_CANCEL_PAIR_DEVICE, get_index(), sizeof(cp),
+				&cp, cancel_pair_rsp, NULL, NULL) == 0) {
 		error("Unable to send cancel_pair_device cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -2140,8 +2061,7 @@ static struct option unpair_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_unpair(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_unpair(int argc, char **argv)
 {
 	struct mgmt_cp_unpair_device cp;
 	uint8_t type = BDADDR_BREDR;
@@ -2171,15 +2091,12 @@ static void cmd_unpair(struct mgmt *mgmt, uint16_t index, int argc,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.addr.bdaddr);
 	cp.addr.type = type;
 	cp.disconnect = 1;
 
-	if (mgmt_send(mgmt, MGMT_OP_UNPAIR_DEVICE, index, sizeof(cp), &cp,
+	if (mgmt_send(mgmt, MGMT_OP_UNPAIR_DEVICE, get_index(), sizeof(cp), &cp,
 						unpair_rsp, NULL, NULL) == 0) {
 		error("Unable to send unpair_device cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -2198,17 +2115,14 @@ static void keys_rsp(uint8_t status, uint16_t len, const void *param,
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_keys(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_keys(int argc, char **argv)
 {
 	struct mgmt_cp_load_link_keys cp;
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 
-	if (mgmt_send(mgmt, MGMT_OP_LOAD_LINK_KEYS, index, sizeof(cp), &cp,
-						keys_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_LOAD_LINK_KEYS, get_index(), sizeof(cp),
+					&cp, keys_rsp, NULL, NULL) == 0) {
 		error("Unable to send load_keys cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -2226,17 +2140,14 @@ static void ltks_rsp(uint8_t status, uint16_t len, const void *param,
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_ltks(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_ltks(int argc, char **argv)
 {
 	struct mgmt_cp_load_long_term_keys cp;
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 
-	if (mgmt_send(mgmt, MGMT_OP_LOAD_LONG_TERM_KEYS, index, sizeof(cp), &cp,
-						ltks_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_LOAD_LONG_TERM_KEYS, get_index(),
+				sizeof(cp), &cp, ltks_rsp, NULL, NULL) == 0) {
 		error("Unable to send load_ltks cmd");
 		return noninteractive_quit(EXIT_SUCCESS);
 	}
@@ -2267,16 +2178,13 @@ static struct option irks_options[] = {
 
 #define MAX_IRKS 4
 
-static void cmd_irks(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_irks(int argc, char **argv)
 {
 	struct mgmt_cp_load_irks *cp;
 	uint8_t buf[sizeof(*cp) + 23 * MAX_IRKS];
 	uint16_t count, local_index;
 	int opt;
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	cp = (void *) buf;
 	count = 0;
 
@@ -2319,7 +2227,7 @@ static void cmd_irks(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 
 	cp->irk_count = cpu_to_le16(count);
 
-	if (mgmt_send(mgmt, MGMT_OP_LOAD_IRKS, index,
+	if (mgmt_send(mgmt, MGMT_OP_LOAD_IRKS, get_index(),
 					sizeof(*cp) + count * 23, cp,
 					irks_rsp, NULL, NULL) == 0) {
 		error("Unable to send load_irks cmd");
@@ -2367,7 +2275,7 @@ static struct option block_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_block(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_block(int argc, char **argv)
 {
 	struct mgmt_cp_block_device cp;
 	uint8_t type = BDADDR_BREDR;
@@ -2397,14 +2305,11 @@ static void cmd_block(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.addr.bdaddr);
 	cp.addr.type = type;
 
-	if (send_cmd(mgmt, MGMT_OP_BLOCK_DEVICE, index, sizeof(cp), &cp,
+	if (send_cmd(mgmt, MGMT_OP_BLOCK_DEVICE, get_index(), sizeof(cp), &cp,
 							block_rsp) == 0) {
 		error("Unable to send block_device cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -2416,8 +2321,7 @@ static void unblock_usage(void)
 	print("Usage: btmgmt unblock [-t type] <remote address>");
 }
 
-static void cmd_unblock(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_unblock(int argc, char **argv)
 {
 	struct mgmt_cp_unblock_device cp;
 	uint8_t type = BDADDR_BREDR;
@@ -2447,22 +2351,18 @@ static void cmd_unblock(struct mgmt *mgmt, uint16_t index, int argc,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.addr.bdaddr);
 	cp.addr.type = type;
 
-	if (send_cmd(mgmt, MGMT_OP_UNBLOCK_DEVICE, index, sizeof(cp), &cp,
+	if (send_cmd(mgmt, MGMT_OP_UNBLOCK_DEVICE, get_index(), sizeof(cp), &cp,
 							block_rsp) == 0) {
 		error("Unable to send unblock_device cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 }
 
-static void cmd_add_uuid(struct mgmt *mgmt, uint16_t index, int argc,
-							char **argv)
+static void cmd_add_uuid(int argc, char **argv)
 {
 	struct mgmt_cp_add_uuid cp;
 	uint128_t uint128;
@@ -2473,9 +2373,6 @@ static void cmd_add_uuid(struct mgmt *mgmt, uint16_t index, int argc,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	if (bt_string2uuid(&uuid, argv[1]) < 0) {
 		print("Invalid UUID: %s", argv[1]);
 		return noninteractive_quit(EXIT_FAILURE);
@@ -2489,15 +2386,14 @@ static void cmd_add_uuid(struct mgmt *mgmt, uint16_t index, int argc,
 
 	cp.svc_hint = atoi(argv[2]);
 
-	if (send_cmd(mgmt, MGMT_OP_ADD_UUID, index, sizeof(cp), &cp,
+	if (send_cmd(mgmt, MGMT_OP_ADD_UUID, get_index(), sizeof(cp), &cp,
 							class_rsp) == 0) {
 		error("Unable to send add_uuid cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 }
 
-static void cmd_remove_uuid(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_remove_uuid(int argc, char **argv)
 {
 	struct mgmt_cp_remove_uuid cp;
 	uint128_t uint128;
@@ -2508,9 +2404,6 @@ static void cmd_remove_uuid(struct mgmt *mgmt, uint16_t index, int argc,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	if (bt_string2uuid(&uuid, argv[1]) < 0) {
 		print("Invalid UUID: %s", argv[1]);
 		return noninteractive_quit(EXIT_FAILURE);
@@ -2522,20 +2415,19 @@ static void cmd_remove_uuid(struct mgmt *mgmt, uint16_t index, int argc,
 	ntoh128((uint128_t *) uuid128.value.uuid128.data, &uint128);
 	htob128(&uint128, (uint128_t *) cp.uuid);
 
-	if (send_cmd(mgmt, MGMT_OP_REMOVE_UUID, index, sizeof(cp), &cp,
+	if (send_cmd(mgmt, MGMT_OP_REMOVE_UUID, get_index(), sizeof(cp), &cp,
 							class_rsp) == 0) {
 		error("Unable to send remove_uuid cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 }
 
-static void cmd_clr_uuids(struct mgmt *mgmt, uint16_t index, int argc,
-								char **argv)
+static void cmd_clr_uuids(int argc, char **argv)
 {
 	char *uuid_any = "00000000-0000-0000-0000-000000000000";
 	char *rm_argv[] = { "rm-uuid", uuid_any, NULL };
 
-	cmd_remove_uuid(mgmt, index, 2, rm_argv);
+	cmd_remove_uuid(2, rm_argv);
 }
 
 static void local_oob_rsp(uint8_t status, uint16_t len, const void *param,
@@ -2582,13 +2474,9 @@ static void local_oob_rsp(uint8_t status, uint16_t len, const void *param,
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_local_oob(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_local_oob(int argc, char **argv)
 {
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
-	if (mgmt_send(mgmt, MGMT_OP_READ_LOCAL_OOB_DATA, index, 0, NULL,
+	if (mgmt_send(mgmt, MGMT_OP_READ_LOCAL_OOB_DATA, get_index(), 0, NULL,
 					local_oob_rsp, NULL, NULL) == 0) {
 		error("Unable to send read_local_oob cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -2629,8 +2517,7 @@ static struct option remote_oob_opt[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_remote_oob(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_remote_oob(int argc, char **argv)
 {
 	struct mgmt_cp_add_remote_oob_data cp;
 	int opt;
@@ -2671,14 +2558,11 @@ static void cmd_remote_oob(struct mgmt *mgmt, uint16_t index,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	str2ba(argv[0], &cp.addr.bdaddr);
 
 	print("Adding OOB data for %s (%s)", argv[0], typestr(cp.addr.type));
 
-	if (mgmt_send(mgmt, MGMT_OP_ADD_REMOTE_OOB_DATA, index,
+	if (mgmt_send(mgmt, MGMT_OP_ADD_REMOTE_OOB_DATA, get_index(),
 				sizeof(cp), &cp, remote_oob_rsp,
 				NULL, NULL) == 0) {
 		error("Unable to send add_remote_oob cmd");
@@ -2704,7 +2588,7 @@ static void did_usage(void)
 	print("       possible source values: bluetooth, usb");
 }
 
-static void cmd_did(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
+static void cmd_did(int argc, char **argv)
 {
 	struct mgmt_cp_set_device_id cp;
 	uint16_t vendor, product, version , source;
@@ -2733,15 +2617,12 @@ static void cmd_did(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 	return noninteractive_quit(EXIT_FAILURE);
 
 done:
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	cp.source = htobs(source);
 	cp.vendor = htobs(vendor);
 	cp.product = htobs(product);
 	cp.version = htobs(version);
 
-	if (mgmt_send(mgmt, MGMT_OP_SET_DEVICE_ID, index, sizeof(cp), &cp,
+	if (mgmt_send(mgmt, MGMT_OP_SET_DEVICE_ID, get_index(), sizeof(cp), &cp,
 						did_rsp, NULL, NULL) == 0) {
 		error("Unable to send set_device_id cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -2765,8 +2646,7 @@ static void static_addr_usage(void)
 	print("Usage: btmgmt static-addr <address>");
 }
 
-static void cmd_static_addr(struct mgmt *mgmt, uint16_t index,
-							int argc, char **argv)
+static void cmd_static_addr(int argc, char **argv)
 {
 	struct mgmt_cp_set_static_address cp;
 
@@ -2775,13 +2655,10 @@ static void cmd_static_addr(struct mgmt *mgmt, uint16_t index,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	str2ba(argv[1], &cp.bdaddr);
 
-	if (mgmt_send(mgmt, MGMT_OP_SET_STATIC_ADDRESS, index, sizeof(cp), &cp,
-					static_addr_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_SET_STATIC_ADDRESS, get_index(),
+			sizeof(cp), &cp, static_addr_rsp, NULL, NULL) == 0) {
 		error("Unable to send set_static_address cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -2810,8 +2687,7 @@ static void options_rsp(uint16_t op, uint16_t id, uint8_t status,
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_public_addr(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_public_addr(int argc, char **argv)
 {
 	struct mgmt_cp_set_public_address cp;
 
@@ -2820,20 +2696,16 @@ static void cmd_public_addr(struct mgmt *mgmt, uint16_t index,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	str2ba(argv[1], &cp.bdaddr);
 
-	if (send_cmd(mgmt, MGMT_OP_SET_PUBLIC_ADDRESS, index, sizeof(cp), &cp,
-							options_rsp) == 0) {
+	if (send_cmd(mgmt, MGMT_OP_SET_PUBLIC_ADDRESS, get_index(),
+					sizeof(cp), &cp, options_rsp) == 0) {
 		error("Unable to send Set Public Address cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 }
 
-static void cmd_ext_config(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_ext_config(int argc, char **argv)
 {
 	struct mgmt_cp_set_external_config cp;
 
@@ -2849,20 +2721,16 @@ static void cmd_ext_config(struct mgmt *mgmt, uint16_t index,
 	else
 		cp.config = atoi(argv[1]);
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
-	if (send_cmd(mgmt, MGMT_OP_SET_EXTERNAL_CONFIG, index, sizeof(cp), &cp,
-							options_rsp) == 0) {
+	if (send_cmd(mgmt, MGMT_OP_SET_EXTERNAL_CONFIG, get_index(),
+					sizeof(cp), &cp, options_rsp) == 0) {
 		error("Unable to send Set External Config cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 }
 
-static void cmd_debug_keys(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_debug_keys(int argc, char **argv)
 {
-	cmd_setting(mgmt, index, MGMT_OP_SET_DEBUG_KEYS, argc, argv);
+	cmd_setting(mgmt, get_index(), MGMT_OP_SET_DEBUG_KEYS, argc, argv);
 }
 
 static void conn_info_rsp(uint8_t status, uint16_t len, const void *param,
@@ -2908,8 +2776,7 @@ static struct option conn_info_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_conn_info(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_conn_info(int argc, char **argv)
 {
 	struct mgmt_cp_get_conn_info cp;
 	uint8_t type = BDADDR_BREDR;
@@ -2939,14 +2806,11 @@ static void cmd_conn_info(struct mgmt *mgmt, uint16_t index,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.addr.bdaddr);
 	cp.addr.type = type;
 
-	if (mgmt_send(mgmt, MGMT_OP_GET_CONN_INFO, index, sizeof(cp), &cp,
+	if (mgmt_send(mgmt, MGMT_OP_GET_CONN_INFO, get_index(), sizeof(cp), &cp,
 					conn_info_rsp, NULL, NULL) == 0) {
 		error("Unable to send get_conn_info cmd");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -2970,8 +2834,7 @@ static void io_cap_usage(void)
 	print("Usage: btmgmt io-cap <cap>");
 }
 
-static void cmd_io_cap(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_io_cap(int argc, char **argv)
 {
 	struct mgmt_cp_set_io_capability cp;
 	uint8_t cap;
@@ -2981,15 +2844,12 @@ static void cmd_io_cap(struct mgmt *mgmt, uint16_t index,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	cap = strtol(argv[1], NULL, 0);
 	memset(&cp, 0, sizeof(cp));
 	cp.io_capability = cap;
 
-	if (mgmt_send(mgmt, MGMT_OP_SET_IO_CAPABILITY, index, sizeof(cp), &cp,
-					io_cap_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_SET_IO_CAPABILITY, get_index(),
+			sizeof(cp), &cp, io_cap_rsp, NULL, NULL) == 0) {
 		error("Unable to send set-io-cap cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -3012,8 +2872,7 @@ static void scan_params_usage(void)
 	print("Usage: btmgmt scan-params <interval> <window>");
 }
 
-static void cmd_scan_params(struct mgmt *mgmt, uint16_t index,
-							int argc, char **argv)
+static void cmd_scan_params(int argc, char **argv)
 {
 	struct mgmt_cp_set_scan_params cp;
 
@@ -3022,14 +2881,11 @@ static void cmd_scan_params(struct mgmt *mgmt, uint16_t index,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	cp.interval = strtol(argv[1], NULL, 0);
 	cp.window = strtol(argv[2], NULL, 0);
 
-	if (mgmt_send(mgmt, MGMT_OP_SET_SCAN_PARAMS, index, sizeof(cp), &cp,
-					scan_params_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_SET_SCAN_PARAMS, get_index(),
+			sizeof(cp), &cp, scan_params_rsp, NULL, NULL) == 0) {
 		error("Unable to send set_scan_params cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -3058,21 +2914,17 @@ static void clock_info_rsp(uint8_t status, uint16_t len, const void *param,
 	noninteractive_quit(EXIT_SUCCESS);
 }
 
-static void cmd_clock_info(struct mgmt *mgmt, uint16_t index,
-							int argc, char **argv)
+static void cmd_clock_info(int argc, char **argv)
 {
 	struct mgmt_cp_get_clock_info cp;
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 
 	if (argc > 1)
 		str2ba(argv[1], &cp.addr.bdaddr);
 
-	if (mgmt_send(mgmt, MGMT_OP_GET_CLOCK_INFO, index, sizeof(cp), &cp,
-					clock_info_rsp, NULL, NULL) == 0) {
+	if (mgmt_send(mgmt, MGMT_OP_GET_CLOCK_INFO, get_index(),
+			sizeof(cp), &cp, clock_info_rsp, NULL, NULL) == 0) {
 		error("Unable to send get_clock_info cmd");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
@@ -3099,8 +2951,7 @@ static struct option add_device_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_add_device(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_add_device(int argc, char **argv)
 {
 	struct mgmt_cp_add_device cp;
 	uint8_t action = 0x00;
@@ -3135,9 +2986,6 @@ static void cmd_add_device(struct mgmt *mgmt, uint16_t index,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.addr.bdaddr);
 	cp.addr.type = type;
@@ -3146,7 +2994,7 @@ static void cmd_add_device(struct mgmt *mgmt, uint16_t index,
 	ba2str(&cp.addr.bdaddr, addr);
 	print("Adding device with %s (%s)", addr, typestr(cp.addr.type));
 
-	if (mgmt_send(mgmt, MGMT_OP_ADD_DEVICE, index, sizeof(cp), &cp,
+	if (mgmt_send(mgmt, MGMT_OP_ADD_DEVICE, get_index(), sizeof(cp), &cp,
 					add_device_rsp, NULL, NULL) == 0) {
 		error("Unable to send add device command");
 		return noninteractive_quit(EXIT_FAILURE);
@@ -3173,8 +3021,7 @@ static struct option del_device_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static void cmd_del_device(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_del_device(int argc, char **argv)
 {
 	struct mgmt_cp_remove_device cp;
 	uint8_t type = BDADDR_BREDR;
@@ -3205,9 +3052,6 @@ static void cmd_del_device(struct mgmt *mgmt, uint16_t index,
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 
-	if (index == MGMT_INDEX_NONE)
-		index = 0;
-
 	memset(&cp, 0, sizeof(cp));
 	str2ba(argv[0], &cp.addr.bdaddr);
 	cp.addr.type = type;
@@ -3215,87 +3059,19 @@ static void cmd_del_device(struct mgmt *mgmt, uint16_t index,
 	ba2str(&cp.addr.bdaddr, addr);
 	print("Removing device with %s (%s)", addr, typestr(cp.addr.type));
 
-	if (mgmt_send(mgmt, MGMT_OP_REMOVE_DEVICE, index, sizeof(cp), &cp,
+	if (mgmt_send(mgmt, MGMT_OP_REMOVE_DEVICE, get_index(), sizeof(cp), &cp,
 					remove_device_rsp, NULL, NULL) == 0) {
 		error("Unable to send remove device command");
 		return noninteractive_quit(EXIT_FAILURE);
 	}
 }
 
-static void cmd_clr_devices(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_clr_devices(int argc, char **argv)
 {
 	char *bdaddr_any = "00:00:00:00:00:00";
 	char *rm_argv[] = { "del-device", bdaddr_any, NULL };
 
-	cmd_del_device(mgmt, index, 2, rm_argv);
-}
-
-struct cmd_info {
-	char *cmd;
-	void (*func)(struct mgmt *mgmt, uint16_t index, int argc, char **argv);
-	char *doc;
-	char * (*gen) (const char *text, int state);
-	void (*disp) (char **matches, int num_matches, int max_length);
-};
-
-static struct cmd_info all_cmd[] = {
-	{ "version",	cmd_version,	"Get the MGMT Version"		},
-	{ "commands",	cmd_commands,	"List supported commands"	},
-	{ "config",	cmd_config,	"Show configuration info"	},
-	{ "info",	cmd_info,	"Show controller info"		},
-	{ "power",	cmd_power,	"Toggle powered state"		},
-	{ "discov",	cmd_discov,	"Toggle discoverable state"	},
-	{ "connectable",cmd_connectable,"Toggle connectable state"	},
-	{ "fast-conn",	cmd_fast_conn,	"Toggle fast connectable state"	},
-	{ "bondable",	cmd_bondable,	"Toggle bondable state"		},
-	{ "pairable",	cmd_bondable,	"Toggle bondable state"		},
-	{ "linksec",	cmd_linksec,	"Toggle link level security"	},
-	{ "ssp",	cmd_ssp,	"Toggle SSP mode"		},
-	{ "sc",		cmd_sc,		"Toogle SC support"		},
-	{ "hs",		cmd_hs,		"Toggle HS support"		},
-	{ "le",		cmd_le,		"Toggle LE support"		},
-	{ "advertising",cmd_advertising,"Toggle LE advertising",	},
-	{ "bredr",	cmd_bredr,	"Toggle BR/EDR support",	},
-	{ "privacy",	cmd_privacy,	"Toggle privacy support"	},
-	{ "class",	cmd_class,	"Set device major/minor class"	},
-	{ "disconnect", cmd_disconnect, "Disconnect device"		},
-	{ "con",	cmd_con,	"List connections"		},
-	{ "find",	cmd_find,	"Discover nearby devices"	},
-	{ "find-service", cmd_find_service, "Discover nearby service"	},
-	{ "name",	cmd_name,	"Set local name"		},
-	{ "pair",	cmd_pair,	"Pair with a remote device"	},
-	{ "cancelpair",	cmd_cancel_pair,"Cancel pairing"		},
-	{ "unpair",	cmd_unpair,	"Unpair device"			},
-	{ "keys",	cmd_keys,	"Load Link Keys"		},
-	{ "ltks",	cmd_ltks,	"Load Long Term Keys"		},
-	{ "irks",	cmd_irks,	"Load Identity Resolving Keys"	},
-	{ "block",	cmd_block,	"Block Device"			},
-	{ "unblock",	cmd_unblock,	"Unblock Device"		},
-	{ "add-uuid",	cmd_add_uuid,	"Add UUID"			},
-	{ "rm-uuid",	cmd_remove_uuid,"Remove UUID"			},
-	{ "clr-uuids",	cmd_clr_uuids,	"Clear UUIDs"			},
-	{ "local-oob",	cmd_local_oob,	"Local OOB data"		},
-	{ "remote-oob",	cmd_remote_oob,	"Remote OOB data"		},
-	{ "did",	cmd_did,	"Set Device ID"			},
-	{ "static-addr",cmd_static_addr,"Set static address"		},
-	{ "public-addr",cmd_public_addr,"Set public address"		},
-	{ "ext-config",	cmd_ext_config,	"External configuration"	},
-	{ "debug-keys",	cmd_debug_keys,	"Toogle debug keys"		},
-	{ "conn-info",	cmd_conn_info,	"Get connection information"	},
-	{ "io-cap",	cmd_io_cap,	"Set IO Capability"		},
-	{ "scan-params",cmd_scan_params,"Set Scan Parameters"		},
-	{ "get-clock",	cmd_clock_info,	"Get Clock Information"		},
-	{ "add-device", cmd_add_device, "Add Device"			},
-	{ "del-device", cmd_del_device, "Remove Device"			},
-	{ "clr-devices",cmd_clr_devices,"Clear Devices"			},
-	{ }
-};
-
-static void cmd_quit(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
-{
-	mainloop_exit_success();
+	cmd_del_device(2, rm_argv);
 }
 
 static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index)
@@ -3338,11 +3114,9 @@ static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index)
 					unconf_index_removed, NULL, NULL);
 	mgmt_register(mgmt, MGMT_EV_NEW_CONFIG_OPTIONS, index,
 					new_config_options, NULL, NULL);
-
 }
 
-static void cmd_select(struct mgmt *mgmt, uint16_t index,
-						int argc, char **argv)
+static void cmd_select(int argc, char **argv)
 {
 	if (argc != 2) {
 		error("Usage: select <index>");
@@ -3367,155 +3141,71 @@ static void cmd_select(struct mgmt *mgmt, uint16_t index,
 	update_prompt(mgmt_index);
 }
 
-static struct cmd_info interactive_cmd[] = {
+static struct interactive_command all_cmd[] = {
+	{ "version",	cmd_version,	"Get the MGMT Version"		},
+	{ "commands",	cmd_commands,	"List supported commands"	},
+	{ "config",	cmd_config,	"Show configuration info"	},
+	{ "info",	cmd_info,	"Show controller info"		},
+	{ "power",	cmd_power,	"Toggle powered state"		},
+	{ "discov",	cmd_discov,	"Toggle discoverable state"	},
+	{ "connectable", cmd_connectable, "Toggle connectable state"	},
+	{ "fast-conn",	cmd_fast_conn,	"Toggle fast connectable state"	},
+	{ "bondable",	cmd_bondable,	"Toggle bondable state"		},
+	{ "pairable",	cmd_bondable,	"Toggle bondable state"		},
+	{ "linksec",	cmd_linksec,	"Toggle link level security"	},
+	{ "ssp",	cmd_ssp,	"Toggle SSP mode"		},
+	{ "sc",		cmd_sc,		"Toogle SC support"		},
+	{ "hs",		cmd_hs,		"Toggle HS support"		},
+	{ "le",		cmd_le,		"Toggle LE support"		},
+	{ "advertising", cmd_advertising, "Toggle LE advertising",	},
+	{ "bredr",	cmd_bredr,	"Toggle BR/EDR support",	},
+	{ "privacy",	cmd_privacy,	"Toggle privacy support"	},
+	{ "class",	cmd_class,	"Set device major/minor class"	},
+	{ "disconnect", cmd_disconnect, "Disconnect device"		},
+	{ "con",	cmd_con,	"List connections"		},
+	{ "find",	cmd_find,	"Discover nearby devices"	},
+	{ "find-service", cmd_find_service, "Discover nearby service"	},
+	{ "name",	cmd_name,	"Set local name"		},
+	{ "pair",	cmd_pair,	"Pair with a remote device"	},
+	{ "cancelpair",	cmd_cancel_pair, "Cancel pairing"		},
+	{ "unpair",	cmd_unpair,	"Unpair device"			},
+	{ "keys",	cmd_keys,	"Load Link Keys"		},
+	{ "ltks",	cmd_ltks,	"Load Long Term Keys"		},
+	{ "irks",	cmd_irks,	"Load Identity Resolving Keys"	},
+	{ "block",	cmd_block,	"Block Device"			},
+	{ "unblock",	cmd_unblock,	"Unblock Device"		},
+	{ "add-uuid",	cmd_add_uuid,	"Add UUID"			},
+	{ "rm-uuid",	cmd_remove_uuid, "Remove UUID"			},
+	{ "clr-uuids",	cmd_clr_uuids,	"Clear UUIDs"			},
+	{ "local-oob",	cmd_local_oob,	"Local OOB data"		},
+	{ "remote-oob",	cmd_remote_oob,	"Remote OOB data"		},
+	{ "did",	cmd_did,	"Set Device ID"			},
+	{ "static-addr", cmd_static_addr, "Set static address"		},
+	{ "public-addr", cmd_public_addr, "Set public address"		},
+	{ "ext-config",	cmd_ext_config,	"External configuration"	},
+	{ "debug-keys",	cmd_debug_keys,	"Toogle debug keys"		},
+	{ "conn-info",	cmd_conn_info,	"Get connection information"	},
+	{ "io-cap",	cmd_io_cap,	"Set IO Capability"		},
+	{ "scan-params", cmd_scan_params, "Set Scan Parameters"		},
+	{ "get-clock",	cmd_clock_info,	"Get Clock Information"		},
+	{ "add-device", cmd_add_device, "Add Device"			},
+	{ "del-device", cmd_del_device, "Remove Device"			},
+	{ "clr-devices", cmd_clr_devices, "Clear Devices"		},
 	{ "select",	cmd_select,	"Select a different index"	},
-	{ "quit",	cmd_quit,	"Exit program"			},
-	{ "exit",	cmd_quit,	"Exit program"			},
-	{ "help",	NULL,		"List supported commands"	},
+	{ },
 	{ }
 };
 
-static char *cmd_generator(const char *text, int state)
-{
-	static int i, j, len;
-	const char *cmd;
-
-	if (!state) {
-		i = 0;
-		j = 0;
-		len = strlen(text);
-	}
-
-	while ((cmd = all_cmd[i].cmd)) {
-		i++;
-
-		if (!strncmp(cmd, text, len))
-			return strdup(cmd);
-	}
-
-	while ((cmd = interactive_cmd[j].cmd)) {
-		j++;
-
-		if (!strncmp(cmd, text, len))
-			return strdup(cmd);
-	}
-
-	return NULL;
-}
-
-static char **cmd_completion(const char *text, int start, int end)
-{
-	char **matches = NULL;
-
-	if (start > 0) {
-		int i;
-
-		for (i = 0; all_cmd[i].cmd; i++) {
-			struct cmd_info *c = &all_cmd[i];
-
-			if (strncmp(c->cmd, rl_line_buffer, start - 1))
-				continue;
-
-			if (!c->gen)
-				continue;
-
-			rl_completion_display_matches_hook = c->disp;
-			matches = rl_completion_matches(text, c->gen);
-			break;
-		}
-	} else {
-		rl_completion_display_matches_hook = NULL;
-		matches = rl_completion_matches(text, cmd_generator);
-	}
-
-	if (!matches)
-		rl_attempted_completion_over = 1;
-
-	return matches;
-}
-
-static struct cmd_info *find_cmd(const char *cmd, struct cmd_info table[])
+static const struct interactive_command *find_cmd(const char *cmd)
 {
 	int i;
 
-	for (i = 0; table[i].cmd; i++) {
-		if (!strcmp(table[i].cmd, cmd))
-			return &table[i];
-	}
-
-	return NULL;
-}
-
-static void rl_handler(char *input)
-{
-	struct cmd_info *c;
-	wordexp_t w;
-	char *cmd, **argv;
-	size_t argc, i;
-
-	if (!input) {
-		rl_insert_text("quit");
-		rl_redisplay();
-		rl_crlf();
-		mainloop_quit();
-		return;
-	}
-
-	if (!strlen(input))
-		goto done;
-
-	if (prompt_input(input))
-		goto done;
-
-	add_history(input);
-
-	if (wordexp(input, &w, WRDE_NOCMD))
-		goto done;
-
-	if (w.we_wordc == 0)
-		goto free_we;
-
-	cmd = w.we_wordv[0];
-	argv = w.we_wordv;
-	argc = w.we_wordc;
-
-	c = find_cmd(cmd, all_cmd);
-	if (!c && interactive)
-		c = find_cmd(cmd, interactive_cmd);
-
-	if (c && c->func) {
-		c->func(mgmt, mgmt_index, argc, argv);
-		goto free_we;
-	}
-
-	if (strcmp(cmd, "help")) {
-		print("Invalid command");
-		goto free_we;
-	}
-
-	print("Available commands:");
-
 	for (i = 0; all_cmd[i].cmd; i++) {
-		c = &all_cmd[i];
-		if (c->doc)
-			print("  %s %-*s %s", c->cmd,
-				(int)(25 - strlen(c->cmd)), "", c->doc ? : "");
-	}
-
-	if (!interactive)
-		goto free_we;
-
-	for (i = 0; interactive_cmd[i].cmd; i++) {
-		c = &interactive_cmd[i];
-		if (c->doc)
-			print("  %s %-*s %s", c->cmd,
-				(int)(25 - strlen(c->cmd)), "", c->doc ? : "");
+		if (!strcmp(all_cmd[i].cmd, cmd))
+			return &all_cmd[i];
 	}
 
-free_we:
-	wordfree(&w);
-done:
-	free(input);
+	return NULL;
 }
 
 static void usage(void)
@@ -3547,29 +3237,8 @@ static struct option main_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
-static bool prompt_read(struct io *io, void *user_data)
-{
-	rl_callback_read_char();
-	return true;
-}
-
-static struct io *setup_stdin(void)
-{
-	struct io *io;
-
-	io = io_new(STDIN_FILENO);
-	if (!io)
-		return io;
-
-	io_set_read_handler(io, prompt_read, NULL, NULL);
-
-	return io;
-}
-
 int main(int argc, char *argv[])
 {
-	struct io *input;
-	uint16_t index = MGMT_INDEX_NONE;
 	int status, opt;
 
 	while ((opt = getopt_long(argc, argv, "+hi:",
@@ -3578,9 +3247,9 @@ int main(int argc, char *argv[])
 		case 'i':
 			if (strlen(optarg) > 3 &&
 					strncasecmp(optarg, "hci", 3) == 0)
-				index = atoi(optarg + 3);
+				mgmt_index = atoi(optarg + 3);
 			else
-				index = atoi(optarg);
+				mgmt_index = atoi(optarg);
 			break;
 		case 'h':
 		default:
@@ -3602,49 +3271,37 @@ int main(int argc, char *argv[])
 	}
 
 	if (argc > 0) {
-		struct cmd_info *c;
+		const struct interactive_command *c;
 
-		c = find_cmd(argv[0], all_cmd);
+		c = find_cmd(argv[0]);
 		if (!c) {
 			fprintf(stderr, "Unknown command: %s\n", argv[0]);
 			mgmt_unref(mgmt);
 			return EXIT_FAILURE;
 		}
 
-		c->func(mgmt, index, argc, argv);
+		c->func(argc, argv);
 	}
 
-	register_mgmt_callbacks(mgmt, index);
+	register_mgmt_callbacks(mgmt, mgmt_index);
 
 	/* Interactive mode */
-	if (!argc)
-		input = setup_stdin();
-	else
-		input = NULL;
-
-	if (input) {
-		interactive = true;
-
-		rl_attempted_completion_function = cmd_completion;
-
-		rl_erase_empty_line = 1;
-		rl_callback_handler_install(NULL, rl_handler);
-
-		update_prompt(index);
-		rl_redisplay();
+	if (!argc) {
+		interactive = interactive_init(PROMPT_ON, prompt_input,
+								all_cmd);
+		if (!interactive) {
+			fprintf(stderr, "Failed to setup interactive mode\n");
+			status = EXIT_FAILURE;
+			goto failed;
+		}
 	}
 
-	mgmt_index = index;
-
 	status = mainloop_run();
 
-	if (input) {
-		io_destroy(input);
-
-		rl_message("");
-		rl_callback_handler_remove();
-	}
+	if (interactive)
+		interactive_cleanup();
 
+failed:
 	mgmt_cancel_all(mgmt);
 	mgmt_unregister_all(mgmt);
 	mgmt_unref(mgmt);
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC 4/5] client/display: Rename to client/interactive
  2015-02-12 17:52 [RFC 1/5] client/display: Add initial code for handling interactive mode Szymon Janc
  2015-02-12 17:52 ` [RFC 2/5] client/display: Prefix remaining functions with interactive_ Szymon Janc
  2015-02-12 17:52 ` [RFC 3/5] tools/btmgmt: Rewrite interactive mode on top of client code Szymon Janc
@ 2015-02-12 17:52 ` Szymon Janc
  2015-02-12 17:52 ` [RFC 5/5] android: Fix btmgmt build Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Szymon Janc @ 2015-02-12 17:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This code is now handling other interactive mode functionality, not
only display.
---
 Makefile.tools                      | 12 ++++++------
 attrib/interactive.c                |  2 +-
 client/agent.c                      |  2 +-
 client/gatt.c                       |  2 +-
 client/{display.c => interactive.c} |  2 +-
 client/{display.h => interactive.h} |  0
 client/main.c                       |  2 +-
 tools/bluetooth-player.c            |  2 +-
 tools/btmgmt.c                      |  2 +-
 tools/obexctl.c                     |  2 +-
 10 files changed, 14 insertions(+), 14 deletions(-)
 rename client/{display.c => interactive.c} (99%)
 rename client/{display.h => interactive.h} (100%)

diff --git a/Makefile.tools b/Makefile.tools
index d721b4a..d112691 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -3,7 +3,7 @@ if CLIENT
 bin_PROGRAMS += client/bluetoothctl
 
 client_bluetoothctl_SOURCES = client/main.c \
-					client/display.h client/display.c \
+					client/interactive.h client/interactive.c \
 					client/agent.h client/agent.c \
 					client/gatt.h client/gatt.c \
 					monitor/uuid.h monitor/uuid.c
@@ -243,7 +243,7 @@ tools_hwdb_LDADD = lib/libbluetooth-internal.la
 
 tools_hcieventmask_LDADD = lib/libbluetooth-internal.la
 
-tools_btmgmt_SOURCES = tools/btmgmt.c src/uuid-helper.c client/display.c
+tools_btmgmt_SOURCES = tools/btmgmt.c src/uuid-helper.c client/interactive.c
 tools_btmgmt_LDADD = lib/libbluetooth-internal.la src/libshared-mainloop.la \
 				-lreadline
 
@@ -298,8 +298,8 @@ noinst_PROGRAMS += attrib/gatttool \
 attrib_gatttool_SOURCES = attrib/gatttool.c attrib/att.c attrib/gatt.c \
 				attrib/gattrib.c btio/btio.c \
 				attrib/gatttool.h attrib/interactive.c \
-				attrib/utils.c src/log.c client/display.c \
-				client/display.h
+				attrib/utils.c src/log.c client/interactive.c \
+				client/interactive.h
 attrib_gatttool_LDADD = lib/libbluetooth-internal.la \
 			src/libshared-mainloop.la \
 			src/libshared-glib.la @GLIB_LIBS@ -lreadline
@@ -314,13 +314,13 @@ tools_obex_server_tool_SOURCES = $(gobex_sources) $(btio_sources) \
 tools_obex_server_tool_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
 
 tools_bluetooth_player_SOURCES = tools/bluetooth-player.c \
-				client/display.h client/display.c
+				client/interactive.h client/interactive.c
 tools_bluetooth_player_LDADD = gdbus/libgdbus-internal.la \
 				src/libshared-mainloop.la \
 				@GLIB_LIBS@ @DBUS_LIBS@ -lreadline
 
 tools_obexctl_SOURCES = tools/obexctl.c \
-				client/display.h client/display.c
+				client/interactive.h client/interactive.c
 tools_obexctl_LDADD = gdbus/libgdbus-internal.la src/libshared-mainloop.la \
 				@GLIB_LIBS@ @DBUS_LIBS@ -lreadline
 endif
diff --git a/attrib/interactive.c b/attrib/interactive.c
index da8bcb9..56e1cae 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -45,7 +45,7 @@
 #include "gattrib.h"
 #include "gatt.h"
 #include "gatttool.h"
-#include "client/display.h"
+#include "client/interactive.h"
 
 static GIOChannel *iochannel = NULL;
 static GAttrib *attrib = NULL;
diff --git a/client/agent.c b/client/agent.c
index 4691afe..e9ba2a9 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -31,7 +31,7 @@
 #include <readline/readline.h>
 #include <gdbus.h>
 
-#include "display.h"
+#include "interactive.h"
 #include "agent.h"
 
 #define AGENT_PATH "/org/bluez/agent"
diff --git a/client/gatt.c b/client/gatt.c
index 4bdbaba..14985a8 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -38,7 +38,7 @@
 #include <gdbus.h>
 
 #include "monitor/uuid.h"
-#include "display.h"
+#include "interactive.h"
 #include "gatt.h"
 
 /* String display constants */
diff --git a/client/display.c b/client/interactive.c
similarity index 99%
rename from client/display.c
rename to client/interactive.c
index 25eafe3..1089f4d 100644
--- a/client/display.c
+++ b/client/interactive.c
@@ -37,7 +37,7 @@
 #include "src/shared/mainloop.h"
 #include "src/shared/io.h"
 
-#include "display.h"
+#include "interactive.h"
 
 static char *saved_prompt = NULL;
 static int saved_point = 0;
diff --git a/client/display.h b/client/interactive.h
similarity index 100%
rename from client/display.h
rename to client/interactive.h
diff --git a/client/main.c b/client/main.c
index 96781b2..17d596a 100644
--- a/client/main.c
+++ b/client/main.c
@@ -40,7 +40,7 @@
 
 #include "monitor/uuid.h"
 #include "agent.h"
-#include "display.h"
+#include "interactive.h"
 #include "gatt.h"
 
 /* String display constants */
diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
index 22e0557..abc77e9 100644
--- a/tools/bluetooth-player.c
+++ b/tools/bluetooth-player.c
@@ -38,7 +38,7 @@
 #include <glib.h>
 #include <gdbus.h>
 
-#include <client/display.h>
+#include "client/interactive.h"
 
 /* String display constants */
 #define COLORED_NEW	COLOR_GREEN "NEW" COLOR_OFF
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index b02af35..46b2f7c 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -48,7 +48,7 @@
 #include "src/uuid-helper.h"
 #include "lib/mgmt.h"
 
-#include "client/display.h"
+#include "client/interactive.h"
 #include "src/shared/mainloop.h"
 #include "src/shared/io.h"
 #include "src/shared/util.h"
diff --git a/tools/obexctl.c b/tools/obexctl.c
index c105b2f..493ae7f 100644
--- a/tools/obexctl.c
+++ b/tools/obexctl.c
@@ -40,7 +40,7 @@
 #include <glib.h>
 #include <gdbus.h>
 
-#include <client/display.h>
+#include "client/interactive.h"
 
 /* String display constants */
 #define COLORED_NEW	COLOR_GREEN "NEW" COLOR_OFF
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC 5/5] android: Fix btmgmt build
  2015-02-12 17:52 [RFC 1/5] client/display: Add initial code for handling interactive mode Szymon Janc
                   ` (2 preceding siblings ...)
  2015-02-12 17:52 ` [RFC 4/5] client/display: Rename to client/interactive Szymon Janc
@ 2015-02-12 17:52 ` Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Szymon Janc @ 2015-02-12 17:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Android doesn't provide readline library. Use dummy interactive
implementation while building for Android. Interactive mode
will not work but batch mode is functional.

Eventually Android implementation might be written based on code
used by haltest.
---
 android/Android.mk    |  1 +
 android/Makefile.am   |  1 +
 android/interactive.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 android/interactive.c

diff --git a/android/Android.mk b/android/Android.mk
index 289c1df..e01ed44 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -493,6 +493,7 @@ LOCAL_SRC_FILES := \
 	bluez/src/shared/util.c \
 	bluez/src/shared/gap.c \
 	bluez/src/uuid-helper.c \
+	bluez/android/interactive.c \
 
 LOCAL_C_INCLUDES := \
 	$(LOCAL_PATH)/bluez \
diff --git a/android/Makefile.am b/android/Makefile.am
index 9e73be4..9115a82 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -220,6 +220,7 @@ endif
 EXTRA_DIST += android/Android.mk android/README \
 				android/bluetoothd-wrapper.c \
 				android/log.c \
+				android/interactive.c \
 				android/bluetoothd.te \
 				android/bluetoothd_snoop.te \
 				android/init.bluetooth.rc \
diff --git a/android/interactive.c b/android/interactive.c
new file mode 100644
index 0000000..7da06f8
--- /dev/null
+++ b/android/interactive.c
@@ -0,0 +1,64 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2015  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#include "client/interactive.h"
+
+
+bool interactive_init(const char *prompt, interactive_prompt_func_t cb,
+					const struct interactive_command *cmd)
+{
+	return false;
+}
+
+void interactive_cleanup(void)
+{
+
+}
+
+void interactive_update_prompt(const char *prompt)
+{
+
+}
+
+void interactive_prompt(const char *msg)
+{
+
+}
+
+void interactive_release_prompt(void)
+{
+
+}
+
+void interactive_printf(const char *fmt, ...)
+{
+
+}
+
+void interactive_hexdump(const unsigned char *buf, size_t len)
+{
+
+}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-12 17:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-12 17:52 [RFC 1/5] client/display: Add initial code for handling interactive mode Szymon Janc
2015-02-12 17:52 ` [RFC 2/5] client/display: Prefix remaining functions with interactive_ Szymon Janc
2015-02-12 17:52 ` [RFC 3/5] tools/btmgmt: Rewrite interactive mode on top of client code Szymon Janc
2015-02-12 17:52 ` [RFC 4/5] client/display: Rename to client/interactive Szymon Janc
2015-02-12 17:52 ` [RFC 5/5] android: Fix btmgmt build Szymon Janc

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.