summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-06-04 10:30:45 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-06-04 10:30:45 +0000
commit729824372e5d7fd1231c73afea1bea061dd85cc1 (patch)
tree4710482ff0356e42a266bc147385719d8a208cdd
parentb3a5bafbf9b521a3c9deabb60c06cf1aa058fe9d (diff)
Implement Manager.FindDeviceByAddress method
-rw-r--r--audio/audio-api.txt6
-rw-r--r--audio/manager.c46
-rw-r--r--audio/manager.h1
3 files changed, 53 insertions, 0 deletions
diff --git a/audio/audio-api.txt b/audio/audio-api.txt
index f391415f..19cefc69 100644
--- a/audio/audio-api.txt
+++ b/audio/audio-api.txt
@@ -39,6 +39,12 @@ Methods
Returns list of headset objects that are configured.
+ array{string} FindDeviceByAddress(string address)
+
+ Searches the list of available devices and returns the
+ first device which matchess address. If no device is
+ found returns a DoesNotExist error.
+
string DefaultHeadset()
Returns the object path for the default headset device.
diff --git a/audio/manager.c b/audio/manager.c
index 748f2b71..1b727f7a 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -137,6 +137,12 @@ DBusHandlerResult err_connect_failed(DBusConnection *conn,
strerror(err));
}
+DBusHandlerResult err_does_not_exist(DBusConnection *conn, DBusMessage *msg)
+{
+ return error_reply(conn, msg, "org.bluez.audio.Error.DoesNotExist",
+ "Does not exist");
+}
+
DBusHandlerResult err_failed(DBusConnection *conn, DBusMessage *msg,
const char *dsc)
{
@@ -1110,6 +1116,44 @@ static DBusHandlerResult am_list_headsets(DBusConnection *conn, DBusMessage *msg
return send_message_and_unref(connection, reply);
}
+static DBusHandlerResult am_find_by_addr(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ const char *path, *address;
+ DBusMessage *reply;
+ DBusError derr;
+ audio_device_t *device;
+ bdaddr_t bda;
+
+ dbus_error_init(&derr);
+ dbus_message_get_args(msg, &derr,
+ DBUS_TYPE_STRING, &address,
+ DBUS_TYPE_INVALID);
+ if (dbus_error_is_set(&derr)) {
+ err_invalid_args(connection, msg, derr.message);
+ dbus_error_free(&derr);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ str2ba(address, &bda);
+
+ device = find_device(&bda);
+
+ if (!device)
+ return err_does_not_exist(conn, msg);
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ path = device->object_path;
+
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_INVALID);
+
+ return send_message_and_unref(conn, reply);
+}
+
static DBusHandlerResult am_get_default_headset(DBusConnection *conn, DBusMessage *msg,
void *data)
{
@@ -1190,6 +1234,8 @@ static DBusMethodVTable manager_methods[] = {
"s", "" },
{ "ListHeadsets", am_list_headsets,
"", "as" },
+ { "FindDeviceByAddress", am_find_by_addr,
+ "s", "s" },
{ "DefaultHeadset", am_get_default_headset,
"", "s" },
{ "ChangeDefaultHeadset", am_change_default_headset,
diff --git a/audio/manager.h b/audio/manager.h
index 78ec63ab..45d93d7f 100644
--- a/audio/manager.h
+++ b/audio/manager.h
@@ -90,6 +90,7 @@ DBusHandlerResult err_not_connected(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult err_not_supported(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult err_connect_failed(DBusConnection *conn,
DBusMessage *msg, int err);
+DBusHandlerResult err_does_not_exist(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult err_failed(DBusConnection *conn, DBusMessage *msg,
const char *dsc);