summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-09-11 14:21:09 -0300
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-09-11 14:21:09 -0300
commit2f9fbeeb5931cda983aa72ed9a53b1f22d0aa85d (patch)
tree6d58eb569ea9a4ccff60f77b3791e06d55058780
parent78eadf19bbee1f52b738d39133296186b3e944fe (diff)
Fix problem that occurs when a device is removed but agent requests are not cancelled.
-rw-r--r--src/agent.c11
-rw-r--r--src/agent.h2
-rw-r--r--src/device.c5
3 files changed, 18 insertions, 0 deletions
diff --git a/src/agent.c b/src/agent.c
index 6b7c8d03..d514d191 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -780,6 +780,17 @@ gboolean agent_matches(struct agent *agent, const char *name, const char *path)
return FALSE;
}
+gboolean agent_is_busy(struct agent *agent, void *user_data)
+{
+ if (agent->request)
+ return FALSE;
+
+ if (user_data && user_data != agent->request->user_data)
+ return FALSE;
+
+ return TRUE;
+}
+
void agent_exit(void)
{
dbus_connection_unref(connection);
diff --git a/src/agent.h b/src/agent.h
index 3846d14e..b94c1ed1 100644
--- a/src/agent.h
+++ b/src/agent.h
@@ -62,6 +62,8 @@ int agent_display_passkey(struct agent *agent, struct btd_device *device,
int agent_cancel(struct agent *agent);
+gboolean agent_is_busy(struct agent *agent, void *user_data);
+
uint8_t agent_get_io_capability(struct agent *agent);
gboolean agent_matches(struct agent *agent, const char *name, const char *path);
diff --git a/src/device.c b/src/device.c
index 52fae4ed..5c8208de 100644
--- a/src/device.c
+++ b/src/device.c
@@ -111,10 +111,15 @@ static GSList *device_drivers = NULL;
static void device_free(gpointer user_data)
{
struct btd_device *device = user_data;
+ struct btd_adapter *adapter = device->adapter;
+ struct agent *agent = adapter_get_agent(adapter);
if (device->agent)
agent_destroy(device->agent, FALSE);
+ if (agent && agent_is_busy(agent, device))
+ agent_cancel(agent);
+
g_slist_foreach(device->uuids, (GFunc) g_free, NULL);
g_slist_free(device->uuids);