summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-06-09 18:27:48 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-06-09 18:27:48 +0000
commit6adf2ab945cdb8442d0f621501748d6e198b28d6 (patch)
treef4b7a64fefbfc41086cd330b367dd068b137857e /hcid
parent058ed7e1548bd66579365a7f8ca1c35ddc05e1da (diff)
Move adapter list from dbus-hci.c to manager.c
Diffstat (limited to 'hcid')
-rw-r--r--hcid/dbus-common.c2
-rw-r--r--hcid/dbus-hci.c177
-rw-r--r--hcid/dbus-service.c4
-rw-r--r--hcid/manager.c217
-rw-r--r--hcid/manager.h10
5 files changed, 215 insertions, 195 deletions
diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c
index 963de209..ffb13dff 100644
--- a/hcid/dbus-common.c
+++ b/hcid/dbus-common.c
@@ -243,7 +243,7 @@ static gboolean system_bus_reconnect(void *data)
}
/* reset the default device */
- set_default_adapter(-1);
+ manager_set_default_adapter(-1);
for (i = 0; i < dl->dev_num; i++, dr++)
hcid_dbus_register_device(dr->dev_id);
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index 5711be12..6d3a2e1d 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -60,37 +60,6 @@
#include "dbus-hci.h"
static DBusConnection *connection = NULL;
-static GSList *adapters = NULL;
-
-static gint adapter_path_cmp(gconstpointer a, gconstpointer b)
-{
- const struct adapter *adapter = a;
- const char *path = b;
-
- return strcmp(adapter->path, path);
-}
-
-static gint adapter_address_cmp(gconstpointer a, gconstpointer b)
-{
- const struct adapter *adapter = a;
- const char *address = b;
-
- return strcmp(adapter->address, address);
-}
-
-struct adapter *adapter_find(const bdaddr_t *sba)
-{
- GSList *match;
- char address[18];
-
- ba2str(sba, address);
-
- match = g_slist_find_custom(adapters, address, adapter_address_cmp);
- if (!match)
- return NULL;
-
- return match->data;
-}
void bonding_request_free(struct bonding_request_info *bonding)
{
@@ -441,19 +410,16 @@ static void do_unregister(gpointer data, gpointer user_data)
int unregister_adapter_path(const char *path)
{
- struct adapter *adapter = NULL;
- GSList *l;
+ struct adapter *adapter;
info("Unregister path: %s", path);
__remove_servers(path);
- l = g_slist_find_custom(adapters, path, adapter_path_cmp);
- if (!l)
+ adapter = manager_find_adapter_by_path(path);
+ if (!adapter)
goto unreg;
- adapter = l->data;
-
/* check pending requests */
reply_pending_requests(path, adapter);
@@ -522,8 +488,6 @@ int unregister_adapter_path(const char *path)
g_slist_free(adapter->devices);
}
- adapters = g_slist_remove(adapters, adapter);
-
g_free(adapter->path);
g_free(adapter);
@@ -551,7 +515,7 @@ unreg:
int hcid_dbus_register_device(uint16_t id)
{
char path[MAX_PATH_LENGTH];
- char *pptr = path, *ptr = path + ADAPTER_PATH_INDEX;
+ char *ptr = path + ADAPTER_PATH_INDEX;
struct adapter *adapter;
snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id);
@@ -579,25 +543,9 @@ int hcid_dbus_register_device(uint16_t id)
goto failed;
}
- /*
- * Send the adapter added signal
- */
- if (hcid_dbus_use_experimental()) {
- g_dbus_emit_signal(connection, "/",
- MANAGER_INTERFACE,
- "AdapterAdded",
- DBUS_TYPE_OBJECT_PATH, &ptr,
- DBUS_TYPE_INVALID);
- }
-
- g_dbus_emit_signal(connection, BASE_PATH, MANAGER_INTERFACE,
- "AdapterAdded",
- DBUS_TYPE_STRING, &pptr,
- DBUS_TYPE_INVALID);
-
__probe_servers(path);
- adapters = g_slist_append(adapters, adapter);
+ manager_add_adapter(adapter);
return 0;
@@ -615,55 +563,17 @@ failed:
int hcid_dbus_unregister_device(uint16_t id)
{
+ struct adapter *adapter;
char path[MAX_PATH_LENGTH];
- char *pptr = path, *ptr = path + ADAPTER_PATH_INDEX;
int ret;
snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id);
+ adapter = manager_find_adapter_by_path(path);
- if (hcid_dbus_use_experimental()) {
- g_dbus_emit_signal(connection, "/",
- MANAGER_INTERFACE,
- "AdapterRemoved",
- DBUS_TYPE_OBJECT_PATH, &ptr,
- DBUS_TYPE_INVALID);
- }
-
- g_dbus_emit_signal(connection, BASE_PATH, MANAGER_INTERFACE,
- "AdapterRemoved",
- DBUS_TYPE_STRING, &pptr,
- DBUS_TYPE_INVALID);
+ manager_remove_adapter(adapter);
ret = unregister_adapter_path(path);
- if (ret == 0 && (get_default_adapter() == id || get_default_adapter() < 0)) {
- int new_default = hci_get_route(NULL);
- set_default_adapter(new_default);
- if (new_default >= 0) {
- snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH,
- new_default);
- if (hcid_dbus_use_experimental()) {
- g_dbus_emit_signal(connection, "/",
- MANAGER_INTERFACE,
- "DefaultAdapterChanged",
- DBUS_TYPE_OBJECT_PATH, &ptr,
- DBUS_TYPE_INVALID);
- }
- g_dbus_emit_signal(connection, BASE_PATH,
- MANAGER_INTERFACE,
- "DefaultAdapterChanged",
- DBUS_TYPE_STRING, &pptr,
- DBUS_TYPE_INVALID);
- } else {
- *path = '\0';
- g_dbus_emit_signal(connection, BASE_PATH,
- MANAGER_INTERFACE,
- "DefaultAdapterChanged",
- DBUS_TYPE_STRING, &pptr,
- DBUS_TYPE_INVALID);
- }
- }
-
return ret;
}
@@ -716,14 +626,13 @@ static void register_devices(bdaddr_t *src, struct adapter *adapter)
int hcid_dbus_start_device(uint16_t id)
{
char path[MAX_PATH_LENGTH];
- char *pptr = path, *ptr = path + ADAPTER_PATH_INDEX;
+ char *ptr = path + ADAPTER_PATH_INDEX;
struct hci_dev_info di;
struct adapter* adapter;
struct hci_conn_list_req *cl = NULL;
struct hci_conn_info *ci;
const char *mode;
int i, err, dd = -1, ret = -1;
- GSList *l;
snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id);
@@ -735,14 +644,12 @@ int hcid_dbus_start_device(uint16_t id)
if (hci_test_bit(HCI_RAW, &di.flags))
return -1;
- l = g_slist_find_custom(adapters, path, adapter_path_cmp);
- if (!l) {
+ adapter = manager_find_adapter_by_path(path);
+ if (!adapter) {
error("Getting %s path data failed!", path);
return -1;
}
- adapter = l->data;
-
if (hci_test_bit(HCI_INQUIRY, &di.flags))
adapter->discov_active = 1;
else
@@ -807,21 +714,8 @@ int hcid_dbus_start_device(uint16_t id)
DBUS_TYPE_STRING, &mode);
}
- if (get_default_adapter() < 0) {
- set_default_adapter(id);
- if (hcid_dbus_use_experimental())
- g_dbus_emit_signal(connection, "/",
- MANAGER_INTERFACE,
- "DefaultAdapterChanged",
- DBUS_TYPE_OBJECT_PATH, &ptr,
- DBUS_TYPE_INVALID);
-
- g_dbus_emit_signal(connection, BASE_PATH,
- MANAGER_INTERFACE,
- "DefaultAdapterChanged",
- DBUS_TYPE_STRING, &pptr,
- DBUS_TYPE_INVALID);
- }
+ if (manager_get_default_adapter() < 0)
+ manager_set_default_adapter(id);
if (hcid_dbus_use_experimental())
register_devices(&di.bdaddr, adapter);
@@ -853,18 +747,15 @@ int hcid_dbus_stop_device(uint16_t id)
char path[MAX_PATH_LENGTH];
struct adapter *adapter;
const char *mode = "off";
- GSList *l;
snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id);
- l = g_slist_find_custom(adapters, path, adapter_path_cmp);
- if (!l) {
+ adapter = manager_find_adapter_by_path(path);
+ if (!adapter) {
error("Getting %s path data failed!", path);
return -1;
}
- adapter = l->data;
-
/* cancel pending timeout */
if (adapter->timeout_id) {
g_source_remove(adapter->timeout_id);
@@ -952,7 +843,7 @@ void hcid_dbus_new_auth_request(bdaddr_t *sba, bdaddr_t *dba, auth_type_t type)
struct adapter *adapter;
struct pending_auth_info *info;
- adapter = adapter_find(sba);
+ adapter = manager_find_adapter(sba);
if (!adapter) {
error("No matching adapter found");
return;
@@ -1017,7 +908,7 @@ int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci)
struct device *device;
struct agent *agent;
- adapter = adapter_find(sba);
+ adapter = manager_find_adapter(sba);
if (!adapter) {
error("No matching adapter found");
return -1;
@@ -1142,7 +1033,7 @@ int hcid_dbus_user_confirm(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey)
char addr[18];
uint8_t type;
- adapter = adapter_find(sba);
+ adapter = manager_find_adapter(sba);
if (!adapter) {
error("No matching adapter found");
return -1;
@@ -1203,7 +1094,7 @@ int hcid_dbus_user_passkey(bdaddr_t *sba, bdaddr_t *dba)
struct agent *agent;
char addr[18];
- adapter = adapter_find(sba);
+ adapter = manager_find_adapter(sba);
if (!adapter) {
error("No matching adapter found");
return -1;
@@ -1237,7 +1128,7 @@ int hcid_dbus_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey)
struct agent *agent;
char addr[18];
- adapter = adapter_find(sba);
+ adapter = manager_find_adapter(sba);
if (!adapter) {
error("No matching adapter found");
return -1;
@@ -1281,7 +1172,7 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer,
ba2str(peer, peer_addr);
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("Unable to find matching adapter");
return;
@@ -1372,7 +1263,7 @@ void hcid_dbus_inquiry_start(bdaddr_t *local)
{
struct adapter *adapter;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("Unable to find matching adapter");
return;
@@ -1535,7 +1426,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
struct remote_dev_info *dev;
bdaddr_t tmp;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("Unable to find matching adapter");
return;
@@ -1636,7 +1527,7 @@ void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status)
if (status)
return;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -1670,7 +1561,7 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
if (status)
return;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -1816,7 +1707,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
ba2str(local, local_addr);
ba2str(peer, peer_addr);
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -1941,7 +1832,7 @@ void hcid_dbus_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class)
if (old_class == class)
return;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -1978,7 +1869,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
char peer_addr[18];
const char *paddr = peer_addr;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -2071,7 +1962,7 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle,
struct adapter *adapter;
GSList *l;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -2136,7 +2027,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status,
return;
}
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -2392,7 +2283,7 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local)
struct hci_request rq;
int dd = -1;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -2442,7 +2333,7 @@ void hcid_dbus_write_class_complete(bdaddr_t *local)
int dd;
uint8_t cls[3];
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -2512,7 +2403,7 @@ void hcid_dbus_pin_code_reply(bdaddr_t *local, void *ptr)
ret_pin_code_req_reply *ret = ptr + EVT_CMD_COMPLETE_SIZE;
GSList *l;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return;
@@ -2534,7 +2425,7 @@ int hcid_dbus_get_io_cap(bdaddr_t *local, bdaddr_t *remote, uint8_t *cap,
char addr[18];
uint8_t type;
- adapter = adapter_find(local);
+ adapter = manager_find_adapter(local);
if (!adapter) {
error("No matching adapter found");
return -1;
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c
index 0f7b34a1..67c5a7cd 100644
--- a/hcid/dbus-service.c
+++ b/hcid/dbus-service.c
@@ -674,7 +674,7 @@ int service_req_auth(const bdaddr_t *src, const bdaddr_t *dst,
char address[18];
gboolean trusted;
- adapter = adapter_find(src);
+ adapter = manager_find_adapter(src);
if (!adapter)
return -EPERM;
@@ -717,7 +717,7 @@ int service_req_auth(const bdaddr_t *src, const bdaddr_t *dst,
int service_cancel_auth(const bdaddr_t *src)
{
- struct adapter *adapter = adapter_find(src);
+ struct adapter *adapter = manager_find_adapter(src);
struct device *device;
struct agent *agent;
char address[18];
diff --git a/hcid/manager.c b/hcid/manager.c
index 24ce93a9..c2d5fdf1 100644
--- a/hcid/manager.c
+++ b/hcid/manager.c
@@ -59,7 +59,9 @@
#include "manager.h"
+static DBusConnection *connection = NULL;
static int default_adapter_id = -1;
+static GSList *adapters = NULL;
static inline DBusMessage *invalid_args(DBusMessage *msg)
{
@@ -388,19 +390,21 @@ static DBusMessage *default_adapter(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- char path[MAX_PATH_LENGTH], *path_ptr = path;
+ struct adapter *adapter;
+ char *path;
- if (default_adapter_id < 0)
+ adapter = manager_find_adapter_by_id(default_adapter_id);
+ if (!adapter)
return no_such_adapter(msg);
reply = dbus_message_new_method_return(msg);
if (!reply)
return NULL;
- snprintf(path, sizeof(path), "/hci%d", default_adapter_id);
+ path = adapter->path + ADAPTER_PATH_INDEX;
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_ptr,
- DBUS_TYPE_INVALID);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
return reply;
}
@@ -409,7 +413,8 @@ static DBusMessage *find_adapter(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- char path[MAX_PATH_LENGTH], *path_ptr = path;
+ struct adapter *adapter;
+ char *path;
struct hci_dev_info di;
const char *pattern;
int dev_id;
@@ -434,14 +439,18 @@ static DBusMessage *find_adapter(DBusConnection *conn,
if (hci_test_bit(HCI_RAW, &di.flags))
return no_such_adapter(msg);
+ adapter = manager_find_adapter_by_id(dev_id);
+ if (!adapter)
+ return no_such_adapter(msg);
+
reply = dbus_message_new_method_return(msg);
if (!reply)
return NULL;
- snprintf(path, sizeof(path), "/hci%d", dev_id);
+ path = adapter->path + ADAPTER_PATH_INDEX;
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_ptr,
- DBUS_TYPE_INVALID);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
return reply;
}
@@ -452,62 +461,36 @@ static DBusMessage *list_adapters(DBusConnection *conn,
DBusMessageIter iter;
DBusMessageIter array_iter;
DBusMessage *reply;
- struct hci_dev_list_req *dl;
- struct hci_dev_req *dr;
- int i, sk;
-
- sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
- if (sk < 0)
- return create_errno_message(msg, errno);
-
- dl = g_malloc0(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
-
- dl->dev_num = HCI_MAX_DEV;
- dr = dl->dev_req;
-
- if (ioctl(sk, HCIGETDEVLIST, dl) < 0) {
- int err = errno;
- close(sk);
- g_free(dl);
- return create_errno_message(msg, err);
- }
-
- dr = dl->dev_req;
+ GSList *l;
reply = dbus_message_new_method_return(msg);
- if (!reply) {
- close(sk);
- g_free(dl);
+ if (!reply)
return NULL;
- }
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
DBUS_TYPE_OBJECT_PATH_AS_STRING, &array_iter);
- for (i = 0; i < dl->dev_num; i++, dr++) {
- char path[MAX_PATH_LENGTH], *path_ptr = path;
+ for (l = adapters; l; l = l->next) {
+ struct adapter *adapter = l->data;
+ char *path;
struct hci_dev_info di;
- if (hci_devinfo(dr->dev_id, &di) < 0)
+ if (hci_devinfo(adapter->dev_id, &di) < 0)
continue;
if (hci_test_bit(HCI_RAW, &di.flags))
continue;
- snprintf(path, sizeof(path), "/hci%d", di.dev_id);
+ path = adapter->path + ADAPTER_PATH_INDEX;
dbus_message_iter_append_basic(&array_iter,
- DBUS_TYPE_OBJECT_PATH, &path_ptr);
+ DBUS_TYPE_OBJECT_PATH, &path);
}
dbus_message_iter_close_container(&iter, &array_iter);
- g_free(dl);
-
- close(sk);
-
return reply;
}
@@ -527,6 +510,8 @@ static GDBusSignalTable manager_signals[] = {
dbus_bool_t manager_init(DBusConnection *conn, const char *path)
{
+ connection = conn;
+
if (hcid_dbus_use_experimental()) {
debug("Registering experimental manager interface");
g_dbus_register_interface(conn, "/", MANAGER_INTERFACE,
@@ -547,12 +532,152 @@ void manager_cleanup(DBusConnection *conn, const char *path)
g_dbus_unregister_interface(conn, "/", MANAGER_INTERFACE);
}
-int get_default_adapter(void)
+static gint adapter_id_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct adapter *adapter = a;
+ uint16_t id = GPOINTER_TO_UINT(b);
+
+ return adapter->dev_id == id ? 0 : -1;
+}
+
+static gint adapter_path_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct adapter *adapter = a;
+ const char *path = b;
+
+ return strcmp(adapter->path, path);
+}
+
+static gint adapter_address_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct adapter *adapter = a;
+ const char *address = b;
+
+ return strcmp(adapter->address, address);
+}
+
+struct adapter *manager_find_adapter(const bdaddr_t *sba)
+{
+ GSList *match;
+ char address[18];
+
+ ba2str(sba, address);
+
+ match = g_slist_find_custom(adapters, address, adapter_address_cmp);
+ if (!match)
+ return NULL;
+
+ return match->data;
+}
+
+struct adapter *manager_find_adapter_by_path(const char *path)
+{
+ GSList *match;
+
+ match = g_slist_find_custom(adapters, path, adapter_path_cmp);
+ if (!match)
+ return NULL;
+
+ return match->data;
+}
+
+struct adapter *manager_find_adapter_by_id(int id)
+{
+ GSList *match;
+
+ match = g_slist_find_custom(adapters, GINT_TO_POINTER(id), adapter_id_cmp);
+ if (!match)
+ return NULL;
+
+ return match->data;
+}
+
+void manager_add_adapter(struct adapter *adapter)
+{
+ const char *ptr = adapter->path + ADAPTER_PATH_INDEX;
+
+ if (hcid_dbus_use_experimental()) {
+ g_dbus_emit_signal(connection, "/",
+ MANAGER_INTERFACE, "AdapterAdded",
+ DBUS_TYPE_OBJECT_PATH, &ptr,
+ DBUS_TYPE_INVALID);
+ }
+
+ g_dbus_emit_signal(connection, BASE_PATH,
+ MANAGER_INTERFACE, "AdapterAdded",
+ DBUS_TYPE_STRING, &adapter->path,
+ DBUS_TYPE_INVALID);
+
+ adapters = g_slist_append(adapters, adapter);
+}
+
+void manager_remove_adapter(struct adapter *adapter)
+{
+ const char *ptr = adapter->path + ADAPTER_PATH_INDEX;
+
+ if (hcid_dbus_use_experimental()) {
+ g_dbus_emit_signal(connection, "/",
+ MANAGER_INTERFACE, "AdapterRemoved",
+ DBUS_TYPE_OBJECT_PATH, &ptr,
+ DBUS_TYPE_INVALID);
+ }
+
+ g_dbus_emit_signal(connection, BASE_PATH,
+ MANAGER_INTERFACE, "AdapterRemoved",
+ DBUS_TYPE_STRING, &adapter->path,
+ DBUS_TYPE_INVALID);
+
+ if ((default_adapter_id == adapter->dev_id || default_adapter_id < 0)) {
+ int new_default = hci_get_route(NULL);
+
+ default_adapter_id = new_default;
+ if (new_default >= 0) {
+ if (hcid_dbus_use_experimental()) {
+ g_dbus_emit_signal(connection, "/",
+ MANAGER_INTERFACE,
+ "DefaultAdapterChanged",
+ DBUS_TYPE_OBJECT_PATH, &ptr,
+ DBUS_TYPE_INVALID);
+ }
+ g_dbus_emit_signal(connection, BASE_PATH,
+ MANAGER_INTERFACE,
+ "DefaultAdapterChanged",
+ DBUS_TYPE_STRING, &adapter->path,
+ DBUS_TYPE_INVALID);
+ } else {
+ g_dbus_emit_signal(connection, BASE_PATH,
+ MANAGER_INTERFACE,
+ "DefaultAdapterChanged",
+ DBUS_TYPE_STRING, &adapter->path,
+ DBUS_TYPE_INVALID);
+ }
+ }
+
+ adapters = g_slist_remove(adapters, adapter);
+}
+
+int manager_get_default_adapter()
{
return default_adapter_id;
}
-void set_default_adapter(int new_default)
+void manager_set_default_adapter(int id)
{
- default_adapter_id = new_default;
+ struct adapter *adapter = manager_find_adapter_by_id(id);
+ const char *ptr = adapter->path + ADAPTER_PATH_INDEX;
+
+ default_adapter_id = id;
+
+ if (hcid_dbus_use_experimental())
+ g_dbus_emit_signal(connection, "/",
+ MANAGER_INTERFACE,
+ "DefaultAdapterChanged",
+ DBUS_TYPE_OBJECT_PATH, &ptr,
+ DBUS_TYPE_INVALID);
+
+ g_dbus_emit_signal(connection, BASE_PATH,
+ MANAGER_INTERFACE,
+ "DefaultAdapterChanged",
+ DBUS_TYPE_STRING, &adapter->path,
+ DBUS_TYPE_INVALID);
}
diff --git a/hcid/manager.h b/hcid/manager.h
index c8924583..2065d5ac 100644
--- a/hcid/manager.h
+++ b/hcid/manager.h
@@ -27,6 +27,10 @@
dbus_bool_t manager_init(DBusConnection *conn, const char *path);
void manager_cleanup(DBusConnection *conn, const char *path);
-int get_default_adapter(void);
-
-void set_default_adapter(int new_default);
+struct adapter *manager_find_adapter(const bdaddr_t *sba);
+struct adapter *manager_find_adapter_by_path(const char *path);
+struct adapter *manager_find_adapter_by_id(int id);
+void manager_add_adapter(struct adapter *adapter);
+void manager_remove_adapter(struct adapter *adapter);
+int manager_get_default_adapter();
+void manager_set_default_adapter(int id);