public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] test/agent.c: rename device into adapter in main
@ 2009-07-02  9:14 Filippo Giunchedi
  2009-07-02  9:14 ` [PATCH 2/5] test/agent.c: rename option device into adapter Filippo Giunchedi
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Filippo Giunchedi @ 2009-07-02  9:14 UTC (permalink / raw)
  To: linux-bluetooth

---
 test/agent.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 01f9b7f..64362e8 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -486,8 +486,8 @@ int main(int argc, char *argv[])
 	const char *capabilities = "DisplayYesNo";
 	struct sigaction sa;
 	DBusConnection *conn;
-	char match_string[128], default_path[128], *device_id = NULL;
-	char *device_path = NULL, *agent_path = NULL, *target = NULL;
+	char match_string[128], default_path[128], *adapter_id = NULL;
+	char *adapter_path = NULL, *agent_path = NULL, *target = NULL;
 	int opt;
 
 	snprintf(default_path, sizeof(default_path),
@@ -496,7 +496,7 @@ int main(int argc, char *argv[])
 	while ((opt = getopt_long(argc, argv, "+i:p:c:rh", main_options, NULL)) != EOF) {
 		switch(opt) {
 		case 'i':
-			device_id = optarg;
+			adapter_id = optarg;
 			break;
 		case 'p':
 			if (optarg[0] != '/') {
@@ -542,17 +542,17 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	if (!device_path)
-		device_path = get_device(conn, device_id);
+	if (!adapter_path)
+		adapter_path = get_device(conn, adapter_id);
 
 	if (target) {
-		if (create_paired_device(conn, device_path, agent_path,
+		if (create_paired_device(conn, adapter_path, agent_path,
 						capabilities, target) < 0) {
 			dbus_connection_unref(conn);
 			exit(1);
 		}
 	} else {
-		if (register_agent(conn, device_path, agent_path,
+		if (register_agent(conn, adapter_path, agent_path,
 							capabilities) < 0) {
 			dbus_connection_unref(conn);
 			exit(1);
@@ -580,9 +580,9 @@ int main(int argc, char *argv[])
 	}
 
 	if (!__io_terminated && !target)
-		unregister_agent(conn, device_path, agent_path);
+		unregister_agent(conn, adapter_path, agent_path);
 
-	free(device_path);
+	free(adapter_path);
 	free(agent_path);
 
 	free(passkey);
-- 
1.6.3.3


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

* [PATCH 2/5] test/agent.c: rename option device into adapter
  2009-07-02  9:14 [PATCH 1/5] test/agent.c: rename device into adapter in main Filippo Giunchedi
@ 2009-07-02  9:14 ` Filippo Giunchedi
  2009-07-02  9:14 ` [PATCH 3/5] test/agent.c: rename device into adapter in functions Filippo Giunchedi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Filippo Giunchedi @ 2009-07-02  9:14 UTC (permalink / raw)
  To: linux-bluetooth

---
 test/agent.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 64362e8..b9485d2 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -468,12 +468,12 @@ static void usage(void)
 	printf("Bluetooth agent ver %s\n\n", VERSION);
 
 	printf("Usage:\n"
-		"\tagent [--device interface] [--path agent-path] <passkey> [<target_device>]\n"
+		"\tagent [--adapter adapter-path] [--path agent-path] <passkey> [<target_device>]\n"
 		"\n");
 }
 
 static struct option main_options[] = {
-	{ "device",	1, 0, 'i' },
+	{ "adapter",	1, 0, 'a' },
 	{ "path",	1, 0, 'p' },
 	{ "capabilites",1, 0, 'c' },
 	{ "reject",	0, 0, 'r' },
@@ -493,9 +493,9 @@ int main(int argc, char *argv[])
 	snprintf(default_path, sizeof(default_path),
 					"/org/bluez/agent_%d", getpid());
 
-	while ((opt = getopt_long(argc, argv, "+i:p:c:rh", main_options, NULL)) != EOF) {
+	while ((opt = getopt_long(argc, argv, "+a:p:c:rh", main_options, NULL)) != EOF) {
 		switch(opt) {
-		case 'i':
+		case 'a':
 			adapter_id = optarg;
 			break;
 		case 'p':
-- 
1.6.3.3


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

* [PATCH 3/5] test/agent.c: rename device into adapter in functions
  2009-07-02  9:14 [PATCH 1/5] test/agent.c: rename device into adapter in main Filippo Giunchedi
  2009-07-02  9:14 ` [PATCH 2/5] test/agent.c: rename option device into adapter Filippo Giunchedi
@ 2009-07-02  9:14 ` Filippo Giunchedi
  2009-07-02  9:14 ` [PATCH 4/5] test/agent.c: find given adapter or use default Filippo Giunchedi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Filippo Giunchedi @ 2009-07-02  9:14 UTC (permalink / raw)
  To: linux-bluetooth

---
 test/agent.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index b9485d2..390b3d8 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -285,7 +285,7 @@ static const DBusObjectPathVTable agent_table = {
 	.message_function = agent_message,
 };
 
-static int register_agent(DBusConnection *conn, const char *device_path,
+static int register_agent(DBusConnection *conn, const char *adapter_path,
 						const char *agent_path,
 						const char *capabilities)
 {
@@ -298,7 +298,7 @@ static int register_agent(DBusConnection *conn, const char *device_path,
 		return -1;
 	}
 
-	msg = dbus_message_new_method_call("org.bluez", device_path,
+	msg = dbus_message_new_method_call("org.bluez", adapter_path,
 					"org.bluez.Adapter", "RegisterAgent");
 	if (!msg) {
 		fprintf(stderr, "Can't allocate new method call\n");
@@ -331,13 +331,13 @@ static int register_agent(DBusConnection *conn, const char *device_path,
 	return 0;
 }
 
-static int unregister_agent(DBusConnection *conn, const char *device_path,
+static int unregister_agent(DBusConnection *conn, const char *adapter_path,
 							const char *agent_path)
 {
 	DBusMessage *msg, *reply;
 	DBusError err;
 
-	msg = dbus_message_new_method_call("org.bluez", device_path,
+	msg = dbus_message_new_method_call("org.bluez", adapter_path,
 					"org.bluez.Adapter", "UnregisterAgent");
 	if (!msg) {
 		fprintf(stderr, "Can't allocate new method call\n");
@@ -371,7 +371,7 @@ static int unregister_agent(DBusConnection *conn, const char *device_path,
 	return 0;
 }
 
-static int create_paired_device(DBusConnection *conn, const char *device_path,
+static int create_paired_device(DBusConnection *conn, const char *adapter_path,
 						const char *agent_path,
 						const char *capabilities,
 						const char *target)
@@ -379,7 +379,7 @@ static int create_paired_device(DBusConnection *conn, const char *device_path,
 	dbus_bool_t success;
 	DBusMessage *msg;
 
-	msg = dbus_message_new_method_call("org.bluez", device_path,
+	msg = dbus_message_new_method_call("org.bluez", adapter_path,
 						"org.bluez.Adapter",
 						"CreatePairedDevice");
 	if (!msg) {
@@ -406,15 +406,15 @@ static int create_paired_device(DBusConnection *conn, const char *device_path,
 	return 0;
 }
 
-static char *get_device(DBusConnection *conn, const char *device)
+static char *get_adapter_path(DBusConnection *conn, const char *adapter)
 {
 	DBusMessage *msg, *reply;
 	DBusError err;
 	const char *tmppath;
 	char *path, *default_path = "/org/bluez/hci0";
 
-	if (device) {
-		path = strdup(device);
+	if (adapter) {
+		path = strdup(adapter);
 		return path;
 	}
 
@@ -543,7 +543,7 @@ int main(int argc, char *argv[])
 	}
 
 	if (!adapter_path)
-		adapter_path = get_device(conn, adapter_id);
+		adapter_path = get_adapter_path(conn, adapter_id);
 
 	if (target) {
 		if (create_paired_device(conn, adapter_path, agent_path,
-- 
1.6.3.3


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

* [PATCH 4/5] test/agent.c: find given adapter or use default
  2009-07-02  9:14 [PATCH 1/5] test/agent.c: rename device into adapter in main Filippo Giunchedi
  2009-07-02  9:14 ` [PATCH 2/5] test/agent.c: rename option device into adapter Filippo Giunchedi
  2009-07-02  9:14 ` [PATCH 3/5] test/agent.c: rename device into adapter in functions Filippo Giunchedi
@ 2009-07-02  9:14 ` Filippo Giunchedi
  2009-07-02  9:14 ` [PATCH 5/5] test/agent.c: rename "target device" into device Filippo Giunchedi
  2009-07-02 14:24 ` [PATCH 1/5] test/agent.c: rename device into adapter in main Johan Hedberg
  4 siblings, 0 replies; 6+ messages in thread
From: Filippo Giunchedi @ 2009-07-02  9:14 UTC (permalink / raw)
  To: linux-bluetooth

modify get_adapter_path to use FindAdapter or use DefaultAdapter if none
is given
---
 test/agent.c |   84 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 69 insertions(+), 15 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 390b3d8..b625b88 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -406,26 +406,79 @@ static int create_paired_device(DBusConnection *conn, const char *adapter_path,
 	return 0;
 }
 
-static char *get_adapter_path(DBusConnection *conn, const char *adapter)
+static char *get_default_adapter_path(DBusConnection *conn)
 {
 	DBusMessage *msg, *reply;
 	DBusError err;
-	const char *tmppath;
-	char *path, *default_path = "/org/bluez/hci0";
+	const char *reply_path;
+	char *path;
+
+	msg = dbus_message_new_method_call("org.bluez", "/",
+					"org.bluez.Manager", "DefaultAdapter");
+
+	if (!msg) {
+		fprintf(stderr, "Can't allocate new method call\n");
+		return NULL;
+	}
+
+	dbus_error_init(&err);
+
+	reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
 
-	if (adapter) {
-		path = strdup(adapter);
-		return path;
+	dbus_message_unref(msg);
+
+	if (!reply) {
+		fprintf(stderr,
+			"Can't get default adapter\n");
+		if (dbus_error_is_set(&err)) {
+			fprintf(stderr, "%s\n", err.message);
+			dbus_error_free(&err);
+		}
+		return NULL;
 	}
 
+	if (!dbus_message_get_args(reply, &err,
+					DBUS_TYPE_OBJECT_PATH, &reply_path,
+					DBUS_TYPE_INVALID)) {
+		fprintf(stderr,
+			"Can't get reply arguments\n");
+		if (dbus_error_is_set(&err)) {
+			fprintf(stderr, "%s\n", err.message);
+			dbus_error_free(&err);
+		}
+		return NULL;
+	}
+
+	path = strdup(reply_path);
+
+	dbus_message_unref(reply);
+
+	dbus_connection_flush(conn);
+
+	return path;
+}
+
+static char *get_adapter_path(DBusConnection *conn, const char *adapter)
+{
+	DBusMessage *msg, *reply;
+	DBusError err;
+	const char *reply_path;
+	char *path;
+
+	if (!adapter)
+		return get_default_adapter_path(conn);
+
 	msg = dbus_message_new_method_call("org.bluez", "/",
-					"org.bluez.Manager", "DefaultAdapter");
+					"org.bluez.Manager", "FindAdapter");
 
 	if (!msg) {
 		fprintf(stderr, "Can't allocate new method call\n");
-		return default_path;
+		return NULL;
 	}
 
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &adapter,
+					DBUS_TYPE_INVALID);
+
 	dbus_error_init(&err);
 
 	reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
@@ -434,27 +487,27 @@ static char *get_adapter_path(DBusConnection *conn, const char *adapter)
 
 	if (!reply) {
 		fprintf(stderr,
-			"Can't get default adapter, using default adapter\n");
+			"Can't find adapter %s\n", adapter);
 		if (dbus_error_is_set(&err)) {
 			fprintf(stderr, "%s\n", err.message);
 			dbus_error_free(&err);
 		}
-		return default_path;
+		return NULL;
 	}
 
 	if (!dbus_message_get_args(reply, &err,
-					DBUS_TYPE_OBJECT_PATH, &tmppath,
+					DBUS_TYPE_OBJECT_PATH, &reply_path,
 					DBUS_TYPE_INVALID)) {
 		fprintf(stderr,
-			"Can't get reply arguments, using default adapter\n");
+			"Can't get reply arguments\n");
 		if (dbus_error_is_set(&err)) {
 			fprintf(stderr, "%s\n", err.message);
 			dbus_error_free(&err);
 		}
-		return default_path;
+		return NULL;
 	}
 
-	path = strdup(tmppath);
+	path = strdup(reply_path);
 
 	dbus_message_unref(reply);
 
@@ -542,8 +595,9 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
+	adapter_path = get_adapter_path(conn, adapter_id);
 	if (!adapter_path)
-		adapter_path = get_adapter_path(conn, adapter_id);
+		exit(1);
 
 	if (target) {
 		if (create_paired_device(conn, adapter_path, agent_path,
-- 
1.6.3.3


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

* [PATCH 5/5] test/agent.c: rename "target device" into device
  2009-07-02  9:14 [PATCH 1/5] test/agent.c: rename device into adapter in main Filippo Giunchedi
                   ` (2 preceding siblings ...)
  2009-07-02  9:14 ` [PATCH 4/5] test/agent.c: find given adapter or use default Filippo Giunchedi
@ 2009-07-02  9:14 ` Filippo Giunchedi
  2009-07-02 14:24 ` [PATCH 1/5] test/agent.c: rename device into adapter in main Johan Hedberg
  4 siblings, 0 replies; 6+ messages in thread
From: Filippo Giunchedi @ 2009-07-02  9:14 UTC (permalink / raw)
  To: linux-bluetooth

---
 test/agent.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index b625b88..4c12ea3 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -374,7 +374,7 @@ static int unregister_agent(DBusConnection *conn, const char *adapter_path,
 static int create_paired_device(DBusConnection *conn, const char *adapter_path,
 						const char *agent_path,
 						const char *capabilities,
-						const char *target)
+						const char *device)
 {
 	dbus_bool_t success;
 	DBusMessage *msg;
@@ -387,7 +387,7 @@ static int create_paired_device(DBusConnection *conn, const char *adapter_path,
 		return -1;
 	}
 
-	dbus_message_append_args(msg, DBUS_TYPE_STRING, &target,
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &device,
 					DBUS_TYPE_OBJECT_PATH, &agent_path,
 					DBUS_TYPE_STRING, &capabilities,
 					DBUS_TYPE_INVALID);
@@ -521,7 +521,7 @@ static void usage(void)
 	printf("Bluetooth agent ver %s\n\n", VERSION);
 
 	printf("Usage:\n"
-		"\tagent [--adapter adapter-path] [--path agent-path] <passkey> [<target_device>]\n"
+		"\tagent [--adapter adapter-path] [--path agent-path] <passkey> [<device>]\n"
 		"\n");
 }
 
@@ -540,7 +540,7 @@ int main(int argc, char *argv[])
 	struct sigaction sa;
 	DBusConnection *conn;
 	char match_string[128], default_path[128], *adapter_id = NULL;
-	char *adapter_path = NULL, *agent_path = NULL, *target = NULL;
+	char *adapter_path = NULL, *agent_path = NULL, *device = NULL;
 	int opt;
 
 	snprintf(default_path, sizeof(default_path),
@@ -584,7 +584,7 @@ int main(int argc, char *argv[])
 	passkey = strdup(argv[0]);
 
 	if (argc > 1)
-		target = strdup(argv[1]);
+		device = strdup(argv[1]);
 
 	if (!agent_path)
 		agent_path = strdup(default_path);
@@ -599,9 +599,9 @@ int main(int argc, char *argv[])
 	if (!adapter_path)
 		exit(1);
 
-	if (target) {
+	if (device) {
 		if (create_paired_device(conn, adapter_path, agent_path,
-						capabilities, target) < 0) {
+						capabilities, device) < 0) {
 			dbus_connection_unref(conn);
 			exit(1);
 		}
@@ -633,7 +633,7 @@ int main(int argc, char *argv[])
 			break;
 	}
 
-	if (!__io_terminated && !target)
+	if (!__io_terminated && !device)
 		unregister_agent(conn, adapter_path, agent_path);
 
 	free(adapter_path);
-- 
1.6.3.3


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

* Re: [PATCH 1/5] test/agent.c: rename device into adapter in main
  2009-07-02  9:14 [PATCH 1/5] test/agent.c: rename device into adapter in main Filippo Giunchedi
                   ` (3 preceding siblings ...)
  2009-07-02  9:14 ` [PATCH 5/5] test/agent.c: rename "target device" into device Filippo Giunchedi
@ 2009-07-02 14:24 ` Johan Hedberg
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2009-07-02 14:24 UTC (permalink / raw)
  To: linux-bluetooth

Hi Filippo,

On Thu, Jul 02, 2009, Filippo Giunchedi wrote:
> ---
>  test/agent.c |   18 +++++++++---------
>  1 files changed, 9 insertions(+), 9 deletions(-)

All five patches have been pushed upstream. Thanks!

Johan

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

end of thread, other threads:[~2009-07-02 14:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-02  9:14 [PATCH 1/5] test/agent.c: rename device into adapter in main Filippo Giunchedi
2009-07-02  9:14 ` [PATCH 2/5] test/agent.c: rename option device into adapter Filippo Giunchedi
2009-07-02  9:14 ` [PATCH 3/5] test/agent.c: rename device into adapter in functions Filippo Giunchedi
2009-07-02  9:14 ` [PATCH 4/5] test/agent.c: find given adapter or use default Filippo Giunchedi
2009-07-02  9:14 ` [PATCH 5/5] test/agent.c: rename "target device" into device Filippo Giunchedi
2009-07-02 14:24 ` [PATCH 1/5] test/agent.c: rename device into adapter in main Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox