diff options
author | Vinicius Gomes <vinicius.gomes@openbossa.org> | 2008-04-03 17:37:38 +0000 |
---|---|---|
committer | Vinicius Gomes <vinicius.gomes@openbossa.org> | 2008-04-03 17:37:38 +0000 |
commit | 83735b4aa67748253b2e3df02847ffb86c131085 (patch) | |
tree | 45be1897a1dab3ecad7f055b8d8242b265c3c98a | |
parent | 4685a04c10fd0ec2bfed0cabb2f26b822d406b4d (diff) |
hcid: creating the device object when the pair is initiated by the remote device.
-rw-r--r-- | hcid/adapter.c | 38 | ||||
-rw-r--r-- | hcid/adapter.h | 5 | ||||
-rw-r--r-- | hcid/dbus-hci.c | 10 |
3 files changed, 42 insertions, 11 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c index 045d425d..04fe4c09 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -2014,7 +2014,7 @@ static DBusHandlerResult adapter_set_remote_alias(DBusConnection *conn, if (new_path) { struct device *device; - device = adapter_get_device(adapter, addr); + device = adapter_find_device(adapter, addr); if (device) { dbus_connection_emit_property_changed(conn, device->path, DEVICE_INTERFACE, @@ -2267,7 +2267,7 @@ static void create_device_req_free(struct create_device_req *create) g_free(create); } -struct device *adapter_get_device(struct adapter *adapter, const char *dest) +struct device *adapter_find_device(struct adapter *adapter, const char *dest) { struct device *device; GSList *l; @@ -2285,6 +2285,34 @@ struct device *adapter_get_device(struct adapter *adapter, const char *dest) return device; } +struct device *adapter_get_device(DBusConnection *conn, + struct adapter *adapter, const gchar *address) +{ + struct device *device; + char path[MAX_PATH_LENGTH]; + + if (!adapter) + return NULL; + + device = adapter_find_device(adapter, address); + if (device) + return device; + + device = device_create(conn, adapter, address, NULL); + if (!device) + return NULL; + + snprintf(path, MAX_PATH_LENGTH, "/hci%d", adapter->dev_id); + + adapter->devices = g_slist_append(adapter->devices, device); + dbus_connection_emit_signal(conn, path, + ADAPTER_INTERFACE, "DeviceCreated", + DBUS_TYPE_OBJECT_PATH, &device->path, + DBUS_TYPE_INVALID); + + return device; +} + static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, struct adapter *adapter) { @@ -2643,7 +2671,7 @@ static DBusHandlerResult adapter_remove_bonding(DBusConnection *conn, struct device *device; gboolean paired = FALSE; - device = adapter_get_device(adapter, addr_ptr); + device = adapter_find_device(adapter, addr_ptr); if (device) { dbus_connection_emit_property_changed(conn, device->path, DEVICE_INTERFACE, @@ -3289,7 +3317,7 @@ static DBusHandlerResult adapter_set_trusted(DBusConnection *conn, struct device *device; gboolean trust = TRUE; - device = adapter_get_device(adapter, address); + device = adapter_find_device(adapter, address); if (device) { dbus_connection_emit_property_changed(conn, device->path, DEVICE_INTERFACE, @@ -3370,7 +3398,7 @@ static DBusHandlerResult adapter_remove_trust(DBusConnection *conn, struct device *device; gboolean trust = FALSE; - device = adapter_get_device(adapter, address); + device = adapter_find_device(adapter, address); if (device) { dbus_connection_emit_property_changed(conn, device->path, DEVICE_INTERFACE, diff --git a/hcid/adapter.h b/hcid/adapter.h index 9da56d3e..280c1d1c 100644 --- a/hcid/adapter.h +++ b/hcid/adapter.h @@ -115,7 +115,10 @@ struct adapter { dbus_bool_t adapter_init(DBusConnection *conn, const char *path); -struct device *adapter_get_device(struct adapter *adapter, const char *dest); +struct device *adapter_get_device(DBusConnection *conn, + struct adapter *adapter, const gchar *address); + +struct device *adapter_find_device(struct adapter *adapter, const char *dest); const char *major_class_str(uint32_t class); diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index f87d0c2e..72ea30a9 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -1006,7 +1006,7 @@ int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci) ba2str(&ci->bdaddr, addr); - device = adapter_get_device(adapter, addr); + device = adapter_find_device(adapter, addr); if (!device) { device = device_create(connection, adapter, addr, NULL); device->created = TRUE; @@ -1090,7 +1090,7 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, struct device *device; gboolean paired = TRUE; - device = adapter_get_device(adapter, paddr); + device = adapter_get_device(connection, adapter, paddr); if (device) { dbus_connection_emit_property_changed(connection, device->path, DEVICE_INTERFACE, @@ -1807,7 +1807,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, if (hcid_dbus_use_experimental()) { struct device *device; - device = adapter_get_device(adapter, paddr); + device = adapter_find_device(adapter, paddr); if (device) { dbus_connection_emit_property_changed(connection, device->path, DEVICE_INTERFACE, @@ -1920,7 +1920,7 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, struct device *device; gboolean connected = TRUE; - device = adapter_get_device(adapter, paddr); + device = adapter_find_device(adapter, paddr); if (device) { dbus_connection_emit_property_changed(connection, device->path, DEVICE_INTERFACE, @@ -2036,7 +2036,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, struct device *device; gboolean connected = FALSE; - device = adapter_get_device(adapter, paddr); + device = adapter_find_device(adapter, paddr); if (device) { dbus_connection_emit_property_changed(connection, device->path, DEVICE_INTERFACE, |