diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-05-30 10:36:03 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2006-05-30 10:36:03 +0000 |
commit | 786cbd0c3e4b70976cf6777eac839d2e4b86641a (patch) | |
tree | 137ceb22a47a67d20f9fb76d7edd80c870590892 | |
parent | bf026c430c11a5bc5e7215cf5937e485663a05f0 (diff) |
Add FindAdapter method
-rw-r--r-- | hcid/Bluetooth.cs | 9 | ||||
-rw-r--r-- | hcid/dbus-api.txt | 5 | ||||
-rw-r--r-- | hcid/dbus-manager.c | 28 |
3 files changed, 38 insertions, 4 deletions
diff --git a/hcid/Bluetooth.cs b/hcid/Bluetooth.cs index 36b17e50..96c4e9ed 100644 --- a/hcid/Bluetooth.cs +++ b/hcid/Bluetooth.cs @@ -30,6 +30,7 @@ namespace Bluetooth internal abstract class ManagerProxy { [Method] public abstract string DefaultAdapter(); + [Method] public abstract string FindAdapter(string pattern); } public delegate void RemoteDeviceFoundHandler(string address, Int16 rssi, @@ -79,17 +80,17 @@ namespace Bluetooth { } - public Adapter(string path) + public Adapter(string pattern) { connection = Bus.GetSystemBus(); service = Service.Get(connection, "org.bluez"); manager = (ManagerProxy) service.GetObject(typeof(ManagerProxy), "/org/bluez"); - if (path == "") + if (pattern == "") path = manager.DefaultAdapter(); - - this.path = path; + else + path = manager.FindAdapter(pattern); adapter = (AdapterProxy) service.GetObject(typeof(AdapterProxy), path); diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt index 5a0333f2..3f763fb8 100644 --- a/hcid/dbus-api.txt +++ b/hcid/dbus-api.txt @@ -127,6 +127,11 @@ Methods uint32 InterfaceVersion() Returns object path for the default adapter. + string FindAdapter(string pattern) + + Returns object path for the specified adapter. Valid + patterns are "hci0" or "00:11:22:33:44:55". + array{string} ListAdapters() Returns list of object paths under /org/bluez/Adapter/ diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 0a43941d..7db28949 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -77,6 +77,33 @@ static DBusHandlerResult default_adapter(DBusConnection *conn, return send_reply_and_unref(conn, reply); } +static DBusHandlerResult find_adapter(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + char path[MAX_PATH_LENGTH], *path_ptr = path; + const char *pattern; + int dev_id; + + dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, + DBUS_TYPE_INVALID); + + dev_id = hci_devid(pattern); + if (dev_id < 0) + return error_no_such_adapter(conn, msg); + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, dev_id); + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &path_ptr, + DBUS_TYPE_INVALID); + + return send_reply_and_unref(conn, reply); +} + static DBusHandlerResult list_adapters(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -160,6 +187,7 @@ static DBusHandlerResult list_services(DBusConnection *conn, static struct service_data methods[] = { { "InterfaceVersion", interface_version }, { "DefaultAdapter", default_adapter }, + { "FindAdapter", find_adapter }, { "ListAdapters", list_adapters }, { "ListServices", list_services }, { NULL, NULL } |