summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hcid/agent.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/hcid/agent.c b/hcid/agent.c
index fca002c2..318a2ed3 100644
--- a/hcid/agent.c
+++ b/hcid/agent.c
@@ -84,8 +84,6 @@ struct agent_request {
static DBusConnection *connection = NULL;
-static void send_cancel_request(struct agent_request *req);
-
static void agent_release(struct agent *agent)
{
DBusMessage *message;
@@ -104,6 +102,31 @@ static void agent_release(struct agent *agent)
send_message_and_unref(connection, message);
}
+static void send_cancel_request(struct agent_request *req)
+{
+ DBusMessage *message;
+
+ message = dbus_message_new_method_call(req->agent->name, req->agent->path,
+ "org.bluez.Agent", "Cancel");
+ if (message == NULL) {
+ error("Couldn't allocate D-Bus message");
+ return;
+ }
+
+ dbus_message_set_no_reply(message, TRUE);
+
+ send_message_and_unref(connection, message);
+}
+
+static void agent_request_free(struct agent_request *req)
+{
+ if (req->call)
+ dbus_pending_call_unref(req->call);
+ if (req->agent && req->agent->request)
+ req->agent->request = NULL;
+ g_free(req);
+}
+
static void agent_free(struct agent *agent)
{
if (!agent)
@@ -112,6 +135,9 @@ static void agent_free(struct agent *agent)
if (agent->request) {
DBusError err;
+ if (agent->request->call)
+ dbus_pending_call_cancel(agent->request->call);
+
dbus_error_init(&err);
dbus_set_error_const(&err, "org.bluez.Error.Failed", "Canceled");
@@ -125,7 +151,10 @@ static void agent_free(struct agent *agent)
dbus_error_free(&err);
- send_cancel_request(agent->request);
+ if (!agent->exited)
+ send_cancel_request(agent->request);
+
+ agent_request_free(agent->request);
}
if (agent->timeout)
@@ -202,15 +231,6 @@ static struct agent_request *agent_request_new(struct agent *agent,
return req;
}
-static void agent_request_free(struct agent_request *req)
-{
- if (req->call)
- dbus_pending_call_unref(req->call);
- if (req->agent && req->agent->request)
- req->agent->request = NULL;
- g_free(req);
-}
-
int agent_cancel(struct agent *agent)
{
DBusMessage *message;
@@ -509,25 +529,6 @@ failed:
return -1;
}
-static void send_cancel_request(struct agent_request *req)
-{
- DBusMessage *message;
-
- message = dbus_message_new_method_call(req->agent->name, req->agent->path,
- "org.bluez.Agent", "Cancel");
- if (message == NULL) {
- error("Couldn't allocate D-Bus message");
- return;
- }
-
- dbus_message_set_no_reply(message, TRUE);
-
- send_message_and_unref(connection, message);
-
- dbus_pending_call_cancel(req->call);
- agent_request_free(req);
-}
-
gboolean agent_matches(struct agent *agent, const char *name, const char *path)
{
if (g_str_equal(agent->name, name) && g_str_equal(agent->path, path))