diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2008-03-11 20:14:19 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2008-03-11 20:14:19 +0000 |
commit | 181a211db506940ebdc18ee8707d85da6561f79e (patch) | |
tree | a06e9813d9a9683b749a703cffc826e1fcb88850 | |
parent | 971ed9531285f7de6b2c7a06095a833f9cbad08a (diff) |
CreateDevice: Check if the device already exists
-rw-r--r-- | hcid/adapter.c | 3 | ||||
-rw-r--r-- | hcid/device.c | 16 | ||||
-rw-r--r-- | hcid/device.h | 1 |
3 files changed, 20 insertions, 0 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c index 495b5b46..23df94a5 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -3389,6 +3389,9 @@ static DBusHandlerResult create_device(DBusConnection *conn, if (check_address(address) < 0) return error_invalid_arguments(conn, msg, NULL); + if (device_find(address)) + return error_already_exists(conn, msg, "Device already exists"); + str2ba(adapter->address, &src); str2ba(address, &dst); err = bt_discover_services(&src, &dst, diff --git a/hcid/device.c b/hcid/device.c index fa1b9b7e..f29e46a9 100644 --- a/hcid/device.c +++ b/hcid/device.c @@ -747,6 +747,22 @@ void device_foreach(GFunc func, gpointer user_data) g_slist_foreach(device_list, func, user_data); } +struct device *device_find(const gchar *address) +{ + GSList *l; + + if (!device_list || !address) + return NULL; + + for (l = device_list; l; l = l->next) { + struct device *device = l->data; + if (strcmp(device->address, address) == 0) + return device; + } + + return NULL; +} + static void device_free(struct device *device) { g_slist_foreach(device->uuids, (GFunc) g_free, NULL); diff --git a/hcid/device.h b/hcid/device.h index d8dca25f..50795ba6 100644 --- a/hcid/device.h +++ b/hcid/device.h @@ -32,6 +32,7 @@ struct device { gboolean device_init(DBusConnection *conn); void device_cleanup(void); void device_foreach(GFunc func, gpointer user_data); +struct device *device_find(const gchar *address); const gchar *device_create(struct adapter *adapter, const gchar *address, GSList *uuids); void device_remove(const gchar *path); |