handsfree-audio: Add Agent tracking

This patch tracks when the Handsfree Audio Agent leaves the system BUS,
and free agent allocated resources.
This commit is contained in:
Claudio Takahasi 2013-02-20 18:55:51 -03:00 committed by Denis Kenzior
parent 7a7bb7399a
commit 555a883ecb
1 changed files with 14 additions and 0 deletions

View File

@ -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);
}