summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlok Barsode <alok.barsode@azingo.com>2008-07-22 21:33:26 +0530
committerLuiz Augusto von Dentz <luiz.dentz@indt.org.br>2008-07-28 10:48:34 -0300
commitee86cf6916b26c167de8f0444778926148726fdf (patch)
tree060ce17692ec9a6b5bcabc98592d1e9eda4219e5
parent661a10565362c5ae0aad6a2ebf6513390cba868e (diff)
Adding adapter_get_path.
Signed-off-by: Alok Barsode <alok.barsode@azingo.com>
-rw-r--r--hcid/adapter.c8
-rw-r--r--hcid/adapter.h1
-rw-r--r--hcid/dbus-hci.c53
-rw-r--r--hcid/manager.c48
4 files changed, 80 insertions, 30 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c
index 0d257ae1..c1e6f3aa 100644
--- a/hcid/adapter.c
+++ b/hcid/adapter.c
@@ -2565,3 +2565,11 @@ uint16_t adapter_get_dev_id(struct adapter *adapter)
{
return adapter->dev_id;
}
+
+const gchar *adapter_get_path(struct adapter *adapter)
+{
+ if (!adapter)
+ return NULL;
+
+ return adapter->path;
+}
diff --git a/hcid/adapter.h b/hcid/adapter.h
index 3446f73d..476fdf1d 100644
--- a/hcid/adapter.h
+++ b/hcid/adapter.h
@@ -176,3 +176,4 @@ struct pending_auth_info *adapter_new_auth_request(struct adapter *adapter,
auth_type_t type);
struct adapter *adapter_create(int id);
uint16_t adapter_get_dev_id(struct adapter *adapter);
+const gchar *adapter_get_path(struct adapter *adapter);
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index c7f63f5d..01c20f1a 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -264,6 +264,7 @@ DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status)
static void adapter_mode_changed(struct adapter *adapter, uint8_t scan_enable)
{
const char *mode;
+ const gchar *path = adapter_get_path(adapter);
adapter->scan_enable = scan_enable;
@@ -300,7 +301,7 @@ static void adapter_mode_changed(struct adapter *adapter, uint8_t scan_enable)
return;
}
- dbus_connection_emit_property_changed(connection, adapter->path,
+ dbus_connection_emit_property_changed(connection, path,
ADAPTER_INTERFACE, "Mode",
DBUS_TYPE_STRING, &mode);
}
@@ -705,6 +706,7 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer,
gboolean paired = TRUE;
struct pending_auth_info *auth;
const gchar *dev_path;
+ const gchar *path;
debug("hcid_dbus_bonding_process_complete: status=%02x", status);
@@ -741,8 +743,9 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer,
device_set_temporary(device, FALSE);
dev_path = device_get_path(device);
+ path = adapter_get_path(adapter);
- g_dbus_emit_signal(connection, adapter->path,
+ g_dbus_emit_signal(connection, path,
ADAPTER_INTERFACE, "DeviceCreated",
DBUS_TYPE_OBJECT_PATH, &dev_path,
DBUS_TYPE_INVALID);
@@ -796,6 +799,7 @@ cleanup:
void hcid_dbus_inquiry_start(bdaddr_t *local)
{
struct adapter *adapter;
+ const gchar *path;
adapter = manager_find_adapter(local);
if (!adapter) {
@@ -815,11 +819,13 @@ void hcid_dbus_inquiry_start(bdaddr_t *local)
if (!adapter->discov_requestor)
adapter->discov_type &= ~RESOLVE_NAME;
- dbus_connection_emit_property_changed(connection, adapter->path,
+ path = adapter_get_path(adapter);
+
+ dbus_connection_emit_property_changed(connection, path,
ADAPTER_INTERFACE, "PeriodicDiscovery",
DBUS_TYPE_BOOLEAN, &adapter->discov_active);
- g_dbus_emit_signal(connection, adapter->path,
+ g_dbus_emit_signal(connection, path,
ADAPTER_INTERFACE, "DiscoveryStarted",
DBUS_TYPE_INVALID);
}
@@ -922,6 +928,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
struct adapter *adapter;
struct remote_dev_info *dev;
bdaddr_t tmp;
+ const gchar *path;
adapter = manager_find_adapter(local);
if (!adapter) {
@@ -929,11 +936,13 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
return;
}
+ path = adapter_get_path(adapter);
+
/* Out of range verification */
if (adapter->pdiscov_active && !adapter->discov_active) {
GSList *l;
- send_out_of_range(adapter->path, adapter->oor_devices);
+ send_out_of_range(path, adapter->oor_devices);
g_slist_foreach(adapter->oor_devices, (GFunc) free, NULL);
g_slist_free(adapter->oor_devices);
@@ -974,7 +983,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
return; /* skip - there is name to resolve */
if (adapter->discov_active) {
- g_dbus_emit_signal(connection, adapter->path,
+ g_dbus_emit_signal(connection, path,
ADAPTER_INTERFACE, "DiscoveryCompleted",
DBUS_TYPE_INVALID);
@@ -1010,6 +1019,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status)
{
struct adapter *adapter;
+ const gchar *path;
/* Don't send the signal if the cmd failed */
if (status)
@@ -1027,7 +1037,9 @@ void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status)
if (!adapter->pdiscov_requestor)
adapter->discov_type &= ~RESOLVE_NAME;
- dbus_connection_emit_property_changed(connection, adapter->path,
+ path = adapter_get_path(adapter);
+
+ dbus_connection_emit_property_changed(connection, path,
ADAPTER_INTERFACE, "PeriodicDiscovery",
DBUS_TYPE_BOOLEAN, &adapter->pdiscov_active);
}
@@ -1035,6 +1047,7 @@ void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status)
void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
{
struct adapter *adapter;
+ const gchar *path;
/* Don't send the signal if the cmd failed */
if (status)
@@ -1068,10 +1081,12 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
adapter->pdiscov_requestor = NULL;
}
- /* workaround: inquiry completed is not sent when exiting from
+ path = adapter_get_path(adapter);
+
+ /* workaround: inquiry completed is not sent when exiting from
* periodic inquiry */
if (adapter->discov_active) {
- g_dbus_emit_signal(connection, adapter->path,
+ g_dbus_emit_signal(connection, path,
ADAPTER_INTERFACE, "DiscoveryCompleted",
DBUS_TYPE_INVALID);
@@ -1079,7 +1094,7 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
}
/* Send discovery completed signal if there isn't name to resolve */
- dbus_connection_emit_property_changed(connection, adapter->path,
+ dbus_connection_emit_property_changed(connection, path,
ADAPTER_INTERFACE, "PeriodicDiscovery",
DBUS_TYPE_BOOLEAN, &adapter->discov_active);
}
@@ -1166,6 +1181,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
dbus_int16_t tmp_rssi = rssi;
uint8_t name_type = 0x00;
name_status_t name_status;
+ const gchar *path;
ba2str(local, local_addr);
ba2str(peer, peer_addr);
@@ -1239,11 +1255,13 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
}
}
+ path = adapter_get_path(adapter);
+
if (name) {
if (name_type != 0x08)
name_status = NAME_SENT;
- emit_device_found(adapter->path, paddr,
+ emit_device_found(path, paddr,
"Address", DBUS_TYPE_STRING, &paddr,
"Class", DBUS_TYPE_UINT32, &class,
"RSSI", DBUS_TYPE_INT16, &tmp_rssi,
@@ -1252,7 +1270,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
g_free(name);
} else {
- emit_device_found(adapter->path, paddr,
+ emit_device_found(path, paddr,
"Address", DBUS_TYPE_STRING, &paddr,
"Class", DBUS_TYPE_UINT32, &class,
"RSSI", DBUS_TYPE_INT16, &tmp_rssi,
@@ -1307,6 +1325,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
char peer_addr[18];
const char *paddr = peer_addr;
const gchar *dev_path;
+ const gchar *path;
adapter = manager_find_adapter(local);
if (!adapter) {
@@ -1365,8 +1384,10 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
adapter->discov_type &= ~RESOLVE_NAME;
}
+ path = adapter_get_path(adapter);
+
if (adapter->discov_active) {
- g_dbus_emit_signal(connection, adapter->path,
+ g_dbus_emit_signal(connection, path,
ADAPTER_INTERFACE, "DiscoveryCompleted",
DBUS_TYPE_INVALID);
@@ -1762,6 +1783,7 @@ void hcid_dbus_write_simple_pairing_mode_complete(bdaddr_t *local)
int dd;
uint8_t mode;
uint16_t dev_id;
+ const gchar *path;
adapter = manager_find_adapter(local);
if (!adapter) {
@@ -1770,16 +1792,17 @@ void hcid_dbus_write_simple_pairing_mode_complete(bdaddr_t *local)
}
dev_id = adapter_get_dev_id(adapter);
+ path = adapter_get_path(adapter);
dd = hci_open_dev(dev_id);
if (dd < 0) {
- error("HCI adapter open failed: %s", adapter->path);
+ error("HCI adapter open failed: %s", path);
return;
}
if (hci_read_simple_pairing_mode(dd, &mode, 1000) < 0) {
error("Can't read class of adapter on %s: %s(%d)",
- adapter->path, strerror(errno), errno);
+ path, strerror(errno), errno);
hci_close_dev(dd);
return;
}
diff --git a/hcid/manager.c b/hcid/manager.c
index 64d3d465..e237742a 100644
--- a/hcid/manager.c
+++ b/hcid/manager.c
@@ -212,6 +212,7 @@ static DBusMessage *default_adapter(DBusConnection *conn,
{
DBusMessage *reply;
struct adapter *adapter;
+ const gchar *path;
adapter = manager_find_adapter_by_id(default_adapter_id);
if (!adapter)
@@ -221,7 +222,9 @@ static DBusMessage *default_adapter(DBusConnection *conn,
if (!reply)
return NULL;
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &adapter->path,
+ path = adapter_get_path(adapter);
+
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
return reply;
@@ -235,6 +238,7 @@ static DBusMessage *find_adapter(DBusConnection *conn,
struct hci_dev_info di;
const char *pattern;
int dev_id;
+ const gchar *path;
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern,
DBUS_TYPE_INVALID))
@@ -264,7 +268,9 @@ static DBusMessage *find_adapter(DBusConnection *conn,
if (!reply)
return NULL;
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &adapter->path,
+ path = adapter_get_path(adapter);
+
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
return reply;
@@ -292,6 +298,7 @@ static DBusMessage *list_adapters(DBusConnection *conn,
struct adapter *adapter = l->data;
struct hci_dev_info di;
dev_id = adapter_get_dev_id(adapter);
+ const gchar *path = adapter_get_path(adapter);
if (hci_devinfo(dev_id, &di) < 0)
continue;
@@ -300,7 +307,7 @@ static DBusMessage *list_adapters(DBusConnection *conn,
continue;
dbus_message_iter_append_basic(&array_iter,
- DBUS_TYPE_OBJECT_PATH, &adapter->path);
+ DBUS_TYPE_OBJECT_PATH, &path);
}
dbus_message_iter_close_container(&iter, &array_iter);
@@ -349,8 +356,9 @@ static gint adapter_path_cmp(gconstpointer a, gconstpointer b)
{
const struct adapter *adapter = a;
const char *path = b;
+ const gchar *adapter_path = adapter_get_path(adapter);
- return strcmp(adapter->path, path);
+ return strcmp(adapter_path, path);
}
static gint adapter_address_cmp(gconstpointer a, gconstpointer b)
@@ -399,9 +407,11 @@ struct adapter *manager_find_adapter_by_id(int id)
static void manager_add_adapter(struct adapter *adapter)
{
+ const gchar *path = adapter_get_path(adapter);
+
g_dbus_emit_signal(connection, "/",
MANAGER_INTERFACE, "AdapterAdded",
- DBUS_TYPE_OBJECT_PATH, &adapter->path,
+ DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
adapters = g_slist_append(adapters, adapter);
@@ -410,10 +420,11 @@ static void manager_add_adapter(struct adapter *adapter)
static void manager_remove_adapter(struct adapter *adapter)
{
uint16_t dev_id = adapter_get_dev_id(adapter);
+ const gchar *path = adapter_get_path(adapter);
g_dbus_emit_signal(connection, "/",
MANAGER_INTERFACE, "AdapterRemoved",
- DBUS_TYPE_OBJECT_PATH, &adapter->path,
+ DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
if ((default_adapter_id == dev_id || default_adapter_id < 0)) {
@@ -429,17 +440,20 @@ static void manager_remove_adapter(struct adapter *adapter)
int manager_register_adapter(int id)
{
struct adapter *adapter = adapter_create(id);
+ const gchar *path;
if(!adapter)
return -1;
- if (!adapter_init(connection, adapter->path, adapter)) {
- error("Adapter interface init failed on path %s", adapter->path);
+ path = adapter_get_path(adapter);
+
+ if (!adapter_init(connection, path, adapter)) {
+ error("Adapter interface init failed on path %s", path);
g_free(adapter);
return -1;
}
- __probe_servers(adapter->path);
+ __probe_servers(path);
manager_add_adapter(adapter);
@@ -449,26 +463,29 @@ int manager_register_adapter(int id)
int manager_unregister_adapter(int id)
{
struct adapter *adapter;
+ const gchar *path;
adapter = manager_find_adapter_by_id(id);
if (!adapter)
return -1;
- info("Unregister path: %s", adapter->path);
+ path = adapter_get_path(adapter);
+
+ info("Unregister path: %s", path);
- __remove_servers(adapter->path);
+ __remove_servers(path);
adapter_stop(adapter);
manager_remove_adapter(adapter);
- if (!adapter_cleanup(connection, adapter->path)) {
+ if (!adapter_cleanup(connection, path)) {
error("Failed to unregister adapter interface on %s object",
- adapter->path);
+ path);
return -1;
}
- g_free(adapter->path);
+ g_free(path);
g_free(adapter);
return 0;
@@ -516,12 +533,13 @@ int manager_get_default_adapter()
void manager_set_default_adapter(int id)
{
struct adapter *adapter = manager_find_adapter_by_id(id);
+ const gchar *path = adapter_get_path(adapter);
default_adapter_id = id;
g_dbus_emit_signal(connection, "/",
MANAGER_INTERFACE,
"DefaultAdapterChanged",
- DBUS_TYPE_OBJECT_PATH, &adapter->path,
+ DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
}