summaryrefslogtreecommitdiffstats
path: root/src/handsfree-audio.c
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2013-02-20 18:55:51 -0300
committerDenis Kenzior <denkenz@gmail.com>2013-02-20 21:27:01 -0600
commit555a883ecb294e8eadbf984a848fee4e58b902ef (patch)
tree52383673854b063a705523090c21244a6700f9c7 /src/handsfree-audio.c
parent7a7bb7399a53fd109172655e43400a77c4ccb6b8 (diff)
downloadofono-555a883ecb294e8eadbf984a848fee4e58b902ef.tar.bz2
handsfree-audio: Add Agent tracking
This patch tracks when the Handsfree Audio Agent leaves the system BUS, and free agent allocated resources.
Diffstat (limited to 'src/handsfree-audio.c')
-rw-r--r--src/handsfree-audio.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 2635d76a..f10aeb4a 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -45,12 +45,16 @@ struct agent {
char *path;
unsigned char *codecs;
int codecs_len;
+ guint watch;
};
static struct agent *agent = NULL;
static void agent_free(struct agent *agent)
{
+ if (agent->watch > 0)
+ g_dbus_remove_watch(ofono_dbus_get_connection(), agent->watch);
+
g_free(agent->owner);
g_free(agent->path);
g_free(agent->codecs);
@@ -67,6 +71,14 @@ static void agent_release(struct agent *agent)
g_dbus_send_message(ofono_dbus_get_connection(), msg);
}
+static void agent_disconnect(DBusConnection *conn, void *user_data)
+{
+ DBG("Agent %s disconnected", agent->owner);
+
+ agent_free(agent);
+ agent = NULL;
+}
+
static DBusMessage *am_get_cards(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
@@ -109,6 +121,8 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
agent->path = g_strdup(path);
agent->codecs = g_memdup(codecs, length);
agent->codecs_len = length;
+ agent->watch = g_dbus_add_disconnect_watch(conn, sender,
+ agent_disconnect, NULL, NULL);
return dbus_message_new_method_return(msg);
}