summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-06-06 08:41:06 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2008-06-06 08:41:06 +0000
commit081beca5ac609c6a90feef695c2df6a8f9144683 (patch)
tree65d59ae922e84400806c4a93820e0e291279e6c5
parent8c504bfaf8042b62dc2e3422321f73beef831b0a (diff)
Improve agent request cancelation
-rw-r--r--hcid/agent.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/hcid/agent.c b/hcid/agent.c
index c8236892..ed9976fe 100644
--- a/hcid/agent.c
+++ b/hcid/agent.c
@@ -90,6 +90,9 @@ static void agent_release(struct agent *agent)
debug("Releasing agent %s, %s", agent->name, agent->path);
+ if (agent->request)
+ agent_cancel(agent);
+
message = dbus_message_new_method_call(agent->name, agent->path,
"org.bluez.Agent", "Release");
if (message == NULL) {
@@ -102,7 +105,7 @@ static void agent_release(struct agent *agent)
send_message_and_unref(connection, message);
}
-static void send_cancel_request(struct agent_request *req)
+static int send_cancel_request(struct agent_request *req)
{
DBusMessage *message;
@@ -110,12 +113,14 @@ static void send_cancel_request(struct agent_request *req)
"org.bluez.Agent", "Cancel");
if (message == NULL) {
error("Couldn't allocate D-Bus message");
- return;
+ return -ENOMEM;
}
dbus_message_set_no_reply(message, TRUE);
send_message_and_unref(connection, message);
+
+ return 0;
}
static void agent_request_free(struct agent_request *req)
@@ -235,17 +240,17 @@ static struct agent_request *agent_request_new(struct agent *agent,
int agent_cancel(struct agent *agent)
{
- DBusMessage *message;
+ int ret;
- message = dbus_message_new_method_call(agent->name, agent->path,
- "org.bluez.Agent", "Cancel");
- if (!message) {
- error("Couldn't allocate D-Bus message");
- return -1;
- }
+ if (!agent->request)
+ return -EINVAL;
- dbus_message_set_no_reply(message, TRUE);
- send_message_and_unref(connection, message);
+ ret = send_cancel_request(agent->request);
+ if (ret < 0)
+ return ret;
+
+ agent_request_free(agent->request);
+ agent->request = NULL;
return 0;
}