diff options
author | Alok Barsode <alok.barsode@azingo.com> | 2008-09-03 12:49:59 +0530 |
---|---|---|
committer | Alok Barsode <alok.barsode@azingo.com> | 2008-09-03 12:49:59 +0530 |
commit | bcb5f7e4d5e570c1acfd5364547d36e970408394 (patch) | |
tree | 11c1b2400ba1150dfc302744b7ad091ca58c2cda | |
parent | 26c84ba158a898984d8678f6493a7d3b00717198 (diff) |
Adding adapter_search_active_conn_by_bdaddr and
adapter_search_active_conn_by_handle.
-rw-r--r-- | src/adapter.c | 51 | ||||
-rw-r--r-- | src/adapter.h | 4 | ||||
-rw-r--r-- | src/dbus-hci.c | 28 | ||||
-rw-r--r-- | src/dbus-hci.h | 1 | ||||
-rw-r--r-- | src/device.c | 23 |
5 files changed, 68 insertions, 39 deletions
diff --git a/src/adapter.c b/src/adapter.c index b58ba49a..db310d19 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -168,6 +168,25 @@ static DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, err > 0 ? strerror(err) : "Connection attempt failed"); } +static int active_conn_find_by_bdaddr(const void *data, const void *user_data) +{ + const struct active_conn_info *con = data; + const bdaddr_t *bdaddr = user_data; + + return bacmp(&con->bdaddr, bdaddr); +} + +static int active_conn_find_by_handle(const void *data, const void *user_data) +{ + const struct active_conn_info *dev = data; + const uint16_t *handle = user_data; + + if (dev->handle == *handle) + return 0; + + return -1; +} + static void send_out_of_range(const char *path, GSList *l) { while (l) { @@ -2928,6 +2947,38 @@ void adapter_remove_active_conn(struct adapter *adapter, g_free(dev); } +struct active_conn_info *adapter_search_active_conn_by_bdaddr(struct adapter *adapter, + bdaddr_t *bda) +{ + GSList *l; + + if (!adapter || !adapter->active_conn) + return NULL; + + l = g_slist_find_custom(adapter->active_conn, &bda, + active_conn_find_by_bdaddr); + if (l) + return l->data; + + return NULL; +} + +struct active_conn_info *adapter_search_active_conn_by_handle(struct adapter *adapter, + uint16_t handle) +{ + GSList *l; + + if (!adapter || !adapter->active_conn) + return NULL; + + l = g_slist_find_custom(adapter->active_conn, &handle, + active_conn_find_by_handle); + if (l) + return l->data; + + return NULL; +} + int btd_register_adapter_driver(struct btd_adapter_driver *driver) { adapter_drivers = g_slist_append(adapter_drivers, driver); diff --git a/src/adapter.h b/src/adapter.h index e0653f2d..50e2d07d 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -179,6 +179,10 @@ void adapter_add_active_conn(struct adapter *adapter, bdaddr_t *bdaddr, uint16_t handle); void adapter_remove_active_conn(struct adapter *adapter, struct active_conn_info *dev); +struct active_conn_info *adapter_search_active_conn_by_bdaddr(struct adapter *adapter, + bdaddr_t *bda); +struct active_conn_info *adapter_search_active_conn_by_handle(struct adapter *adapter, + uint16_t handle); struct btd_adapter_driver { const char *name; diff --git a/src/dbus-hci.c b/src/dbus-hci.c index 665cf621..95bbc38c 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -91,25 +91,6 @@ void bonding_request_free(struct bonding_request_info *bonding) g_free(bonding); } -int active_conn_find_by_bdaddr(const void *data, const void *user_data) -{ - const struct active_conn_info *con = data; - const bdaddr_t *bdaddr = user_data; - - return bacmp(&con->bdaddr, bdaddr); -} - -static int active_conn_find_by_handle(const void *data, const void *user_data) -{ - const struct active_conn_info *dev = data; - const uint16_t *handle = user_data; - - if (dev->handle == *handle) - return 0; - - return -1; -} - DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status) { switch (status) { @@ -1129,7 +1110,6 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, struct adapter *adapter; struct btd_device *device; struct active_conn_info *dev; - GSList *l; gboolean connected = FALSE; struct pending_auth_info *auth; const gchar *destination; @@ -1147,13 +1127,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, return; } - l = g_slist_find_custom(adapter->active_conn, &handle, - active_conn_find_by_handle); - - if (!l) - return; - - dev = l->data; + dev = adapter_search_active_conn_by_handle(adapter, handle); ba2str(&dev->bdaddr, peer_addr); diff --git a/src/dbus-hci.h b/src/dbus-hci.h index 72b22741..f13ef740 100644 --- a/src/dbus-hci.h +++ b/src/dbus-hci.h @@ -53,7 +53,6 @@ DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status); int cancel_discovery(struct adapter *adapter); int cancel_periodic_discovery(struct adapter *adapter); -int active_conn_find_by_bdaddr(const void *data, const void *user_data); void bonding_request_free(struct bonding_request_info *dev); int set_limited_discoverable(int dd, const uint8_t *cls, gboolean limited); diff --git a/src/device.c b/src/device.c index b41c6ff5..5ebbdbc6 100644 --- a/src/device.c +++ b/src/device.c @@ -152,6 +152,7 @@ static DBusMessage *get_properties(DBusConnection *conn, uint32_t class; int i; GSList *l; + struct active_conn_info *dev; reply = dbus_message_new_method_return(msg); if (!reply) @@ -207,8 +208,8 @@ static DBusMessage *get_properties(DBusConnection *conn, DBUS_TYPE_BOOLEAN, &boolean); /* Connected */ - if (g_slist_find_custom(adapter->active_conn, &dst, - active_conn_find_by_bdaddr)) + dev = adapter_search_active_conn_by_bdaddr(adapter, &dst); + if (dev) boolean = TRUE; else boolean = FALSE; @@ -408,7 +409,6 @@ static gboolean disconnect_timeout(gpointer user_data) { struct btd_device *device = user_data; struct active_conn_info *ci; - GSList *l; disconnect_cp cp; bdaddr_t bda; int dd; @@ -417,12 +417,12 @@ static gboolean disconnect_timeout(gpointer user_data) device->disconn_timer = 0; str2ba(device->address, &bda); - l = g_slist_find_custom(device->adapter->active_conn, - &bda, active_conn_find_by_bdaddr); - if (!l) + + ci = adapter_search_active_conn_by_bdaddr(device->adapter, &bda); + + if (!ci) return FALSE; - ci = l->data; dd = hci_open_dev(dev_id); if (dd < 0) goto fail; @@ -444,13 +444,14 @@ static DBusMessage *disconnect(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct btd_device *device = user_data; - GSList *l; bdaddr_t bda; + struct active_conn_info *dev; str2ba(device->address, &bda); - l = g_slist_find_custom(device->adapter->active_conn, - &bda, active_conn_find_by_bdaddr); - if (!l) + + dev = adapter_search_active_conn_by_bdaddr(device->adapter, &bda); + + if (!dev) return g_dbus_create_error(msg, ERROR_INTERFACE ".NotConnected", "Device is not connected"); |