diff --git a/audio/gateway.c b/audio/gateway.c
index 45b25a1..9e96296 100644
--- a/audio/gateway.c
+++ b/audio/gateway.c
char *name; /* Bus id */
char *path; /* D-Bus path */
guint watch; /* Disconnect watch */
+ DBusPendingCall *call;
};
struct connect_cb {
if (!agent)
return;
+ if (agent->call)
+ dbus_pending_call_unref(agent->call);
+
g_free(agent->name);
g_free(agent->path);
g_free(agent);
}
}
+static void agent_cancel(struct hf_agent *agent)
+{
+ if (!agent->call)
+ return;
+
+ dbus_pending_call_cancel(agent->call);
+ dbus_pending_call_unref(agent->call);
+ agent->call = NULL;
+}
+
static void agent_disconnect(struct audio_device *dev, struct hf_agent *agent)
{
DBusMessage *msg;
"org.bluez.HandsfreeAgent", "Release");
g_dbus_send_message(btd_get_dbus_connection(), msg);
+
+ agent_cancel(agent);
}
static gboolean agent_sendfd(struct hf_agent *agent, int fd,
struct audio_device *dev = data;
struct gateway *gw = dev->gateway;
DBusMessage *msg;
- DBusPendingCall *call;
+
+ if (agent->call)
+ return FALSE;
msg = dbus_message_new_method_call(agent->name, agent->path,
"org.bluez.HandsfreeAgent", "NewConnection");
DBUS_TYPE_INVALID);
if (dbus_connection_send_with_reply(btd_get_dbus_connection(), msg,
- &call, -1) == FALSE) {
+ &agent->call, -1) == FALSE) {
dbus_message_unref(msg);
return FALSE;
}
- dbus_pending_call_set_notify(call, notify, dev, NULL);
- dbus_pending_call_unref(call);
+ dbus_pending_call_set_notify(agent->call, notify, dev, NULL);
dbus_message_unref(msg);
return TRUE;
{
struct audio_device *dev = data;
struct gateway *gw = dev->gateway;
+ struct hf_agent *agent = gw->agent;
DBusMessage *reply = dbus_pending_call_steal_reply(call);
DBusError derr;
- if (!dev->gateway->rfcomm) {
- DBG("RFCOMM disconnected from server before agent reply");
- goto done;
- }
+ dbus_pending_call_unref(agent->call);
+ agent->call = NULL;
dbus_error_init(&derr);
if (!dbus_set_error_from_message(&derr, reply)) {
gw->sco = NULL;
}
+ if (gw->agent)
+ agent_cancel(gw->agent);
+
change_state(device, GATEWAY_STATE_DISCONNECTED);
g_set_error(&gerr, GATEWAY_ERROR,
GATEWAY_ERROR_DISCONNECTED, "Disconnected");