diff options
author | Cidorvan Leite <cidorvan.leite@openbossa.org> | 2008-04-10 22:36:58 +0000 |
---|---|---|
committer | Cidorvan Leite <cidorvan.leite@openbossa.org> | 2008-04-10 22:36:58 +0000 |
commit | fb27732e05fb7b69c3b784ed8a6aaed2d9d939ae (patch) | |
tree | f6d262f6a6bf0733c761399b8e15b7ed130ae0c9 /hcid/adapter.c | |
parent | 61a6576b2b7badd8963219873b631e6a51df612c (diff) |
Added local agent in CreatePairedDevice
Diffstat (limited to 'hcid/adapter.c')
-rw-r--r-- | hcid/adapter.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c index 66ac4d0e..0934ad02 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -231,10 +231,17 @@ int pending_remote_name_cancel(struct adapter *adapter) return err; } +static void device_agent_removed(struct agent *agent, struct device *device) +{ + if (device->agent == agent) + device->agent = NULL; +} + static struct bonding_request_info *bonding_request_new(DBusConnection *conn, DBusMessage *msg, struct adapter *adapter, - const char *address) + const char *address, + const char *agent_path) { struct bonding_request_info *bonding; struct device *device; @@ -244,10 +251,18 @@ static struct bonding_request_info *bonding_request_new(DBusConnection *conn, bonding->conn = dbus_connection_ref(conn); bonding->msg = dbus_message_ref(msg); - /* FIXME: should be removed on 4.0 */ if (hcid_dbus_use_experimental()) { device = adapter_get_device(conn, adapter, address); + if (!device) + return NULL; + device->temporary = TRUE; + + if (agent_path && strcmp(agent_path, "/")) + device->agent = agent_create(adapter, + dbus_message_get_sender(msg), agent_path, + NULL, (agent_remove_cb) device_agent_removed, + device); } str2ba(address, &bonding->bdaddr); @@ -2277,19 +2292,12 @@ struct device *adapter_find_device(struct adapter *adapter, const char *dest) return device; } -struct device *adapter_get_device(DBusConnection *conn, - struct adapter *adapter, const gchar *address) +struct device *adapter_create_device(DBusConnection *conn, + struct adapter *adapter, const char *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; @@ -2326,6 +2334,21 @@ void adapter_remove_device(DBusConnection *conn, struct adapter *adapter, adapter->devices = g_slist_remove(adapter->devices, device); } +struct device *adapter_get_device(DBusConnection *conn, + struct adapter *adapter, const gchar *address) +{ + struct device *device; + + if (!adapter) + return NULL; + + device = adapter_find_device(adapter, address); + if (device) + return device; + + return adapter_create_device(conn, adapter, address); +} + static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, struct adapter *adapter) { @@ -2495,7 +2518,8 @@ static DBusHandlerResult create_bonding(DBusConnection *conn, DBusMessage *msg, if (sk < 0) return error_connection_attempt_failed(conn, msg, 0); - adapter->bonding = bonding_request_new(conn, msg, adapter, address); + adapter->bonding = bonding_request_new(conn, msg, adapter, address, + agent_path); if (!adapter->bonding) { close(sk); return DBUS_HANDLER_RESULT_NEED_MEMORY; |