From 82c37ba9d5fb114aa5d0bde1e5ab4421fbd616c7 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 25 Sep 2012 15:35:33 +0300 Subject: [PATCH] core: Monitor external profile processes --- src/profile.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/profile.c b/src/profile.c index fa1b0a0c1..97379a99e 100644 --- a/src/profile.c +++ b/src/profile.c @@ -43,10 +43,13 @@ struct ext_profile { struct btd_profile p; + char *name; char *owner; char *uuid; char *path; + + guint id; }; static GSList *profiles = NULL; @@ -138,6 +141,15 @@ static void remove_ext(struct ext_profile *ext) g_free(ext); } +static void ext_exited(DBusConnection *conn, void *user_data) +{ + struct ext_profile *ext = user_data; + + DBG("External profile %s exited", ext->name); + + remove_ext(ext); +} + DBusMessage *btd_profile_reg_ext(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -167,6 +179,9 @@ DBusMessage *btd_profile_reg_ext(DBusConnection *conn, DBusMessage *msg, if (!ext) return btd_error_invalid_args(msg); + ext->id = g_dbus_add_disconnect_watch(conn, sender, ext_exited, ext, + NULL); + return dbus_message_new_method_return(msg); } @@ -186,6 +201,7 @@ DBusMessage *btd_profile_unreg_ext(DBusConnection *conn, DBusMessage *msg, if (!ext) return btd_error_does_not_exist(msg); + g_dbus_remove_watch(conn, ext->id); remove_ext(ext); return dbus_message_new_method_return(msg); @@ -195,14 +211,18 @@ void btd_profile_cleanup(void) { while (ext_profiles) { struct ext_profile *ext = ext_profiles->data; + DBusConnection *conn = btd_get_dbus_connection(); DBusMessage *msg; + DBG("Releasing %s", ext->name); + msg = dbus_message_new_method_call(ext->owner, ext->path, "org.bluez.Profile", "Release"); if (msg) - g_dbus_send_message(btd_get_dbus_connection(), msg); + g_dbus_send_message(conn, msg); + g_dbus_remove_watch(conn, ext->id); remove_ext(ext); } } -- 2.47.3