Add manager_foreach_adapter()

Ultimately manager_get_adapters shouldn't be needed at all. By
introducing manager_foreach_adapter most instances can be removed.
This commit is contained in:
Johan Hedberg 2010-12-19 13:25:51 +02:00
parent 2eb9e50527
commit 4efb97bdae
13 changed files with 59 additions and 69 deletions

View File

@ -44,8 +44,8 @@
#include "log.h"
#include "../src/manager.h"
#include "../src/adapter.h"
#include "../src/manager.h"
#include "../src/device.h"
#include "device.h"

View File

@ -48,8 +48,8 @@
#include "glib-helper.h"
#include "btio.h"
#include "../src/manager.h"
#include "../src/adapter.h"
#include "../src/manager.h"
#include "../src/device.h"
#include "log.h"

View File

@ -47,9 +47,9 @@
#include "uinput.h"
#include "../src/storage.h"
#include "../src/adapter.h"
#include "../src/manager.h"
#include "../src/dbus-common.h"
#include "adapter.h"
#include "../src/device.h"
#include "device.h"

View File

@ -41,8 +41,8 @@
#include "plugin.h"
#include "log.h"
#include "manager.h"
#include "adapter.h"
#include "manager.h"
#include "device.h"
#include "event.h"

View File

@ -46,8 +46,8 @@
#include "hcid.h"
#include "sdpd.h"
#include "manager.h"
#include "adapter.h"
#include "manager.h"
#include "device.h"
#include "dbus-common.h"
#include "event.h"
@ -974,43 +974,17 @@ static void adapter_emit_uuids_updated(struct btd_adapter *adapter)
g_strfreev(uuids);
}
/*
* adapter_services_inc_rem - Insert or remove UUID from adapter
*/
static void adapter_service_ins_rem(const bdaddr_t *bdaddr, void *rec,
gboolean insert)
void adapter_service_insert(struct btd_adapter *adapter, void *rec)
{
GSList *l;
for (l = manager_get_adapters(); l != NULL; l = g_slist_next(l)) {
struct btd_adapter *adapter = l->data;
if (bacmp(bdaddr, BDADDR_ANY) != 0 &&
bacmp(bdaddr, &adapter->bdaddr) != 0)
continue;
if (insert == TRUE)
adapter->services = sdp_list_insert_sorted(
adapter->services, rec,
record_sort);
else
adapter->services = sdp_list_remove(adapter->services,
rec);
adapter_emit_uuids_updated(adapter);
}
adapter->services = sdp_list_insert_sorted(adapter->services, rec,
record_sort);
adapter_emit_uuids_updated(adapter);
}
void adapter_service_insert(const bdaddr_t *bdaddr, void *rec)
void adapter_service_remove(struct btd_adapter *adapter, void *rec)
{
/* TRUE to include service*/
adapter_service_ins_rem(bdaddr, rec, TRUE);
}
void adapter_service_remove(const bdaddr_t *bdaddr, void *rec)
{
/* FALSE to remove service*/
adapter_service_ins_rem(bdaddr, rec, FALSE);
adapter->services = sdp_list_remove(adapter->services, rec);
adapter_emit_uuids_updated(adapter);
}
sdp_list_t *adapter_get_services(struct btd_adapter *adapter)
@ -1971,9 +1945,8 @@ static void clear_blocked(struct btd_adapter *adapter)
strerror(-err), -err);
}
static void probe_driver(gpointer data, gpointer user_data)
static void probe_driver(struct btd_adapter *adapter, gpointer user_data)
{
struct btd_adapter *adapter = data;
struct btd_adapter_driver *driver = user_data;
int err;
@ -3117,15 +3090,12 @@ void adapter_resume_discovery(struct btd_adapter *adapter)
int btd_register_adapter_driver(struct btd_adapter_driver *driver)
{
GSList *adapters;
adapter_drivers = g_slist_append(adapter_drivers, driver);
if (driver->probe == NULL)
return 0;
adapters = manager_get_adapters();
g_slist_foreach(adapters, probe_driver, driver);
manager_foreach_adapter(probe_driver, driver);
return 0;
}

View File

@ -151,8 +151,8 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
uint8_t *eir_data, size_t eir_length);
void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode);
void adapter_update_local_name(struct btd_adapter *adapter, const char *name);
void adapter_service_insert(const bdaddr_t *bdaddr, void *rec);
void adapter_service_remove(const bdaddr_t *bdaddr, void *rec);
void adapter_service_insert(struct btd_adapter *adapter, void *rec);
void adapter_service_remove(struct btd_adapter *adapter, void *rec);
sdp_list_t *adapter_get_services(struct btd_adapter *adapter);
void btd_adapter_class_changed(struct btd_adapter *adapter,
uint32_t new_class);

View File

@ -42,8 +42,8 @@
#include "log.h"
#include "manager.h"
#include "adapter.h"
#include "manager.h"
#include "event.h"
#include "dbus-common.h"

View File

@ -47,8 +47,8 @@
#include "textfile.h"
#include "hcid.h"
#include "manager.h"
#include "adapter.h"
#include "manager.h"
#include "device.h"
#include "error.h"
#include "glib-helper.h"

View File

@ -380,6 +380,11 @@ struct btd_adapter *manager_find_adapter_by_id(int id)
return match->data;
}
void manager_foreach_adapter(adapter_cb func, gpointer user_data)
{
g_slist_foreach(adapters, (GFunc) func, user_data);
}
GSList *manager_get_adapters(void)
{
return adapters;

View File

@ -27,6 +27,8 @@
#define MANAGER_INTERFACE "org.bluez.Manager"
typedef void (*adapter_cb) (struct btd_adapter *adapter, gpointer user_data);
dbus_bool_t manager_init(DBusConnection *conn, const char *path);
void manager_cleanup(DBusConnection *conn, const char *path);
@ -35,6 +37,7 @@ struct btd_adapter *manager_find_adapter(const bdaddr_t *sba);
struct btd_adapter *manager_find_adapter_by_address(const char *address);
struct btd_adapter *manager_find_adapter_by_path(const char *path);
struct btd_adapter *manager_find_adapter_by_id(int id);
void manager_foreach_adapter(adapter_cb func, gpointer user_data);
GSList *manager_get_adapters(void);
struct btd_adapter *btd_manager_register_adapter(int id);
int btd_manager_unregister_adapter(int id);

View File

@ -36,8 +36,8 @@
#include <glib.h>
#include "log.h"
#include "manager.h"
#include "adapter.h"
#include "manager.h"
#include "hcid.h"
enum rfkill_type {

View File

@ -41,6 +41,7 @@
#include "sdpd.h"
#include "log.h"
#include "adapter.h"
#include "manager.h"
static sdp_list_t *service_db;
static sdp_list_t *access_db;
@ -169,6 +170,7 @@ void sdp_svcdb_set_collectable(sdp_record_t *record, int sock)
*/
void sdp_record_add(const bdaddr_t *device, sdp_record_t *rec)
{
struct btd_adapter *adapter;
sdp_access_t *dev;
SDPDBG("Adding rec : 0x%lx", (long) rec);
@ -185,7 +187,14 @@ void sdp_record_add(const bdaddr_t *device, sdp_record_t *rec)
access_db = sdp_list_insert_sorted(access_db, dev, access_sort);
adapter_service_insert(device, rec);
if (bacmp(device, BDADDR_ANY) == 0) {
manager_foreach_adapter(adapter_service_insert, rec);
return;
}
adapter = manager_find_adapter(device);
if (adapter)
adapter_service_insert(adapter, rec);
}
static sdp_list_t *record_locate(uint32_t handle)
@ -252,14 +261,20 @@ int sdp_record_remove(uint32_t handle)
service_db = sdp_list_remove(service_db, r);
p = access_locate(handle);
if (p) {
a = p->data;
if (a) {
adapter_service_remove(&a->device, r);
access_db = sdp_list_remove(access_db, a);
access_free(a);
}
}
if (p == NULL || p->data == NULL)
return 0;
a = p->data;
if (bacmp(&a->device, BDADDR_ANY) != 0) {
struct btd_adapter *adapter = manager_find_adapter(&a->device);
if (adapter)
adapter_service_remove(adapter, r);
} else
manager_foreach_adapter(adapter_service_remove, r);
access_db = sdp_list_remove(access_db, a);
access_free(a);
return 0;
}
@ -326,6 +341,6 @@ void sdp_init_services_list(bdaddr_t *device)
SDPDBG("adding record with handle %x", access->handle);
adapter_service_insert(device, rec);
manager_foreach_adapter(adapter_service_insert, rec);
}
}

View File

@ -46,8 +46,8 @@
#include "sdpd.h"
#include "log.h"
#include "manager.h"
#include "adapter.h"
#include "manager.h"
static sdp_record_t *server = NULL;
@ -95,18 +95,15 @@ static void update_db_timestamp(void)
static void update_svclass_list(const bdaddr_t *src)
{
GSList *adapters = manager_get_adapters();
for (; adapters; adapters = adapters->next) {
struct btd_adapter *adapter = adapters->data;
bdaddr_t bdaddr;
adapter_get_address(adapter, &bdaddr);
if (bacmp(src, BDADDR_ANY) == 0 || bacmp(src, &bdaddr) == 0)
if (bacmp(src, BDADDR_ANY) != 0) {
struct btd_adapter *adapter = manager_find_adapter(src);
if (adapter)
btd_adapter_services_updated(adapter);
return;
}
manager_foreach_adapter((adapter_cb) btd_adapter_services_updated,
NULL);
}
void register_public_browse_group(void)